diff options
author | Brad King <brad.king@kitware.com> | 2015-09-18 13:09:07 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-09-18 14:02:53 (GMT) |
commit | 109a7a245acf0c367ac092f6c9a20661e7a31529 (patch) | |
tree | b4e786f43b4bec7a75f4854e10cd0745e82c765d /Modules/CMakeDetermineCompilerId.cmake | |
parent | 828c05b9f567e0652ebbee6df2799a189ff586fe (diff) | |
download | CMake-109a7a245acf0c367ac092f6c9a20661e7a31529.zip CMake-109a7a245acf0c367ac092f6c9a20661e7a31529.tar.gz CMake-109a7a245acf0c367ac092f6c9a20661e7a31529.tar.bz2 |
Ninja: Detect MSVC /showIncludes prefix with compiler flags (#15596)
Move detection over to the compiler id logic where we have already
constructed the list of compiler flags from ARG1 and CMAKE_<LANG>_FLAGS.
Pass the flags when we execute "cl" with "/showIncludes". Also pass "/c"
because we only need to compile, not link. Check the compiler process
exit code before trusting its output.
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index b73996b..df6daf3 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,6 +105,7 @@ 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_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) @@ -638,3 +645,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() |