diff cmake/function/MalikaniaDefineTest.cmake @ 200:0a285d62ace7

windows: initial VS2017 support While here, do some cleanup in CMake files for a better hierarchy.
author David Demelier <markand@malikania.fr>
date Wed, 28 Nov 2018 22:01:55 +0100
parents 74afc5a41c83
children c973501abe36
line wrap: on
line diff
--- a/cmake/function/MalikaniaDefineTest.cmake	Tue Oct 30 13:21:55 2018 +0100
+++ b/cmake/function/MalikaniaDefineTest.cmake	Wed Nov 28 22:01:55 2018 +0100
@@ -24,12 +24,14 @@
 #       NAME            Test name (must be lowercase)
 #       SOURCES         Test sources files
 #       LIBRARIES       (Optional) Libraries to link to
-#       RESOURCES       (Optional) Resources files to copy verbatim
 #       FLAGS           (Optional) Add list of compile definitions
 # )
 #
-# This will generate a target named test-<name> where name is the parameter NAME. The test is created
-# under CMAKE_BINARY_DIR/test/<NAME> and resources are copied there with the same hierarchy.
+# This will generate a target named test-<name> where name is the parameter
+# NAME.
+#
+# The variables CMAKE_SOURCE_DIR, CMAKE_BINARY_DIR, CMAKE_CURRENT_SOURCE_DIR
+# and CMAKE_CURRENT_BINARY_DIR are automatically set.
 #
 
 include(CMakeParseArguments)
@@ -47,34 +49,10 @@
 		message(FATAL_ERROR "Missing SOURCES parameter")
 	endif ()
 
-	file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME})
-
-	if (UNIX)
-		list(APPEND TEST_LIBRARIES pthread)
-	endif ()
-
-	# Resources files added before as custom output
-	foreach (f ${TEST_RESOURCES})
-		get_filename_component(absolute ${f} ABSOLUTE)
-		file(RELATIVE_PATH basename ${CMAKE_CURRENT_SOURCE_DIR} ${absolute})
-		set(output ${CMAKE_BINARY_DIR}/test/${TEST_NAME}/${basename})
-
-		add_custom_command(
-			OUTPUT ${output}
-			COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output}
-			DEPENDS ${absolute}
-		)
-
-		list(APPEND TEST_SOURCES ${absolute})
-		list(APPEND outputs ${output})
-	endforeach ()
-
-	add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${outputs})
-	source_group(private\\Resources FILES ${outputs})
+	add_executable(test-${TEST_NAME} ${TEST_SOURCES})
 	target_compile_definitions(
 		test-${TEST_NAME}
 		PRIVATE
-			BOOST_TEST_DYN_LINK
 			CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}"
 			CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
 			CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"
@@ -82,19 +60,8 @@
 			${TEST_FLAGS}
 	)
 
-	set_target_properties(
-		test-${TEST_NAME}
-		PROPERTIES
-			RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
-	)
-	foreach (c ${CMAKE_CONFIGURATION_TYPES})
-		string(TOUPPER ${c} cu)
-		set_target_properties(
-			test-${TEST_NAME}
-			PROPERTIES
-				RUNTIME_OUTPUT_DIRECTORY_${cu} ${CMAKE_BINARY_DIR}/bin/${c}
-		)
-	endforeach ()
+	set_target_properties(test-${TEST_NAME} PROPERTIES FOLDER "tests")
+
 	add_test(
 		NAME ${TEST_NAME}
 		COMMAND $<TARGET_FILE:test-${TEST_NAME}>
@@ -105,6 +72,8 @@
 		test-${TEST_NAME}
 		${TEST_LIBRARIES}
 		Boost::boost
+		Boost::dynamic_linking
+		Boost::disable_autolinking
 		Boost::unit_test_framework
 	)
 endfunction()