Merge topic 'ninja-refactor-msvc-deps'
109a7a24
Ninja: Detect MSVC /showIncludes prefix with compiler flags (#15596)828c05b9
Ninja: Refactor lookup of cmcldeps locationc73fbda6
CMakeDetermineCompilerId: Drop unused code path
This commit is contained in:
commit
4f640afc1a
|
@ -53,12 +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_CMCLDEPS_EXECUTABLE@
|
||||
@SET_CMAKE_CL_SHOWINCLUDES_PREFIX@
|
||||
|
|
|
@ -54,12 +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_CMCLDEPS_EXECUTABLE@
|
||||
@SET_CMAKE_CL_SHOWINCLUDES_PREFIX@
|
||||
|
|
|
@ -1,34 +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)
|
||||
string(REPLACE "cmake.exe" "cmcldeps.exe" CMAKE_CMCLDEPS_EXECUTABLE ${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_CMCLDEPS_EXECUTABLE "set(CMAKE_CMCLDEPS_EXECUTABLE \"${CMAKE_CMCLDEPS_EXECUTABLE}\")")
|
||||
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)
|
||||
|
@ -314,29 +321,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.
|
||||
|
@ -650,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()
|
||||
|
|
|
@ -371,7 +371,7 @@ cmNinjaTargetGenerator
|
|||
mf->GetSafeDefinition("CMAKE_C_COMPILER") :
|
||||
mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
|
||||
cldeps = "\"";
|
||||
cldeps += mf->GetSafeDefinition("CMAKE_CMCLDEPS_EXECUTABLE");
|
||||
cldeps += cmSystemTools::GetCMClDepsCommand();
|
||||
cldeps += "\" " + lang + " $in \"$DEP_FILE\" $out \"";
|
||||
cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
|
||||
cldeps += "\" \"" + cl + "\" ";
|
||||
|
|
|
@ -2216,6 +2216,7 @@ static std::string cmSystemToolsCTestCommand;
|
|||
static std::string cmSystemToolsCPackCommand;
|
||||
static std::string cmSystemToolsCMakeCursesCommand;
|
||||
static std::string cmSystemToolsCMakeGUICommand;
|
||||
static std::string cmSystemToolsCMClDepsCommand;
|
||||
static std::string cmSystemToolsCMakeRoot;
|
||||
void cmSystemTools::FindCMakeResources(const char* argv0)
|
||||
{
|
||||
|
@ -2308,6 +2309,13 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
|
|||
{
|
||||
cmSystemToolsCMakeCursesCommand = "";
|
||||
}
|
||||
cmSystemToolsCMClDepsCommand = exe_dir;
|
||||
cmSystemToolsCMClDepsCommand += "/cmcldeps";
|
||||
cmSystemToolsCMClDepsCommand += cmSystemTools::GetExecutableExtension();
|
||||
if(!cmSystemTools::FileExists(cmSystemToolsCMClDepsCommand.c_str()))
|
||||
{
|
||||
cmSystemToolsCMClDepsCommand = "";
|
||||
}
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
// Install tree has "<prefix>/bin/cmake" and "<prefix><CMAKE_DATA_DIR>".
|
||||
|
@ -2374,6 +2382,12 @@ std::string const& cmSystemTools::GetCMakeGUICommand()
|
|||
return cmSystemToolsCMakeGUICommand;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string const& cmSystemTools::GetCMClDepsCommand()
|
||||
{
|
||||
return cmSystemToolsCMClDepsCommand;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string const& cmSystemTools::GetCMakeRoot()
|
||||
{
|
||||
|
|
|
@ -426,6 +426,7 @@ public:
|
|||
static std::string const& GetCMakeCommand();
|
||||
static std::string const& GetCMakeGUICommand();
|
||||
static std::string const& GetCMakeCursesCommand();
|
||||
static std::string const& GetCMClDepsCommand();
|
||||
static std::string const& GetCMakeRoot();
|
||||
|
||||
/** Echo a message in color using KWSys's Terminal cprintf. */
|
||||
|
|
Loading…
Reference in New Issue