From 8cc384f6299d60d705330f712031c2851498aa62 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 25 Mar 2020 11:06:54 -0400 Subject: Compilers: Add paths from -print-sysroot to system prefix path --- Modules/CMakeASMCompiler.cmake.in | 1 + Modules/CMakeCCompiler.cmake.in | 1 + Modules/CMakeCUDACompiler.cmake.in | 1 + Modules/CMakeCXXCompiler.cmake.in | 1 + Modules/CMakeDetermineASMCompiler.cmake | 11 +++++++++++ Modules/CMakeDetermineCCompiler.cmake | 10 ++++++++++ Modules/CMakeDetermineCUDACompiler.cmake | 10 ++++++++++ Modules/CMakeDetermineCXXCompiler.cmake | 10 ++++++++++ Modules/CMakeDetermineCompiler.cmake | 15 +++++++++++++++ Modules/CMakeDetermineFortranCompiler.cmake | 10 ++++++++++ Modules/CMakeFortranCompiler.cmake.in | 1 + Modules/Platform/UnixPaths.cmake | 4 ++++ 12 files changed, 75 insertions(+) diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in index 858c053..3953b30 100644 --- a/Modules/CMakeASMCompiler.cmake.in +++ b/Modules/CMakeASMCompiler.cmake.in @@ -12,6 +12,7 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_VERSION "@_CMAKE_ASM_COMPILER_VERSION@") set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@") @_SET_CMAKE_ASM_COMPILER_ID_VENDOR_MATCH@ @_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_ASM_COMPILER_SYSROOT@ set(CMAKE_ASM@ASM_DIALECT@_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_ASM@ASM_DIALECT@_LINKER_PREFERENCE 0) diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 9b8d423..eea3f5d 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -15,6 +15,7 @@ set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@") set(CMAKE_C_COMPILER_FRONTEND_VARIANT "@CMAKE_C_COMPILER_FRONTEND_VARIANT@") set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@") @_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_C_COMPILER_SYSROOT@ @SET_MSVC_C_ARCHITECTURE_ID@ @SET_CMAKE_XCODE_ARCHS@ set(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCUDACompiler.cmake.in b/Modules/CMakeCUDACompiler.cmake.in index 14a39a9..289e96e 100644 --- a/Modules/CMakeCUDACompiler.cmake.in +++ b/Modules/CMakeCUDACompiler.cmake.in @@ -16,6 +16,7 @@ set(CMAKE_CUDA_SIMULATE_ID "@CMAKE_CUDA_SIMULATE_ID@") set(CMAKE_CUDA_COMPILER_FRONTEND_VARIANT "@CMAKE_CUDA_COMPILER_FRONTEND_VARIANT@") set(CMAKE_CUDA_SIMULATE_VERSION "@CMAKE_CUDA_SIMULATE_VERSION@") @SET_MSVC_CUDA_ARCHITECTURE_ID@ +@_SET_CMAKE_CUDA_COMPILER_SYSROOT@ set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX") set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX") diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index efb8abf..09bdc23 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -17,6 +17,7 @@ set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@") set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "@CMAKE_CXX_COMPILER_FRONTEND_VARIANT@") set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@") @_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_CXX_COMPILER_SYSROOT@ @SET_MSVC_CXX_ARCHITECTURE_ID@ @SET_CMAKE_XCODE_ARCHS@ set(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index 86fb057..bc8b86b 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -134,6 +134,9 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) list(GET _all_compileid_matches "-1" CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID) endif() endif() + + _cmake_find_compiler_sysroot(ASM${ASM_DIALECT}) + unset(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT) unset(_all_compileid_matches) unset(_compileid) @@ -211,6 +214,14 @@ foreach(_var set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}") endforeach() +if(CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_ASM_COMPILER_SYSROOT + "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT \"${CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_ASM_COMPILER_SYSROOT "") +endif() + if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH) set(_SET_CMAKE_ASM_COMPILER_ID_VENDOR_MATCH "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH [==[${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH}]==])") diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 9d395e5..f870956 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -115,6 +115,8 @@ if(NOT CMAKE_C_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(C CFLAGS CMakeCCompilerId.c) + _cmake_find_compiler_sysroot(C) + # Set old compiler and platform id variables. if(CMAKE_C_COMPILER_ID STREQUAL "GNU") set(CMAKE_COMPILER_IS_GNUCC 1) @@ -191,6 +193,14 @@ include(CMakeFindBinUtils) include(Compiler/${CMAKE_C_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_C_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_C_COMPILER_SYSROOT + "set(CMAKE_C_COMPILER_SYSROOT \"${CMAKE_C_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_C_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_C_COMPILER_SYSROOT "") +endif() + if(CMAKE_C_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID "set(CMAKE_C_COMPILER_ARCHITECTURE_ID ${CMAKE_C_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 95c3cc9..55ca800 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -70,6 +70,8 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(CUDA CUDAFLAGS CMakeCUDACompilerId.cu) + + _cmake_find_compiler_sysroot(CUDA) endif() set(_CMAKE_PROCESSING_LANGUAGE "CUDA") @@ -189,6 +191,14 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") endif() endif() +if(CMAKE_CUDA_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_CUDA_COMPILER_SYSROOT + "set(CMAKE_CUDA_COMPILER_SYSROOT \"${CMAKE_CUDA_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_CUDA_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_CUDA_COMPILER_SYSROOT "") +endif() + # Determine CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index ebac435..e6b46b8 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -110,6 +110,8 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS CMakeCXXCompilerId.cpp) + _cmake_find_compiler_sysroot(CXX) + # Set old compiler and platform id variables. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_COMPILER_IS_GNUCXX 1) @@ -189,6 +191,14 @@ include(CMakeFindBinUtils) include(Compiler/${CMAKE_CXX_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_CXX_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_CXX_COMPILER_SYSROOT + "set(CMAKE_CXX_COMPILER_SYSROOT \"${CMAKE_CXX_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_CXX_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_CXX_COMPILER_SYSROOT "") +endif() + if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID "set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index c37adae..7afae8a 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -118,3 +118,18 @@ macro(_cmake_find_compiler_path lang) endif() endif() endmacro() + +function(_cmake_find_compiler_sysroot lang) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") + execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -print-sysroot + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE _cmake_sysroot_run_out + ERROR_VARIABLE _cmake_sysroot_run_err) + + if(_cmake_sysroot_run_out AND NOT _cmake_sysroot_run_err AND IS_DIRECTORY "${_cmake_sysroot_run_out}/usr") + set(CMAKE_${lang}_COMPILER_SYSROOT "${_cmake_sysroot_run_out}/usr" PARENT_SCOPE) + else() + set(CMAKE_${lang}_COMPILER_SYSROOT "" PARENT_SCOPE) + endif() + endif() +endfunction() diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 6731abe..5f5a70a 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -186,6 +186,8 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS CMakeFortranCompilerId.F) + _cmake_find_compiler_sysroot(Fortran) + # Fall back to old is-GNU test. if(NOT CMAKE_Fortran_COMPILER_ID) execute_process(COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_Fortran_COMPILER_ID_FLAGS_LIST} -E "${CMAKE_ROOT}/Modules/CMakeTestGNU.c" @@ -276,6 +278,14 @@ if(CMAKE_Fortran_XL_CPP) "set(CMAKE_Fortran_XL_CPP \"${CMAKE_Fortran_XL_CPP}\")") endif() +if(CMAKE_Fortran_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_Fortran_COMPILER_SYSROOT + "set(CMAKE_Fortran_COMPILER_SYSROOT \"${CMAKE_Fortran_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_Fortran_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_Fortran_COMPILER_SYSROOT "") +endif() + if(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID "set(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID ${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 34f44aa..06ee528 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -8,6 +8,7 @@ set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@") set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@") @_SET_CMAKE_Fortran_XL_CPP@ @_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_Fortran_COMPILER_SYSROOT@ @SET_MSVC_Fortran_ARCHITECTURE_ID@ set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_Fortran_COMPILER_AR "@CMAKE_Fortran_COMPILER_AR@") diff --git a/Modules/Platform/UnixPaths.cmake b/Modules/Platform/UnixPaths.cmake index 97f744d..98c83aa 100644 --- a/Modules/Platform/UnixPaths.cmake +++ b/Modules/Platform/UnixPaths.cmake @@ -86,6 +86,10 @@ set(_CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES_INIT unset(_cmake_sysroot_compile) +if(CMAKE_COMPILER_SYSROOT) + list(PREPEND CMAKE_SYSTEM_PREFIX_PATH "${CMAKE_COMPILER_SYSROOT}") +endif() + # Enable use of lib32 and lib64 search path variants by default. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) -- cgit v0.12