RunCMakeTest.cmake 2.5 KB

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