Mercurial > malikania
comparison cmake/function/MalikaniaDefineTest.cmake @ 183:387f6b0a5420
CMake: remove vera until we get clang-tidy, #903
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 19 Oct 2018 20:27:02 +0200 |
parents | 3107ce017c3a |
children | 74afc5a41c83 |
comparison
equal
deleted
inserted
replaced
182:3107ce017c3a | 183:387f6b0a5420 |
---|---|
19 # | 19 # |
20 # malikania_create_test | 20 # malikania_create_test |
21 # --------------------- | 21 # --------------------- |
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 | 27 # RESOURCES (Optional) Resources files to copy verbatim |
28 # FLAGS (Optional) Add list of compile definitions | 28 # FLAGS (Optional) Add list of compile definitions |
29 # ) | 29 # ) |
30 # | 30 # |
31 # This will generate a target named test-<name> where name is the parameter NAME. The test is created | 31 # This will generate a target named test-<name> where name is the parameter NAME. The test is created |
32 # under CMAKE_BINARY_DIR/test/<NAME> and resources are copied there with the same hierarchy. | 32 # under CMAKE_BINARY_DIR/test/<NAME> and resources are copied there with the same hierarchy. |
33 # | 33 # |
34 | 34 |
35 include(CMakeParseArguments) | 35 include(CMakeParseArguments) |
36 | 36 |
37 include(${CMAKE_CURRENT_LIST_DIR}/MalikaniaVeraCheck.cmake) | 37 function(malikania_create_test) |
38 set(singleArgs NAME) | |
39 set(multiArgs FLAGS LIBRARIES SOURCES RESOURCES) | |
38 | 40 |
39 function(malikania_create_test) | 41 cmake_parse_arguments(TEST "" "${singleArgs}" "${multiArgs}" ${ARGN}) |
40 set(singleArgs NAME) | |
41 set(multiArgs FLAGS LIBRARIES SOURCES RESOURCES) | |
42 | 42 |
43 cmake_parse_arguments(TEST "" "${singleArgs}" "${multiArgs}" ${ARGN}) | 43 if (NOT TEST_NAME) |
44 message(FATAL_ERROR "Missing NAME parameter") | |
45 endif () | |
46 if (NOT TEST_SOURCES) | |
47 message(FATAL_ERROR "Missing SOURCES parameter") | |
48 endif () | |
44 | 49 |
45 if (NOT TEST_NAME) | 50 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) |
46 message(FATAL_ERROR "Missing NAME parameter") | |
47 endif () | |
48 if (NOT TEST_SOURCES) | |
49 message(FATAL_ERROR "Missing SOURCES parameter") | |
50 endif () | |
51 | 51 |
52 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) | 52 if (UNIX) |
53 list(APPEND TEST_LIBRARIES pthread) | |
54 endif () | |
53 | 55 |
54 if (UNIX) | 56 # Resources files added before as custom output |
55 list(APPEND TEST_LIBRARIES pthread) | 57 foreach (f ${TEST_RESOURCES}) |
56 endif () | 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}) | |
57 | 61 |
58 # Resources files added before as custom output | 62 add_custom_command( |
59 foreach (f ${TEST_RESOURCES}) | 63 OUTPUT ${output} |
60 get_filename_component(absolute ${f} ABSOLUTE) | 64 COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} |
61 file(RELATIVE_PATH basename ${CMAKE_CURRENT_SOURCE_DIR} ${absolute}) | 65 DEPENDS ${absolute} |
62 set(output ${CMAKE_BINARY_DIR}/test/${TEST_NAME}/${basename}) | 66 ) |
63 | 67 |
64 add_custom_command( | 68 list(APPEND TEST_SOURCES ${absolute}) |
65 OUTPUT ${output} | 69 list(APPEND outputs ${output}) |
66 COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} | 70 endforeach () |
67 DEPENDS ${absolute} | |
68 ) | |
69 | 71 |
70 list(APPEND TEST_SOURCES ${absolute}) | 72 add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${outputs}) |
71 list(APPEND outputs ${output}) | 73 source_group(private\\Resources FILES ${outputs}) |
72 endforeach () | 74 target_compile_definitions( |
75 test-${TEST_NAME} | |
76 PRIVATE | |
77 BOOST_TEST_DYN_LINK | |
78 CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" | |
79 CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" | |
80 ${TEST_FLAGS} | |
81 ) | |
73 | 82 |
74 add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${outputs}) | 83 set_target_properties( |
75 source_group(private\\Resources FILES ${outputs}) | 84 test-${TEST_NAME} |
76 target_compile_definitions( | 85 PROPERTIES |
77 test-${TEST_NAME} | 86 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin |
78 PRIVATE | 87 ) |
79 BOOST_TEST_DYN_LINK | 88 foreach (c ${CMAKE_CONFIGURATION_TYPES}) |
80 CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" | 89 string(TOUPPER ${c} cu) |
81 CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" | 90 set_target_properties( |
82 ${TEST_FLAGS} | 91 test-${TEST_NAME} |
83 ) | 92 PROPERTIES |
93 RUNTIME_OUTPUT_DIRECTORY_${cu} ${CMAKE_BINARY_DIR}/bin/${c} | |
94 ) | |
95 endforeach () | |
96 add_test( | |
97 NAME ${TEST_NAME} | |
98 COMMAND $<TARGET_FILE:test-${TEST_NAME}> | |
99 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} | |
100 ) | |
84 | 101 |
85 set_target_properties( | 102 target_link_libraries( |
86 test-${TEST_NAME} | 103 test-${TEST_NAME} |
87 PROPERTIES | 104 ${TEST_LIBRARIES} |
88 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin | 105 Boost::boost |
89 ) | 106 Boost::unit_test_framework |
90 foreach (c ${CMAKE_CONFIGURATION_TYPES}) | 107 ) |
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( | |
99 NAME ${TEST_NAME} | |
100 COMMAND $<TARGET_FILE:test-${TEST_NAME}> | |
101 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} | |
102 ) | |
103 | |
104 target_link_libraries( | |
105 test-${TEST_NAME} | |
106 ${TEST_LIBRARIES} | |
107 Boost::boost | |
108 Boost::unit_test_framework | |
109 ) | |
110 | |
111 add_dependencies(tests test-${TEST_NAME}) | |
112 | |
113 malikania_vera_check(test-${TEST_NAME} "${TEST_SOURCES}") | |
114 endfunction() | 108 endfunction() |