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.
This commit is contained in:
parent
828c05b9f5
commit
109a7a245a
|
@ -53,11 +53,14 @@ if(CMAKE_C_LIBRARY_ARCHITECTURE)
|
|||
set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_C_LIBRARY_ARCHITECTURE@")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "@CMAKE_C_CL_SHOWINCLUDES_PREFIX@")
|
||||
if(CMAKE_C_CL_SHOWINCLUDES_PREFIX)
|
||||
set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}")
|
||||
endif()
|
||||
|
||||
@CMAKE_C_SYSROOT_FLAG_CODE@
|
||||
@CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
|
||||
|
||||
set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "@CMAKE_C_IMPLICIT_LINK_LIBRARIES@")
|
||||
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_DIRECTORIES@")
|
||||
set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
|
||||
|
||||
@SET_CMAKE_CL_SHOWINCLUDES_PREFIX@
|
||||
|
|
|
@ -54,11 +54,14 @@ if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
|
|||
set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_CXX_LIBRARY_ARCHITECTURE@")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "@CMAKE_CXX_CL_SHOWINCLUDES_PREFIX@")
|
||||
if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX)
|
||||
set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}")
|
||||
endif()
|
||||
|
||||
@CMAKE_CXX_SYSROOT_FLAG_CODE@
|
||||
@CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
|
||||
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "@CMAKE_CXX_IMPLICIT_LINK_LIBRARIES@")
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES@")
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
|
||||
|
||||
@SET_CMAKE_CL_SHOWINCLUDES_PREFIX@
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
|
||||
#=============================================================================
|
||||
# Copyright 2012 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
#
|
||||
# When using Ninja cl.exe is wrapped by cmcldeps to extract the included
|
||||
# headers for dependency tracking.
|
||||
#
|
||||
# cmcldeps path is set, and cmcldeps needs to know the localized string
|
||||
# in front of each include path, so it can remove it.
|
||||
#
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_C_COMPILER AND CMAKE_COMMAND)
|
||||
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_C_COMPILER} /nologo /showIncludes ${showdir}/main.c
|
||||
WORKING_DIRECTORY ${showdir} OUTPUT_VARIABLE outLine)
|
||||
string(REGEX MATCH "\n([^:]*:[^:]*:[ \t]*)" tmp "${outLine}")
|
||||
set(localizedPrefix "${CMAKE_MATCH_1}")
|
||||
set(SET_CMAKE_CL_SHOWINCLUDES_PREFIX "set(CMAKE_CL_SHOWINCLUDES_PREFIX \"${localizedPrefix}\")")
|
||||
endif()
|
|
@ -173,7 +173,6 @@ endif ()
|
|||
|
||||
include(CMakeFindBinUtils)
|
||||
if(MSVC_C_ARCHITECTURE_ID)
|
||||
include(${CMAKE_ROOT}/Modules/CMakeClDeps.cmake)
|
||||
set(SET_MSVC_C_ARCHITECTURE_ID
|
||||
"set(MSVC_C_ARCHITECTURE_ID ${MSVC_C_ARCHITECTURE_ID})")
|
||||
endif()
|
||||
|
|
|
@ -171,7 +171,6 @@ endif ()
|
|||
|
||||
include(CMakeFindBinUtils)
|
||||
if(MSVC_CXX_ARCHITECTURE_ID)
|
||||
include(${CMAKE_ROOT}/Modules/CMakeClDeps.cmake)
|
||||
set(SET_MSVC_CXX_ARCHITECTURE_ID
|
||||
"set(MSVC_CXX_ARCHITECTURE_ID ${MSVC_CXX_ARCHITECTURE_ID})")
|
||||
endif()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue