mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-17 04:31:04 -06:00
launcher: support setting a compiler launcher through the environment
This makes it much easier to use a launcher for all CMake projects in an environment rather than having to remember to pass the setting to every CMake build.
This commit is contained in:
10
Help/envvar/CMAKE_LANG_COMPILER_LAUNCHER.rst
Normal file
10
Help/envvar/CMAKE_LANG_COMPILER_LAUNCHER.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
CMAKE_<LANG>_COMPILER_LAUNCHER
|
||||
------------------------------
|
||||
|
||||
.. include:: ENV_VAR.txt
|
||||
|
||||
Default compiler launcher to use for the specified language. Will only be used
|
||||
by CMake to initialize the variable on the first configuration. Afterwards, it
|
||||
is available through the cache setting of the variable of the same name. For
|
||||
any configuration run (including the first), the environment variable will be
|
||||
ignored if the :variable:`CMAKE_<LANG>_COMPILER_LAUNCHER` variable is defined.
|
||||
@@ -28,6 +28,7 @@ Environment Variables that Control the Build
|
||||
/envvar/CMAKE_GENERATOR_INSTANCE
|
||||
/envvar/CMAKE_GENERATOR_PLATFORM
|
||||
/envvar/CMAKE_GENERATOR_TOOLSET
|
||||
/envvar/CMAKE_LANG_COMPILER_LAUNCHER
|
||||
/envvar/CMAKE_MSVCIDE_RUN_PATH
|
||||
/envvar/CMAKE_NO_VERBOSE
|
||||
/envvar/CMAKE_OSX_ARCHITECTURES
|
||||
|
||||
5
Help/release/dev/compiler-launcher-env.rst
Normal file
5
Help/release/dev/compiler-launcher-env.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
compiler-launcher-env
|
||||
---------------------
|
||||
|
||||
* The :envvar:`CMAKE_<LANG>_COMPILER_LAUNCHER` environment variable may now be
|
||||
used to initialize the :variable:`CMAKE_<LANG>_COMPILER_LAUNCHER` variable.
|
||||
@@ -5,3 +5,6 @@ Default value for :prop_tgt:`<LANG>_COMPILER_LAUNCHER` target property.
|
||||
This variable is used to initialize the property on each target as it is
|
||||
created. This is done only when ``<LANG>`` is ``C``, ``CXX``, ``Fortran``,
|
||||
or ``CUDA``.
|
||||
|
||||
This variable is initialized to the :envvar:`CMAKE_<LANG>_COMPILER_LAUNCHER`
|
||||
environment variable if it is set.
|
||||
|
||||
@@ -110,6 +110,11 @@ if(CMAKE_C_STANDARD_LIBRARIES_INIT)
|
||||
mark_as_advanced(CMAKE_C_STANDARD_LIBRARIES)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_C_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_C_COMPILER_LAUNCHER})
|
||||
set(CMAKE_C_COMPILER_LAUNCHER "$ENV{CMAKE_C_COMPILER_LAUNCHER}"
|
||||
CACHE STRING "Compiler launcher for C.")
|
||||
endif()
|
||||
|
||||
include(CMakeCommonLanguageInclude)
|
||||
|
||||
# now define the following rule variables
|
||||
|
||||
@@ -82,6 +82,11 @@ if(CMAKE_CUDA_STANDARD_LIBRARIES_INIT)
|
||||
mark_as_advanced(CMAKE_CUDA_STANDARD_LIBRARIES)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CUDA_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_CUDA_COMPILER_LAUNCHER})
|
||||
set(CMAKE_CUDA_COMPILER_LAUNCHER "$ENV{CMAKE_CUDA_COMPILER_LAUNCHER}"
|
||||
CACHE STRING "Compiler launcher for CUDA.")
|
||||
endif()
|
||||
|
||||
include(CMakeCommonLanguageInclude)
|
||||
|
||||
# now define the following rules:
|
||||
|
||||
@@ -207,6 +207,11 @@ if(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
|
||||
mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CXX_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_CXX_COMPILER_LAUNCHER})
|
||||
set(CMAKE_CXX_COMPILER_LAUNCHER "$ENV{CMAKE_CXX_COMPILER_LAUNCHER}"
|
||||
CACHE STRING "Compiler launcher for CXX.")
|
||||
endif()
|
||||
|
||||
include(CMakeCommonLanguageInclude)
|
||||
|
||||
# now define the following rules:
|
||||
|
||||
@@ -163,6 +163,11 @@ set(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
|
||||
|
||||
cmake_initialize_per_config_variable(CMAKE_Fortran_FLAGS "Flags used by the Fortran compiler")
|
||||
|
||||
if(NOT CMAKE_Fortran_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_Fortran_COMPILER_LAUNCHER})
|
||||
set(CMAKE_Fortran_COMPILER_LAUNCHER "$ENV{CMAKE_Fortran_COMPILER_LAUNCHER}"
|
||||
CACHE STRING "Compiler launcher for Fortran.")
|
||||
endif()
|
||||
|
||||
include(CMakeCommonLanguageInclude)
|
||||
|
||||
# now define the following rule variables
|
||||
|
||||
3
Tests/RunCMake/CompilerLauncher/C-common.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/C-common.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
enable_language(C)
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.c)
|
||||
1
Tests/RunCMake/CompilerLauncher/C-env-Build-stdout.txt
Normal file
1
Tests/RunCMake/CompilerLauncher/C-env-Build-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
1
Tests/RunCMake/CompilerLauncher/C-env.cmake
Normal file
1
Tests/RunCMake/CompilerLauncher/C-env.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(C-common.cmake)
|
||||
3
Tests/RunCMake/CompilerLauncher/C-launch-env.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/C-launch-env.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
set(CTEST_USE_LAUNCHERS 1)
|
||||
include(CTestUseLaunchers)
|
||||
include(C-env.cmake)
|
||||
@@ -1,4 +1,2 @@
|
||||
enable_language(C)
|
||||
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_COMMAND};-E;env;USED_LAUNCHER=1")
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.c)
|
||||
include(C-common.cmake)
|
||||
|
||||
3
Tests/RunCMake/CompilerLauncher/CUDA-common.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/CUDA-common.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
enable_language(CUDA)
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.cu)
|
||||
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
1
Tests/RunCMake/CompilerLauncher/CUDA-env.cmake
Normal file
1
Tests/RunCMake/CompilerLauncher/CUDA-env.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(CUDA-common.cmake)
|
||||
3
Tests/RunCMake/CompilerLauncher/CUDA-launch-env.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/CUDA-launch-env.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
set(CTEST_USE_LAUNCHERS 1)
|
||||
include(CTestUseLaunchers)
|
||||
include(CUDA-env.cmake)
|
||||
@@ -1,4 +1,2 @@
|
||||
enable_language(CUDA)
|
||||
set(CMAKE_CUDA_COMPILER_LAUNCHER "${CMAKE_COMMAND};-E;env;USED_LAUNCHER=1")
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.cu)
|
||||
include(CUDA-common.cmake)
|
||||
|
||||
3
Tests/RunCMake/CompilerLauncher/CXX-common.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/CXX-common.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
enable_language(CXX)
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.cxx)
|
||||
1
Tests/RunCMake/CompilerLauncher/CXX-env-Build-stdout.txt
Normal file
1
Tests/RunCMake/CompilerLauncher/CXX-env-Build-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
1
Tests/RunCMake/CompilerLauncher/CXX-env.cmake
Normal file
1
Tests/RunCMake/CompilerLauncher/CXX-env.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(CXX-common.cmake)
|
||||
3
Tests/RunCMake/CompilerLauncher/CXX-launch-env.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/CXX-launch-env.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
set(CTEST_USE_LAUNCHERS 1)
|
||||
include(CTestUseLaunchers)
|
||||
include(CXX-env.cmake)
|
||||
@@ -1,4 +1,2 @@
|
||||
enable_language(CXX)
|
||||
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_COMMAND};-E;env;USED_LAUNCHER=1")
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.cxx)
|
||||
include(CXX-common.cmake)
|
||||
|
||||
3
Tests/RunCMake/CompilerLauncher/Fortran-common.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/Fortran-common.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
enable_language(Fortran)
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.F)
|
||||
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
@@ -0,0 +1 @@
|
||||
.*-E env USED_LAUNCHER=1.*
|
||||
1
Tests/RunCMake/CompilerLauncher/Fortran-env.cmake
Normal file
1
Tests/RunCMake/CompilerLauncher/Fortran-env.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(Fortran-common.cmake)
|
||||
3
Tests/RunCMake/CompilerLauncher/Fortran-launch-env.cmake
Normal file
3
Tests/RunCMake/CompilerLauncher/Fortran-launch-env.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
set(CTEST_USE_LAUNCHERS 1)
|
||||
include(CTestUseLaunchers)
|
||||
include(Fortran-env.cmake)
|
||||
@@ -1,4 +1,2 @@
|
||||
enable_language(Fortran)
|
||||
set(CMAKE_Fortran_COMPILER_LAUNCHER "${CMAKE_COMMAND};-E;env;USED_LAUNCHER=1")
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
add_executable(main main.F)
|
||||
include(Fortran-common.cmake)
|
||||
|
||||
@@ -15,6 +15,13 @@ function(run_compiler_launcher lang)
|
||||
run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
|
||||
endfunction()
|
||||
|
||||
function(run_compiler_launcher_env lang)
|
||||
string(REGEX REPLACE "-.*" "" core_lang "${lang}")
|
||||
set(ENV{CMAKE_${core_lang}_COMPILER_LAUNCHER} "${CMAKE_COMMAND};-E;env;USED_LAUNCHER=1")
|
||||
run_compiler_launcher(${lang})
|
||||
unset(ENV{CMAKE_${core_lang}_COMPILER_LAUNCHER})
|
||||
endfunction()
|
||||
|
||||
set(langs C CXX)
|
||||
if(CMake_TEST_CUDA)
|
||||
list(APPEND langs CUDA)
|
||||
@@ -25,7 +32,9 @@ endif()
|
||||
|
||||
foreach(lang ${langs})
|
||||
run_compiler_launcher(${lang})
|
||||
run_compiler_launcher_env(${lang}-env)
|
||||
if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
|
||||
run_compiler_launcher(${lang}-launch)
|
||||
run_compiler_launcher_env(${lang}-launch-env)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
Reference in New Issue
Block a user