diff options
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index c699315..2e74100 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -75,6 +75,12 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_EXECUTABLE_FORMAT "Unknown" CACHE INTERNAL "Executable file format") endif() + if(CMAKE_GENERATOR STREQUAL "Ninja" AND MSVC_${lang}_ARCHITECTURE_ID) + CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX(${lang}) + else() + set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "") + endif() + # Display the final identification result. if(CMAKE_${lang}_COMPILER_ID) if(CMAKE_${lang}_COMPILER_VERSION) @@ -99,9 +105,12 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" PARENT_SCOPE) + set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE) + set(CMAKE_${lang}_COMPILER_LINKS_STATICALLY "${CMAKE_${lang}_COMPILER_LINKS_STATICALLY}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE) set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE) + set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE) endfunction() include(CMakeCompilerIdDetection) @@ -201,6 +210,9 @@ Id flags: ${testflags} else() set(id_system_version "") endif() + if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + set(id_WindowsTargetPlatformVersion "<WindowsTargetPlatformVersion>${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}</WindowsTargetPlatformVersion>") + endif() if(id_platform STREQUAL ARM) set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>") else() @@ -313,29 +325,17 @@ Id flags: ${testflags} endif() endif() else() - if(COMMAND EXECUTE_PROCESS) - execute_process( - COMMAND "${CMAKE_${lang}_COMPILER}" - ${CMAKE_${lang}_COMPILER_ID_ARG1} - ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} - ${testflags} - "${src}" - WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR} - OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT - ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT - RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT - ) - else() - exec_program( - "${CMAKE_${lang}_COMPILER}" ${CMAKE_${lang}_COMPILER_ID_DIR} - ARGS ${CMAKE_${lang}_COMPILER_ID_ARG1} - ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} - ${testflags} - \"${src}\" - OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT - RETURN_VALUE CMAKE_${lang}_COMPILER_ID_RESULT - ) - endif() + execute_process( + COMMAND "${CMAKE_${lang}_COMPILER}" + ${CMAKE_${lang}_COMPILER_ID_ARG1} + ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} + ${testflags} + "${src}" + WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR} + OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT + ) endif() # Check the result of compilation. @@ -487,6 +487,9 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) if("${info}" MATCHES "INFO:qnxnto\\[\\]") set(COMPILER_QNXNTO 1) endif() + if("${info}" MATCHES "INFO:dialect_default\\[([^]\"]*)\\]") + set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_MATCH_1}") + endif() endforeach() # Construct compiler version from components if needed. @@ -530,6 +533,13 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) endif() endif() + if(UNIX) + execute_process(COMMAND file "${file}" OUTPUT_VARIABLE out ERROR_VARIABLE out) + if(out MATCHES "statically linked") + set(CMAKE_${lang}_COMPILER_LINKS_STATICALLY 1 PARENT_SCOPE) + endif() + endif() + # Check if a valid compiler and platform were found. if(COMPILER_ID AND NOT COMPILER_ID_TWICE) set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}") @@ -590,6 +600,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE) set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE) set(COMPILER_QNXNTO "${COMPILER_QNXNTO}" PARENT_SCOPE) + set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE) endfunction() #----------------------------------------------------------------------------- @@ -645,3 +656,27 @@ function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang) endif() endforeach() endfunction() + +function(CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX lang) + # Run this MSVC-compatible compiler to detect what the /showIncludes + # option displays. We can use a C source even with the C++ compiler + # because MSVC-compatible compilers handle both and show the same output. + set(showdir ${CMAKE_BINARY_DIR}/CMakeFiles/ShowIncludes) + file(WRITE ${showdir}/foo.h "\n") + file(WRITE ${showdir}/main.c "#include \"foo.h\" \nint main(){}\n") + execute_process( + COMMAND "${CMAKE_${lang}_COMPILER}" + ${CMAKE_${lang}_COMPILER_ID_ARG1} + ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} + /nologo /showIncludes /c main.c + WORKING_DIRECTORY ${showdir} + OUTPUT_VARIABLE out + ERROR_VARIABLE err + RESULT_VARIABLE res + ) + if(res EQUAL 0 AND "${out}" MATCHES "\n([^:]*:[^:]*:[ \t]*)") + set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_MATCH_1}" PARENT_SCOPE) + else() + set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "" PARENT_SCOPE) + endif() +endfunction() |