summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-09-21 13:25:27 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-09-21 13:25:27 (GMT)
commit4f640afc1aa571a4a1a9083b62e3d2787db84bf3 (patch)
tree3c5cf71b90f4ebd92524f17949f01872fdb07473
parent82a0c7be3f6a00119f3ba00b0d1a4f73cbbb140c (diff)
parent109a7a245acf0c367ac092f6c9a20661e7a31529 (diff)
downloadCMake-4f640afc1aa571a4a1a9083b62e3d2787db84bf3.zip
CMake-4f640afc1aa571a4a1a9083b62e3d2787db84bf3.tar.gz
CMake-4f640afc1aa571a4a1a9083b62e3d2787db84bf3.tar.bz2
Merge topic 'ninja-refactor-msvc-deps'
109a7a24 Ninja: Detect MSVC /showIncludes prefix with compiler flags (#15596) 828c05b9 Ninja: Refactor lookup of cmcldeps location c73fbda6 CMakeDetermineCompilerId: Drop unused code path
-rw-r--r--Modules/CMakeCCompiler.cmake.in8
-rw-r--r--Modules/CMakeCXXCompiler.cmake.in8
-rw-r--r--Modules/CMakeClDeps.cmake34
-rw-r--r--Modules/CMakeDetermineCCompiler.cmake1
-rw-r--r--Modules/CMakeDetermineCXXCompiler.cmake1
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake65
-rw-r--r--Source/cmNinjaTargetGenerator.cxx2
-rw-r--r--Source/cmSystemTools.cxx14
-rw-r--r--Source/cmSystemTools.h1
9 files changed, 68 insertions, 66 deletions
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in
index 2ad2f34..c72e338 100644
--- a/Modules/CMakeCCompiler.cmake.in
+++ b/Modules/CMakeCCompiler.cmake.in
@@ -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@
diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in
index c6582a7..52e44f6 100644
--- a/Modules/CMakeCXXCompiler.cmake.in
+++ b/Modules/CMakeCXXCompiler.cmake.in
@@ -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@
diff --git a/Modules/CMakeClDeps.cmake b/Modules/CMakeClDeps.cmake
deleted file mode 100644
index b46e7c2..0000000
--- a/Modules/CMakeClDeps.cmake
+++ /dev/null
@@ -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()
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index 9bd1d67..4b0d278 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -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()
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index f25a2db..680356d 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -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()
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 81f4ae6..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)
@@ -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()
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 752c8a7..f46c5b9 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -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 + "\" ";
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 005a803..2675066 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -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>".
@@ -2375,6 +2383,12 @@ std::string const& cmSystemTools::GetCMakeGUICommand()
}
//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCMClDepsCommand()
+{
+ return cmSystemToolsCMClDepsCommand;
+}
+
+//----------------------------------------------------------------------------
std::string const& cmSystemTools::GetCMakeRoot()
{
return cmSystemToolsCMakeRoot;
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index d14897f..e88170a 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -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. */