Mercurial > irccd
comparison cmake/function/IrccdDefineTest.cmake @ 0:1158cffe5a5e
Initial import
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 08 Feb 2016 16:43:14 +0100 |
parents | |
children | ff26bd33a45d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1158cffe5a5e |
---|---|
1 # | |
2 # IrccdDefineTest.cmake -- CMake build system for irccd | |
3 # | |
4 # Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> | |
5 # | |
6 # Permission to use, copy, modify, and/or distribute this software for any | |
7 # purpose with or without fee is hereby granted, provided that the above | |
8 # copyright notice and this permission notice appear in all copies. | |
9 # | |
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 # | |
18 | |
19 # | |
20 # irccd_define_test | |
21 # ------------------------------------------------------------------- | |
22 # | |
23 # irccd_define_test( | |
24 # NAME the test name | |
25 # SOURCES the sources files | |
26 # LIBRARIES (Optional) libraries to link | |
27 # RESOURCES (Optional) some resources file to copy | |
28 # ) | |
29 # | |
30 # Create a unit test named test-${NAME} | |
31 # | |
32 # Resources files are copied VERBATIM into the same directory. | |
33 # | |
34 | |
35 function(irccd_define_test) | |
36 set(oneValueArgs NAME) | |
37 set(multiValueArgs SOURCES LIBRARIES RESOURCES) | |
38 | |
39 cmake_parse_arguments(TEST "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | |
40 | |
41 if (NOT TEST_NAME) | |
42 message(FATAL_ERROR "Please set NAME") | |
43 endif () | |
44 if (NOT TEST_SOURCES) | |
45 message(FATAL_ERROR "Please set SOURCES") | |
46 endif () | |
47 | |
48 foreach (r ${TEST_RESOURCES}) | |
49 file(RELATIVE_PATH output ${CMAKE_CURRENT_SOURCE_DIR} ${r}) | |
50 | |
51 add_custom_command( | |
52 OUTPUT ${CMAKE_BINARY_DIR}/tests/${output} | |
53 COMMAND ${CMAKE_COMMAND} -E copy ${r} ${CMAKE_BINARY_DIR}/tests/${output} | |
54 DEPENDS ${r} | |
55 ) | |
56 | |
57 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/tests/${output}) | |
58 endforeach () | |
59 | |
60 # Always link to googletest | |
61 list(APPEND TEST_LIBRARIES extern-gtest) | |
62 | |
63 # Executable | |
64 add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${TEST_RESOURCES} ${RESOURCES}) | |
65 target_link_libraries(test-${TEST_NAME} ${TEST_LIBRARIES}) | |
66 source_group(Auto-generated FILES ${RESOURCES}) | |
67 | |
68 target_include_directories( | |
69 test-${TEST_NAME} | |
70 PRIVATE | |
71 ${irccd_SOURCE_DIR} | |
72 ) | |
73 | |
74 target_compile_definitions( | |
75 test-${TEST_NAME} | |
76 PRIVATE | |
77 IRCCD_TESTS_DIRECTORY="${CMAKE_BINARY_DIR}/tests" | |
78 ) | |
79 | |
80 # Tests are all in the same directory | |
81 set_target_properties( | |
82 test-${TEST_NAME} | |
83 PROPERTIES | |
84 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests | |
85 RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/tests | |
86 RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/tests | |
87 RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests | |
88 RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests | |
89 ) | |
90 | |
91 if (UNIX) | |
92 set_target_properties(test-${TEST_NAME} PROPERTIES LINK_FLAGS -pthread) | |
93 endif () | |
94 | |
95 # And test | |
96 add_test( | |
97 NAME test-${TEST_NAME} | |
98 COMMAND test-${TEST_NAME} | |
99 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests | |
100 ) | |
101 endfunction() |