cmake_minimum_required ( VERSION 3.17 )

FOREACH (policy CMP0054 CMP0057 CMP0042 CMP0074 CMP0110)
	IF (POLICY ${policy})
		CMAKE_POLICY ( SET ${policy} NEW )
	ENDIF ()
ENDFOREACH ()

message ( STATUS "Inside directory src..." )

#set (CMAKE_DEBUG_TARGET_PROPERTIES
#		INCLUDE_DIRECTORIES
#		COMPILE_DEFINITIONS
#		LINK_LIBRARIES
#		POSITION_INDEPENDENT_CODE
#		CONTAINER_SIZE_REQUIRED
#		LIB_VERSION
#		)

# columnar and secondary modules
include ( GetColumnar )
target_link_libraries ( lextra INTERFACE columnar::columnar_api columnar::secondary_api columnar::knn_api )

target_include_directories ( lextra INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} )
get_banner ( CONFIGURE_FLAGS )
infomsg ( "${CONFIGURE_FLAGS}" )

infomsg ( "Generating config files..." )
configure_file ( "${MANTICORE_SOURCE_DIR}/config/config_cmake.h.in"
		"${MANTICORE_BINARY_DIR}/config/config_.h" ESCAPE_QUOTES )
configure_file ( "${MANTICORE_SOURCE_DIR}/config/config_indexer_cmake.h.in"
		"${MANTICORE_BINARY_DIR}/config/config_indexer_.h" ESCAPE_QUOTES )

# avoid config rebuild if configuration produces the same file
execute_process ( COMMAND ${CMAKE_COMMAND} -E copy_if_different "${MANTICORE_BINARY_DIR}/config/config_.h" "${MANTICORE_BINARY_DIR}/config/config.h" )
execute_process ( COMMAND ${CMAKE_COMMAND} -E copy_if_different "${MANTICORE_BINARY_DIR}/config/config_indexer_.h" "${MANTICORE_BINARY_DIR}/config/config_indexer.h" )

add_library ( generated_config INTERFACE )
target_include_directories ( generated_config INTERFACE "${MANTICORE_BINARY_DIR}/config" )
target_link_libraries ( lextra INTERFACE generated_config )

add_library ( lmanticore_coro OBJECT coroutine.cpp coro_stack.cpp task_dispatcher.cpp coroutine.h coro_stack.h coro_waker.h task_dispatcher.h )
target_link_libraries ( lmanticore_coro PRIVATE lextra )

add_library ( conversion OBJECT conversion.cpp )
target_link_libraries ( conversion PRIVATE lextra )

add_subdirectory ( std )
add_subdirectory ( stripper )
add_subdirectory ( tokenizer )
add_subdirectory ( schema )
add_subdirectory ( dict )
add_subdirectory ( sphinxquery )
add_subdirectory ( indexing_sources )

# main bunch of sources (for libsphinx)
add_library ( lmanticore STATIC sphinx.cpp sphinxutils.cpp
		sphinxsort.cpp sortsetup.cpp sphinxexpr.cpp sphinxfilter.cpp sphinxsearch.cpp sphinxrt.cpp accumulator.cpp uuid_docid.cpp
		sphinxjson.cpp sphinxaot.cpp sphinxplugin.cpp sphinxudf.c sphinxqcache.cpp 
		attribute.cpp secondaryindex.cpp killlist.cpp searchnode.cpp json/cJSON_test.c sphinxpq.cpp
		global_idf.cpp docstore.cpp lz4/lz4.c lz4/lz4hc.c snippetfunctor.cpp snippetindex.cpp
		snippetstream.cpp snippetpassage.cpp threadutils.cpp sphinxversion.cpp datareader.cpp
		indexformat.cpp indexsettings.cpp fileutils.cpp threads_detached.cpp hazard_pointer.cpp
		task_info.cpp mini_timer.cpp fileio.cpp memio.cpp queryprofile.cpp columnarfilter.cpp columnargrouper.cpp
		columnarlib.cpp collation.cpp histogram.cpp
		timeout_queue.cpp columnarrt.cpp columnarmisc.cpp exprtraits.cpp columnarexpr.cpp
		sphinx_alter.cpp columnarsort.cpp binlog.cpp chunksearchctx.cpp client_task_info.cpp
		indexfiles.cpp indexfilebase.cpp attrindex_builder.cpp queryfilter.cpp aggregate.cpp secondarylib.cpp costestimate.cpp
		docidlookup.cpp tracer.cpp attrindex_merge.cpp distinct.cpp hyperloglog.cpp pseudosharding.cpp geodist.cpp
		datetime.cpp grouper.cpp exprdatetime.cpp detail/indexlink.cpp knnmisc.cpp knnlib.cpp libutils.cpp
		aggrexpr.cpp joinsorter.cpp queuecreator.cpp exprgeodist.cpp exprremap.cpp exprdocstore.cpp schematransform.cpp
		attr_embedding.cpp embeddingutils.cpp hybridexecutor.cpp
		sortergroup.cpp sortertraits.cpp sorterprecalc.cpp querycontext.cpp skip_cache.cpp jsonsi.cpp sorterscroll.cpp )

if (WIN32)
target_link_libraries ( lmanticore PRIVATE dbghelp AdvAPI32 ShLwApi )
endif()

include ( GetRBitmap )
add_library ( indexcheck OBJECT indexcheck.cpp indexcheck.h )
target_link_libraries ( indexcheck PRIVATE lextra roaring::roaring )
target_link_libraries ( lmanticore PUBLIC indexcheck )

target_link_libraries ( lmanticore PUBLIC lextra indexcheck conversion manticore_std stripper tokenizer
		schema dict sphinxquery sourcedoc lmanticore_coro )

if (WITH_ICU OR WITH_JIEBA)
	add_library ( lcjk cjkpreprocessor.cpp )
	target_link_libraries ( lcjk PUBLIC lextra )

	if (WITH_ICU)
		add_library ( lmanticore_icu icu.cpp )
		target_link_libraries ( lmanticore_icu PRIVATE icu::icu lcjk )
		target_link_libraries ( lmanticore PUBLIC lmanticore_icu )
	endif ()

	if (WITH_JIEBA)
		add_library ( lmanticore_jieba jieba.cpp jieba.h )
		target_link_libraries ( lmanticore_jieba PRIVATE jieba::jieba lcjk )
		target_link_libraries ( lmanticore PUBLIC lmanticore_jieba )
	endif ()
endif ()

if (WITH_STEMMER)
	target_link_libraries ( lmanticore PRIVATE stemmer::stemmer )
endif ()
if (WITH_RE2)
	target_link_libraries ( lmanticore PRIVATE re2::re2 )
endif ()

if (WIN32)
	if (NOT CMAKE_CROSSCOMPILING)
		target_compile_options ( lmanticore PRIVATE /bigobj )
	endif ()
endif ()
if (NOT WIN32)
	add_lib_for ( shm_open rt lmanticore )
endif ()

# Boost is required dependency now
set ( Boost_USE_MULTITHREADED ON )
set ( Boost_USE_STATIC_LIBS ON )
# todo: as alternative we can try to recompile boost with clang, but precompiled also quite ok
if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL Windows)
	set ( Boost_COMPILER vc142 )
endif ()
# ver 1.64 for process; filesystem need for process; ver 1.71 for limit_handles
find_package ( Boost 1.71.0 REQUIRED COMPONENTS context filesystem  )
target_link_libraries ( lextra INTERFACE Boost::boost Boost::context )

# Fixme! That is temporary solution - as we just use some headers of Boost::fiber, and that is available by default.
# If we link with the lib, we should find_package for component fiber, and then link with it. *NOT* that is not necessary.
# But Windows implicitly links with boost::fibers even if we just include some of that headers. That is why BOOST_ALL_NO_LIB
# is poisoned into lextra interface - to avoid such behavior.
# (we don't link with fiber since our custom build dockers doesn't include it, and they need to be rebuilt before)
target_compile_definitions ( lextra INTERFACE BOOST_ALL_NO_LIB=1 )

# The headers is not neccessary for executable build, but nesessary for MSVC and other projects
# all the (non-generated) headers
# So if you add headers to the project and NOT see them in visual studio solution - just list them here!
set ( HEADERS sphinxfilter.h sphinxint.h sphinxpq.h sphinxrt.h
		sphinxsort.h sphinxutils.h sphinxexpr.h sphinx.h sphinxjson.h sphinxplugin.h sphinxqcache.h
		sphinxsearch.h sphinxstd.h sphinxudf.h lz4/lz4.h lz4/lz4hc.h http/http_parser.h secondaryindex.h
		searchnode.h killlist.h attribute.h accumulator.h uuid_docid.h global_idf.h event.h threadutils.h threadutils_impl.h
		hazard_pointer.h task_info.h mini_timer.h collation.h histogram.h sortsetup.h
		indexsettings.h columnarlib.h fileio.h memio.h memio_impl.h queryprofile.h columnarfilter.h columnargrouper.h fileutils.h
		libutils.h conversion.h columnarsort.h sortcomp.h binlog_defs.h binlog.h ${MANTICORE_BINARY_DIR}/config/config.h
		chunksearchctx.h indexfilebase.h indexfiles.h attrindex_builder.h queryfilter.h aggregate.h secondarylib.h
		costestimate.h docidlookup.h tracer.h attrindex_merge.h columnarmisc.h distinct.h hyperloglog.h pseudosharding.h datetime.h
		grouper.h exprdatetime.h geodist.h detail/indexlink.h detail/expmeter.h knnmisc.h knnlib.h match_impl.h std/string_impl.h
		aggrexpr.h joinsorter.h queuecreator.h exprgeodist.h exprremap.h exprdocstore.h schematransform.h attr_embedding.h embeddingutils.h hybridexecutor.h sortergroup.h
		sortertraits.h sorterprecalc.h querycontext.h skip_cache.h jsonsi.h jieba.h cjkpreprocessor.h sorterscroll.h )

set ( SEARCHD_H searchdaemon.h searchdconfig.h searchdddl.h searchdexpr.h searchdha.h searchdreplication.h searchdsql.h
		searchdtask.h client_task_info.h taskflushattrs.h taskflushbinlog.h taskflushmutable.h taskglobalidf.h
		taskmalloctrim.h taskping.h taskpreread.h tasksavestate.h net_action_accept.h
		netreceive_api.h netreceive_http.h netreceive_ql.h networking_daemon.h query_status.h
		compressed_zlib_mysql.h sphinxql_debug.h stackmock.h searchdssl.h digest_sha1.h
		client_session.h compressed_zstd_mysql.h docs_collector.h index_rotator.h config_reloader.h searchdhttp.h timeout_queue.h
		netpoll.h pollable_event.h netfetch.h searchdbuddy.h sphinxql_second.h sphinxql_extra.h sphinxjsonquery.h
		frontendschema.h debug_cmds.h dynamic_idx.h sphinxexcerpt.h querystats.h
		searchd_shard.h
		facetutils.h
		auth/auth.h auth/auth_common.h auth/auth_proto_http.h auth/auth_proto_mysql.h auth/auth_proto_api.h digest_sha256.h auth/auth_perms.h auth/gcm_nonce.h auth/auth_log.h )


# add the extra targets in the case we want on-the-fly grammar compiler
include (mybison)

MY_BISON ( ExprParser sphinxexpr sphinxexpr.cpp LMANTICORE )
MY_BISON ( SelectParser sphinxselect sphinx.cpp LMANTICORE )
MY_BISON ( JsonParser sphinxjson sphinxjson.cpp LMANTICORE )
MY_BISON ( SQLParser sphinxql searchdsql.cpp SEARCHD )
MY_BISON ( DDLParser ddl searchdddl.cpp SEARCHD )
MY_BISON ( SQLDebugParser sphinxql_debug sphinxql_debug.cpp SEARCHD )
MY_BISON ( SQLSecondParser sphinxql_second sphinxql_second.cpp SEARCHD )
MY_BISON ( SQLExtraParser sphinxql_extra sphinxql_extra.cpp SEARCHD )
source_group ( "Grammar sources" FILES ${LMANTICORE_BISON} ${SEARCHD_BISON} )

# add the extra targets in the case we want on-the-fly lex compiler
MY_FLEX ( Jsonlex sphinxjson sphinxjson.cpp LMANTICORE )
MY_FLEX ( Exprlex sphinxexpr sphinxexpr.cpp LMANTICORE )
MY_FLEX ( SQLlex sphinxql searchdsql.cpp SEARCHD )
MY_FLEX ( DDLlex ddl searchdddl.cpp SEARCHD )
MY_FLEX ( SQLDebuglex sphinxql_debug sphinxql_debug.cpp SEARCHD )
MY_FLEX ( SQLSecondlex sphinxql_second sphinxql_second.cpp SEARCHD )
MY_FLEX ( SQLExtralex sphinxql_extra sphinxql_extra.cpp SEARCHD )
source_group ( "Lexer sources" FILES ${LMANTICORE_FLEX} ${SEARCHD_FLEX} )

diag ( LMANTICORE_BISON SEARCHD_BISON LMANTICORE_FLEX SEARCHD_FLEX )

# our mega-lib
target_sources ( lmanticore PUBLIC ${LMANTICORE_BISON} ${LMANTICORE_FLEX} ${HEADERS} ${CHARSET_FILES} ${CHARSET_TEMPLATE} "../misc/manticore.natvis" )
target_link_libraries ( lmanticore PUBLIC uni-algo::uni-algo )

add_library ( lsearchd OBJECT searchdha.cpp http/http_parser.c searchdhttp.cpp
		searchdtask.cpp taskping.cpp taskmalloctrim.cpp taskglobalidf.cpp tasksavestate.cpp
		taskflushbinlog.cpp taskflushattrs.cpp taskflushmutable.cpp taskpreread.cpp
		searchdaemon.cpp searchdfields.cpp searchdconfig.cpp
		searchdsql.cpp searchdddl.cpp networking_daemon.cpp
		net_action_accept.cpp netreceive_api.cpp
		netreceive_http.cpp netreceive_ql.cpp query_status.cpp
		sphinxql_debug.cpp sphinxql_second.cpp stackmock.cpp docs_collector.cpp index_rotator.cpp config_reloader.cpp netpoll.cpp
		pollable_event.cpp netfetch.cpp searchdbuddy.cpp searchdhttpcompat.cpp sphinxql_extra.cpp searchdreplication.cpp sphinxjsonquery.cpp
		frontendschema.cpp compressed_http.cpp debug_cmds.cpp jsonqueryfilter.cpp dynamic_idx.cpp sphinxexcerpt.cpp searchdexpr.cpp querystats.cpp
		searchd_shard.cpp
		facetutils.cpp
		auth/auth.cpp auth/auth_common.cpp auth/auth_proto_http.cpp auth/auth_proto_mysql.cpp auth/auth_proto_api.cpp auth/auth_perms.cpp auth/gcm_nonce.cpp auth/auth_log.cpp auth/auth_bootstrap.cpp)
		
target_sources ( lsearchd PUBLIC ${SEARCHD_SRCS_TESTABLE} ${SEARCHD_H} ${SEARCHD_BISON} ${SEARCHD_FLEX} )
add_library ( digest_sha1 digest_sha1.cpp )
add_library ( digest_sha256 digest_sha256.cpp )
target_link_libraries ( digest_sha1 PRIVATE lextra )
target_link_libraries ( digest_sha256 PRIVATE lextra )
add_subdirectory ( sqlchecks )
target_link_libraries ( lsearchd PUBLIC sqlchecks digest_sha1 digest_sha256 lextra nlohmann_json::nlohmann_json )
target_link_libraries ( lsearchd INTERFACE Boost::filesystem )
if (WIN32)
target_link_libraries ( lsearchd PRIVATE iphlpapi WS2_32 wsock32 )
endif()

if (WITH_ZLIB OR WITH_ZSTD)
	target_sources ( lsearchd PRIVATE compressed_mysql_layer.cpp compressed_mysql_layer.h )
	if (WITH_ZLIB)
		target_sources ( lsearchd PRIVATE compressed_zlib_mysql.cpp )
		target_link_libraries ( lsearchd PRIVATE ZLIB::ZLIB )
	endif ()

	if (WITH_ZSTD)
		target_sources ( lsearchd PRIVATE compressed_zstd_mysql.cpp )
		if (DL_ZSTD)
			target_link_libraries ( lsearchd PRIVATE ZSTD::ZSTD_ld )
		else ()
			target_link_libraries ( lsearchd PRIVATE ZSTD::ZSTD )
		endif ()
	endif ()
endif ()

if (WITH_CURL)
	if (DL_CURL)
		target_link_libraries ( lsearchd PRIVATE CURL::libcurl_ld )
	else ()
		target_link_libraries ( lsearchd PRIVATE CURL::libcurl )
	endif ()
endif ()

add_subdirectory ( perfetto )
if (TARGET perfetto)
	target_link_libraries ( lextra INTERFACE perfetto )
endif()

# stub library for all except daemon - to avoid link with openssl
add_library ( stub_ssl searchdssl_stub.cpp )
target_link_libraries ( stub_ssl PRIVATE lextra )

# support for ssl. Actual only for physical daemon
add_library ( searchd_ssl searchdssl.cpp )
target_link_libraries ( searchd_ssl PUBLIC lextra )
if (WITH_SSL)
	target_link_libraries ( searchd_ssl PRIVATE OpenSSL::SSL )
	target_link_libraries ( searchd_ssl PRIVATE OpenSSL::Crypto )
	target_link_libraries ( digest_sha1 PRIVATE OpenSSL::SSL )
	target_link_libraries ( digest_sha1 PRIVATE OpenSSL::Crypto )
	target_link_libraries ( digest_sha256 PRIVATE OpenSSL::SSL )
	target_link_libraries ( digest_sha256 PRIVATE OpenSSL::Crypto )
	if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
		target_link_options ( searchd_ssl INTERFACE $<${ONLYGNUCLANGC_CXX}:-Wl,--exclude-libs,libssl.a,--exclude-libs,libcrypto.a> )
		target_link_options ( digest_sha1 INTERFACE $<${ONLYGNUCLANGC_CXX}:-Wl,--exclude-libs,libssl.a,--exclude-libs,libcrypto.a> )
		target_link_options ( digest_sha256 INTERFACE $<${ONLYGNUCLANGC_CXX}:-Wl,--exclude-libs,libssl.a,--exclude-libs,libcrypto.a> )
	endif()
	target_compile_options ( searchd_ssl PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-deprecated-declarations>" )
	if (WIN32 AND TARGET OpenSSL::applink)
		target_link_libraries ( searchd_ssl PRIVATE OpenSSL::applink )
		target_compile_options ( OpenSSL::applink INTERFACE $<${CLANGWIN}:-Wno-pedantic -Wno-missing-prototypes> )
	endif ()
endif (WITH_SSL)

# support for replication
add_subdirectory ( replication )
target_link_libraries ( lsearchd PUBLIC repli_stuff)

trace ( lextra )
trace ( lsearchd )

add_subdirectory ( daemon )

# our executables
add_executable ( searchd searchd.cpp )
target_link_libraries ( searchd daemon searchd_ssl lmanticore lsearchd )

if (NOT STATIC_BINARY)
	add_executable ( indexer indexer.cpp )
	add_executable ( indextool indextool.cpp )
	add_executable ( spelldump spelldump.cpp )
	add_executable ( wordbreaker wordbreaker.cpp )
	add_executable ( index_converter index_converter.cpp )
	target_link_libraries ( indexer indexer_sources lmanticore )
	target_link_libraries ( indextool lmanticore )
	target_link_libraries ( spelldump lmanticore )
	target_link_libraries ( wordbreaker lmanticore )
	target_link_libraries ( index_converter lmanticore )
	add_library ( udfexample MODULE udfexample.c )
	target_compile_options ( udfexample PRIVATE "$<${CLANGWIN}:-Wno-deprecated-declarations>" )
endif ()

if (SPLIT_SYMBOLS)
	include ( split )
	split_dbg ( indexer )
	split_dbg ( indextool )
	split_dbg ( searchd )
	split_dbg ( spelldump )
	split_dbg ( wordbreaker )
	split_dbg ( index_converter )
endif ()

# These targets remain in their split components, but bundle builds stage the
# same payload into the bundle component too via install_component_and_bundle().
install_component_and_bundle ( searchd TARGETS searchd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
if (NOT STATIC_BINARY)
	install_component_and_bundle ( tools TARGETS indexer indextool spelldump wordbreaker RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
	install_component_and_bundle ( converter TARGETS index_converter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
	install_component_and_bundle ( devel FILES sphinxudf.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manticore )
endif ()

# install windows runtime libraries - for final targets, and also for immediate testing
if (WIN32)
	set ( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE )
	include ( InstallRequiredSystemLibraries )
	addruntime ( "${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}" common )
	getruntime ( libs common )
	# Windows bundle archives need the same redistributables as the split packages.
	install_component_and_bundle ( common PROGRAMS ${libs} DESTINATION bin )
	unset ( libs )
	getruntime ( libs daemon )
	install_component_and_bundle ( searchd PROGRAMS ${libs} DESTINATION bin )
	unset ( libs )
	getruntime ( libs indexer )
	install_component_and_bundle ( tools PROGRAMS ${libs} DESTINATION bin )
	if (BUILD_TESTING)
#		getruntime ( libs indexer ) # is just set above
		getruntime ( libs common )
		getruntime ( libs daemon )
		add_custom_command ( TARGET searchd POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${libs} "$<TARGET_FILE_DIR:searchd>" VERBATIM )
	endif ()
endif ()

# ---------------------------- benching stuff ----------------------------
set ( WITH_BENCHES OFF CACHE BOOL "Build development benches" )
if (WITH_BENCHES)
	add_subdirectory ( gbenches )
	add_feature_info ( benches WITH_BENCHES "development benchmarks" )
endif ()

if (NOT BUILD_TESTING)
	return ()
endif ()

# ---------------------------- Below is pure testing stuff ----------------------------

if (CMAKE_VERSION VERSION_GREATER 3.1.0 AND NOT DISABLE_GTESTS AND NOT TEST_SPECIAL_EXTERNAL)
	add_subdirectory ( gtests )
endif ()

add_executable ( tests EXCLUDE_FROM_ALL tests.cpp )
target_link_libraries ( tests PUBLIC lmanticore )

if (WITH_MYSQL)
	# compile rtestconfig.h
	hsnippet ( rtestconfig testrt.conf )

	set ( DATAFLD "${MANTICORE_BINARY_DIR}/test/data" )
	file ( MAKE_DIRECTORY ${DATAFLD} )
	source_group ( "Testing config" FILES testrt.conf.in )
	add_executable ( testrt testrt.cpp ${MANTICORE_BINARY_DIR}/config/rtestconfig.h )
	target_compile_definitions ( testrt PRIVATE "DATAFLD=\"${DATAFLD}/\"" )
	target_link_libraries ( testrt PRIVATE source_mysql PUBLIC lmanticore $<$<PLATFORM_ID:Windows>:psapi> )
	if (HAVE_RTESTCONFIG_H)
		target_compile_definitions ( testrt PRIVATE "-DHAVE_RTESTCONFIG_H" )
	endif ()

	# testrt is alive, however it needs database 'lj' accessible
	# in order to work. So, avoid it's calling till the base is persist
	# in out CI env
	if (0)

		add_test ( NAME "\"Remove dump index\""
				COMMAND ${CMAKE_COMMAND} -E remove "${DATAFLD}/dump.*" )
		SET_TESTS_PROPERTIES ( "\"Remove dump index\"" PROPERTIES FIXTURES_SETUP TESTRT )

		add_test ( NAME "\"Internal rt src/testrt\""
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
				COMMAND testrt )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt\"" PROPERTIES FIXTURES_REQUIRED TESTRT )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt\"" PROPERTIES RESOURCE_LOCK DbAccess )

		add_test ( NAME "\"Internal rt src/testrt step 1000\""
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
				COMMAND testrt 1000 )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 1000\"" PROPERTIES FIXTURES_REQUIRED TESTRT )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 1000\"" PROPERTIES RESOURCE_LOCK DbAccess )

		add_test ( NAME "\"Internal rt src/testrt step 100\""
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
				COMMAND testrt 100 )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 100\"" PROPERTIES FIXTURES_REQUIRED TESTRT )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 1000\"" PROPERTIES RESOURCE_LOCK DbAccess )

		add_test ( NAME "\"Internal rt src/testrt step 10\""
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
				COMMAND testrt 10 )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 10\"" PROPERTIES FIXTURES_REQUIRED TESTRT )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 1000\"" PROPERTIES RESOURCE_LOCK DbAccess )

		add_test ( NAME "\"Internal rt src/testrt step 1\""
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
				COMMAND testrt 1 )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 1\"" PROPERTIES FIXTURES_REQUIRED TESTRT )
		SET_TESTS_PROPERTIES ( "\"Internal rt src/testrt step 1000\"" PROPERTIES RESOURCE_LOCK DbAccess )

	endif (0)
endif (WITH_MYSQL)

if (NOT TEST_SPECIAL_EXTERNAL)

	# since cmake 3.18 names need fixup
	include ( fixup_test_name )

	# first check syntax
	if (NOT WIN32)
		find_package ( PythonInterp QUIET )
		if (PYTHONINTERP_FOUND AND NOT DISABLE_GTESTS)
			fixup_test_name ( RESERVED_TEST "SphinxQL reserved keywords consistency" )
			message ( STATUS "python binary is ${PYTHON_EXECUTABLE}" ) # !COMMIT
			add_test ( NAME ${RESERVED_TEST}
					WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
					COMMAND ${PYTHON_EXECUTABLE} reserved.py )
			SET_TESTS_PROPERTIES ( ${RESERVED_TEST} PROPERTIES LABELS LINTER )
		endif ()
	endif ()

#	fixup_test_name ( tst "Internal src/tests" )
#	add_test ( NAME ${tst} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMAND "tests" )
endif ()

add_subdirectory ( fuzzer )
