summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-12-02 14:29:09 +0000
committerKitware Robot <kwrobot@kitware.com>2020-12-02 09:29:16 -0500
commit9e76ad9ccdb304ce21354c33b6c535eb9556e38d (patch)
tree7cc9567cd7133427ad9a7de40cb5d08b15255de9
parent2b0152ce093ac041d6e68084eea01f66e5bbb3fa (diff)
parentf8d8faff8d01323d5a48a3b9be55cf9b6e10d5b4 (diff)
downloadcmake-9e76ad9ccdb304ce21354c33b6c535eb9556e38d.tar.gz
Merge topic 'ninja-deps-updates'
f8d8faff8d Ninja Generators: Homogenize configuration with Makefiles Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5557
-rw-r--r--Modules/Platform/Windows-Intel-C.cmake20
-rw-r--r--Modules/Platform/Windows-Intel-CXX.cmake22
-rw-r--r--Modules/Platform/Windows-Intel.cmake14
-rw-r--r--Modules/Platform/Windows-MSVC.cmake3
-rw-r--r--Source/cmNinjaTargetGenerator.cxx64
-rw-r--r--Source/cmNinjaTargetGenerator.h2
6 files changed, 78 insertions, 47 deletions
diff --git a/Modules/Platform/Windows-Intel-C.cmake b/Modules/Platform/Windows-Intel-C.cmake
index 3cbc7a5206..152b27c30d 100644
--- a/Modules/Platform/Windows-Intel-C.cmake
+++ b/Modules/Platform/Windows-Intel-C.cmake
@@ -1,11 +1,27 @@
include(Platform/Windows-Intel)
__windows_compiler_intel(C)
-set(CMAKE_NINJA_DEPTYPE_C intel) # special value handled by CMake
+
set(CMAKE_DEPFILE_FLAGS_C "-QMMD -QMT <DEP_TARGET> -QMF <DEP_FILE>")
+set(CMAKE_C_DEPFILE_FORMAT gcc)
+
+if(CMAKE_GENERATOR MATCHES "^Ninja")
+ if(_CMAKE_NINJA_VERSION VERSION_LESS 1.9)
+ # This ninja version is too old to support the Intel depfile format.
+ # Fall back to msvc depfile format.
+ set(CMAKE_DEPFILE_FLAGS_C "/showIncludes")
+ set(CMAKE_C_DEPFILE_FORMAT msvc)
+ endif()
+endif()
if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
AND CMAKE_GENERATOR MATCHES "Makefiles|WMake")
# dependencies are computed by the compiler itself
- set(CMAKE_C_DEPFILE_FORMAT gcc)
set(CMAKE_C_DEPENDS_USE_COMPILER TRUE)
endif()
+
+if("${CMAKE_SOURCE_DIR}${CMAKE_BINARY_DIR}" MATCHES " ")
+ # The Intel compiler does not properly escape spaces in a depfile.
+ # Fall back to msvc depfile format.
+ set(CMAKE_DEPFILE_FLAGS_C "/showIncludes")
+ set(CMAKE_C_DEPFILE_FORMAT msvc)
+endif()
diff --git a/Modules/Platform/Windows-Intel-CXX.cmake b/Modules/Platform/Windows-Intel-CXX.cmake
index 6539f6496c..ce33ae186a 100644
--- a/Modules/Platform/Windows-Intel-CXX.cmake
+++ b/Modules/Platform/Windows-Intel-CXX.cmake
@@ -1,12 +1,28 @@
include(Platform/Windows-Intel)
set(_COMPILE_CXX " /TP")
__windows_compiler_intel(CXX)
-set(CMAKE_NINJA_DEPTYPE_CXX intel) # special value handled by CMake
+
set(CMAKE_DEPFILE_FLAGS_CXX "-QMMD -QMT <DEP_TARGET> -QMF <DEP_FILE>")
+set(CMAKE_CXX_DEPFILE_FORMAT gcc)
+
+if(CMAKE_GENERATOR MATCHES "^Ninja")
+ if(_CMAKE_NINJA_VERSION VERSION_LESS 1.9)
+ # This ninja version is too old to support the Intel depfile format.
+ # Fall back to msvc depfile format.
+ set(CMAKE_DEPFILE_FLAGS_CXX "/showIncludes")
+ set(CMAKE_CXX_DEPFILE_FORMAT msvc)
+ endif()
+endif()
if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
AND CMAKE_GENERATOR MATCHES "Makefiles|WMake")
# dependencies are computed by the compiler itself
- set(CMAKE_CXX_DEPFILE_FORMAT gcc)
- set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE)
+ set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE)
+endif()
+
+if("${CMAKE_SOURCE_DIR}${CMAKE_BINARY_DIR}" MATCHES " ")
+ # The Intel compiler does not properly escape spaces in a depfile.
+ # Fall back to msvc depfile format.
+ set(CMAKE_DEPFILE_FLAGS_CXX "/showIncludes")
+ set(CMAKE_CXX_DEPFILE_FORMAT msvc)
endif()
diff --git a/Modules/Platform/Windows-Intel.cmake b/Modules/Platform/Windows-Intel.cmake
index 5d8f7fc35f..01f8dd0b15 100644
--- a/Modules/Platform/Windows-Intel.cmake
+++ b/Modules/Platform/Windows-Intel.cmake
@@ -8,6 +8,20 @@ if(__WINDOWS_INTEL)
endif()
set(__WINDOWS_INTEL 1)
+
+if (CMAKE_GENERATOR MATCHES "^Ninja")
+ # retrieve ninja version to enable dependencies configuration
+ # against Ninja capabilities
+ execute_process(COMMAND "${CMAKE_MAKE_PROGRAM}" --version
+ RESULT_VARIABLE _CMAKE_NINJA_RESULT
+ OUTPUT_VARIABLE _CMAKE_NINJA_VERSION
+ ERROR_VARIABLE _CMAKE_NINJA_VERSION)
+ if (NOT _CMAKE_NINJA_RESULT AND _CMAKE_NINJA_VERSION MATCHES "[0-9]+(\\.[0-9]+)*")
+ set (_CMAKE_NINJA_VERSION "${CMAKE_MATCH_0}")
+ endif()
+ unset(_CMAKE_NINJA_RESULT)
+endif()
+
include(Platform/Windows-MSVC)
macro(__windows_compiler_intel lang)
__windows_compiler_msvc(${lang})
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index ec5758cc7a..08afd6124e 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -435,11 +435,10 @@ macro(__windows_compiler_msvc lang)
set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -MDd)
endif()
set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON)
- set(CMAKE_NINJA_DEPTYPE_${lang} msvc)
+
__windows_compiler_msvc_enable_rc("${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_${lang}}")
# define generic information about compiler dependencies
- # activation is done on per language platform configuration basis
if (MSVC_VERSION GREATER 1300)
set(CMAKE_DEPFILE_FLAGS_${lang} "/showIncludes")
set(CMAKE_${lang}_DEPFILE_FORMAT msvc)
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 4ac08e0593..99f1b45247 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -12,7 +12,9 @@
#include <utility>
#include <cm/memory>
+#include <cm/string_view>
#include <cmext/algorithm>
+#include <cmext/string_view>
#include <cm3p/json/value.h>
#include <cm3p/json/writer.h>
@@ -245,32 +247,6 @@ void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
}
-bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
-{
- std::string const& deptype = this->GetMakefile()->GetSafeDefinition(
- cmStrCat("CMAKE_NINJA_DEPTYPE_", lang));
- if (deptype == "msvc") {
- return true;
- }
- if (deptype == "intel") {
- // Ninja does not really define "intel", but we use it to switch based
- // on whether this environment supports "gcc" or "msvc" deptype.
- if (!this->GetGlobalGenerator()->SupportsMultilineDepfile()) {
- // This ninja version is too old to support the Intel depfile format.
- // Fall back to msvc deptype.
- return true;
- }
- if ((this->Makefile->GetHomeDirectory().find(' ') != std::string::npos) ||
- (this->Makefile->GetHomeOutputDirectory().find(' ') !=
- std::string::npos)) {
- // The Intel compiler does not properly escape spaces in a depfile.
- // Fall back to msvc deptype.
- return true;
- }
- }
- return false;
-}
-
// TODO: Refactor with
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
@@ -727,10 +703,6 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
std::string cldeps;
if (!compilationPreprocesses) {
// The compiler will not do preprocessing, so it has no such dependencies.
- } else if (this->NeedDepTypeMSVC(lang)) {
- rule.DepType = "msvc";
- rule.DepFile.clear();
- flags += " /showIncludes";
} else if (mf->IsOn(cmStrCat("CMAKE_NINJA_CMCLDEPS_", lang))) {
// For the MS resource compiler we need cmcldeps, but skip dependencies
// for source-file try_compile cases because they are always fresh.
@@ -746,16 +718,23 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
"\" \"", cl, "\" ");
}
} else {
- rule.DepType = "gcc";
- rule.DepFile = "$DEP_FILE";
+ const auto& depType = this->GetMakefile()->GetSafeDefinition(
+ cmStrCat("CMAKE_", lang, "_DEPFILE_FORMAT"));
+ if (depType == "msvc"_s) {
+ rule.DepType = "msvc";
+ rule.DepFile.clear();
+ } else {
+ rule.DepType = "gcc";
+ rule.DepFile = "$DEP_FILE";
+ }
+ vars.DependencyFile = rule.DepFile.c_str();
+ vars.DependencyTarget = "$out";
+
const std::string flagsName = cmStrCat("CMAKE_DEPFILE_FLAGS_", lang);
std::string depfileFlags = mf->GetSafeDefinition(flagsName);
if (!depfileFlags.empty()) {
- cmSystemTools::ReplaceString(depfileFlags, "<DEP_FILE>", "$DEP_FILE");
- cmSystemTools::ReplaceString(depfileFlags, "<DEP_TARGET>", "$out");
- cmSystemTools::ReplaceString(
- depfileFlags, "<CMAKE_C_COMPILER>",
- cmToCStr(mf->GetDefinition("CMAKE_C_COMPILER")));
+ rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
+ depfileFlags, vars);
flags += cmStrCat(' ', depfileFlags);
}
}
@@ -875,6 +854,14 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
compileCmds.front().insert(0, cldeps);
}
+ const auto& extraCommands = this->GetMakefile()->GetSafeDefinition(
+ cmStrCat("CMAKE_", lang, "_DEPENDS_EXTRA_COMMANDS"));
+ if (!extraCommands.empty()) {
+ auto commandList = cmExpandedList(extraCommands);
+ compileCmds.insert(compileCmds.end(), commandList.cbegin(),
+ commandList.cend());
+ }
+
for (std::string& i : compileCmds) {
i = cmStrCat(launcher, i);
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
@@ -1161,7 +1148,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
vars["DEFINES"] = this->ComputeDefines(source, language, config);
vars["INCLUDES"] = this->ComputeIncludes(source, language, config);
- if (!this->NeedDepTypeMSVC(language)) {
+ if (this->GetMakefile()->GetSafeDefinition(
+ cmStrCat("CMAKE_", language, "_DEPFILE_FORMAT")) != "msvc"_s) {
bool replaceExt(false);
if (!language.empty()) {
std::string repVar =
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index 4ba37ad03c..83a434240b 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -42,8 +42,6 @@ public:
std::string GetTargetName() const;
- bool NeedDepTypeMSVC(const std::string& lang) const;
-
protected:
bool SetMsvcTargetPdbVariable(cmNinjaVars&, const std::string& config) const;