Mercurial > code
annotate cmake/CodeDefineModule.cmake @ 618:1ae8106369e5
Options: initial reimport, closes #705
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 26 Sep 2017 09:50:02 +0200 |
parents | 266f32919d0a |
children |
rev | line source |
---|---|
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 # CMakeLists.txt -- code building for common code |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 # |
617
266f32919d0a
Misc: update copyright headers, closes #686
David Demelier <markand@malikania.fr>
parents:
615
diff
changeset
|
4 # Copyright (c) 2013-2017 David Demelier <markand@malikania.fr> |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 # Permission to use, copy, modify, and/or distribute this software for any |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 # purpose with or without fee is hereby granted, provided that the above |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 # copyright notice and this permission notice appear in all copies. |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 # code_define_module |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 # ------------------------------------------------------------------- |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 # code_define_module( |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
24 # NAME lowercase name |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
25 # SOURCES source files |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
26 # LIBRARIES (Optional) libraries |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
27 # INCLUDES (Optional) include directories |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
28 # FLAGS (Optional) flags |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
29 # ) |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
30 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
31 # Create a test for the given module. |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 # This macro adds a new option WITH_<uppercase NAME> to test the module. |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 # If the module has a file test/main.cpp in its directory, a target test-<NAME> is created. |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 # |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 include(CMakeParseArguments) |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
39 |
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
40 function(code_define_module) |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
41 set(oneValueArgs NAME) |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
42 set(multiValueArgs SOURCES LIBRARIES INCLUDES FLAGS) |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
43 |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
44 cmake_parse_arguments(MOD "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
46 if (NOT MOD_NAME) |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
47 message(FATAL_ERROR "Argument NAME is not set") |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
48 endif () |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
50 # Create the option for enabling the test. |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
51 string(TOUPPER ${MOD_NAME} optionname) |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
52 option(WITH_${optionname} "Enable ${MOD_NAME}" On) |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
54 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp AND WITH_${optionname}) |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
55 # Create test executable. |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
56 add_executable(test-${MOD_NAME} ${MOD_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp) |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
57 set_target_properties( |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
58 test-${MOD_NAME} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
59 PROPERTIES |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
60 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
61 RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
62 RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
63 RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
64 RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
65 ) |
612
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
66 target_compile_definitions( |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
67 test-${MOD_NAME} |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
68 PRIVATE |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
69 BOOST_TEST_DYN_LINK |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
70 ${MOD_FLAGS} |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
71 ) |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
72 target_include_directories( |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
73 test-${MOD_NAME} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
74 PRIVATE |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
75 ${CMAKE_CURRENT_SOURCE_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
76 ${MOD_INCLUDES} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
77 ) |
612
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
78 target_link_libraries( |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
79 test-${MOD_NAME} |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
80 Boost::unit_test_framework |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
81 ${MOD_LIBRARIES} |
18ec7f4fc3de
Js: new style, closes #685
David Demelier <markand@malikania.fr>
parents:
548
diff
changeset
|
82 ) |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 |
548
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
84 # Register the test. |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
85 add_test( |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
86 NAME ${MOD_NAME} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
87 COMMAND test-${MOD_NAME} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
88 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
89 ) |
f48bb09bccc7
Misc: huge cleanup, switch to spaces
David Demelier <markand@malikania.fr>
parents:
516
diff
changeset
|
90 endif () |
516
cc50a80dc163
CMake: change code_define_module and rename the CMake file
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
91 endfunction() |