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:
Ben Boeckel
2019-11-27 18:44:58 -05:00
parent 7046a52198
commit 6f48c59257
33 changed files with 88 additions and 12 deletions

View 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.

View File

@@ -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

View 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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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:

View File

@@ -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:

View File

@@ -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

View File

@@ -0,0 +1,3 @@
enable_language(C)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
add_executable(main main.c)

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
include(C-common.cmake)

View File

@@ -0,0 +1,3 @@
set(CTEST_USE_LAUNCHERS 1)
include(CTestUseLaunchers)
include(C-env.cmake)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
enable_language(CUDA)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
add_executable(main main.cu)

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
include(CUDA-common.cmake)

View File

@@ -0,0 +1,3 @@
set(CTEST_USE_LAUNCHERS 1)
include(CTestUseLaunchers)
include(CUDA-env.cmake)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
enable_language(CXX)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
add_executable(main main.cxx)

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
include(CXX-common.cmake)

View File

@@ -0,0 +1,3 @@
set(CTEST_USE_LAUNCHERS 1)
include(CTestUseLaunchers)
include(CXX-env.cmake)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
enable_language(Fortran)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
add_executable(main main.F)

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
.*-E env USED_LAUNCHER=1.*

View File

@@ -0,0 +1 @@
include(Fortran-common.cmake)

View File

@@ -0,0 +1,3 @@
set(CTEST_USE_LAUNCHERS 1)
include(CTestUseLaunchers)
include(Fortran-env.cmake)

View File

@@ -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)

View File

@@ -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()