set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)

if(Boost_FOUND)
	include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS})
	link_directories(${CMAKE_BINARY_DIR}/lib ${Boost_LIBRARY_DIRS})
	file(GLOB headers *.h)
	add_custom_target(tests DEPENDS tests)
	set(test_list odbc sqlite mysql)
	foreach(test_item ${test_list})
		set(test_name ${test_item}_tests)
		add_executable(${test_name} ${test_item}_test.cpp main.cpp ${headers})
		if (NANODBC_STATIC)
			target_link_libraries(${test_name} nanodbc ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
		else()
			target_link_libraries(${test_name} nanodbc ${Boost_LIBRARIES})
		endif()
		add_test(NAME ${test_name} COMMAND ${test_name})
		add_custom_target(${test_item}_test
			COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name})
		add_custom_target(${test_item}_check
			COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name}
			DEPENDS ${test_name})
		# add ${test_name} to the tests group
		add_dependencies(tests ${test_name})
	endforeach()
else()
	message(FATAL_ERROR "can not find boost")
endif()
