23a206b2a52ee0235d70a1d73af8c930a73581e7
[platform/upstream/cmake.git] / Modules / CTestUseLaunchers.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 CTestUseLaunchers
6 -----------------
7
8 Set the RULE_LAUNCH_* global properties when CTEST_USE_LAUNCHERS is on.
9
10 CTestUseLaunchers is automatically included when you include(CTest).
11 However, it is split out into its own module file so projects can use
12 the CTEST_USE_LAUNCHERS functionality independently.
13
14 To use launchers, set CTEST_USE_LAUNCHERS to ON in a ctest -S
15 dashboard script, and then also set it in the cache of the configured
16 project.  Both cmake and ctest need to know the value of it for the
17 launchers to work properly.  CMake needs to know in order to generate
18 proper build rules, and ctest, in order to produce the proper error
19 and warning analysis.
20
21 For convenience, you may set the ENV variable
22 CTEST_USE_LAUNCHERS_DEFAULT in your ctest -S script, too.  Then, as
23 long as your CMakeLists uses include(CTest) or
24 include(CTestUseLaunchers), it will use the value of the ENV variable
25 to initialize a CTEST_USE_LAUNCHERS cache variable.  This cache
26 variable initialization only occurs if CTEST_USE_LAUNCHERS is not
27 already defined.
28
29 .. versionadded:: 3.8
30   If CTEST_USE_LAUNCHERS is on in a ctest -S script
31   the ctest_configure command will add -DCTEST_USE_LAUNCHERS:BOOL=TRUE
32   to the cmake command used to configure the project.
33 #]=======================================================================]
34
35 if(NOT DEFINED CTEST_USE_LAUNCHERS AND DEFINED ENV{CTEST_USE_LAUNCHERS_DEFAULT})
36   set(CTEST_USE_LAUNCHERS "$ENV{CTEST_USE_LAUNCHERS_DEFAULT}"
37     CACHE INTERNAL "CTEST_USE_LAUNCHERS initial value from ENV")
38 endif()
39
40 if(NOT "${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
41   set(CTEST_USE_LAUNCHERS 0)
42 endif()
43
44 if(CTEST_USE_LAUNCHERS)
45   set(__launch_common_options
46     "--target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR>")
47
48   set(__launch_compile_options
49     "${__launch_common_options} --output <OBJECT> --source <SOURCE> --language <LANGUAGE>")
50
51   set(__launch_link_options
52     "${__launch_common_options} --output <TARGET> --target-type <TARGET_TYPE> --language <LANGUAGE>")
53
54   set(__launch_custom_options
55     "${__launch_common_options} --output <OUTPUT>")
56
57   if("${CMAKE_GENERATOR}" MATCHES "Ninja")
58     string(APPEND __launch_compile_options " --filter-prefix <CMAKE_CL_SHOWINCLUDES_PREFIX>")
59   endif()
60
61   set(CTEST_LAUNCH_COMPILE
62     "\"${CMAKE_CTEST_COMMAND}\" --launch ${__launch_compile_options} --")
63
64   set(CTEST_LAUNCH_LINK
65     "\"${CMAKE_CTEST_COMMAND}\" --launch ${__launch_link_options} --")
66
67   set(CTEST_LAUNCH_CUSTOM
68     "\"${CMAKE_CTEST_COMMAND}\" --launch ${__launch_custom_options} --")
69
70   set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CTEST_LAUNCH_COMPILE}")
71   set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CTEST_LAUNCH_LINK}")
72   set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${CTEST_LAUNCH_CUSTOM}")
73 endif()