Mercurial > malikania
comparison 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 |
comparison
equal
deleted
inserted
replaced
199:9ef01392a7f1 | 200:0a285d62ace7 |
---|---|
22 # | 22 # |
23 # malikania_create_test( | 23 # malikania_create_test( |
24 # NAME Test name (must be lowercase) | 24 # NAME Test name (must be lowercase) |
25 # SOURCES Test sources files | 25 # SOURCES Test sources files |
26 # LIBRARIES (Optional) Libraries to link to | 26 # LIBRARIES (Optional) Libraries to link to |
27 # RESOURCES (Optional) Resources files to copy verbatim | |
28 # FLAGS (Optional) Add list of compile definitions | 27 # FLAGS (Optional) Add list of compile definitions |
29 # ) | 28 # ) |
30 # | 29 # |
31 # This will generate a target named test-<name> where name is the parameter NAME. The test is created | 30 # This will generate a target named test-<name> where name is the parameter |
32 # under CMAKE_BINARY_DIR/test/<NAME> and resources are copied there with the same hierarchy. | 31 # NAME. |
32 # | |
33 # The variables CMAKE_SOURCE_DIR, CMAKE_BINARY_DIR, CMAKE_CURRENT_SOURCE_DIR | |
34 # and CMAKE_CURRENT_BINARY_DIR are automatically set. | |
33 # | 35 # |
34 | 36 |
35 include(CMakeParseArguments) | 37 include(CMakeParseArguments) |
36 | 38 |
37 function(malikania_create_test) | 39 function(malikania_create_test) |
45 endif () | 47 endif () |
46 if (NOT TEST_SOURCES) | 48 if (NOT TEST_SOURCES) |
47 message(FATAL_ERROR "Missing SOURCES parameter") | 49 message(FATAL_ERROR "Missing SOURCES parameter") |
48 endif () | 50 endif () |
49 | 51 |
50 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) | 52 add_executable(test-${TEST_NAME} ${TEST_SOURCES}) |
51 | |
52 if (UNIX) | |
53 list(APPEND TEST_LIBRARIES pthread) | |
54 endif () | |
55 | |
56 # Resources files added before as custom output | |
57 foreach (f ${TEST_RESOURCES}) | |
58 get_filename_component(absolute ${f} ABSOLUTE) | |
59 file(RELATIVE_PATH basename ${CMAKE_CURRENT_SOURCE_DIR} ${absolute}) | |
60 set(output ${CMAKE_BINARY_DIR}/test/${TEST_NAME}/${basename}) | |
61 | |
62 add_custom_command( | |
63 OUTPUT ${output} | |
64 COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} | |
65 DEPENDS ${absolute} | |
66 ) | |
67 | |
68 list(APPEND TEST_SOURCES ${absolute}) | |
69 list(APPEND outputs ${output}) | |
70 endforeach () | |
71 | |
72 add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${outputs}) | |
73 source_group(private\\Resources FILES ${outputs}) | |
74 target_compile_definitions( | 53 target_compile_definitions( |
75 test-${TEST_NAME} | 54 test-${TEST_NAME} |
76 PRIVATE | 55 PRIVATE |
77 BOOST_TEST_DYN_LINK | |
78 CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" | 56 CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" |
79 CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" | 57 CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" |
80 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}" | 58 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}" |
81 CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}" | 59 CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}" |
82 ${TEST_FLAGS} | 60 ${TEST_FLAGS} |
83 ) | 61 ) |
84 | 62 |
85 set_target_properties( | 63 set_target_properties(test-${TEST_NAME} PROPERTIES FOLDER "tests") |
86 test-${TEST_NAME} | 64 |
87 PROPERTIES | |
88 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin | |
89 ) | |
90 foreach (c ${CMAKE_CONFIGURATION_TYPES}) | |
91 string(TOUPPER ${c} cu) | |
92 set_target_properties( | |
93 test-${TEST_NAME} | |
94 PROPERTIES | |
95 RUNTIME_OUTPUT_DIRECTORY_${cu} ${CMAKE_BINARY_DIR}/bin/${c} | |
96 ) | |
97 endforeach () | |
98 add_test( | 65 add_test( |
99 NAME ${TEST_NAME} | 66 NAME ${TEST_NAME} |
100 COMMAND $<TARGET_FILE:test-${TEST_NAME}> | 67 COMMAND $<TARGET_FILE:test-${TEST_NAME}> |
101 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} | 68 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} |
102 ) | 69 ) |
103 | 70 |
104 target_link_libraries( | 71 target_link_libraries( |
105 test-${TEST_NAME} | 72 test-${TEST_NAME} |
106 ${TEST_LIBRARIES} | 73 ${TEST_LIBRARIES} |
107 Boost::boost | 74 Boost::boost |
75 Boost::dynamic_linking | |
76 Boost::disable_autolinking | |
108 Boost::unit_test_framework | 77 Boost::unit_test_framework |
109 ) | 78 ) |
110 endfunction() | 79 endfunction() |