Mercurial > molko
annotate cmake/MolkoDefineTest.cmake @ 277:1d10983fc0d7
cmake: cleanup
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 13 Dec 2020 11:25:11 +0100 |
parents | 97f55f6b9593 |
children |
rev | line source |
---|---|
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 # |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 # MolkoDefineTest.cmake -- CMake build system for molko |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 # |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 # Copyright (c) 2020 David Demelier <markand@malikania.fr> |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 # |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 # Permission to use, copy, modify, and/or distribute this software for any |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 # purpose with or without fee is hereby granted, provided that the above |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 # copyright notice and this permission notice appear in all copies. |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 # |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 # |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
19 # |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
20 # # molko_define_test |
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
21 # |
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
22 # Create unit test. |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
23 # |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
24 # ## Synopsis |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
25 # |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
26 # ```cmake |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
27 # molko_define_test( |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
28 # TARGET target name |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
29 # SOURCES src1, src2, srcn |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
30 # ASSETS (Optional) list of assets to build |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
31 # FLAGS (Optional) C flags (without -D) |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
32 # LIBRARIES (Optional) libraries to link |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
33 # INCLUDES (Optional) includes |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
34 # ) |
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
35 # ``` |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
36 # |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
37 # Create an executable with the name *TARGET* and a test case of the same name |
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
38 # with the given *SOURCES*. |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
39 # |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
40 # Optional include paths, libraries and flags can be specified via *INCLUDES*, |
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
41 # *LIBRARIES* and *FLAGS* arguments respectively. |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
42 # |
245
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
43 # If argument *ASSETS* is set, they are generated in the target binary |
97f55f6b9593
doc: add CMake macros documentation
David Demelier <markand@malikania.fr>
parents:
243
diff
changeset
|
44 # directory. |
243
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
45 # |
71b3b7036de7
misc: lot of cleanups,
David Demelier <markand@malikania.fr>
parents:
242
diff
changeset
|
46 |
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
47 include(${CMAKE_CURRENT_LIST_DIR}/MolkoBuildAssets.cmake) |
221 | 48 include(${CMAKE_CURRENT_LIST_DIR}/MolkoSetCompilerFlags.cmake) |
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
50 function(molko_define_test) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
51 set(options) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 set(oneValueArgs TARGET) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 set(multiValueArgs ASSETS FLAGS INCLUDES LIBRARIES SOURCES) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
54 |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
55 cmake_parse_arguments(TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
56 |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
57 if (NOT TEST_TARGET) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
58 message(FATAL_ERROR "Missing TARGET argument") |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 endif () |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
60 if (NOT TEST_SOURCES) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
61 message(FATAL_ERROR "Missing SOURCES argument") |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
62 endif () |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
63 |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
64 molko_build_assets("${TEST_ASSETS}" OUTPUTS) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
65 |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
66 add_executable(test-${TEST_TARGET} ${TEST_SOURCES} ${OUTPUTS}) |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
67 target_compile_definitions(test-${TEST_TARGET} PRIVATE ${TEST_FLAGS}) |
123
2cbea8172926
cmake: fix usage of assets for tests
David Demelier <markand@malikania.fr>
parents:
121
diff
changeset
|
68 target_include_directories( |
2cbea8172926
cmake: fix usage of assets for tests
David Demelier <markand@malikania.fr>
parents:
121
diff
changeset
|
69 test-${TEST_TARGET} |
2cbea8172926
cmake: fix usage of assets for tests
David Demelier <markand@malikania.fr>
parents:
121
diff
changeset
|
70 PRIVATE |
2cbea8172926
cmake: fix usage of assets for tests
David Demelier <markand@malikania.fr>
parents:
121
diff
changeset
|
71 ${CMAKE_CURRENT_BINARY_DIR} |
2cbea8172926
cmake: fix usage of assets for tests
David Demelier <markand@malikania.fr>
parents:
121
diff
changeset
|
72 ${TEST_INCLUDES} |
2cbea8172926
cmake: fix usage of assets for tests
David Demelier <markand@malikania.fr>
parents:
121
diff
changeset
|
73 ) |
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
74 target_link_libraries( |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
75 test-${TEST_TARGET} |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
76 PRIVATE |
242
4c24604efcab
cmake: create build hierarchy similar to install, closes #2518 @1h
David Demelier <markand@malikania.fr>
parents:
221
diff
changeset
|
77 libmlk-core |
4c24604efcab
cmake: create build hierarchy similar to install, closes #2518 @1h
David Demelier <markand@malikania.fr>
parents:
221
diff
changeset
|
78 libmlk-adventure |
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 libgreatest |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
80 ${TEST_LIBRARIES} |
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 ) |
221 | 82 |
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 add_test(NAME ${TEST_TARGET} COMMAND test-${TEST_TARGET}) |
121
789b23e01f52
misc: reorganize hierarchy, closes #2490
David Demelier <markand@malikania.fr>
parents:
119
diff
changeset
|
84 set_target_properties(test-${TEST_TARGET} PROPERTIES FOLDER tests) |
221 | 85 |
86 molko_set_compiler_flags(test-${TEST_TARGET}) | |
119
43e04bf2c350
cmake: add tests, continue #2487 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 endfunction() |