Debian Codegraph @

Tests/RunCMake/CpsMapConfig/RunCMakeTest.cmake

raw
1 include(RunCMake)
2
3 function(build_project test)
4 set(RunCMake_TEST_NO_CLEAN FALSE)
5 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
6 if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
7 list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
8 endif()
9
10 run_cmake(${test})
11
12 set(RunCMake_TEST_NO_CLEAN TRUE)
13 run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . --config Release)
14 endfunction()
15
16 #[[
17 These tests are not testing CPS as such, but rather are testing the way that
18 CMake maps configurations; specifically, which MAP_IMPORTED_CONFIG_<CONFIG> is
19 considered when selecting a configuration of a target required by another
20 target for which a non-standard configuration has been selected.
21
22 It happens that CMake's behavior is to always use the configuration of the
23 project being built, and not the selected configuration of the consumer of the
24 target for which configuration selection is occurring. This turns out to be
25 advantageous, as it makes it relatively simple to use chains of interface
26 targets to select along multiple configuration axes, since it is relatively
27 simple for projects to set CMAKE_MAP_IMPORTED_CONFIG_<CONFIG> to a list of
28 preferred values along each axis and be sure the same list will be used for
29 each level of selection.
30
31 This test/example uses the following hierarchy:
32 target "animal", configurations "cat", "dog"
33 targets "cat", "dog", configurations "tame", "wild"
34
35 The consuming project sets CMAKE_MAP_IMPORTED_CONFIG_<CONFIG> to the list of
36 desired values on each of the two axes, e.g. "CAT;TAME". This causes CMake to
37 select the "CAT" configuration of the "animal" target, which links "cat",
38 then, because CMake is still using MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE},
39 to select the "TAME" configuration of the "cat" target.
40
41 A more practical example is described by CPS, at
42 https://cps-org.github.io/cps/recommendations.html.
43
44 The main reason this is a "CPS" test is because CPS makes it possible to
45 provide targets which implement multiple configuration axes in a way that is
46 surprisingly usable by CMake consumers. However, CMake itself has no way of
47 generating such exports as of when this test is being added (CMake 4.3). Thus,
48 it is testing something which is suggested by CPS, but is unlikely to be
49 encountered in a CMake-created package. (In principle, however, a hand-written
50 CMake-script package description could produce equivalent imported targets.)
51 #]]
52
53 build_project(TestTameCat)
54 build_project(TestWildCat)
55 build_project(TestTameDog)
56 build_project(TestWildDog)