summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CMakeLists.txt3
-rw-r--r--Source/CMakeVersion.cmake2
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.cxx182
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.h4
-rw-r--r--Source/CTest/cmCTestScriptHandler.cxx7
-rw-r--r--Source/Modules/CheckCXXLinkerFlag.cmake29
-rw-r--r--Source/bindexplib.cxx53
-rw-r--r--Source/cmAlgorithms.h8
-rw-r--r--Source/cmCommands.cxx4
-rw-r--r--Source/cmCommonTargetGenerator.cxx76
-rw-r--r--Source/cmCommonTargetGenerator.h40
-rw-r--r--Source/cmComputeTargetDepends.cxx5
-rw-r--r--Source/cmCustomCommandGenerator.cxx8
-rw-r--r--Source/cmExportTryCompileFileGenerator.cxx3
-rw-r--r--Source/cmExtraCodeLiteGenerator.cxx5
-rw-r--r--Source/cmExtraEclipseCDT4Generator.cxx38
-rw-r--r--Source/cmExtraEclipseCDT4Generator.h2
-rw-r--r--Source/cmExtraKateGenerator.cxx38
-rw-r--r--Source/cmExtraKateGenerator.h8
-rw-r--r--Source/cmFileAPICMakeFiles.cxx3
-rw-r--r--Source/cmFileAPICodemodel.cxx8
-rw-r--r--Source/cmForEachCommand.cxx275
-rw-r--r--Source/cmFunctionCommand.cxx78
-rw-r--r--Source/cmGeneratorExpression.cxx10
-rw-r--r--Source/cmGeneratorExpression.h2
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx21
-rw-r--r--Source/cmGeneratorExpressionEvaluator.h16
-rw-r--r--Source/cmGeneratorExpressionParser.cxx64
-rw-r--r--Source/cmGeneratorExpressionParser.h10
-rw-r--r--Source/cmGeneratorTarget.cxx54
-rw-r--r--Source/cmGeneratorTarget.h7
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.cxx13
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.h4
-rw-r--r--Source/cmGlobalCommonGenerator.cxx4
-rw-r--r--Source/cmGlobalGenerator.cxx83
-rw-r--r--Source/cmGlobalGenerator.h18
-rw-r--r--Source/cmGlobalGhsMultiGenerator.cxx9
-rw-r--r--Source/cmGlobalGhsMultiGenerator.h4
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx645
-rw-r--r--Source/cmGlobalNinjaGenerator.h197
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.cxx263
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.h13
-rw-r--r--Source/cmGlobalVisualStudio10Generator.cxx9
-rw-r--r--Source/cmGlobalVisualStudio10Generator.h5
-rw-r--r--Source/cmGlobalVisualStudio7Generator.cxx13
-rw-r--r--Source/cmGlobalVisualStudio7Generator.h5
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx32
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.cxx23
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx8
-rw-r--r--Source/cmGlobalXCodeGenerator.h4
-rw-r--r--Source/cmGraphVizWriter.cxx2
-rw-r--r--Source/cmLinkLineComputer.cxx30
-rw-r--r--Source/cmLinkLineComputer.h2
-rw-r--r--Source/cmLocalCommonGenerator.cxx10
-rw-r--r--Source/cmLocalCommonGenerator.h8
-rw-r--r--Source/cmLocalGenerator.cxx59
-rw-r--r--Source/cmLocalGenerator.h1
-rw-r--r--Source/cmLocalNinjaGenerator.cxx139
-rw-r--r--Source/cmLocalNinjaGenerator.h24
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx25
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.h2
-rw-r--r--Source/cmMakefile.cxx224
-rw-r--r--Source/cmMakefile.h12
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx55
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx92
-rw-r--r--Source/cmMakefileTargetGenerator.cxx123
-rw-r--r--Source/cmMakefileTargetGenerator.h8
-rw-r--r--Source/cmMakefileUtilityTargetGenerator.cxx3
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx465
-rw-r--r--Source/cmNinjaNormalTargetGenerator.h25
-rw-r--r--Source/cmNinjaTargetGenerator.cxx324
-rw-r--r--Source/cmNinjaTargetGenerator.h104
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.cxx51
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.h4
-rw-r--r--Source/cmOSXBundleGenerator.cxx71
-rw-r--r--Source/cmOSXBundleGenerator.h21
-rw-r--r--Source/cmOutputConverter.cxx23
-rw-r--r--Source/cmOutputConverter.h9
-rw-r--r--Source/cmPolicies.h9
-rw-r--r--Source/cmQtAutoGenGlobalInitializer.cxx8
-rw-r--r--Source/cmQtAutoGenGlobalInitializer.h2
-rw-r--r--Source/cmQtAutoGenInitializer.cxx13
-rw-r--r--Source/cmState.cxx13
-rw-r--r--Source/cmState.h3
-rw-r--r--Source/cmTarget.cxx9
-rw-r--r--Source/cmTarget.h3
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx5
-rw-r--r--Source/cmake.cxx5
-rw-r--r--Source/cmake.h7
-rw-r--r--Source/cmcmd.cxx17
90 files changed, 3035 insertions, 1390 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index d050fb7..ff313d6 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -693,6 +693,8 @@ set(SRCS
cmDuration.h
cmDuration.cxx
+
+ bindexplib.cxx
)
SET_PROPERTY(SOURCE cmProcessOutput.cxx APPEND PROPERTY COMPILE_DEFINITIONS
@@ -715,7 +717,6 @@ if (WIN32)
set(SRCS ${SRCS}
cmCallVisualStudioMacro.cxx
cmCallVisualStudioMacro.h
- bindexplib.cxx
)
if(NOT UNIX)
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index cdd0893..88afed4 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,7 +1,7 @@
# CMake version number components.
set(CMake_VERSION_MAJOR 3)
set(CMake_VERSION_MINOR 16)
-set(CMake_VERSION_PATCH 20191209)
+set(CMake_VERSION_PATCH 20191217)
#set(CMake_VERSION_RC 0)
set(CMake_VERSION_IS_DIRTY 0)
diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx
index a5ec1ae..c1ecaf1 100644
--- a/Source/CTest/cmCTestMemCheckHandler.cxx
+++ b/Source/CTest/cmCTestMemCheckHandler.cxx
@@ -2,9 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestMemCheckHandler.h"
+#include <algorithm>
#include <chrono>
#include <cstring>
#include <iostream>
+#include <iterator>
#include <sstream>
#include <utility>
@@ -12,6 +14,7 @@
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmDuration.h"
#include "cmSystemTools.h"
@@ -162,12 +165,13 @@ int cmCTestMemCheckHandler::PostProcessHandler()
void cmCTestMemCheckHandler::GenerateTestCommand(
std::vector<std::string>& args, int test)
{
- std::string index;
- std::ostringstream stream;
+ std::string index = std::to_string(test);
std::string memcheckcommand =
cmSystemTools::ConvertToOutputPath(this->MemoryTester);
- stream << test;
- index = stream.str();
+
+ std::vector<std::string> dirs;
+ bool nextArgIsDir = false;
+
for (std::string arg : this->MemoryTesterDynamicOptions) {
std::string::size_type pos = arg.find("??");
if (pos != std::string::npos) {
@@ -177,6 +181,16 @@ void cmCTestMemCheckHandler::GenerateTestCommand(
memcheckcommand += " \"";
memcheckcommand += arg;
memcheckcommand += "\"";
+
+ if (nextArgIsDir) {
+ nextArgIsDir = false;
+ dirs.push_back(arg);
+ }
+
+ if (this->MemoryTesterStyle == cmCTestMemCheckHandler::DRMEMORY &&
+ (arg == "-logdir" || arg == "-symcache_dir")) {
+ nextArgIsDir = true;
+ }
}
// Create a copy of the memory tester environment variable.
// This is used for memory testing programs that pass options
@@ -208,6 +222,11 @@ void cmCTestMemCheckHandler::GenerateTestCommand(
memcheckcommand += " " + memTesterEnvironmentVariable;
args.push_back(memTesterEnvironmentVariable);
}
+
+ for (std::string const& dir : dirs) {
+ cmSystemTools::MakeDirectory(dir);
+ }
+
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Memory check command: " << memcheckcommand << std::endl,
this->Quiet);
@@ -300,6 +319,9 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
case cmCTestMemCheckHandler::VALGRIND:
xml.Attribute("Checker", "Valgrind");
break;
+ case cmCTestMemCheckHandler::DRMEMORY:
+ xml.Attribute("Checker", "DrMemory");
+ break;
case cmCTestMemCheckHandler::PURIFY:
xml.Attribute("Checker", "Purify");
break;
@@ -387,11 +409,11 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"MemCheck log files can be found here: "
- "( * corresponds to test number)"
+ "(<#> corresponds to test number)"
<< std::endl,
this->Quiet);
std::string output = this->MemoryTesterOutputFile;
- cmSystemTools::ReplaceString(output, "??", "*");
+ cmSystemTools::ReplaceString(output, "??", "<#>");
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, output << std::endl,
this->Quiet);
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
@@ -437,6 +459,10 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
if (testerName.find("valgrind") != std::string::npos ||
this->CTest->GetCTestConfiguration("MemoryCheckType") == "Valgrind") {
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
+ } else if (testerName.find("drmemory") != std::string::npos ||
+ this->CTest->GetCTestConfiguration("MemoryCheckType") ==
+ "DrMemory") {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::DRMEMORY;
} else if (testerName.find("purify") != std::string::npos) {
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
} else if (testerName.find("BC") != std::string::npos) {
@@ -453,6 +479,10 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->MemoryTester = this->CTest->GetCTestConfiguration("ValgrindCommand");
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
} else if (cmSystemTools::FileExists(
+ this->CTest->GetCTestConfiguration("DrMemoryCommand"))) {
+ this->MemoryTester = this->CTest->GetCTestConfiguration("DrMemoryCommand");
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::DRMEMORY;
+ } else if (cmSystemTools::FileExists(
this->CTest->GetCTestConfiguration("BoundsCheckerCommand"))) {
this->MemoryTester =
this->CTest->GetCTestConfiguration("BoundsCheckerCommand");
@@ -498,6 +528,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
} else if (checkType == "Valgrind") {
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
+ } else if (checkType == "DrMemory") {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::DRMEMORY;
}
}
if (this->MemoryTester.empty()) {
@@ -519,6 +551,10 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
.empty()) {
memoryTesterOptions =
this->CTest->GetCTestConfiguration("ValgrindCommandOptions");
+ } else if (!this->CTest->GetCTestConfiguration("DrMemoryCommandOptions")
+ .empty()) {
+ memoryTesterOptions =
+ this->CTest->GetCTestConfiguration("DrMemoryCommandOptions");
}
this->MemoryTesterOptions =
cmSystemTools::ParseArguments(memoryTesterOptions);
@@ -554,6 +590,64 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->MemoryTesterOutputFile);
break;
}
+ case cmCTestMemCheckHandler::DRMEMORY: {
+ std::string tempDrMemoryDir =
+ this->CTest->GetBinaryDir() + "/Testing/Temporary/DrMemory";
+
+ if (!cmContains(this->MemoryTesterOptions, "-quiet")) {
+ this->MemoryTesterOptions.emplace_back("-quiet");
+ }
+
+ if (!cmContains(this->MemoryTesterOptions, "-batch")) {
+ this->MemoryTesterOptions.emplace_back("-batch");
+ }
+
+ this->MemoryTesterDynamicOptions.emplace_back("-logdir");
+ auto logdirOption =
+ std::find(this->MemoryTesterOptions.begin(),
+ this->MemoryTesterOptions.end(), "-logdir");
+ if (logdirOption == this->MemoryTesterOptions.end()) {
+ // No logdir found in memory tester options
+ std::string drMemoryLogDir = tempDrMemoryDir + "/??";
+ this->MemoryTesterDynamicOptions.push_back(drMemoryLogDir);
+ this->MemoryTesterOutputFile = drMemoryLogDir;
+ } else {
+ // Use logdir found in memory tester options
+ auto logdirLocation = std::next(logdirOption);
+ this->MemoryTesterOutputFile = *logdirLocation;
+ this->MemoryTesterDynamicOptions.push_back(*logdirLocation);
+ this->MemoryTesterOptions.erase(logdirOption, logdirLocation + 1);
+ }
+ this->MemoryTesterOutputFile += "/*/results.txt";
+
+ if (std::find(this->MemoryTesterOptions.begin(),
+ this->MemoryTesterOptions.end(),
+ "-symcache_dir") == this->MemoryTesterOptions.end()) {
+ this->MemoryTesterDynamicOptions.emplace_back("-symcache_dir");
+ std::string drMemoryCacheDir = tempDrMemoryDir + "/cache";
+ this->MemoryTesterDynamicOptions.push_back(drMemoryCacheDir);
+ }
+
+ if (!this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
+ .empty()) {
+ if (!cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile"))) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find memory checker suppression file: "
+ << this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile")
+ << std::endl);
+ return false;
+ }
+ this->MemoryTesterOptions.emplace_back("-suppress");
+ this->MemoryTesterOptions.push_back(
+ this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile"));
+ }
+
+ this->MemoryTesterOptions.emplace_back("--");
+
+ break;
+ }
case cmCTestMemCheckHandler::PURIFY: {
std::string outputFile;
#ifdef _WIN32
@@ -667,6 +761,8 @@ bool cmCTestMemCheckHandler::ProcessMemCheckOutput(const std::string& str,
switch (this->MemoryTesterStyle) {
case cmCTestMemCheckHandler::VALGRIND:
return this->ProcessMemCheckValgrindOutput(str, log, results);
+ case cmCTestMemCheckHandler::DRMEMORY:
+ return this->ProcessMemCheckDrMemoryOutput(str, log, results);
case cmCTestMemCheckHandler::PURIFY:
return this->ProcessMemCheckPurifyOutput(str, log, results);
case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
@@ -932,6 +1028,47 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
return defects == 0;
}
+bool cmCTestMemCheckHandler::ProcessMemCheckDrMemoryOutput(
+ const std::string& str, std::string& log, std::vector<int>& results)
+{
+ std::vector<std::string> lines;
+ cmsys::SystemTools::Split(str, lines);
+
+ cmsys::RegularExpression drMemoryError("^Error #[0-9]+");
+
+ cmsys::RegularExpression unaddressableAccess("UNADDRESSABLE ACCESS");
+ cmsys::RegularExpression uninitializedRead("UNINITIALIZED READ");
+ cmsys::RegularExpression invalidHeapArgument("INVALID HEAP ARGUMENT");
+ cmsys::RegularExpression leak("LEAK");
+ cmsys::RegularExpression handleLeak("HANDLE LEAK");
+
+ int defects = 0;
+
+ std::ostringstream ostr;
+ for (const auto& l : lines) {
+ ostr << l << std::endl;
+ if (drMemoryError.find(l)) {
+ defects++;
+ if (unaddressableAccess.find(l)) {
+ results[cmCTestMemCheckHandler::UMR]++;
+ } else if (uninitializedRead.find(l)) {
+ results[cmCTestMemCheckHandler::UMR]++;
+ } else if (leak.find(l)) {
+ results[cmCTestMemCheckHandler::MLK]++;
+ } else if (handleLeak.find(l)) {
+ results[cmCTestMemCheckHandler::MLK]++;
+ } else if (invalidHeapArgument.find(l)) {
+ results[cmCTestMemCheckHandler::FMM]++;
+ }
+ }
+ }
+
+ log = ostr.str();
+
+ this->DefectCount += defects;
+ return defects == 0;
+}
+
bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
const std::string& str, std::string& log, std::vector<int>& results)
{
@@ -991,6 +1128,8 @@ void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int test)
this->Quiet);
if (this->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER) {
this->PostProcessBoundsCheckerTest(res, test);
+ } else if (this->MemoryTesterStyle == cmCTestMemCheckHandler::DRMEMORY) {
+ this->PostProcessDrMemoryTest(res, test);
} else {
std::vector<std::string> files;
this->TestOutputFileNames(test, files);
@@ -1045,6 +1184,37 @@ void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(
this->Quiet);
}
+void cmCTestMemCheckHandler::PostProcessDrMemoryTest(
+ cmCTestTestHandler::cmCTestTestResult& res, int test)
+{
+ std::string drMemoryLogDir = this->MemoryTesterOutputFile.substr(
+ 0, this->MemoryTesterOutputFile.find("/*/results.txt"));
+
+ // replace placeholder of test
+ std::string::size_type pos = drMemoryLogDir.find("??");
+ if (pos != std::string::npos) {
+ drMemoryLogDir.replace(pos, 2, std::to_string(test));
+ }
+
+ cmsys::Glob g;
+ g.FindFiles(drMemoryLogDir + "/resfile.*");
+ const std::vector<std::string>& files = g.GetFiles();
+
+ for (const std::string& f : files) {
+ cmsys::ifstream ifs(f.c_str());
+ if (!ifs) {
+ std::string log = "Cannot read memory tester output file: " + f;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
+ return;
+ }
+ std::string resultFileLocation;
+ cmSystemTools::GetLineFromStream(ifs, resultFileLocation);
+ this->AppendMemTesterOutput(res, resultFileLocation);
+ ifs.close();
+ cmSystemTools::RemoveFile(f);
+ }
+}
+
void cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res,
std::string const& ofile)
{
diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h
index eda65f7..52667f8 100644
--- a/Source/CTest/cmCTestMemCheckHandler.h
+++ b/Source/CTest/cmCTestMemCheckHandler.h
@@ -43,6 +43,7 @@ private:
UNKNOWN = 0,
VALGRIND,
PURIFY,
+ DRMEMORY,
BOUNDS_CHECKER,
// checkers after here do not use the standard error list
ADDRESS_SANITIZER,
@@ -132,6 +133,8 @@ private:
std::vector<int>& results);
bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
std::vector<int>& results);
+ bool ProcessMemCheckDrMemoryOutput(const std::string& str, std::string& log,
+ std::vector<int>& results);
bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log,
std::vector<int>& results);
bool ProcessMemCheckSanitizerOutput(const std::string& str, std::string& log,
@@ -142,6 +145,7 @@ private:
void PostProcessTest(cmCTestTestResult& res, int test);
void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
+ void PostProcessDrMemoryTest(cmCTestTestResult& res, int test);
//! append MemoryTesterOutputFile to the test log
void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index 60facbd..7803e37 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -340,6 +340,13 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
this->SetRunCurrentScript(true);
this->UpdateElapsedTime();
+ // set the CTEST_CONFIGURATION_TYPE variable to the current value of the
+ // the -C argument on the command line.
+ if (!this->CTest->GetConfigType().empty()) {
+ this->Makefile->AddDefinition("CTEST_CONFIGURATION_TYPE",
+ this->CTest->GetConfigType());
+ }
+
// add the script arg if defined
if (!script_arg.empty()) {
this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg);
diff --git a/Source/Modules/CheckCXXLinkerFlag.cmake b/Source/Modules/CheckCXXLinkerFlag.cmake
new file mode 100644
index 0000000..6cb1ba3
--- /dev/null
+++ b/Source/Modules/CheckCXXLinkerFlag.cmake
@@ -0,0 +1,29 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+include_guard(GLOBAL)
+include(CheckCXXSourceCompiles)
+include(CMakeCheckCompilerFlagCommonPatterns)
+
+function(check_cxx_linker_flag _flag _var)
+ if(CMAKE_VERSION VERSION_LESS "3.14")
+ set(CMAKE_REQUIRED_LIBRARIES "${_flag}")
+ else()
+ set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}")
+ endif()
+
+ # Normalize locale during test compilation.
+ set(_locale_vars LC_ALL LC_MESSAGES LANG)
+ foreach(v IN LISTS _locale_vars)
+ set(_locale_vars_saved_${v} "$ENV{${v}}")
+ set(ENV{${v}} C)
+ endforeach()
+ check_compiler_flag_common_patterns(_common_patterns)
+ check_cxx_source_compiles("int main() { return 0; }" ${_var}
+ ${_common_patterns}
+ )
+ foreach(v IN LISTS _locale_vars)
+ set(ENV{${v}} ${_locale_vars_saved_${v}})
+ endforeach()
+ set(${_var} "${${_var}}" PARENT_SCOPE)
+endfunction()
diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx
index b85cc33..0b2750d 100644
--- a/Source/bindexplib.cxx
+++ b/Source/bindexplib.cxx
@@ -64,32 +64,36 @@
*/
#include "bindexplib.h"
-#include <iostream>
+#include <cstddef>
#include <sstream>
#include <vector>
-#include <windows.h>
+#ifdef _WIN32
+# include <windows.h>
+
+# include "cmsys/Encoding.hxx"
+#endif
-#include "cmsys/Encoding.hxx"
#include "cmsys/FStream.hxx"
#include "cmSystemTools.h"
-#ifndef IMAGE_FILE_MACHINE_ARM
-# define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
-#endif
+#ifdef _WIN32
+# ifndef IMAGE_FILE_MACHINE_ARM
+# define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
+# endif
-#ifndef IMAGE_FILE_MACHINE_THUMB
-# define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian
-#endif
+# ifndef IMAGE_FILE_MACHINE_THUMB
+# define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian
+# endif
-#ifndef IMAGE_FILE_MACHINE_ARMNT
-# define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
-#endif
+# ifndef IMAGE_FILE_MACHINE_ARMNT
+# define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
+# endif
-#ifndef IMAGE_FILE_MACHINE_ARM64
-# define IMAGE_FILE_MACHINE_ARM64 0xaa64 // ARM64 Little-Endian
-#endif
+# ifndef IMAGE_FILE_MACHINE_ARM64
+# define IMAGE_FILE_MACHINE_ARM64 0xaa64 // ARM64 Little-Endian
+# endif
typedef struct cmANON_OBJECT_HEADER_BIGOBJ
{
@@ -306,6 +310,7 @@ private:
SymbolTableType* SymbolTable;
bool IsI386;
};
+#endif
bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename,
std::set<std::string>& symbols,
@@ -315,15 +320,15 @@ bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename,
// break up command line into a vector
std::vector<std::string> command;
command.push_back(nmPath);
- command.push_back("--no-weak");
- command.push_back("--defined-only");
- command.push_back("--format=posix");
- command.push_back(filename);
+ command.emplace_back("--no-weak");
+ command.emplace_back("--defined-only");
+ command.emplace_back("--format=posix");
+ command.emplace_back(filename);
// run the command
int exit_code = 0;
- cmSystemTools::RunSingleCommand(command, &output, &output, &exit_code, "",
- cmSystemTools::OUTPUT_NONE);
+ cmSystemTools::RunSingleCommand(command, &output, &output, &exit_code,
+ nullptr, cmSystemTools::OUTPUT_NONE);
if (exit_code != 0) {
fprintf(stderr, "llvm-nm returned an error: %s\n", output.c_str());
@@ -336,7 +341,7 @@ bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename,
if (line.empty()) { // last line
continue;
}
- size_t sym_end = line.find(" ");
+ size_t sym_end = line.find(' ');
if (sym_end == std::string::npos) {
fprintf(stderr, "Couldn't parse llvm-nm output line: %s\n",
line.c_str());
@@ -366,6 +371,9 @@ bool DumpFile(std::string const& nmPath, const char* filename,
std::set<std::string>& symbols,
std::set<std::string>& dataSymbols)
{
+#ifndef _WIN32
+ return DumpFileWithLlvmNm(nmPath, filename, symbols, dataSymbols);
+#else
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
@@ -446,6 +454,7 @@ bool DumpFile(std::string const& nmPath, const char* filename,
CloseHandle(hFileMapping);
CloseHandle(hFile);
return true;
+#endif
}
bool bindexplib::AddObjectFile(const char* filename)
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index e83f160..def3ac7 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -146,6 +146,14 @@ void cmDeleteAll(Range const& r)
}
template <typename T>
+void cmAppend(std::vector<std::unique_ptr<T>>& v,
+ std::vector<std::unique_ptr<T>>&& r)
+{
+ std::transform(r.begin(), r.end(), std::back_inserter(v),
+ [](std::unique_ptr<T>& item) { return std::move(item); });
+}
+
+template <typename T>
void cmAppend(std::vector<T*>& v, std::vector<std::unique_ptr<T>> const& r)
{
std::transform(r.begin(), r.end(), std::back_inserter(v),
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 563e0f1..896b6a9 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -78,6 +78,7 @@
#include "cmTargetCompileOptionsCommand.h"
#include "cmTargetIncludeDirectoriesCommand.h"
#include "cmTargetLinkLibrariesCommand.h"
+#include "cmTargetLinkOptionsCommand.h"
#include "cmTargetPrecompileHeadersCommand.h"
#include "cmTargetSourcesCommand.h"
#include "cmTryCompileCommand.h"
@@ -107,7 +108,6 @@
# include "cmSourceGroupCommand.h"
# include "cmSubdirDependsCommand.h"
# include "cmTargetLinkDirectoriesCommand.h"
-# include "cmTargetLinkOptionsCommand.h"
# include "cmUseMangledMesaCommand.h"
# include "cmUtilitySourceCommand.h"
# include "cmVariableRequiresCommand.h"
@@ -257,6 +257,7 @@ void GetProjectCommands(cmState* state)
cmTargetIncludeDirectoriesCommand);
state->AddBuiltinCommand("target_link_libraries",
cmTargetLinkLibrariesCommand);
+ state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand);
state->AddBuiltinCommand("target_sources", cmTargetSourcesCommand);
state->AddBuiltinCommand("try_compile",
cm::make_unique<cmTryCompileCommand>());
@@ -277,7 +278,6 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("install_programs", cmInstallProgramsCommand);
state->AddBuiltinCommand("add_link_options", cmAddLinkOptionsCommand);
state->AddBuiltinCommand("link_libraries", cmLinkLibrariesCommand);
- state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand);
state->AddBuiltinCommand("target_link_directories",
cmTargetLinkDirectoriesCommand);
state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index 19a096b..9106e70 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -25,27 +25,29 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
, GlobalCommonGenerator(static_cast<cmGlobalCommonGenerator*>(
gt->LocalGenerator->GetGlobalGenerator()))
- , ConfigName(LocalCommonGenerator->GetConfigName())
+ , ConfigNames(LocalCommonGenerator->GetConfigNames())
{
}
cmCommonTargetGenerator::~cmCommonTargetGenerator() = default;
-std::string const& cmCommonTargetGenerator::GetConfigName() const
+std::vector<std::string> const& cmCommonTargetGenerator::GetConfigNames() const
{
- return this->ConfigName;
+ return this->ConfigNames;
}
-const char* cmCommonTargetGenerator::GetFeature(const std::string& feature)
+const char* cmCommonTargetGenerator::GetFeature(const std::string& feature,
+ const std::string& config)
{
- return this->GeneratorTarget->GetFeature(feature, this->ConfigName);
+ return this->GeneratorTarget->GetFeature(feature, config);
}
void cmCommonTargetGenerator::AddModuleDefinitionFlag(
- cmLinkLineComputer* linkLineComputer, std::string& flags)
+ cmLinkLineComputer* linkLineComputer, std::string& flags,
+ const std::string& config)
{
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName());
+ this->GeneratorTarget->GetModuleDefinitionInfo(config);
if (!mdi || mdi->DefFile.empty()) {
return;
}
@@ -94,57 +96,60 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags(
}
}
-std::string cmCommonTargetGenerator::GetFlags(const std::string& l)
+std::string cmCommonTargetGenerator::GetFlags(const std::string& l,
+ const std::string& config)
{
- auto i = this->FlagsByLanguage.find(l);
- if (i == this->FlagsByLanguage.end()) {
+ auto i = this->Configs[config].FlagsByLanguage.find(l);
+ if (i == this->Configs[config].FlagsByLanguage.end()) {
std::string flags;
- this->LocalCommonGenerator->GetTargetCompileFlags(
- this->GeneratorTarget, this->ConfigName, l, flags);
+ this->LocalCommonGenerator->GetTargetCompileFlags(this->GeneratorTarget,
+ config, l, flags);
ByLanguageMap::value_type entry(l, flags);
- i = this->FlagsByLanguage.insert(entry).first;
+ i = this->Configs[config].FlagsByLanguage.insert(entry).first;
}
return i->second;
}
-std::string cmCommonTargetGenerator::GetDefines(const std::string& l)
+std::string cmCommonTargetGenerator::GetDefines(const std::string& l,
+ const std::string& config)
{
- auto i = this->DefinesByLanguage.find(l);
- if (i == this->DefinesByLanguage.end()) {
+ auto i = this->Configs[config].DefinesByLanguage.find(l);
+ if (i == this->Configs[config].DefinesByLanguage.end()) {
std::set<std::string> defines;
- this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget,
- this->ConfigName, l, defines);
+ this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget, config,
+ l, defines);
std::string definesString;
this->LocalCommonGenerator->JoinDefines(defines, definesString, l);
ByLanguageMap::value_type entry(l, definesString);
- i = this->DefinesByLanguage.insert(entry).first;
+ i = this->Configs[config].DefinesByLanguage.insert(entry).first;
}
return i->second;
}
-std::string cmCommonTargetGenerator::GetIncludes(std::string const& l)
+std::string cmCommonTargetGenerator::GetIncludes(std::string const& l,
+ const std::string& config)
{
- auto i = this->IncludesByLanguage.find(l);
- if (i == this->IncludesByLanguage.end()) {
+ auto i = this->Configs[config].IncludesByLanguage.find(l);
+ if (i == this->Configs[config].IncludesByLanguage.end()) {
std::string includes;
- this->AddIncludeFlags(includes, l);
+ this->AddIncludeFlags(includes, l, config);
ByLanguageMap::value_type entry(l, includes);
- i = this->IncludesByLanguage.insert(entry).first;
+ i = this->Configs[config].IncludesByLanguage.insert(entry).first;
}
return i->second;
}
-std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories()
- const
+std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories(
+ const std::string& config) const
{
std::vector<std::string> dirs;
std::set<cmGeneratorTarget const*> emitted;
if (cmComputeLinkInformation* cli =
- this->GeneratorTarget->GetLinkInformation(this->ConfigName)) {
+ this->GeneratorTarget->GetLinkInformation(config)) {
cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
for (auto const& item : items) {
cmGeneratorTarget const* linkee = item.Target;
@@ -165,19 +170,24 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories()
return dirs;
}
-std::string cmCommonTargetGenerator::ComputeTargetCompilePDB() const
+std::string cmCommonTargetGenerator::ComputeTargetCompilePDB(
+ const std::string& config) const
{
std::string compilePdbPath;
if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
return compilePdbPath;
}
- compilePdbPath =
- this->GeneratorTarget->GetCompilePDBPath(this->GetConfigName());
+ compilePdbPath = this->GeneratorTarget->GetCompilePDBPath(config);
if (compilePdbPath.empty()) {
// Match VS default: `$(IntDir)vc$(PlatformToolsetVersion).pdb`.
// A trailing slash tells the toolchain to add its default file name.
- compilePdbPath = this->GeneratorTarget->GetSupportDirectory() + "/";
+ compilePdbPath = this->GeneratorTarget->GetSupportDirectory();
+ if (this->GlobalCommonGenerator->IsMultiConfig()) {
+ compilePdbPath += "/";
+ compilePdbPath += config;
+ }
+ compilePdbPath += "/";
if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
// Match VS default for static libs: `$(IntDir)$(ProjectName).pdb`.
compilePdbPath += this->GeneratorTarget->GetName();
@@ -188,10 +198,10 @@ std::string cmCommonTargetGenerator::ComputeTargetCompilePDB() const
return compilePdbPath;
}
-std::string cmCommonTargetGenerator::GetManifests()
+std::string cmCommonTargetGenerator::GetManifests(const std::string& config)
{
std::vector<cmSourceFile const*> manifest_srcs;
- this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
+ this->GeneratorTarget->GetManifests(manifest_srcs, config);
std::vector<std::string> manifests;
manifests.reserve(manifest_srcs.size());
diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h
index 17792d6..2796470 100644
--- a/Source/cmCommonTargetGenerator.h
+++ b/Source/cmCommonTargetGenerator.h
@@ -25,42 +25,50 @@ public:
cmCommonTargetGenerator(cmGeneratorTarget* gt);
virtual ~cmCommonTargetGenerator();
- std::string const& GetConfigName() const;
+ std::vector<std::string> const& GetConfigNames() const;
protected:
// Feature query methods.
- const char* GetFeature(const std::string& feature);
+ const char* GetFeature(const std::string& feature,
+ const std::string& config);
// Helper to add flag for windows .def file.
void AddModuleDefinitionFlag(cmLinkLineComputer* linkLineComputer,
- std::string& flags);
+ std::string& flags, const std::string& config);
cmGeneratorTarget* GeneratorTarget;
cmMakefile* Makefile;
cmLocalCommonGenerator* LocalCommonGenerator;
cmGlobalCommonGenerator* GlobalCommonGenerator;
- std::string ConfigName;
+ std::vector<std::string> ConfigNames;
void AppendFortranFormatFlags(std::string& flags,
cmSourceFile const& source);
- virtual void AddIncludeFlags(std::string& flags,
- std::string const& lang) = 0;
+ virtual void AddIncludeFlags(std::string& flags, std::string const& lang,
+ const std::string& config) = 0;
void AppendOSXVerFlag(std::string& flags, const std::string& lang,
const char* name, bool so);
- using ByLanguageMap = std::map<std::string, std::string>;
- std::string GetFlags(const std::string& l);
- ByLanguageMap FlagsByLanguage;
- std::string GetDefines(const std::string& l);
- ByLanguageMap DefinesByLanguage;
- std::string GetIncludes(std::string const& l);
- ByLanguageMap IncludesByLanguage;
- std::string GetManifests();
+ std::string GetFlags(const std::string& l, const std::string& config);
+ std::string GetDefines(const std::string& l, const std::string& config);
+ std::string GetIncludes(std::string const& l, const std::string& config);
+ std::string GetManifests(const std::string& config);
+
+ std::vector<std::string> GetLinkedTargetDirectories(
+ const std::string& config) const;
+ std::string ComputeTargetCompilePDB(const std::string& config) const;
- std::vector<std::string> GetLinkedTargetDirectories() const;
- std::string ComputeTargetCompilePDB() const;
+private:
+ using ByLanguageMap = std::map<std::string, std::string>;
+ struct ByConfig
+ {
+ ByLanguageMap FlagsByLanguage;
+ ByLanguageMap DefinesByLanguage;
+ ByLanguageMap IncludesByLanguage;
+ };
+ std::map<std::string, ByConfig> Configs;
};
#endif
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index c22cf4a..58ec53a 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -158,9 +158,8 @@ void cmComputeTargetDepends::GetTargetDirectDepends(cmGeneratorTarget const* t,
void cmComputeTargetDepends::CollectTargets()
{
// Collect all targets from all generators.
- std::vector<cmLocalGenerator*> const& lgens =
- this->GlobalGenerator->GetLocalGenerators();
- for (cmLocalGenerator* lgen : lgens) {
+ auto const& lgens = this->GlobalGenerator->GetLocalGenerators();
+ for (const auto& lgen : lgens) {
for (const auto& ti : lgen->GetGeneratorTargets()) {
int index = static_cast<int>(this->Targets.size());
this->TargetIndex[ti.get()] = index;
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index c1f412d..955f03b 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -201,7 +201,9 @@ void cmCustomCommandGenerator::AppendArguments(unsigned int c,
if (this->OldStyle) {
cmd += escapeForShellOldStyle(emulator[j]);
} else {
- cmd += this->LG->EscapeForShell(emulator[j], this->MakeVars);
+ cmd +=
+ this->LG->EscapeForShell(emulator[j], this->MakeVars, false, false,
+ this->MakeVars && this->LG->IsNinjaMulti());
}
}
@@ -222,7 +224,9 @@ void cmCustomCommandGenerator::AppendArguments(unsigned int c,
if (this->OldStyle) {
cmd += escapeForShellOldStyle(arg);
} else {
- cmd += this->LG->EscapeForShell(arg, this->MakeVars);
+ cmd +=
+ this->LG->EscapeForShell(arg, this->MakeVars, false, false,
+ this->MakeVars && this->LG->IsNinjaMulti());
}
}
}
diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx
index fafa51b..3df6a5c 100644
--- a/Source/cmExportTryCompileFileGenerator.cxx
+++ b/Source/cmExportTryCompileFileGenerator.cxx
@@ -70,7 +70,8 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE,
- cmTarget::VisibilityNormal, tgt->Target->GetMakefile());
+ cmTarget::VisibilityNormal, tgt->Target->GetMakefile(),
+ true);
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx
index 3557e5c..de40c77 100644
--- a/Source/cmExtraCodeLiteGenerator.cxx
+++ b/Source/cmExtraCodeLiteGenerator.cxx
@@ -117,9 +117,8 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
{
std::vector<std::string> retval;
// for each target in the workspace create a codelite project
- const std::vector<cmLocalGenerator*>& lgs =
- this->GlobalGenerator->GetLocalGenerators();
- for (cmLocalGenerator* lg : lgs) {
+ const auto& lgs = this->GlobalGenerator->GetLocalGenerators();
+ for (const auto& lg : lgs) {
for (const auto& lt : lg->GetGeneratorTargets()) {
cmStateEnums::TargetType type = lt->GetType();
std::string const& outputDir = lg->GetCurrentBinaryDirectory();
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
index cf79375..78cabce 100644
--- a/Source/cmExtraEclipseCDT4Generator.cxx
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -99,7 +99,7 @@ void cmExtraEclipseCDT4Generator::EnableLanguage(
void cmExtraEclipseCDT4Generator::Generate()
{
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+ const auto& lg = this->GlobalGenerator->GetLocalGenerators()[0];
const cmMakefile* mf = lg->GetMakefile();
std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
@@ -176,7 +176,7 @@ void cmExtraEclipseCDT4Generator::Generate()
void cmExtraEclipseCDT4Generator::CreateSettingsResourcePrefsFile()
{
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+ const auto& lg = this->GlobalGenerator->GetLocalGenerators()[0];
cmMakefile* mf = lg->GetMakefile();
const std::string filename =
@@ -199,7 +199,7 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
assert(this->HomeDirectory != this->HomeOutputDirectory);
// set up the project name: <project>-Source@<baseSourcePathName>
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+ const auto& lg = this->GlobalGenerator->GetLocalGenerators()[0];
std::string name = cmExtraEclipseCDT4Generator::GenerateProjectName(
lg->GetProjectName(), "Source",
cmExtraEclipseCDT4Generator::GetPathBasename(this->HomeDirectory));
@@ -232,9 +232,9 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
const char* envVar,
- cmLocalGenerator* lg)
+ cmLocalGenerator& lg)
{
- cmMakefile* mf = lg->GetMakefile();
+ cmMakefile* mf = lg.GetMakefile();
// get the variables from the environment and from the cache and then
// figure out which one to use:
@@ -244,7 +244,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
std::string cacheEntryName = cmStrCat("CMAKE_ECLIPSE_ENVVAR_", envVar);
const std::string* cacheValue =
- lg->GetState()->GetInitializedCacheValue(cacheEntryName);
+ lg.GetState()->GetInitializedCacheValue(cacheEntryName);
// now we have both, decide which one to use
std::string valueToUse;
@@ -257,7 +257,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
valueToUse = envVarValue;
mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
cacheEntryName.c_str(), cmStateEnums::STRING, true);
- mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
+ mf->GetCMakeInstance()->SaveCache(lg.GetBinaryDirectory());
} else if (!envVarSet && cacheValue != nullptr) {
// It is already in the cache, but not in the env, so use it from the cache
valueToUse = *cacheValue;
@@ -273,7 +273,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
cacheEntryName.c_str(), cmStateEnums::STRING,
true);
- mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
+ mf->GetCMakeInstance()->SaveCache(lg.GetBinaryDirectory());
}
}
@@ -284,7 +284,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
void cmExtraEclipseCDT4Generator::CreateProjectFile()
{
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+ const auto& lg = this->GlobalGenerator->GetLocalGenerators()[0];
cmMakefile* mf = lg->GetMakefile();
const std::string filename = this->HomeOutputDirectory + "/.project";
@@ -351,15 +351,15 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
// set vsvars32.bat environment available at CMake time,
// but not necessarily when eclipse is open
if (compilerId == "MSVC") {
- AddEnvVar(environment, "PATH", lg);
- AddEnvVar(environment, "INCLUDE", lg);
- AddEnvVar(environment, "LIB", lg);
- AddEnvVar(environment, "LIBPATH", lg);
+ AddEnvVar(environment, "PATH", *lg);
+ AddEnvVar(environment, "INCLUDE", *lg);
+ AddEnvVar(environment, "LIB", *lg);
+ AddEnvVar(environment, "LIBPATH", *lg);
} else if (compilerId == "Intel") {
// if the env.var is set, use this one and put it in the cache
// if the env.var is not set, but the value is in the cache,
// use it from the cache:
- AddEnvVar(environment, "INTEL_LICENSE_FILE", lg);
+ AddEnvVar(environment, "INTEL_LICENSE_FILE", *lg);
}
AppendDictionary(xml, "org.eclipse.cdt.make.core.environment",
environment.str());
@@ -495,7 +495,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
cmExtraEclipseCDT4Generator::AppendLinkedResource(
xml, linkName, "virtual:/virtual", VirtualFolder);
- for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
+ for (const auto& lg : this->GlobalGenerator->GetLocalGenerators()) {
cmMakefile* makefile = lg->GetMakefile();
const auto& targets = lg->GetGeneratorTargets();
@@ -606,7 +606,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
{
std::set<std::string> emmited;
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+ const auto& lg = this->GlobalGenerator->GetLocalGenerators()[0];
const cmMakefile* mf = lg->GetMakefile();
const std::string filename = this->HomeOutputDirectory + "/.cproject";
@@ -752,7 +752,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// add pre-processor definitions to allow eclipse to gray out sections
emmited.clear();
- for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
+ for (const auto& lgen : this->GlobalGenerator->GetLocalGenerators()) {
if (const char* cdefs =
lgen->GetMakefile()->GetProperty("COMPILE_DEFINITIONS")) {
@@ -859,7 +859,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// include dirs
emmited.clear();
- for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
+ for (const auto& lgen : this->GlobalGenerator->GetLocalGenerators()) {
const auto& targets = lgen->GetGeneratorTargets();
for (const auto& target : targets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
@@ -914,7 +914,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// add all executable and library targets and some of the GLOBAL
// and UTILITY targets
- for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
+ for (const auto& lgen : this->GlobalGenerator->GetLocalGenerators()) {
const auto& targets = lgen->GetGeneratorTargets();
std::string subdir = lgen->MaybeConvertToRelativePath(
this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h
index ff4c59e..a7aa549 100644
--- a/Source/cmExtraEclipseCDT4Generator.h
+++ b/Source/cmExtraEclipseCDT4Generator.h
@@ -86,7 +86,7 @@ private:
std::set<std::string>& emittedDirs);
static void AddEnvVar(std::ostream& out, const char* envVar,
- cmLocalGenerator* lg);
+ cmLocalGenerator& lg);
void WriteGroups(std::vector<cmSourceGroup> const& sourceGroups,
std::string& linkName, cmXMLWriter& xml);
diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx
index bbbc281..e463420 100644
--- a/Source/cmExtraKateGenerator.cxx
+++ b/Source/cmExtraKateGenerator.cxx
@@ -41,21 +41,21 @@ cmExternalMakefileProjectGeneratorFactory* cmExtraKateGenerator::GetFactory()
void cmExtraKateGenerator::Generate()
{
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+ const auto& lg = this->GlobalGenerator->GetLocalGenerators()[0];
const cmMakefile* mf = lg->GetMakefile();
this->ProjectName = this->GenerateProjectName(
lg->GetProjectName(), mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
this->GetPathBasename(lg->GetBinaryDirectory()));
this->UseNinja = (this->GlobalGenerator->GetName() == "Ninja");
- this->CreateKateProjectFile(lg);
- this->CreateDummyKateProjectFile(lg);
+ this->CreateKateProjectFile(*lg);
+ this->CreateDummyKateProjectFile(*lg);
}
void cmExtraKateGenerator::CreateKateProjectFile(
- const cmLocalGenerator* lg) const
+ const cmLocalGenerator& lg) const
{
- std::string filename = cmStrCat(lg->GetBinaryDirectory(), "/.kateproject");
+ std::string filename = cmStrCat(lg.GetBinaryDirectory(), "/.kateproject");
cmGeneratedFileStream fout(filename);
if (!fout) {
return;
@@ -65,21 +65,21 @@ void cmExtraKateGenerator::CreateKateProjectFile(
fout <<
"{\n"
"\t\"name\": \"" << this->ProjectName << "\",\n"
- "\t\"directory\": \"" << lg->GetSourceDirectory() << "\",\n"
+ "\t\"directory\": \"" << lg.GetSourceDirectory() << "\",\n"
"\t\"files\": [ { " << this->GenerateFilesString(lg) << "} ],\n";
/* clang-format on */
this->WriteTargets(lg, fout);
fout << "}\n";
}
-void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
+void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator& lg,
cmGeneratedFileStream& fout) const
{
- cmMakefile const* mf = lg->GetMakefile();
+ cmMakefile const* mf = lg.GetMakefile();
const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
const std::string& makeArgs =
mf->GetSafeDefinition("CMAKE_KATE_MAKE_ARGUMENTS");
- std::string const& homeOutputDir = lg->GetBinaryDirectory();
+ std::string const& homeOutputDir = lg.GetBinaryDirectory();
/* clang-format off */
fout <<
@@ -110,8 +110,7 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
// add all executable and library targets and some of the GLOBAL
// and UTILITY targets
- for (cmLocalGenerator* localGen :
- this->GlobalGenerator->GetLocalGenerators()) {
+ for (const auto& localGen : this->GlobalGenerator->GetLocalGenerators()) {
const auto& targets = localGen->GetGeneratorTargets();
std::string currentDir = localGen->GetCurrentBinaryDirectory();
bool topLevel = (currentDir == localGen->GetBinaryDirectory());
@@ -205,10 +204,10 @@ void cmExtraKateGenerator::AppendTarget(cmGeneratedFileStream& fout,
}
void cmExtraKateGenerator::CreateDummyKateProjectFile(
- const cmLocalGenerator* lg) const
+ const cmLocalGenerator& lg) const
{
std::string filename =
- cmStrCat(lg->GetBinaryDirectory(), '/', this->ProjectName, ".kateproject");
+ cmStrCat(lg.GetBinaryDirectory(), '/', this->ProjectName, ".kateproject");
cmGeneratedFileStream fout(filename);
if (!fout) {
return;
@@ -219,26 +218,25 @@ void cmExtraKateGenerator::CreateDummyKateProjectFile(
}
std::string cmExtraKateGenerator::GenerateFilesString(
- const cmLocalGenerator* lg) const
+ const cmLocalGenerator& lg) const
{
- std::string s = cmStrCat(lg->GetSourceDirectory(), "/.git");
+ std::string s = cmStrCat(lg.GetSourceDirectory(), "/.git");
if (cmSystemTools::FileExists(s)) {
return "\"git\": 1 ";
}
- s = cmStrCat(lg->GetSourceDirectory(), "/.svn");
+ s = cmStrCat(lg.GetSourceDirectory(), "/.svn");
if (cmSystemTools::FileExists(s)) {
return "\"svn\": 1 ";
}
- s = cmStrCat(lg->GetSourceDirectory(), '/');
+ s = cmStrCat(lg.GetSourceDirectory(), '/');
std::set<std::string> files;
std::string tmp;
- const std::vector<cmLocalGenerator*>& lgs =
- this->GlobalGenerator->GetLocalGenerators();
+ const auto& lgs = this->GlobalGenerator->GetLocalGenerators();
- for (cmLocalGenerator* lgen : lgs) {
+ for (const auto& lgen : lgs) {
cmMakefile* makefile = lgen->GetMakefile();
const std::vector<std::string>& listFiles = makefile->GetListFiles();
for (std::string const& listFile : listFiles) {
diff --git a/Source/cmExtraKateGenerator.h b/Source/cmExtraKateGenerator.h
index be1376a..1fb81b4 100644
--- a/Source/cmExtraKateGenerator.h
+++ b/Source/cmExtraKateGenerator.h
@@ -25,16 +25,16 @@ public:
void Generate() override;
private:
- void CreateKateProjectFile(const cmLocalGenerator* lg) const;
- void CreateDummyKateProjectFile(const cmLocalGenerator* lg) const;
- void WriteTargets(const cmLocalGenerator* lg,
+ void CreateKateProjectFile(const cmLocalGenerator& lg) const;
+ void CreateDummyKateProjectFile(const cmLocalGenerator& lg) const;
+ void WriteTargets(const cmLocalGenerator& lg,
cmGeneratedFileStream& fout) const;
void AppendTarget(cmGeneratedFileStream& fout, const std::string& target,
const std::string& make, const std::string& makeArgs,
const std::string& path,
const std::string& homeOutputDir) const;
- std::string GenerateFilesString(const cmLocalGenerator* lg) const;
+ std::string GenerateFilesString(const cmLocalGenerator& lg) const;
std::string GetPathBasename(const std::string& path) const;
std::string GenerateProjectName(const std::string& name,
const std::string& type,
diff --git a/Source/cmFileAPICMakeFiles.cxx b/Source/cmFileAPICMakeFiles.cxx
index f419997..44ba96c 100644
--- a/Source/cmFileAPICMakeFiles.cxx
+++ b/Source/cmFileAPICMakeFiles.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFileAPICMakeFiles.h"
+#include <memory>
#include <string>
#include <vector>
@@ -67,7 +68,7 @@ Json::Value CMakeFiles::DumpInputs()
cmGlobalGenerator* gg =
this->FileAPI.GetCMakeInstance()->GetGlobalGenerator();
- for (cmLocalGenerator const* lg : gg->GetLocalGenerators()) {
+ for (const auto& lg : gg->GetLocalGenerators()) {
cmMakefile const* mf = lg->GetMakefile();
for (std::string const& file : mf->GetListFiles()) {
inputs.append(this->DumpInput(file));
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx
index d7993c7..d6afb77 100644
--- a/Source/cmFileAPICodemodel.cxx
+++ b/Source/cmFileAPICodemodel.cxx
@@ -469,17 +469,17 @@ void CodemodelConfig::ProcessDirectories()
{
cmGlobalGenerator* gg =
this->FileAPI.GetCMakeInstance()->GetGlobalGenerator();
- std::vector<cmLocalGenerator*> const& localGens = gg->GetLocalGenerators();
+ auto const& localGens = gg->GetLocalGenerators();
// Add directories in forward order to process parents before children.
this->Directories.reserve(localGens.size());
- for (cmLocalGenerator* lg : localGens) {
+ for (const auto& lg : localGens) {
auto directoryIndex =
static_cast<Json::ArrayIndex>(this->Directories.size());
this->Directories.emplace_back();
Directory& d = this->Directories[directoryIndex];
d.Snapshot = lg->GetStateSnapshot().GetBuildsystemDirectory();
- d.LocalGenerator = lg;
+ d.LocalGenerator = lg.get();
this->DirectoryMap[d.Snapshot] = directoryIndex;
d.ProjectIndex = this->AddProject(d.Snapshot);
@@ -554,7 +554,7 @@ Json::Value CodemodelConfig::DumpTargets()
std::vector<cmGeneratorTarget*> targetList;
cmGlobalGenerator* gg =
this->FileAPI.GetCMakeInstance()->GetGlobalGenerator();
- for (cmLocalGenerator const* lg : gg->GetLocalGenerators()) {
+ for (const auto& lg : gg->GetLocalGenerators()) {
cmAppend(targetList, lg->GetGeneratorTargets());
}
std::sort(targetList.begin(), targetList.end(),
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index 91cd4ef..ac48287 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -3,12 +3,15 @@
#include "cmForEachCommand.h"
#include <algorithm>
+#include <cassert>
#include <cstddef>
// NOTE The declaration of `std::abs` has moved to `cmath` since C++17
// See https://en.cppreference.com/w/cpp/numeric/math/abs
// ALERT But IWYU used to lint `#include`s do not "understand"
// conditional compilation (i.e. `#if __cplusplus >= 201703L`)
#include <cstdlib>
+#include <iterator>
+#include <map>
#include <utility>
#include <cm/memory>
@@ -29,7 +32,7 @@ namespace {
class cmForEachFunctionBlocker : public cmFunctionBlocker
{
public:
- cmForEachFunctionBlocker(cmMakefile* mf);
+ explicit cmForEachFunctionBlocker(cmMakefile* mf);
~cmForEachFunctionBlocker() override;
cm::string_view StartCommandName() const override { return "foreach"_s; }
@@ -41,10 +44,33 @@ public:
bool Replay(std::vector<cmListFileFunction> functions,
cmExecutionStatus& inStatus) override;
+ void SetIterationVarsCount(const std::size_t varsCount)
+ {
+ this->IterationVarsCount = varsCount;
+ }
+ void SetZipLists() { this->ZipLists = true; }
+
std::vector<std::string> Args;
private:
+ struct InvokeResult
+ {
+ bool Restore;
+ bool Break;
+ };
+
+ bool ReplayItems(std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus);
+
+ bool ReplayZipLists(std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus);
+
+ InvokeResult invoke(std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus, cmMakefile& mf);
+
cmMakefile* Makefile;
+ std::size_t IterationVarsCount = 0u;
+ bool ZipLists = false;
};
cmForEachFunctionBlocker::cmForEachFunctionBlocker(cmMakefile* mf)
@@ -70,70 +96,240 @@ bool cmForEachFunctionBlocker::ArgumentsMatch(cmListFileFunction const& lff,
bool cmForEachFunctionBlocker::Replay(
std::vector<cmListFileFunction> functions, cmExecutionStatus& inStatus)
{
- cmMakefile& mf = inStatus.GetMakefile();
- // at end of for each execute recorded commands
+ return this->ZipLists ? this->ReplayZipLists(functions, inStatus)
+ : this->ReplayItems(functions, inStatus);
+}
+
+bool cmForEachFunctionBlocker::ReplayItems(
+ std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus)
+{
+ assert("Unexpected number of iteration variables" &&
+ this->IterationVarsCount == 1);
+
+ auto& mf = inStatus.GetMakefile();
+
+ // At end of for each execute recorded commands
// store the old value
std::string oldDef;
if (mf.GetDefinition(this->Args.front())) {
oldDef = mf.GetDefinition(this->Args.front());
}
+ auto restore = false;
for (std::string const& arg : cmMakeRange(this->Args).advance(1)) {
- // set the variable to the loop value
+ // Set the variable to the loop value
mf.AddDefinition(this->Args.front(), arg);
// Invoke all the functions that were collected in the block.
- for (cmListFileFunction const& func : functions) {
- cmExecutionStatus status(mf);
- mf.ExecuteCommand(func, status);
- if (status.GetReturnInvoked()) {
- inStatus.SetReturnInvoked();
- // restore the variable to its prior value
- mf.AddDefinition(this->Args.front(), oldDef);
- return true;
- }
- if (status.GetBreakInvoked()) {
- // restore the variable to its prior value
- mf.AddDefinition(this->Args.front(), oldDef);
- return true;
- }
- if (status.GetContinueInvoked()) {
- break;
- }
- if (cmSystemTools::GetFatalErrorOccured()) {
- return true;
+ auto r = this->invoke(functions, inStatus, mf);
+ restore = r.Restore;
+ if (r.Break) {
+ break;
+ }
+ }
+
+ if (restore) {
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args.front(), oldDef);
+ }
+ return true;
+}
+
+bool cmForEachFunctionBlocker::ReplayZipLists(
+ std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus)
+{
+ assert("Unexpected number of iteration variables" &&
+ this->IterationVarsCount >= 1);
+
+ auto& mf = inStatus.GetMakefile();
+
+ // Expand the list of list-variables into a list of lists of strings
+ std::vector<std::vector<std::string>> values;
+ values.reserve(this->Args.size() - this->IterationVarsCount);
+ // Also track the longest list size
+ std::size_t maxItems = 0u;
+ for (auto const& var :
+ cmMakeRange(this->Args).advance(this->IterationVarsCount)) {
+ std::vector<std::string> items;
+ auto const& value = mf.GetSafeDefinition(var);
+ if (!value.empty()) {
+ cmExpandList(value, items, true);
+ }
+ maxItems = std::max(maxItems, items.size());
+ values.emplace_back(std::move(items));
+ }
+
+ // Form the list of iteration variables
+ std::vector<std::string> iterationVars;
+ if (this->IterationVarsCount > 1) {
+ // If multiple iteration variables has given,
+ // just copy them to the `iterationVars` list.
+ iterationVars.reserve(values.size());
+ std::copy(this->Args.begin(),
+ this->Args.begin() + this->IterationVarsCount,
+ std::back_inserter(iterationVars));
+ } else {
+ // In case of the only iteration variable,
+ // generate names as `var_name_N`,
+ // where `N` is the count of lists to zip
+ iterationVars.resize(values.size());
+ const auto iter_var_prefix = this->Args.front() + "_";
+ auto i = 0u;
+ std::generate(
+ iterationVars.begin(), iterationVars.end(),
+ [&]() -> std::string { return iter_var_prefix + std::to_string(i++); });
+ }
+ assert("Sanity check" && iterationVars.size() == values.size());
+
+ // Store old values for iteration variables
+ std::map<std::string, std::string> oldDefs;
+ for (auto i = 0u; i < values.size(); ++i) {
+ if (mf.GetDefinition(iterationVars[i])) {
+ oldDefs.emplace(iterationVars[i], mf.GetDefinition(iterationVars[i]));
+ }
+ }
+
+ // Form a vector of current positions in all lists (Ok, vectors) of values
+ std::vector<decltype(values)::value_type::iterator> positions;
+ positions.reserve(values.size());
+ std::transform(
+ values.begin(), values.end(), std::back_inserter(positions),
+ // Set the initial position to the beginning of every list
+ [](decltype(values)::value_type& list) { return list.begin(); });
+ assert("Sanity check" && positions.size() == values.size());
+
+ auto restore = false;
+ // Iterate over all the lists simulateneously
+ for (auto i = 0u; i < maxItems; ++i) {
+ // Declare iteration variables
+ for (auto j = 0u; j < values.size(); ++j) {
+ // Define (or not) the iteration variable if the current position
+ // still not at the end...
+ if (positions[j] != values[j].end()) {
+ mf.AddDefinition(iterationVars[j], *positions[j]);
+ ++positions[j];
+ } else {
+ mf.RemoveDefinition(iterationVars[j]);
}
}
+ // Invoke all the functions that were collected in the block.
+ auto r = this->invoke(functions, inStatus, mf);
+ restore = r.Restore;
+ if (r.Break) {
+ break;
+ }
}
- // restore the variable to its prior value
- mf.AddDefinition(this->Args.front(), oldDef);
+ // Restore the variables to its prior value
+ if (restore) {
+ for (auto const& p : oldDefs) {
+ mf.AddDefinition(p.first, p.second);
+ }
+ }
return true;
}
-bool HandleInMode(std::vector<std::string> const& args, cmMakefile& makefile)
+auto cmForEachFunctionBlocker::invoke(
+ std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus, cmMakefile& mf) -> InvokeResult
+{
+ InvokeResult result = { true, false };
+ // Invoke all the functions that were collected in the block.
+ for (cmListFileFunction const& func : functions) {
+ cmExecutionStatus status(mf);
+ mf.ExecuteCommand(func, status);
+ if (status.GetReturnInvoked()) {
+ inStatus.SetReturnInvoked();
+ result.Break = true;
+ break;
+ }
+ if (status.GetBreakInvoked()) {
+ result.Break = true;
+ break;
+ }
+ if (status.GetContinueInvoked()) {
+ break;
+ }
+ if (cmSystemTools::GetFatalErrorOccured()) {
+ result.Restore = false;
+ result.Break = true;
+ break;
+ }
+ }
+ return result;
+}
+
+bool HandleInMode(std::vector<std::string> const& args,
+ std::vector<std::string>::const_iterator kwInIter,
+ cmMakefile& makefile)
{
+ assert("A valid iterator expected" && kwInIter != args.end());
+
auto fb = cm::make_unique<cmForEachFunctionBlocker>(&makefile);
- fb->Args.push_back(args.front());
+
+ // Copy iteration variable names first
+ std::copy(args.begin(), kwInIter, std::back_inserter(fb->Args));
+ // Remember the count of given iteration variable names
+ const auto varsCount = fb->Args.size();
+ fb->SetIterationVarsCount(varsCount);
enum Doing
{
DoingNone,
DoingLists,
- DoingItems
+ DoingItems,
+ DoingZipLists
};
Doing doing = DoingNone;
- for (std::string const& arg : cmMakeRange(args).advance(2)) {
+ // Iterate over arguments past the "IN" keyword
+ for (std::string const& arg : cmMakeRange(++kwInIter, args.end())) {
if (arg == "LISTS") {
+ if (doing == DoingZipLists) {
+ makefile.IssueMessage(MessageType::FATAL_ERROR,
+ "ZIP_LISTS can not be used with LISTS or ITEMS");
+ return true;
+ }
+ if (varsCount != 1u) {
+ makefile.IssueMessage(
+ MessageType::FATAL_ERROR,
+ "ITEMS or LISTS require exactly one iteration variable");
+ return true;
+ }
doing = DoingLists;
+
} else if (arg == "ITEMS") {
+ if (doing == DoingZipLists) {
+ makefile.IssueMessage(MessageType::FATAL_ERROR,
+ "ZIP_LISTS can not be used with LISTS or ITEMS");
+ return true;
+ }
+ if (varsCount != 1u) {
+ makefile.IssueMessage(
+ MessageType::FATAL_ERROR,
+ "ITEMS or LISTS require exactly one iteration variable");
+ return true;
+ }
doing = DoingItems;
+
+ } else if (arg == "ZIP_LISTS") {
+ if (doing != DoingNone) {
+ makefile.IssueMessage(MessageType::FATAL_ERROR,
+ "ZIP_LISTS can not be used with LISTS or ITEMS");
+ return true;
+ }
+ doing = DoingZipLists;
+ fb->SetZipLists();
+
} else if (doing == DoingLists) {
auto const& value = makefile.GetSafeDefinition(arg);
if (!value.empty()) {
cmExpandList(value, fb->Args, true);
}
- } else if (doing == DoingItems) {
+
+ } else if (doing == DoingItems || doing == DoingZipLists) {
fb->Args.push_back(arg);
+
} else {
makefile.IssueMessage(MessageType::FATAL_ERROR,
cmStrCat("Unknown argument:\n", " ", arg, "\n"));
@@ -141,6 +337,18 @@ bool HandleInMode(std::vector<std::string> const& args, cmMakefile& makefile)
}
}
+ // If `ZIP_LISTS` given and variables count more than 1,
+ // make sure the given lists count matches variables...
+ if (doing == DoingZipLists && varsCount > 1u &&
+ (2u * varsCount) != fb->Args.size()) {
+ makefile.IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Expected ", std::to_string(varsCount),
+ " list variables, but given ",
+ std::to_string(fb->Args.size() - varsCount)));
+ return true;
+ }
+
makefile.AddFunctionBlocker(std::move(fb));
return true;
@@ -155,8 +363,9 @@ bool cmForEachCommand(std::vector<std::string> const& args,
status.SetError("called with incorrect number of arguments");
return false;
}
- if (args.size() > 1 && args[1] == "IN") {
- return HandleInMode(args, status.GetMakefile());
+ auto kwInIter = std::find(args.begin(), args.end(), "IN");
+ if (kwInIter != args.end()) {
+ return HandleInMode(args, kwInIter, status.GetMakefile());
}
// create a function blocker
@@ -216,6 +425,8 @@ bool cmForEachCommand(std::vector<std::string> const& args,
} else {
fb->Args = args;
}
+
+ fb->SetIterationVarsCount(1u);
status.GetMakefile().AddFunctionBlocker(std::move(fb));
return true;
diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
index b3ddfe0..4b2f145 100644
--- a/Source/cmFunctionCommand.cxx
+++ b/Source/cmFunctionCommand.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFunctionCommand.h"
-#include <sstream>
#include <utility>
#include <cm/memory>
@@ -19,8 +18,20 @@
#include "cmRange.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
namespace {
+std::string const ARGC = "ARGC";
+std::string const ARGN = "ARGN";
+std::string const ARGV = "ARGV";
+std::string const CMAKE_CURRENT_FUNCTION = "CMAKE_CURRENT_FUNCTION";
+std::string const CMAKE_CURRENT_FUNCTION_LIST_FILE =
+ "CMAKE_CURRENT_FUNCTION_LIST_FILE";
+std::string const CMAKE_CURRENT_FUNCTION_LIST_DIR =
+ "CMAKE_CURRENT_FUNCTION_LIST_DIR";
+std::string const CMAKE_CURRENT_FUNCTION_LIST_LINE =
+ "CMAKE_CURRENT_FUNCTION_LIST_LINE";
+
// define the class for function commands
class cmFunctionHelperCommand
{
@@ -36,8 +47,8 @@ public:
std::vector<cmListFileFunction> Functions;
cmPolicies::PolicyMap Policies;
std::string FilePath;
+ long Line;
};
-}
bool cmFunctionHelperCommand::operator()(
std::vector<cmListFileArgument> const& args,
@@ -52,9 +63,9 @@ bool cmFunctionHelperCommand::operator()(
// make sure the number of arguments passed is at least the number
// required by the signature
if (expandedArgs.size() < this->Args.size() - 1) {
- std::string errorMsg = cmStrCat(
+ auto const errorMsg = cmStrCat(
"Function invoked with incorrect arguments for function named: ",
- this->Args[0]);
+ this->Args.front());
inStatus.SetError(errorMsg);
return false;
}
@@ -63,30 +74,40 @@ bool cmFunctionHelperCommand::operator()(
this->Policies);
// set the value of argc
- makefile.AddDefinition("ARGC", std::to_string(expandedArgs.size()));
- makefile.MarkVariableAsUsed("ARGC");
+ makefile.AddDefinition(ARGC, std::to_string(expandedArgs.size()));
+ makefile.MarkVariableAsUsed(ARGC);
// set the values for ARGV0 ARGV1 ...
- for (unsigned int t = 0; t < expandedArgs.size(); ++t) {
- std::ostringstream tmpStream;
- tmpStream << "ARGV" << t;
- makefile.AddDefinition(tmpStream.str(), expandedArgs[t]);
- makefile.MarkVariableAsUsed(tmpStream.str());
+ for (auto t = 0u; t < expandedArgs.size(); ++t) {
+ auto const value = cmStrCat(ARGV, std::to_string(t));
+ makefile.AddDefinition(value, expandedArgs[t]);
+ makefile.MarkVariableAsUsed(value);
}
// define the formal arguments
- for (unsigned int j = 1; j < this->Args.size(); ++j) {
+ for (auto j = 1u; j < this->Args.size(); ++j) {
makefile.AddDefinition(this->Args[j], expandedArgs[j - 1]);
}
// define ARGV and ARGN
- std::string argvDef = cmJoin(expandedArgs, ";");
- auto eit = expandedArgs.begin() + (this->Args.size() - 1);
- std::string argnDef = cmJoin(cmMakeRange(eit, expandedArgs.end()), ";");
- makefile.AddDefinition("ARGV", argvDef);
- makefile.MarkVariableAsUsed("ARGV");
- makefile.AddDefinition("ARGN", argnDef);
- makefile.MarkVariableAsUsed("ARGN");
+ auto const argvDef = cmJoin(expandedArgs, ";");
+ auto const eit = expandedArgs.begin() + (this->Args.size() - 1);
+ auto const argnDef = cmJoin(cmMakeRange(eit, expandedArgs.end()), ";");
+ makefile.AddDefinition(ARGV, argvDef);
+ makefile.MarkVariableAsUsed(ARGV);
+ makefile.AddDefinition(ARGN, argnDef);
+ makefile.MarkVariableAsUsed(ARGN);
+
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION, this->Args.front());
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_FILE, this->FilePath);
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_FILE);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_DIR,
+ cmSystemTools::GetFilenamePath(this->FilePath));
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_DIR);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_LINE,
+ std::to_string(this->Line));
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_LINE);
// Invoke all the functions that were collected in the block.
// for each function
@@ -100,7 +121,7 @@ bool cmFunctionHelperCommand::operator()(
return false;
}
if (status.GetReturnInvoked()) {
- return true;
+ break;
}
}
@@ -129,7 +150,8 @@ bool cmFunctionFunctionBlocker::ArgumentsMatch(cmListFileFunction const& lff,
std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.Arguments, expandedArguments,
this->GetStartingContext().FilePath.c_str());
- return expandedArguments.empty() || expandedArguments[0] == this->Args[0];
+ return expandedArguments.empty() ||
+ expandedArguments.front() == this->Args.front();
}
bool cmFunctionFunctionBlocker::Replay(
@@ -141,11 +163,14 @@ bool cmFunctionFunctionBlocker::Replay(
f.Args = this->Args;
f.Functions = std::move(functions);
f.FilePath = this->GetStartingContext().FilePath;
+ f.Line = this->GetStartingContext().Line;
mf.RecordPolicies(f.Policies);
- mf.GetState()->AddScriptedCommand(this->Args[0], std::move(f));
+ mf.GetState()->AddScriptedCommand(this->Args.front(), std::move(f));
return true;
}
+} // anonymous namespace
+
bool cmFunctionCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
@@ -155,10 +180,9 @@ bool cmFunctionCommand(std::vector<std::string> const& args,
}
// create a function blocker
- {
- auto fb = cm::make_unique<cmFunctionFunctionBlocker>();
- cmAppend(fb->Args, args);
- status.GetMakefile().AddFunctionBlocker(std::move(fb));
- }
+ auto fb = cm::make_unique<cmFunctionFunctionBlocker>();
+ cmAppend(fb->Args, args);
+ status.GetMakefile().AddFunctionBlocker(std::move(fb));
+
return true;
}
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index de43d3e..81d1e46 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -8,7 +8,6 @@
#include "cmsys/RegularExpression.hxx"
-#include "cmAlgorithms.h"
#include "cmGeneratorExpressionContext.h"
#include "cmGeneratorExpressionDAGChecker.h"
#include "cmGeneratorExpressionEvaluator.h"
@@ -22,6 +21,8 @@ cmGeneratorExpression::cmGeneratorExpression(cmListFileBacktrace backtrace)
{
}
+cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression() = default;
+
cmGeneratorExpression::~cmGeneratorExpression() = default;
std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
@@ -86,7 +87,7 @@ const std::string& cmCompiledGeneratorExpression::EvaluateWithContext(
this->Output.clear();
- for (const cmGeneratorExpressionEvaluator* it : this->Evaluators) {
+ for (const auto& it : this->Evaluators) {
this->Output += it->Evaluate(&context, dagChecker);
this->SeenTargetProperties.insert(context.SeenTargetProperties.cbegin(),
@@ -129,11 +130,6 @@ cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
}
}
-cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
-{
- cmDeleteAll(this->Evaluators);
-}
-
std::string cmGeneratorExpression::StripEmptyListElements(
const std::string& input)
{
diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h
index cd35e1e..c4be3a1 100644
--- a/Source/cmGeneratorExpression.h
+++ b/Source/cmGeneratorExpression.h
@@ -163,7 +163,7 @@ private:
friend class cmGeneratorExpression;
cmListFileBacktrace Backtrace;
- std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
+ std::vector<std::unique_ptr<cmGeneratorExpressionEvaluator>> Evaluators;
const std::string Input;
bool NeedsEvaluation;
bool EvaluateForBuildsystem;
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index e0ae170..4129a0c 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -2,10 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGeneratorExpressionEvaluator.h"
-#include <algorithm>
#include <sstream>
-#include "cmAlgorithms.h"
#include "cmGeneratorExpressionContext.h"
#include "cmGeneratorExpressionNode.h"
@@ -16,6 +14,8 @@ GeneratorExpressionContent::GeneratorExpressionContent(
{
}
+GeneratorExpressionContent::~GeneratorExpressionContent() = default;
+
std::string GeneratorExpressionContent::GetOriginalExpression() const
{
return std::string(this->StartContent, this->ContentLength);
@@ -25,14 +25,13 @@ std::string GeneratorExpressionContent::ProcessArbitraryContent(
const cmGeneratorExpressionNode* node, const std::string& identifier,
cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagChecker,
- std::vector<std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator
- pit) const
+ std::vector<cmGeneratorExpressionEvaluatorVector>::const_iterator pit) const
{
std::string result;
const auto pend = this->ParamChildren.end();
for (; pit != pend; ++pit) {
- for (cmGeneratorExpressionEvaluator* pExprEval : *pit) {
+ for (auto& pExprEval : *pit) {
if (node->RequiresLiteralInput()) {
if (pExprEval->GetType() != cmGeneratorExpressionEvaluator::Text) {
reportError(context, this->GetOriginalExpression(),
@@ -64,8 +63,7 @@ std::string GeneratorExpressionContent::Evaluate(
{
std::string identifier;
{
- for (cmGeneratorExpressionEvaluator* pExprEval :
- this->IdentifierChildren) {
+ for (auto& pExprEval : this->IdentifierChildren) {
identifier += pExprEval->Evaluate(context, dagChecker);
if (context->HadError) {
return std::string();
@@ -126,7 +124,7 @@ std::string GeneratorExpressionContent::EvaluateParameters(
return std::string();
}
std::string parameter;
- for (cmGeneratorExpressionEvaluator* pExprEval : *pit) {
+ for (auto& pExprEval : *pit) {
parameter += pExprEval->Evaluate(context, dagChecker);
if (context->HadError) {
return std::string();
@@ -174,10 +172,3 @@ std::string GeneratorExpressionContent::EvaluateParameters(
}
return std::string();
}
-
-GeneratorExpressionContent::~GeneratorExpressionContent()
-{
- cmDeleteAll(this->IdentifierChildren);
- std::for_each(this->ParamChildren.begin(), this->ParamChildren.end(),
- cmDeleteAll<std::vector<cmGeneratorExpressionEvaluator*>>);
-}
diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h
index b10bb5b..10496fd 100644
--- a/Source/cmGeneratorExpressionEvaluator.h
+++ b/Source/cmGeneratorExpressionEvaluator.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <cstddef>
+#include <memory>
#include <string>
#include <utility>
#include <vector>
@@ -36,6 +37,9 @@ struct cmGeneratorExpressionEvaluator
cmGeneratorExpressionDAGChecker*) const = 0;
};
+using cmGeneratorExpressionEvaluatorVector =
+ std::vector<std::unique_ptr<cmGeneratorExpressionEvaluator>>;
+
struct TextContent : public cmGeneratorExpressionEvaluator
{
TextContent(const char* start, size_t length)
@@ -68,13 +72,13 @@ struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
{
GeneratorExpressionContent(const char* startContent, size_t length);
- void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
+ void SetIdentifier(cmGeneratorExpressionEvaluatorVector&& identifier)
{
this->IdentifierChildren = std::move(identifier);
}
void SetParameters(
- std::vector<std::vector<cmGeneratorExpressionEvaluator*>> parameters)
+ std::vector<cmGeneratorExpressionEvaluatorVector>&& parameters)
{
this->ParamChildren = std::move(parameters);
}
@@ -102,12 +106,12 @@ private:
const cmGeneratorExpressionNode* node, const std::string& identifier,
cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagChecker,
- std::vector<std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator
- pit) const;
+ std::vector<cmGeneratorExpressionEvaluatorVector>::const_iterator pit)
+ const;
private:
- std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
- std::vector<std::vector<cmGeneratorExpressionEvaluator*>> ParamChildren;
+ cmGeneratorExpressionEvaluatorVector IdentifierChildren;
+ std::vector<cmGeneratorExpressionEvaluatorVector> ParamChildren;
const char* StartContent;
size_t ContentLength;
};
diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx
index d6cc6ab..4159a7b 100644
--- a/Source/cmGeneratorExpressionParser.cxx
+++ b/Source/cmGeneratorExpressionParser.cxx
@@ -6,6 +6,9 @@
#include <cstddef>
#include <utility>
+#include <cm/memory>
+#include <cmext/memory>
+
#include "cmAlgorithms.h"
#include "cmGeneratorExpressionEvaluator.h"
@@ -17,7 +20,7 @@ cmGeneratorExpressionParser::cmGeneratorExpressionParser(
}
void cmGeneratorExpressionParser::Parse(
- std::vector<cmGeneratorExpressionEvaluator*>& result)
+ cmGeneratorExpressionEvaluatorVector& result)
{
it = this->Tokens.begin();
@@ -27,40 +30,38 @@ void cmGeneratorExpressionParser::Parse(
}
static void extendText(
- std::vector<cmGeneratorExpressionEvaluator*>& result,
+ cmGeneratorExpressionEvaluatorVector& result,
std::vector<cmGeneratorExpressionToken>::const_iterator it)
{
if (!result.empty() &&
(*(result.end() - 1))->GetType() ==
cmGeneratorExpressionEvaluator::Text) {
- TextContent* textContent = static_cast<TextContent*>(*(result.end() - 1));
- textContent->Extend(it->Length);
+ cm::static_reference_cast<TextContent>(*(result.end() - 1))
+ .Extend(it->Length);
} else {
- TextContent* textContent = new TextContent(it->Content, it->Length);
- result.push_back(textContent);
+ auto textContent = cm::make_unique<TextContent>(it->Content, it->Length);
+ result.push_back(std::move(textContent));
}
}
static void extendResult(
- std::vector<cmGeneratorExpressionEvaluator*>& result,
- const std::vector<cmGeneratorExpressionEvaluator*>& contents)
+ cmGeneratorExpressionParser::cmGeneratorExpressionEvaluatorVector& result,
+ cmGeneratorExpressionParser::cmGeneratorExpressionEvaluatorVector&& contents)
{
if (!result.empty() &&
(*(result.end() - 1))->GetType() ==
cmGeneratorExpressionEvaluator::Text &&
contents.front()->GetType() == cmGeneratorExpressionEvaluator::Text) {
- TextContent* textContent = static_cast<TextContent*>(*(result.end() - 1));
- textContent->Extend(
- static_cast<TextContent*>(contents.front())->GetLength());
- delete contents.front();
- cmAppend(result, contents.begin() + 1, contents.end());
- } else {
- cmAppend(result, contents);
+ cm::static_reference_cast<TextContent>(*(result.end() - 1))
+ .Extend(
+ cm::static_reference_cast<TextContent>(contents.front()).GetLength());
+ contents.erase(contents.begin());
}
+ cmAppend(result, std::move(contents));
}
void cmGeneratorExpressionParser::ParseGeneratorExpression(
- std::vector<cmGeneratorExpressionEvaluator*>& result)
+ cmGeneratorExpressionEvaluatorVector& result)
{
assert(this->it != this->Tokens.end());
unsigned int nestedLevel = this->NestingLevel;
@@ -68,7 +69,7 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
auto startToken = this->it - 1;
- std::vector<cmGeneratorExpressionEvaluator*> identifier;
+ cmGeneratorExpressionEvaluatorVector identifier;
while (this->it->TokenType != cmGeneratorExpressionToken::EndExpression &&
this->it->TokenType != cmGeneratorExpressionToken::ColonSeparator) {
if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) {
@@ -87,18 +88,18 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
if (this->it != this->Tokens.end() &&
this->it->TokenType == cmGeneratorExpressionToken::EndExpression) {
- GeneratorExpressionContent* content = new GeneratorExpressionContent(
+ auto content = cm::make_unique<GeneratorExpressionContent>(
startToken->Content,
this->it->Content - startToken->Content + this->it->Length);
assert(this->it != this->Tokens.end());
++this->it;
--this->NestingLevel;
content->SetIdentifier(std::move(identifier));
- result.push_back(content);
+ result.push_back(std::move(content));
return;
}
- std::vector<std::vector<cmGeneratorExpressionEvaluator*>> parameters;
+ std::vector<cmGeneratorExpressionEvaluatorVector> parameters;
std::vector<std::vector<cmGeneratorExpressionToken>::const_iterator>
commaTokens;
std::vector<cmGeneratorExpressionToken>::const_iterator colonToken;
@@ -169,7 +170,7 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
// treat the '$<' as having been plain text, along with the
// corresponding : and , tokens that might have been found.
extendText(result, startToken);
- extendResult(result, identifier);
+ extendResult(result, std::move(identifier));
if (!parameters.empty()) {
extendText(result, colonToken);
@@ -179,7 +180,7 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
assert(parameters.size() > commaTokens.size());
for (; pit != pend; ++pit, ++commaIt) {
if (!pit->empty() && !emptyParamTermination) {
- extendResult(result, *pit);
+ extendResult(result, std::move(*pit));
}
if (commaIt != commaTokens.end()) {
extendText(result, *commaIt);
@@ -193,15 +194,15 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
size_t contentLength =
((this->it - 1)->Content - startToken->Content) + (this->it - 1)->Length;
- GeneratorExpressionContent* content =
- new GeneratorExpressionContent(startToken->Content, contentLength);
+ auto content = cm::make_unique<GeneratorExpressionContent>(
+ startToken->Content, contentLength);
content->SetIdentifier(std::move(identifier));
content->SetParameters(std::move(parameters));
- result.push_back(content);
+ result.push_back(std::move(content));
}
void cmGeneratorExpressionParser::ParseContent(
- std::vector<cmGeneratorExpressionEvaluator*>& result)
+ cmGeneratorExpressionEvaluatorVector& result)
{
assert(this->it != this->Tokens.end());
switch (this->it->TokenType) {
@@ -213,17 +214,16 @@ void cmGeneratorExpressionParser::ParseContent(
// A comma in 'plain text' could have split text that should
// otherwise be continuous. Extend the last text content instead of
// creating a new one.
- TextContent* textContent =
- static_cast<TextContent*>(*(result.end() - 1));
- textContent->Extend(this->it->Length);
+ cm::static_reference_cast<TextContent>(*(result.end() - 1))
+ .Extend(this->it->Length);
assert(this->it != this->Tokens.end());
++this->it;
return;
}
}
- cmGeneratorExpressionEvaluator* n =
- new TextContent(this->it->Content, this->it->Length);
- result.push_back(n);
+ auto n =
+ cm::make_unique<TextContent>(this->it->Content, this->it->Length);
+ result.push_back(std::move(n));
assert(this->it != this->Tokens.end());
++this->it;
return;
diff --git a/Source/cmGeneratorExpressionParser.h b/Source/cmGeneratorExpressionParser.h
index e663496..1ba1654 100644
--- a/Source/cmGeneratorExpressionParser.h
+++ b/Source/cmGeneratorExpressionParser.h
@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include <memory>
#include <vector>
#include "cmGeneratorExpressionLexer.h"
@@ -15,11 +16,14 @@ struct cmGeneratorExpressionParser
{
cmGeneratorExpressionParser(std::vector<cmGeneratorExpressionToken> tokens);
- void Parse(std::vector<cmGeneratorExpressionEvaluator*>& result);
+ using cmGeneratorExpressionEvaluatorVector =
+ std::vector<std::unique_ptr<cmGeneratorExpressionEvaluator>>;
+
+ void Parse(cmGeneratorExpressionEvaluatorVector& result);
private:
- void ParseContent(std::vector<cmGeneratorExpressionEvaluator*>&);
- void ParseGeneratorExpression(std::vector<cmGeneratorExpressionEvaluator*>&);
+ void ParseContent(cmGeneratorExpressionEvaluatorVector&);
+ void ParseGeneratorExpression(cmGeneratorExpressionEvaluatorVector&);
private:
std::vector<cmGeneratorExpressionToken>::const_iterator it;
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index d0b5f9e..19d5b4d 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -649,6 +649,7 @@ void cmGeneratorTarget::ClearSourcesCache()
this->KindedSourcesMap.clear();
this->LinkImplementationLanguageIsContextDependent = true;
this->Objects.clear();
+ this->VisitedConfigsForObjects.clear();
}
void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
@@ -738,7 +739,7 @@ void cmGeneratorTarget::GetObjectSources(
{
IMPLEMENT_VISIT(SourceKindObjectSource);
- if (!this->Objects.empty()) {
+ if (this->VisitedConfigsForObjects.count(config)) {
return;
}
@@ -747,16 +748,17 @@ void cmGeneratorTarget::GetObjectSources(
}
this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
+ this->VisitedConfigsForObjects.insert(config);
}
void cmGeneratorTarget::ComputeObjectMapping()
{
- if (!this->Objects.empty()) {
+ auto const& configs = this->Makefile->GetGeneratorConfigs();
+ std::set<std::string> configSet(configs.begin(), configs.end());
+ if (configSet == this->VisitedConfigsForObjects) {
return;
}
- std::vector<std::string> const& configs =
- this->Makefile->GetGeneratorConfigs();
for (std::string const& c : configs) {
std::vector<cmSourceFile const*> sourceFiles;
this->GetObjectSources(sourceFiles, c);
@@ -1116,7 +1118,8 @@ bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
}
bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
- std::string const& prop, cmGeneratorExpressionContext* context) const
+ std::string const& prop, cmGeneratorExpressionContext* context,
+ bool usage_requirements_only) const
{
std::string const key = prop + '@' + context->Config;
auto i = this->MaybeInterfacePropertyExists.find(key);
@@ -1135,7 +1138,7 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
context->HeadTarget ? context->HeadTarget : this;
if (cmLinkInterfaceLibraries const* iface =
this->GetLinkInterfaceLibraries(context->Config, headTarget,
- true)) {
+ usage_requirements_only)) {
if (iface->HadHeadSensitiveCondition) {
// With a different head target we may get to a library with
// this interface property.
@@ -1145,7 +1148,8 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
// head target, so we can follow them.
for (cmLinkItem const& lib : iface->Libraries) {
if (lib.Target &&
- lib.Target->MaybeHaveInterfaceProperty(prop, context)) {
+ lib.Target->MaybeHaveInterfaceProperty(
+ prop, context, usage_requirements_only)) {
maybeInterfaceProp = true;
break;
}
@@ -1159,12 +1163,14 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
std::string cmGeneratorTarget::EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context,
- cmGeneratorExpressionDAGChecker* dagCheckerParent) const
+ cmGeneratorExpressionDAGChecker* dagCheckerParent,
+ bool usage_requirements_only) const
{
std::string result;
// If the property does not appear transitively at all, we are done.
- if (!this->MaybeHaveInterfaceProperty(prop, context)) {
+ if (!this->MaybeHaveInterfaceProperty(prop, context,
+ usage_requirements_only)) {
return result;
}
@@ -1196,8 +1202,8 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty(
p, context->LG, context, headTarget, &dagChecker, this);
}
- if (cmLinkInterfaceLibraries const* iface =
- this->GetLinkInterfaceLibraries(context->Config, headTarget, true)) {
+ if (cmLinkInterfaceLibraries const* iface = this->GetLinkInterfaceLibraries(
+ context->Config, headTarget, usage_requirements_only)) {
for (cmLinkItem const& lib : iface->Libraries) {
// Broken code can have a target in its own link interface.
// Don't follow such link interface entries so as not to create a
@@ -1211,8 +1217,8 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty(
context->EvaluateForBuildsystem, context->Backtrace,
context->Language);
std::string libResult = cmGeneratorExpression::StripEmptyListElements(
- lib.Target->EvaluateInterfaceProperty(prop, &libContext,
- &dagChecker));
+ lib.Target->EvaluateInterfaceProperty(prop, &libContext, &dagChecker,
+ usage_requirements_only));
if (!libResult.empty()) {
if (result.empty()) {
result = std::move(libResult);
@@ -1240,7 +1246,8 @@ void AddInterfaceEntries(cmGeneratorTarget const* headTarget,
std::string const& config, std::string const& prop,
std::string const& lang,
cmGeneratorExpressionDAGChecker* dagChecker,
- std::vector<EvaluatedTargetPropertyEntry>& entries)
+ std::vector<EvaluatedTargetPropertyEntry>& entries,
+ bool usage_requirements_only = true)
{
if (cmLinkImplementationLibraries const* impl =
headTarget->GetLinkImplementationLibraries(config)) {
@@ -1253,9 +1260,9 @@ void AddInterfaceEntries(cmGeneratorTarget const* headTarget,
cmGeneratorExpressionContext context(
headTarget->GetLocalGenerator(), config, false, headTarget,
headTarget, true, lib.Backtrace, lang);
- cmExpandList(
- lib.Target->EvaluateInterfaceProperty(prop, &context, dagChecker),
- ee.Values);
+ cmExpandList(lib.Target->EvaluateInterfaceProperty(
+ prop, &context, dagChecker, usage_requirements_only),
+ ee.Values);
ee.ContextDependent = context.HadContextSensitiveCondition;
entries.emplace_back(std::move(ee));
}
@@ -2508,11 +2515,11 @@ void cmGeneratorTarget::ComputeModuleDefinitionInfo(
info.WindowsExportAllSymbols =
this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
-#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
+#if !defined(CMAKE_BOOTSTRAP)
info.DefFileGenerated =
info.WindowsExportAllSymbols || info.Sources.size() > 1;
#else
- // Our __create_def helper is only available on Windows.
+ // Our __create_def helper is not available during CMake bootstrap.
info.DefFileGenerated = false;
#endif
if (info.DefFileGenerated) {
@@ -3663,7 +3670,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
this->LinkOptionsEntries);
AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
- &dagChecker, entries);
+ &dagChecker, entries,
+ this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
processOptions(this, entries, result, uniqueOptions, debugOptions,
"link options", OptionsParse::Shell);
@@ -3918,7 +3926,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
this->LinkDirectoriesEntries);
AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
- &dagChecker, entries);
+ &dagChecker, entries,
+ this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
processLinkDirectories(this, entries, result, uniqueDirectories,
debugDirectories);
@@ -3956,7 +3965,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
}
}
AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
- &dagChecker, entries);
+ &dagChecker, entries,
+ this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
processOptions(this, entries, result, uniqueOptions, false, "link depends",
OptionsParse::None);
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 336c91f..eabd3fa9 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -707,7 +707,8 @@ public:
std::string EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context,
- cmGeneratorExpressionDAGChecker* dagCheckerParent) const;
+ cmGeneratorExpressionDAGChecker* dagCheckerParent,
+ bool usage_requirements_only = true) const;
bool HaveInstallTreeRPATH(const std::string& config) const;
@@ -766,6 +767,7 @@ private:
};
using SourceEntriesType = std::map<cmSourceFile const*, SourceEntry>;
SourceEntriesType SourceDepends;
+ mutable std::set<std::string> VisitedConfigsForObjects;
mutable std::map<cmSourceFile const*, std::string> Objects;
std::set<cmSourceFile const*> ExplicitObjectName;
mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
@@ -886,7 +888,8 @@ private:
mutable std::unordered_map<std::string, bool> MaybeInterfacePropertyExists;
bool MaybeHaveInterfaceProperty(std::string const& prop,
- cmGeneratorExpressionContext* context) const;
+ cmGeneratorExpressionContext* context,
+ bool usage_requirements_only) const;
using TargetPropertyEntryVector =
std::vector<std::unique_ptr<TargetPropertyEntry>>;
diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx
index 51d681d..06943e7 100644
--- a/Source/cmGlobalBorlandMakefileGenerator.cxx
+++ b/Source/cmGlobalBorlandMakefileGenerator.cxx
@@ -2,6 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalBorlandMakefileGenerator.h"
+#include <utility>
+
+#include <cm/memory>
+
#include "cmDocumentationEntry.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
@@ -35,15 +39,14 @@ void cmGlobalBorlandMakefileGenerator::EnableLanguage(
}
//! Create a local generator appropriate to this Global Generator
-cmLocalGenerator* cmGlobalBorlandMakefileGenerator::CreateLocalGenerator(
- cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator>
+cmGlobalBorlandMakefileGenerator::CreateLocalGenerator(cmMakefile* mf)
{
- cmLocalUnixMakefileGenerator3* lg =
- new cmLocalUnixMakefileGenerator3(this, mf);
+ auto lg = cm::make_unique<cmLocalUnixMakefileGenerator3>(this, mf);
lg->SetMakefileVariableSize(32);
lg->SetMakeCommandEscapeTargetTwice(true);
lg->SetBorlandMakeCurlyHack(true);
- return lg;
+ return std::unique_ptr<cmLocalGenerator>(std::move(lg));
}
void cmGlobalBorlandMakefileGenerator::GetDocumentation(
diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h
index da04743..291220c 100644
--- a/Source/cmGlobalBorlandMakefileGenerator.h
+++ b/Source/cmGlobalBorlandMakefileGenerator.h
@@ -4,6 +4,7 @@
#define cmGlobalBorlandMakefileGenerator_h
#include <iosfwd>
+#include <memory>
#include "cmGlobalNMakeMakefileGenerator.h"
@@ -33,7 +34,8 @@ public:
static void GetDocumentation(cmDocumentationEntry& entry);
//! Create a local generator appropriate to this Global Generator
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
/**
* Try to determine system information such as shared library
diff --git a/Source/cmGlobalCommonGenerator.cxx b/Source/cmGlobalCommonGenerator.cxx
index d6c0a87..e04eef1 100644
--- a/Source/cmGlobalCommonGenerator.cxx
+++ b/Source/cmGlobalCommonGenerator.cxx
@@ -25,11 +25,11 @@ std::map<std::string, cmGlobalCommonGenerator::DirectoryTarget>
cmGlobalCommonGenerator::ComputeDirectoryTargets() const
{
std::map<std::string, DirectoryTarget> dirTargets;
- for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (const auto& lg : this->LocalGenerators) {
std::string const& currentBinaryDir(
lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
DirectoryTarget& dirTarget = dirTargets[currentBinaryDir];
- dirTarget.LG = lg;
+ dirTarget.LG = lg.get();
// The directory-level rule should depend on the target-level rules
// for all targets in the directory.
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 8dfc0ce..b27c3dc 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -300,7 +300,7 @@ void cmGlobalGenerator::ForceLinkerLanguages()
bool cmGlobalGenerator::CheckTargetsForMissingSources() const
{
bool failed = false;
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
for (const auto& target : localGen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
@@ -340,7 +340,7 @@ bool cmGlobalGenerator::CheckTargetsForType() const
return false;
}
bool failed = false;
- for (cmLocalGenerator* generator : this->LocalGenerators) {
+ for (const auto& generator : this->LocalGenerators) {
for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::EXECUTABLE &&
target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
@@ -368,7 +368,7 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
return false;
}
bool failed = false;
- for (cmLocalGenerator* generator : this->LocalGenerators) {
+ for (const auto& generator : this->LocalGenerators) {
for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
@@ -1204,13 +1204,12 @@ void cmGlobalGenerator::ClearEnabledLanguages()
void cmGlobalGenerator::CreateLocalGenerators()
{
this->LocalGeneratorSearchIndex.clear();
- cmDeleteAll(this->LocalGenerators);
this->LocalGenerators.clear();
this->LocalGenerators.reserve(this->Makefiles.size());
for (cmMakefile* m : this->Makefiles) {
- cmLocalGenerator* lg = this->CreateLocalGenerator(m);
- this->LocalGenerators.push_back(lg);
- this->IndexLocalGenerator(lg);
+ auto lg = this->CreateLocalGenerator(m);
+ this->IndexLocalGenerator(lg.get());
+ this->LocalGenerators.push_back(std::move(lg));
}
}
@@ -1300,7 +1299,7 @@ void cmGlobalGenerator::CreateImportedGenerationObjects(
this->CreateGenerationObjects(ImportedOnly);
auto const mfit =
std::find(this->Makefiles.begin(), this->Makefiles.end(), mf);
- cmLocalGenerator* lg =
+ auto& lg =
this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)];
for (std::string const& t : targets) {
cmGeneratorTarget* gt = lg->FindGeneratorTargetToUse(t);
@@ -1353,7 +1352,7 @@ void cmGlobalGenerator::ComputeBuildFileGenerators()
std::vector<cmExportBuildFileGenerator*> gens =
this->Makefiles[i]->GetExportBuildFileGenerators();
for (cmExportBuildFileGenerator* g : gens) {
- g->Compute(this->LocalGenerators[i]);
+ g->Compute(this->LocalGenerators[i].get());
}
}
}
@@ -1392,7 +1391,7 @@ bool cmGlobalGenerator::Compute()
}
// Add generator specific helper commands
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
localGen->AddHelperCommands();
}
@@ -1402,16 +1401,16 @@ bool cmGlobalGenerator::Compute()
// on the original cmTarget instance. It accumulates features
// across all configurations. Some refactoring is needed to
// compute a per-config resulta purely during generation.
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
if (!localGen->ComputeTargetCompileFeatures()) {
return false;
}
}
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
cmMakefile* mf = localGen->GetMakefile();
for (cmInstallGenerator* g : mf->GetInstallGenerators()) {
- if (!g->Compute(localGen)) {
+ if (!g->Compute(localGen.get())) {
return false;
}
}
@@ -1421,7 +1420,7 @@ bool cmGlobalGenerator::Compute()
// Trace the dependencies, after that no custom commands should be added
// because their dependencies might not be handled correctly
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
localGen->TraceDependencies();
}
@@ -1433,7 +1432,7 @@ bool cmGlobalGenerator::Compute()
this->ForceLinkerLanguages();
// Compute the manifest of main targets generated.
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
localGen->ComputeTargetManifest();
}
@@ -1450,7 +1449,7 @@ bool cmGlobalGenerator::Compute()
return false;
}
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
localGen->ComputeHomeRelativeOutputPath();
}
@@ -1563,16 +1562,27 @@ bool cmGlobalGenerator::QtAutoGen()
bool cmGlobalGenerator::AddAutomaticSources()
{
- for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (const auto& lg : this->LocalGenerators) {
lg->CreateEvaluationFileOutputs();
for (const auto& gt : lg->GetGeneratorTargets()) {
- if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
+ gt->GetType() == cmStateEnums::UTILITY ||
+ gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
continue;
}
lg->AddUnityBuild(gt.get());
lg->AddPchDependencies(gt.get());
}
}
+ // The above transformations may have changed the classification of sources.
+ // Clear the source list and classification cache (KindedSources) of all
+ // targets so that it will be recomputed correctly by the generators later
+ // now that the above transformations are done for all targets.
+ for (const auto& lg : this->LocalGenerators) {
+ for (const auto& gt : lg->GetGeneratorTargets()) {
+ gt->ClearSourcesCache();
+ }
+ }
return true;
}
@@ -1673,7 +1683,7 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
for (unsigned int i = 0; i < this->Makefiles.size(); ++i) {
cmMakefile* mf = this->Makefiles[i];
for (cmTarget* ownedImpTgt : mf->GetOwnedImportedTargets()) {
- cmLocalGenerator* lg = this->LocalGenerators[i];
+ cmLocalGenerator* lg = this->LocalGenerators[i].get();
auto gt = cm::make_unique<cmGeneratorTarget>(ownedImpTgt, lg);
importedMap[ownedImpTgt] = gt.get();
lg->AddOwnedImportedGeneratorTarget(std::move(gt));
@@ -1683,7 +1693,7 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
// Construct per-target generator information.
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
this->CreateGeneratorTargets(targetTypes, this->Makefiles[i],
- this->LocalGenerators[i], importedMap);
+ this->LocalGenerators[i].get(), importedMap);
}
}
@@ -1695,7 +1705,6 @@ void cmGlobalGenerator::ClearGeneratorMembers()
cmDeleteAll(this->Makefiles);
this->Makefiles.clear();
- cmDeleteAll(this->LocalGenerators);
this->LocalGenerators.clear();
this->AliasTargets.clear();
@@ -2036,9 +2045,10 @@ void cmGlobalGenerator::EnableInstallTarget()
this->InstallTargetEnabled = true;
}
-cmLocalGenerator* cmGlobalGenerator::CreateLocalGenerator(cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator> cmGlobalGenerator::CreateLocalGenerator(
+ cmMakefile* mf)
{
- return new cmLocalGenerator(this, mf);
+ return cm::make_unique<cmLocalGenerator>(this, mf);
}
void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator* gen,
@@ -2133,7 +2143,7 @@ int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
void cmGlobalGenerator::FillProjectMap()
{
this->ProjectMap.clear(); // make sure we start with a clean map
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
// for each local generator add all projects
cmStateSnapshot snp = localGen->GetStateSnapshot();
std::string name;
@@ -2141,7 +2151,7 @@ void cmGlobalGenerator::FillProjectMap()
std::string snpProjName = snp.GetProjectName();
if (name != snpProjName) {
name = snpProjName;
- this->ProjectMap[name].push_back(localGen);
+ this->ProjectMap[name].push_back(localGen.get());
}
snp = snp.GetBuildsystemDirectoryParent();
} while (snp.IsValid());
@@ -2466,6 +2476,7 @@ void cmGlobalGenerator::AddGlobalTarget_EditCache(
}
GlobalTargetInfo gti;
gti.Name = editCacheTargetName;
+ gti.PerConfig = false;
cmCustomCommandLine singleLine;
// Use generator preference for the edit_cache rule if it is defined.
@@ -2500,6 +2511,7 @@ void cmGlobalGenerator::AddGlobalTarget_RebuildCache(
gti.Name = rebuildCacheTargetName;
gti.Message = "Running CMake to regenerate build system...";
gti.UsesTerminal = true;
+ gti.PerConfig = false;
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCMakeCommand());
singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
@@ -2644,7 +2656,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti,
{
// Package
cmTarget target(gti.Name, cmStateEnums::GLOBAL_TARGET,
- cmTarget::VisibilityNormal, mf);
+ cmTarget::VisibilityNormal, mf, gti.PerConfig);
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE");
std::vector<std::string> no_outputs;
@@ -2756,13 +2768,12 @@ void cmGlobalGenerator::GetFilesReplacedDuringGenerate(
std::back_inserter(filenames));
}
-void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
- TargetDependSet& originalTargets,
- cmLocalGenerator* root,
- GeneratorVector const& generators)
+void cmGlobalGenerator::GetTargetSets(
+ TargetDependSet& projectTargets, TargetDependSet& originalTargets,
+ cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
{
// loop over all local generators
- for (cmLocalGenerator* generator : generators) {
+ for (auto generator : generators) {
// check to make sure generator is not excluded
if (this->IsExcluded(root, generator)) {
continue;
@@ -2952,7 +2963,7 @@ void cmGlobalGenerator::WriteSummary()
"/CMakeFiles/TargetDirectories.txt");
cmGeneratedFileStream fout(fname);
- for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (const auto& lg : this->LocalGenerators) {
for (const auto& tgt : lg->GetGeneratorTargets()) {
if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
@@ -3102,7 +3113,7 @@ cmGlobalGenerator::GetFilenameTargetDepends(cmSourceFile* sf) const
void cmGlobalGenerator::ProcessEvaluationFiles()
{
std::vector<std::string> generatedFiles;
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (auto& localGen : this->LocalGenerators) {
localGen->ProcessEvaluationFiles(generatedFiles);
}
}
@@ -3118,7 +3129,7 @@ bool cmGlobalGenerator::GenerateCPackPropertiesFile()
cmake::InstalledFilesMap const& installedFiles =
this->CMakeInstance->GetInstalledFiles();
- cmLocalGenerator* lg = this->LocalGenerators[0];
+ const auto& lg = this->LocalGenerators[0];
cmMakefile* mf = lg->GetMakefile();
std::vector<std::string> configs;
@@ -3137,8 +3148,8 @@ bool cmGlobalGenerator::GenerateCPackPropertiesFile()
for (auto const& i : installedFiles) {
cmInstalledFile const& installedFile = i.second;
- cmCPackPropertiesGenerator cpackPropertiesGenerator(lg, installedFile,
- configs);
+ cmCPackPropertiesGenerator cpackPropertiesGenerator(
+ lg.get(), installedFile, configs);
cpackPropertiesGenerator.Generate(file, config, configs);
}
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 0e87357..107df4d 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -90,11 +90,14 @@ struct GeneratedMakeCommand
class cmGlobalGenerator
{
public:
+ using LocalGeneratorVector = std::vector<std::unique_ptr<cmLocalGenerator>>;
+
//! Free any memory allocated with the GlobalGenerator
cmGlobalGenerator(cmake* cm);
virtual ~cmGlobalGenerator();
- virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
+ virtual std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf);
//! Get the name for this generator
virtual std::string GetName() const { return "Generic"; }
@@ -249,7 +252,7 @@ public:
{
return this->Makefiles;
}
- const std::vector<cmLocalGenerator*>& GetLocalGenerators() const
+ const LocalGeneratorVector& GetLocalGenerators() const
{
return this->LocalGenerators;
}
@@ -476,13 +479,17 @@ public:
int RecursionDepth;
+ virtual void GetQtAutoGenConfigs(std::vector<std::string>& configs) const
+ {
+ configs.emplace_back("$<CONFIG>");
+ }
+
protected:
- using GeneratorVector = std::vector<cmLocalGenerator*>;
// for a project collect all its targets by following depend
// information, and also collect all the targets
void GetTargetSets(TargetDependSet& projectTargets,
TargetDependSet& originalTargets, cmLocalGenerator* root,
- GeneratorVector const&);
+ std::vector<cmLocalGenerator*>& generators);
bool IsRootOnlyTarget(cmGeneratorTarget* target) const;
void AddTargetDepends(const cmGeneratorTarget* target,
TargetDependSet& projectTargets);
@@ -525,6 +532,7 @@ protected:
std::vector<std::string> Depends;
std::string WorkingDir;
bool UsesTerminal = false;
+ bool PerConfig = true;
};
void CreateDefaultGlobalTargets(std::vector<GlobalTargetInfo>& targets);
@@ -541,7 +549,7 @@ protected:
std::string ConfiguredFilesPath;
cmake* CMakeInstance;
std::vector<cmMakefile*> Makefiles;
- std::vector<cmLocalGenerator*> LocalGenerators;
+ LocalGeneratorVector LocalGenerators;
cmMakefile* CurrentConfigureMakefile;
// map from project name to vector of local generators in that project
std::map<std::string, std::vector<cmLocalGenerator*>> ProjectMap;
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx
index 7afcd49..bb9dd37 100644
--- a/Source/cmGlobalGhsMultiGenerator.cxx
+++ b/Source/cmGlobalGhsMultiGenerator.cxx
@@ -8,6 +8,8 @@
#include <ostream>
#include <utility>
+#include <cm/memory>
+
#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
#include "cmGeneratedFileStream.h"
@@ -40,10 +42,11 @@ cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm)
cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator() = default;
-cmLocalGenerator* cmGlobalGhsMultiGenerator::CreateLocalGenerator(
- cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator>
+cmGlobalGhsMultiGenerator::CreateLocalGenerator(cmMakefile* mf)
{
- return new cmLocalGhsMultiGenerator(this, mf);
+ return std::unique_ptr<cmLocalGenerator>(
+ cm::make_unique<cmLocalGhsMultiGenerator>(this, mf));
}
void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry& entry)
diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h
index 7cd8c79..989b12c 100644
--- a/Source/cmGlobalGhsMultiGenerator.h
+++ b/Source/cmGlobalGhsMultiGenerator.h
@@ -4,6 +4,7 @@
#define cmGhsMultiGenerator_h
#include <iosfwd>
+#include <memory>
#include <set>
#include <string>
#include <utility>
@@ -34,7 +35,8 @@ public:
}
//! create the correct local generator
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
/// @return the name of this generator.
static std::string GetActualName() { return "Green Hills MULTI"; }
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index da21d6c..11dd705 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -9,6 +9,7 @@
#include <sstream>
#include <cm/memory>
+#include <cmext/memory>
#include "cmsys/FStream.hxx"
@@ -114,6 +115,11 @@ std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string& lit)
std::string result = lit;
cmSystemTools::ReplaceString(result, "$", "$$");
cmSystemTools::ReplaceString(result, "\n", "$\n");
+ if (this->IsMultiConfig()) {
+ cmSystemTools::ReplaceString(result,
+ cmStrCat('$', this->GetCMakeCFGIntDir()),
+ this->GetCMakeCFGIntDir());
+ }
return result;
}
@@ -248,8 +254,8 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
const std::string& command, const std::string& description,
const std::string& comment, const std::string& depfile,
const std::string& job_pool, bool uses_terminal, bool restat,
- const cmNinjaDeps& outputs, const cmNinjaDeps& explicitDeps,
- const cmNinjaDeps& orderOnlyDeps)
+ const cmNinjaDeps& outputs, const std::string& config,
+ const cmNinjaDeps& explicitDeps, const cmNinjaDeps& orderOnlyDeps)
{
this->AddCustomCommandRule();
@@ -282,7 +288,11 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
if (!depfile.empty()) {
vars["depfile"] = depfile;
}
- this->WriteBuild(*this->BuildFileStream, build);
+ if (config.empty()) {
+ this->WriteBuild(*this->GetCommonFileStream(), build);
+ } else {
+ this->WriteBuild(*this->GetConfigFileStream(config), build);
+ }
}
if (this->ComputingUnknownDependencies) {
@@ -304,14 +314,15 @@ void cmGlobalNinjaGenerator::AddMacOSXContentRule()
}
void cmGlobalNinjaGenerator::WriteMacOSXContentBuild(std::string input,
- std::string output)
+ std::string output,
+ const std::string& config)
{
this->AddMacOSXContentRule();
{
cmNinjaBuild build("COPY_OSX_CONTENT");
build.Outputs.push_back(std::move(output));
build.ExplicitDeps.push_back(std::move(input));
- this->WriteBuild(*this->BuildFileStream, build);
+ this->WriteBuild(*this->GetConfigFileStream(config), build);
}
}
@@ -429,9 +440,11 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
// Virtual public methods.
-cmLocalGenerator* cmGlobalNinjaGenerator::CreateLocalGenerator(cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator> cmGlobalNinjaGenerator::CreateLocalGenerator(
+ cmMakefile* mf)
{
- return new cmLocalNinjaGenerator(this, mf);
+ return std::unique_ptr<cmLocalGenerator>(
+ cm::make_unique<cmLocalNinjaGenerator>(this, mf));
}
codecvt::Encoding cmGlobalNinjaGenerator::GetMakefileEncoding() const
@@ -470,14 +483,16 @@ void cmGlobalNinjaGenerator::Generate()
msg.str());
return;
}
- if (!this->OpenBuildFileStream()) {
+ if (!this->OpenBuildFileStreams()) {
return;
}
if (!this->OpenRulesFileStream()) {
return;
}
- this->TargetDependsClosures.clear();
+ for (auto& it : this->Configs) {
+ it.second.TargetDependsClosures.clear();
+ }
this->InitOutputPathPrefix();
this->TargetAll = this->NinjaOutputPath("all");
@@ -493,19 +508,26 @@ void cmGlobalNinjaGenerator::Generate()
this->cmGlobalGenerator::Generate();
this->WriteAssumedSourceDependencies();
- this->WriteTargetAliases(*this->BuildFileStream);
- this->WriteFolderTargets(*this->BuildFileStream);
- this->WriteUnknownExplicitDependencies(*this->BuildFileStream);
- this->WriteBuiltinTargets(*this->BuildFileStream);
+ this->WriteTargetAliases(*this->GetCommonFileStream());
+ this->WriteFolderTargets(*this->GetCommonFileStream());
+ this->WriteUnknownExplicitDependencies(*this->GetCommonFileStream());
+ this->WriteBuiltinTargets(*this->GetCommonFileStream());
if (cmSystemTools::GetErrorOccuredFlag()) {
this->RulesFileStream->setstate(std::ios::failbit);
- this->BuildFileStream->setstate(std::ios::failbit);
+ for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) {
+ this->GetConfigFileStream(config)->setstate(std::ios::failbit);
+ }
+ this->GetCommonFileStream()->setstate(std::ios::failbit);
}
this->CloseCompileCommandsStream();
this->CloseRulesFileStream();
- this->CloseBuildFileStream();
+ this->CloseBuildFileStreams();
+
+ if (!this->WriteDefaultBuildFile()) {
+ return;
+ }
}
bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf)
@@ -609,6 +631,17 @@ bool cmGlobalNinjaGenerator::CheckFortran(cmMakefile* mf) const
void cmGlobalNinjaGenerator::EnableLanguage(
std::vector<std::string> const& langs, cmMakefile* mf, bool optional)
{
+ if (this->IsMultiConfig()) {
+ if (!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
+ mf->AddCacheDefinition(
+ "CMAKE_CONFIGURATION_TYPES", "Debug;Release;MinSizeRel;RelWithDebInfo",
+ "Semicolon separated list of supported configuration types, only "
+ "supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything "
+ "else will be ignored",
+ cmStateEnums::STRING);
+ }
+ }
+
this->cmGlobalGenerator::EnableLanguage(langs, mf, optional);
for (std::string const& l : langs) {
if (l == "NONE") {
@@ -650,7 +683,7 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalNinjaGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& /*projectName*/,
const std::string& /*projectDir*/,
- std::vector<std::string> const& targetNames, const std::string& /*config*/,
+ std::vector<std::string> const& targetNames, const std::string& config,
bool /*fast*/, int jobs, bool verbose,
std::vector<std::string> const& makeOptions)
{
@@ -666,6 +699,9 @@ cmGlobalNinjaGenerator::GenerateBuildCommand(
makeCommand.Add("-j", std::to_string(jobs));
}
+ this->AppendNinjaFileArgument(makeCommand,
+ config.empty() ? "Debug" : config);
+
makeCommand.Add(makeOptions.begin(), makeOptions.end());
for (const auto& tname : targetNames) {
if (!tname.empty()) {
@@ -707,44 +743,53 @@ void cmGlobalNinjaGenerator::ComputeTargetObjectDirectory(
cmGeneratorTarget* gt) const
{
// Compute full path to object file directory for this target.
- std::string dir =
- cmStrCat(gt->LocalGenerator->GetCurrentBinaryDirectory(), '/',
- gt->LocalGenerator->GetTargetDirectory(gt), '/');
+ std::string dir = cmStrCat(gt->LocalGenerator->GetCurrentBinaryDirectory(),
+ '/', gt->LocalGenerator->GetTargetDirectory(gt),
+ '/', this->GetCMakeCFGIntDir(), '/');
gt->ObjectDirectory = dir;
}
// Private methods
-bool cmGlobalNinjaGenerator::OpenBuildFileStream()
+bool cmGlobalNinjaGenerator::OpenBuildFileStreams()
{
- // Compute Ninja's build file path.
- std::string buildFilePath =
- cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), '/',
- cmGlobalNinjaGenerator::NINJA_BUILD_FILE);
+ if (!this->OpenFileStream(this->BuildFileStream,
+ cmGlobalNinjaGenerator::NINJA_BUILD_FILE)) {
+ return false;
+ }
+
+ // Write a comment about this file.
+ *this->BuildFileStream
+ << "# This file contains all the build statements describing the\n"
+ << "# compilation DAG.\n\n";
+
+ return true;
+}
+bool cmGlobalNinjaGenerator::OpenFileStream(
+ std::unique_ptr<cmGeneratedFileStream>& stream, const std::string& name)
+{
// Get a stream where to generate things.
- if (!this->BuildFileStream) {
- this->BuildFileStream = cm::make_unique<cmGeneratedFileStream>(
- buildFilePath, false, this->GetMakefileEncoding());
- if (!(*this->BuildFileStream)) {
+ if (!stream) {
+ // Compute Ninja's build file path.
+ std::string path =
+ cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), '/', name);
+ stream = cm::make_unique<cmGeneratedFileStream>(
+ path, false, this->GetMakefileEncoding());
+ if (!(*stream)) {
// An error message is generated by the constructor if it cannot
// open the file.
return false;
}
- }
-
- // Write the do not edit header.
- this->WriteDisclaimer(*this->BuildFileStream);
- // Write a comment about this file.
- *this->BuildFileStream
- << "# This file contains all the build statements describing the\n"
- << "# compilation DAG.\n\n";
+ // Write the do not edit header.
+ this->WriteDisclaimer(*stream);
+ }
return true;
}
-void cmGlobalNinjaGenerator::CloseBuildFileStream()
+void cmGlobalNinjaGenerator::CloseBuildFileStreams()
{
if (this->BuildFileStream) {
this->BuildFileStream.reset();
@@ -755,25 +800,11 @@ void cmGlobalNinjaGenerator::CloseBuildFileStream()
bool cmGlobalNinjaGenerator::OpenRulesFileStream()
{
- // Compute Ninja's build file path.
- std::string rulesFilePath =
- cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), '/',
- cmGlobalNinjaGenerator::NINJA_RULES_FILE);
-
- // Get a stream where to generate things.
- if (!this->RulesFileStream) {
- this->RulesFileStream = cm::make_unique<cmGeneratedFileStream>(
- rulesFilePath, false, this->GetMakefileEncoding());
- if (!(*this->RulesFileStream)) {
- // An error message is generated by the constructor if it cannot
- // open the file.
- return false;
- }
+ if (!this->OpenFileStream(this->RulesFileStream,
+ cmGlobalNinjaGenerator::NINJA_RULES_FILE)) {
+ return false;
}
- // Write the do not edit header.
- this->WriteDisclaimer(*this->RulesFileStream);
-
// Write comment about this file.
/* clang-format off */
*this->RulesFileStream
@@ -819,10 +850,10 @@ std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath(
return f->second;
}
- cmLocalNinjaGenerator* ng =
- static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
- std::string const& bin_dir = ng->GetState()->GetBinaryDirectory();
- std::string convPath = ng->MaybeConvertToRelativePath(bin_dir, path);
+ const auto& ng =
+ cm::static_reference_cast<cmLocalNinjaGenerator>(this->LocalGenerators[0]);
+ std::string const& bin_dir = ng.GetState()->GetBinaryDirectory();
+ std::string convPath = ng.MaybeConvertToRelativePath(bin_dir, path);
convPath = this->NinjaOutputPath(convPath);
#ifdef _WIN32
std::replace(convPath.begin(), convPath.end(), '/', '\\');
@@ -831,9 +862,10 @@ std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath(
.first->second;
}
-void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName)
+void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName,
+ const std::string& config)
{
- this->AdditionalCleanFiles.emplace(std::move(fileName));
+ this->Configs[config].AdditionalCleanFiles.emplace(std::move(fileName));
}
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
@@ -901,23 +933,22 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
"Assume dependencies for generated source file.",
/*depfile*/ "", /*job_pool*/ "",
/*uses_terminal*/ false,
- /*restat*/ true, cmNinjaDeps(1, asd.first),
+ /*restat*/ true, cmNinjaDeps(1, asd.first), "",
cmNinjaDeps(), orderOnlyDeps);
}
}
-std::string OrderDependsTargetForTarget(cmGeneratorTarget const* target)
+std::string cmGlobalNinjaGenerator::OrderDependsTargetForTarget(
+ cmGeneratorTarget const* target, const std::string& config)
{
- return "cmake_object_order_depends_target_" + target->GetName();
+ return "cmake_object_order_depends_target_" + target->GetName() + "_" +
+ config;
}
void cmGlobalNinjaGenerator::AppendTargetOutputs(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
- cmNinjaTargetDepends depends)
+ const std::string& config, cmNinjaTargetDepends depends)
{
- std::string configName =
- target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
-
// for frameworks, we want the real name, not smple name
// frameworks always appear versioned, and the build.ninja
// will always attempt to manage symbolic links instead
@@ -929,19 +960,19 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs(
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: {
if (depends == DependOnTargetOrdering) {
- outputs.push_back(OrderDependsTargetForTarget(target));
+ outputs.push_back(OrderDependsTargetForTarget(target, config));
break;
}
}
// FALLTHROUGH
case cmStateEnums::EXECUTABLE: {
outputs.push_back(this->ConvertToNinjaPath(target->GetFullPath(
- configName, cmStateEnums::RuntimeBinaryArtifact, realname)));
+ config, cmStateEnums::RuntimeBinaryArtifact, realname)));
break;
}
case cmStateEnums::OBJECT_LIBRARY: {
if (depends == DependOnTargetOrdering) {
- outputs.push_back(OrderDependsTargetForTarget(target));
+ outputs.push_back(OrderDependsTargetForTarget(target, config));
break;
}
}
@@ -951,7 +982,11 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs(
std::string path =
target->GetLocalGenerator()->GetCurrentBinaryDirectory() +
std::string("/") + target->GetName();
- outputs.push_back(this->ConvertToNinjaPath(path));
+ std::string output = this->ConvertToNinjaPath(path);
+ if (target->Target->IsPerConfig()) {
+ output = this->BuildAlias(output, config);
+ }
+ outputs.push_back(output);
break;
}
@@ -962,6 +997,7 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs(
void cmGlobalNinjaGenerator::AppendTargetDepends(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
+ const std::string& config, const std::string& fileConfig,
cmNinjaTargetDepends depends)
{
if (target->GetType() == cmStateEnums::GLOBAL_TARGET) {
@@ -970,7 +1006,7 @@ void cmGlobalNinjaGenerator::AppendTargetDepends(
std::string d =
target->GetLocalGenerator()->GetCurrentBinaryDirectory() + "/" +
util.Value;
- outputs.push_back(this->ConvertToNinjaPath(d));
+ outputs.push_back(this->BuildAlias(this->ConvertToNinjaPath(d), config));
}
} else {
cmNinjaDeps outs;
@@ -979,7 +1015,14 @@ void cmGlobalNinjaGenerator::AppendTargetDepends(
if (targetDep->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- this->AppendTargetOutputs(targetDep, outs, depends);
+ // For some reason, object libraries show up as "utility" dependencies
+ // even though they're used for linking. Treat them as link dependencies.
+ if (targetDep.IsUtil() &&
+ targetDep->GetType() != cmStateEnums::OBJECT_LIBRARY) {
+ this->AppendTargetOutputs(targetDep, outs, fileConfig, depends);
+ } else {
+ this->AppendTargetOutputs(targetDep, outs, config, depends);
+ }
}
std::sort(outs.begin(), outs.end());
cmAppend(outputs, outs);
@@ -987,21 +1030,24 @@ void cmGlobalNinjaGenerator::AppendTargetDepends(
}
void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
- cmGeneratorTarget const* target, cmNinjaDeps& outputs)
+ cmGeneratorTarget const* target, cmNinjaDeps& outputs,
+ const std::string& config)
{
cmNinjaOuts outs;
- this->AppendTargetDependsClosure(target, outs, true);
+ this->AppendTargetDependsClosure(target, outs, config, true);
cmAppend(outputs, outs);
}
void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
- cmGeneratorTarget const* target, cmNinjaOuts& outputs, bool omit_self)
+ cmGeneratorTarget const* target, cmNinjaOuts& outputs,
+ const std::string& config, bool omit_self)
{
// try to locate the target in the cache
- auto find = this->TargetDependsClosures.lower_bound(target);
+ auto find = this->Configs[config].TargetDependsClosures.lower_bound(target);
- if (find == this->TargetDependsClosures.end() || find->first != target) {
+ if (find == this->Configs[config].TargetDependsClosures.end() ||
+ find->first != target) {
// We now calculate the closure outputs by inspecting the dependent
// targets recursively.
// For that we have to distinguish between a local result set that is only
@@ -1016,10 +1062,10 @@ void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
}
// Collect the dependent targets for _this_ target
- this->AppendTargetDependsClosure(dep_target, this_outs, false);
+ this->AppendTargetDependsClosure(dep_target, this_outs, config, false);
}
- find = this->TargetDependsClosures.emplace_hint(find, target,
- std::move(this_outs));
+ find = this->Configs[config].TargetDependsClosures.emplace_hint(
+ find, target, std::move(this_outs));
}
// now fill the outputs of the final result from the newly generated cache
@@ -1029,29 +1075,48 @@ void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
// finally generate the outputs of the target itself, if applicable
cmNinjaDeps outs;
if (!omit_self) {
- this->AppendTargetOutputs(target, outs);
+ this->AppendTargetOutputs(target, outs, config);
}
outputs.insert(outs.begin(), outs.end());
}
void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
- cmGeneratorTarget* target)
+ cmGeneratorTarget* target,
+ const std::string& config)
{
- std::string buildAlias = this->NinjaOutputPath(alias);
+ std::string outputPath = this->NinjaOutputPath(alias);
+ std::string buildAlias = this->BuildAlias(outputPath, config);
cmNinjaDeps outputs;
- this->AppendTargetOutputs(target, outputs);
- // Mark the target's outputs as ambiguous to ensure that no other target uses
- // the output as an alias.
+ this->AppendTargetOutputs(target, outputs, config);
+ // Mark the target's outputs as ambiguous to ensure that no other target
+ // uses the output as an alias.
for (std::string const& output : outputs) {
- TargetAliases[output] = nullptr;
+ this->TargetAliases[output].GeneratorTarget = nullptr;
+ for (const std::string& config2 :
+ this->Makefiles.front()->GetGeneratorConfigs()) {
+ this->Configs[config2].TargetAliases[output].GeneratorTarget = nullptr;
+ }
}
// Insert the alias into the map. If the alias was already present in the
// map and referred to another target, mark it as ambiguous.
- std::pair<TargetAliasMap::iterator, bool> newAlias =
- TargetAliases.insert(std::make_pair(buildAlias, target));
- if (newAlias.second && newAlias.first->second != target) {
- newAlias.first->second = nullptr;
+ TargetAlias ta;
+ ta.GeneratorTarget = target;
+ ta.Config = config;
+ std::pair<TargetAliasMap::iterator, bool> newAliasGlobal =
+ this->TargetAliases.insert(std::make_pair(buildAlias, ta));
+ if (newAliasGlobal.second &&
+ newAliasGlobal.first->second.GeneratorTarget != target) {
+ newAliasGlobal.first->second.GeneratorTarget = nullptr;
+ }
+ if (config != "all") {
+ std::pair<TargetAliasMap::iterator, bool> newAliasConfig =
+ this->Configs[config].TargetAliases.insert(
+ std::make_pair(outputPath, ta));
+ if (newAliasConfig.second &&
+ newAliasConfig.first->second.GeneratorTarget != target) {
+ newAliasConfig.first->second.GeneratorTarget = nullptr;
+ }
}
}
@@ -1061,10 +1126,10 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
os << "# Target aliases.\n\n";
cmNinjaBuild build("phony");
- build.Outputs.emplace_back("");
- for (auto const& ta : TargetAliases) {
+ build.Outputs.emplace_back();
+ for (auto const& ta : this->TargetAliases) {
// Don't write ambiguous aliases.
- if (!ta.second) {
+ if (!ta.second.GeneratorTarget) {
continue;
}
@@ -1074,14 +1139,43 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
continue;
}
- // Outputs
- build.Outputs[0] = ta.first;
- // Explicit depdendencies
+ build.Outputs.front() = ta.first;
build.ExplicitDeps.clear();
- this->AppendTargetOutputs(ta.second, build.ExplicitDeps);
- // Write
+ if (ta.second.Config == "all") {
+ for (auto const& config :
+ ta.second.GeneratorTarget->Makefile->GetGeneratorConfigs()) {
+ this->AppendTargetOutputs(ta.second.GeneratorTarget,
+ build.ExplicitDeps, config);
+ }
+ } else {
+ this->AppendTargetOutputs(ta.second.GeneratorTarget, build.ExplicitDeps,
+ ta.second.Config);
+ }
this->WriteBuild(os, build);
}
+
+ if (this->IsMultiConfig()) {
+ for (auto const& config : this->Makefiles.front()->GetGeneratorConfigs()) {
+ for (auto const& ta : this->Configs[config].TargetAliases) {
+ // Don't write ambiguous aliases.
+ if (!ta.second.GeneratorTarget) {
+ continue;
+ }
+
+ // Don't write alias if there is a already a custom command with
+ // matching output
+ if (this->HasCustomCommandOutput(ta.first)) {
+ continue;
+ }
+
+ build.Outputs.front() = ta.first;
+ build.ExplicitDeps.clear();
+ this->AppendTargetOutputs(ta.second.GeneratorTarget,
+ build.ExplicitDeps, config);
+ this->WriteBuild(*this->GetConfigFileStream(config), build);
+ }
+ }
+ }
}
void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
@@ -1097,24 +1191,58 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
cmGlobalNinjaGenerator::WriteDivider(os);
std::string const& currentBinaryDir = it.first;
DirectoryTarget const& dt = it.second;
+ std::vector<std::string> configs;
+ dt.LG->GetMakefile()->GetConfigurations(configs, true);
+ if (configs.empty()) {
+ configs.emplace_back();
+ }
// Setup target
+ cmNinjaDeps configDeps;
build.Comment = "Folder: " + currentBinaryDir;
- build.Outputs.emplace_back(
- this->ConvertToNinjaPath(currentBinaryDir + "/all"));
- for (DirectoryTarget::Target const& t : dt.Targets) {
- if (!t.ExcludeFromAll) {
- this->AppendTargetOutputs(t.GT, build.ExplicitDeps);
+ build.Outputs.emplace_back();
+ for (auto const& config : configs) {
+ build.ExplicitDeps.clear();
+ build.Outputs.front() = this->BuildAlias(
+ this->ConvertToNinjaPath(currentBinaryDir + "/all"), config);
+ configDeps.emplace_back(build.Outputs.front());
+ for (DirectoryTarget::Target const& t : dt.Targets) {
+ if (!t.ExcludeFromAll) {
+ this->AppendTargetOutputs(t.GT, build.ExplicitDeps, config);
+ }
}
+ for (DirectoryTarget::Dir const& d : dt.Children) {
+ if (!d.ExcludeFromAll) {
+ build.ExplicitDeps.emplace_back(this->BuildAlias(
+ this->ConvertToNinjaPath(d.Path + "/all"), config));
+ }
+ }
+ // Write target
+ this->WriteBuild(os, build);
}
- for (DirectoryTarget::Dir const& d : dt.Children) {
- if (!d.ExcludeFromAll) {
- build.ExplicitDeps.emplace_back(
- this->ConvertToNinjaPath(d.Path + "/all"));
+
+ // Add shortcut target
+ if (this->IsMultiConfig()) {
+ for (auto const& config : configs) {
+ build.ExplicitDeps = { this->BuildAlias(
+ this->ConvertToNinjaPath(currentBinaryDir + "/all"), config) };
+ build.Outputs.front() =
+ this->ConvertToNinjaPath(currentBinaryDir + "/all");
+ this->WriteBuild(*this->GetConfigFileStream(config), build);
}
}
- // Write target
- this->WriteBuild(os, build);
+
+ // Add target for all configs
+ if (this->IsMultiConfig()) {
+ build.ExplicitDeps.clear();
+ for (auto const& config : configs) {
+ build.ExplicitDeps.push_back(this->BuildAlias(
+ this->ConvertToNinjaPath(currentBinaryDir + "/all"), config));
+ }
+ build.Outputs.front() = this->BuildAlias(
+ this->ConvertToNinjaPath(currentBinaryDir + "/all"), "all");
+ this->WriteBuild(*this->GetCommonFileStream(), build);
+ }
}
}
@@ -1148,7 +1276,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
// get the list of files that cmake itself has generated as a
// product of configuration.
- for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (const auto& lg : this->LocalGenerators) {
// get the vector of files created by this makefile and convert them
// to ninja paths, which are all relative in respect to the build directory
for (std::string const& file : lg->GetMakefile()->GetOutputFiles()) {
@@ -1247,10 +1375,13 @@ void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
cmGlobalNinjaGenerator::WriteDivider(os);
os << "# Built-in targets\n\n";
- this->WriteTargetDefault(os);
this->WriteTargetRebuildManifest(os);
this->WriteTargetClean(os);
this->WriteTargetHelp(os);
+
+ for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) {
+ this->WriteTargetDefault(*this->GetConfigFileStream(config));
+ }
}
void cmGlobalNinjaGenerator::WriteTargetDefault(std::ostream& os)
@@ -1268,7 +1399,7 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
return;
}
- cmLocalGenerator* lg = this->LocalGenerators[0];
+ const auto& lg = this->LocalGenerators[0];
{
cmNinjaRule rule("RERUN_CMAKE");
@@ -1287,9 +1418,9 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
cmNinjaBuild reBuild("RERUN_CMAKE");
reBuild.Comment = "Re-run CMake if any of its inputs changed.";
- reBuild.Outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE));
+ this->AddRebuildManifestOutputs(reBuild.Outputs);
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
for (std::string const& fi : localGen->GetMakefile()->GetListFiles()) {
reBuild.ImplicitDeps.push_back(this->ConvertToNinjaPath(fi));
}
@@ -1376,14 +1507,14 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
std::string cmGlobalNinjaGenerator::CMakeCmd() const
{
- cmLocalGenerator* lgen = this->LocalGenerators.at(0);
+ const auto& lgen = this->LocalGenerators.at(0);
return lgen->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
cmOutputConverter::SHELL);
}
std::string cmGlobalNinjaGenerator::NinjaCmd() const
{
- cmLocalGenerator* lgen = this->LocalGenerators[0];
+ const auto& lgen = this->LocalGenerators[0];
if (lgen != nullptr) {
return lgen->ConvertToOutputFormat(this->NinjaCommand,
cmOutputConverter::SHELL);
@@ -1413,13 +1544,27 @@ bool cmGlobalNinjaGenerator::SupportsMultilineDepfile() const
bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
{
- cmLocalGenerator* lgr = this->LocalGenerators.at(0);
+ const auto& lgr = this->LocalGenerators.at(0);
std::string cleanScriptRel = "CMakeFiles/clean_additional.cmake";
std::string cleanScriptAbs =
cmStrCat(lgr->GetBinaryDirectory(), '/', cleanScriptRel);
+ std::vector<std::string> configs;
+ this->Makefiles[0]->GetConfigurations(configs, true);
+ if (configs.empty()) {
+ configs.emplace_back();
+ }
// Check if there are additional files to clean
- if (this->AdditionalCleanFiles.empty()) {
+ bool empty = true;
+ for (auto const& config : configs) {
+ auto const it = this->Configs.find(config);
+ if (it != this->Configs.end() &&
+ !it->second.AdditionalCleanFiles.empty()) {
+ empty = false;
+ break;
+ }
+ }
+ if (empty) {
// Remove cmake clean script file if it exists
cmSystemTools::RemoveFile(cleanScriptAbs);
return false;
@@ -1431,14 +1576,23 @@ bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
if (!fout) {
return false;
}
- fout << "# Additional clean files\n\n";
- fout << "file(REMOVE_RECURSE\n";
- for (std::string const& acf : this->AdditionalCleanFiles) {
- fout << " "
- << cmOutputConverter::EscapeForCMake(ConvertToNinjaPath(acf))
- << '\n';
+ fout << "# Additional clean files\ncmake_minimum_required(VERSION 3.16)\n";
+ for (auto const& config : configs) {
+ auto const it = this->Configs.find(config);
+ if (it != this->Configs.end() &&
+ !it->second.AdditionalCleanFiles.empty()) {
+ fout << "\nif(\"${CONFIG}\" STREQUAL \"\" OR \"${CONFIG}\" STREQUAL \""
+ << config << "\")\n";
+ fout << " file(REMOVE_RECURSE\n";
+ for (std::string const& acf : it->second.AdditionalCleanFiles) {
+ fout << " "
+ << cmOutputConverter::EscapeForCMake(ConvertToNinjaPath(acf))
+ << '\n';
+ }
+ fout << " )\n";
+ fout << "endif()\n";
+ }
}
- fout << ")\n";
}
// Register clean script file
lgr->GetMakefile()->AddCMakeOutputFile(cleanScriptAbs);
@@ -1447,7 +1601,7 @@ bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
{
cmNinjaRule rule("CLEAN_ADDITIONAL");
rule.Command = cmStrCat(
- CMakeCmd(), " -P ",
+ CMakeCmd(), " -DCONFIG=$CONFIG -P ",
lgr->ConvertToOutputFormat(this->NinjaOutputPath(cleanScriptRel),
cmOutputConverter::SHELL));
rule.Description = "Cleaning additional files...";
@@ -1459,9 +1613,19 @@ bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
{
cmNinjaBuild build("CLEAN_ADDITIONAL");
build.Comment = "Clean additional files.";
- build.Outputs.push_back(
- this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
- WriteBuild(os, build);
+ build.Outputs.emplace_back();
+ for (auto const& config : configs) {
+ build.Outputs.front() = this->BuildAlias(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()), config);
+ build.Variables["CONFIG"] = config;
+ WriteBuild(os, build);
+ }
+ if (this->IsMultiConfig()) {
+ build.Outputs.front() =
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName());
+ build.Variables["CONFIG"] = "";
+ WriteBuild(os, build);
+ }
}
// Return success
return true;
@@ -1476,22 +1640,91 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
// Write rule
{
cmNinjaRule rule("CLEAN");
- rule.Command = NinjaCmd() + " -t clean";
+ rule.Command = NinjaCmd() + " $FILE_ARG -t clean $TARGETS";
rule.Description = "Cleaning all built files...";
rule.Comment = "Rule for cleaning all built files.";
WriteRule(*this->RulesFileStream, rule);
}
+ auto const configs = this->Makefiles.front()->GetGeneratorConfigs();
+
// Write build
{
cmNinjaBuild build("CLEAN");
build.Comment = "Clean all the built files.";
- build.Outputs.push_back(this->NinjaOutputPath(this->GetCleanTargetName()));
- if (additionalFiles) {
- build.ExplicitDeps.push_back(
- this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ build.Outputs.emplace_back();
+
+ for (auto const& config : configs) {
+ build.Outputs.front() = this->BuildAlias(
+ this->NinjaOutputPath(this->GetCleanTargetName()), config);
+ if (this->IsMultiConfig()) {
+ build.Variables["TARGETS"] =
+ cmStrCat(this->BuildAlias(GetByproductsForCleanTargetName(), config),
+ " ", GetByproductsForCleanTargetName());
+ }
+ build.ExplicitDeps.clear();
+ if (additionalFiles) {
+ build.ExplicitDeps.push_back(this->BuildAlias(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()),
+ config));
+ }
+ for (auto const& fileConfig : configs) {
+ if (this->IsMultiConfig()) {
+ build.Variables["FILE_ARG"] = cmStrCat(
+ "-f ", cmGlobalNinjaMultiGenerator::GetNinjaFilename(fileConfig));
+ }
+ this->WriteBuild(*this->GetConfigFileStream(fileConfig), build);
+ }
}
+
+ if (this->IsMultiConfig()) {
+ build.Outputs.front() = this->BuildAlias(
+ this->NinjaOutputPath(this->GetCleanTargetName()), "all");
+ build.ExplicitDeps.clear();
+
+ if (additionalFiles) {
+ build.ExplicitDeps.push_back(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ }
+
+ build.Variables["TARGETS"] = "";
+
+ for (auto const& fileConfig : configs) {
+ build.Variables["FILE_ARG"] = cmStrCat(
+ "-f ", cmGlobalNinjaMultiGenerator::GetNinjaFilename(fileConfig));
+ this->WriteBuild(*this->GetConfigFileStream(fileConfig), build);
+ }
+ }
+ }
+
+ if (this->IsMultiConfig()) {
+ cmNinjaBuild build("phony");
+ build.Outputs.emplace_back(
+ this->NinjaOutputPath(this->GetCleanTargetName()));
+ build.ExplicitDeps.emplace_back();
+
+ for (auto const& config : configs) {
+ build.ExplicitDeps.front() = this->BuildAlias(
+ this->NinjaOutputPath(this->GetCleanTargetName()), config);
+ this->WriteBuild(*this->GetConfigFileStream(config), build);
+ }
+ }
+
+ // Write byproducts
+ if (this->IsMultiConfig()) {
+ cmNinjaBuild build("phony");
+ build.Comment = "Clean byproducts.";
+ build.Outputs.emplace_back(
+ this->ConvertToNinjaPath(GetByproductsForCleanTargetName()));
+ build.ExplicitDeps = this->ByproductsForCleanTarget;
WriteBuild(os, build);
+
+ for (auto const& config : configs) {
+ build.Outputs.front() = this->BuildAlias(
+ this->ConvertToNinjaPath(GetByproductsForCleanTargetName()), config);
+ build.ExplicitDeps = this->Configs[config].ByproductsForCleanTarget;
+ WriteBuild(os, build);
+ }
}
}
@@ -1809,11 +2042,9 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
snapshot.GetDirectory().SetRelativePathTopSource(dir_top_src.c_str());
snapshot.GetDirectory().SetRelativePathTopBinary(dir_top_bld.c_str());
auto mfd = cm::make_unique<cmMakefile>(this, snapshot);
- std::unique_ptr<cmLocalNinjaGenerator> lgd(
- static_cast<cmLocalNinjaGenerator*>(
- this->CreateLocalGenerator(mfd.get())));
+ auto lgd = this->CreateLocalGenerator(mfd.get());
this->Makefiles.push_back(mfd.release());
- this->LocalGenerators.push_back(lgd.release());
+ this->LocalGenerators.push_back(std::move(lgd));
}
std::vector<cmDyndepObjectInfo> objects;
@@ -2000,3 +2231,137 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
}
return 0;
}
+
+void cmGlobalNinjaGenerator::AppendDirectoryForConfig(
+ const std::string& prefix, const std::string& config,
+ const std::string& suffix, std::string& dir)
+{
+ if (!config.empty() && this->IsMultiConfig()) {
+ dir += prefix;
+ dir += config;
+ dir += suffix;
+ }
+}
+
+const char* cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE = "common.ninja";
+const char* cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION = ".ninja";
+
+cmGlobalNinjaMultiGenerator::cmGlobalNinjaMultiGenerator(cmake* cm)
+ : cmGlobalNinjaGenerator(cm)
+{
+ cm->GetState()->SetIsGeneratorMultiConfig(true);
+ cm->GetState()->SetNinjaMulti(true);
+}
+
+void cmGlobalNinjaMultiGenerator::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalNinjaMultiGenerator::GetActualName();
+ entry.Brief = "Generates build-<Config>.ninja files.";
+}
+
+std::string cmGlobalNinjaMultiGenerator::ExpandCFGIntDir(
+ const std::string& str, const std::string& config) const
+{
+ std::string result = str;
+ cmSystemTools::ReplaceString(result, this->GetCMakeCFGIntDir(), config);
+ return result;
+}
+
+bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams()
+{
+ if (!this->OpenFileStream(this->CommonFileStream,
+ cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE)) {
+ return false;
+ }
+
+ // Write a comment about this file.
+ *this->CommonFileStream
+ << "# This file contains build statements common to all "
+ "configurations.\n\n";
+
+ for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) {
+ if (!this->OpenFileStream(this->ConfigFileStreams[config],
+ GetNinjaFilename(config))) {
+ return false;
+ }
+
+ // Write a comment about this file.
+ *this->ConfigFileStreams[config]
+ << "# This file contains build statements specific to the \"" << config
+ << "\"\n# configuration.\n\n";
+ }
+
+ return true;
+}
+
+void cmGlobalNinjaMultiGenerator::CloseBuildFileStreams()
+{
+ if (this->CommonFileStream) {
+ this->CommonFileStream.reset();
+ } else {
+ cmSystemTools::Error("Common file stream was not open.");
+ }
+
+ for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) {
+ if (this->ConfigFileStreams[config]) {
+ this->ConfigFileStreams[config].reset();
+ } else {
+ cmSystemTools::Error(
+ cmStrCat("Config file stream for \"", config, "\" was not open."));
+ }
+ }
+}
+
+void cmGlobalNinjaMultiGenerator::AppendNinjaFileArgument(
+ GeneratedMakeCommand& command, const std::string& config) const
+{
+ command.Add("-f");
+ command.Add(GetNinjaFilename(config));
+}
+
+std::string cmGlobalNinjaMultiGenerator::GetNinjaFilename(
+ const std::string& config)
+{
+ return cmStrCat("build-", config,
+ cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION);
+}
+
+void cmGlobalNinjaMultiGenerator::AddRebuildManifestOutputs(
+ cmNinjaDeps& outputs) const
+{
+ for (auto const& config : this->Makefiles.front()->GetGeneratorConfigs()) {
+ outputs.push_back(this->NinjaOutputPath(GetNinjaFilename(config)));
+ }
+ if (this->Makefiles.front()->GetDefinition(
+ "CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE")) {
+ outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE));
+ }
+}
+
+void cmGlobalNinjaMultiGenerator::GetQtAutoGenConfigs(
+ std::vector<std::string>& configs) const
+{
+ auto const oldSize = configs.size();
+ this->Makefiles.front()->GetConfigurations(configs);
+ if (configs.size() == oldSize) {
+ configs.emplace_back();
+ }
+}
+
+bool cmGlobalNinjaMultiGenerator::WriteDefaultBuildFile()
+{
+ auto const* defaultConfig = this->Makefiles.front()->GetDefinition(
+ "CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE");
+ if (defaultConfig) {
+ std::unique_ptr<cmGeneratedFileStream> defaultStream;
+ if (!this->OpenFileStream(defaultStream, NINJA_BUILD_FILE)) {
+ return false;
+ }
+ *defaultStream << "# This file is a convenience file generated by\n"
+ << "# CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE.\n\n"
+ << "include " << this->GetNinjaFilename(defaultConfig)
+ << "\n";
+ }
+
+ return true;
+}
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 244e9fd..6ebb31d 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -22,6 +22,7 @@
#include "cmGlobalGeneratorFactory.h"
#include "cmNinjaTypes.h"
#include "cmPolicies.h"
+#include "cmStringAlgorithms.h"
class cmCustomCommand;
class cmGeneratorTarget;
@@ -73,7 +74,7 @@ public:
static void WriteDivider(std::ostream& os);
static std::string EncodeRuleName(std::string const& name);
- static std::string EncodeLiteral(const std::string& lit);
+ std::string EncodeLiteral(const std::string& lit);
std::string EncodePath(const std::string& path);
cmLinkLineComputer* CreateLinkLineComputer(
@@ -111,11 +112,12 @@ public:
const std::string& command, const std::string& description,
const std::string& comment, const std::string& depfile,
const std::string& pool, bool uses_terminal, bool restat,
- const cmNinjaDeps& outputs,
+ const cmNinjaDeps& outputs, const std::string& config,
const cmNinjaDeps& explicitDeps = cmNinjaDeps(),
const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps());
- void WriteMacOSXContentBuild(std::string input, std::string output);
+ void WriteMacOSXContentBuild(std::string input, std::string output,
+ const std::string& config);
/**
* Write a rule statement to @a os.
@@ -156,7 +158,8 @@ public:
return new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaGenerator>();
}
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
std::string GetName() const override
{
@@ -204,7 +207,13 @@ public:
}
const char* GetCleanTargetName() const override { return "clean"; }
- cmGeneratedFileStream* GetBuildFileStream() const
+ virtual cmGeneratedFileStream* GetConfigFileStream(
+ const std::string& /*config*/) const
+ {
+ return this->BuildFileStream.get();
+ }
+
+ virtual cmGeneratedFileStream* GetCommonFileStream() const
{
return this->BuildFileStream.get();
}
@@ -231,12 +240,17 @@ public:
MapToNinjaPathImpl MapToNinjaPath() { return { this }; }
// -- Additional clean files
- void AddAdditionalCleanFile(std::string fileName);
+ void AddAdditionalCleanFile(std::string fileName, const std::string& config);
const char* GetAdditionalCleanTargetName() const
{
return "CMakeFiles/clean.additional";
}
+ static const char* GetByproductsForCleanTargetName()
+ {
+ return "CMakeFiles/cmake_byproducts_for_clean_target";
+ }
+
void AddCXXCompileCommand(const std::string& commandLine,
const std::string& sourceFile);
@@ -260,9 +274,9 @@ public:
/// Called when we have seen the given custom command. Returns true
/// if we has seen it before.
- bool SeenCustomCommand(cmCustomCommand const* cc)
+ bool SeenCustomCommand(cmCustomCommand const* cc, const std::string& config)
{
- return !this->CustomCommands.insert(cc).second;
+ return !this->Configs[config].CustomCommands.insert(cc).second;
}
/// Called when we have seen the given custom command output.
@@ -284,25 +298,43 @@ public:
ASD.insert(deps.begin(), deps.end());
}
+ static std::string OrderDependsTargetForTarget(
+ cmGeneratorTarget const* target, const std::string& config);
+
void AppendTargetOutputs(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
+ const std::string& config,
cmNinjaTargetDepends depends = DependOnTargetArtifact);
void AppendTargetDepends(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
+ const std::string& config, const std::string& fileConfig,
cmNinjaTargetDepends depends = DependOnTargetArtifact);
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
- cmNinjaDeps& outputs);
+ cmNinjaDeps& outputs,
+ const std::string& config);
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
- cmNinjaOuts& outputs, bool omit_self);
+ cmNinjaOuts& outputs,
+ const std::string& config, bool omit_self);
+
+ void AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir) override;
+
+ virtual void AppendNinjaFileArgument(GeneratedMakeCommand& /*command*/,
+ const std::string& /*config*/) const
+ {
+ }
- const std::vector<cmLocalGenerator*>& GetLocalGenerators() const
+ virtual void AddRebuildManifestOutputs(cmNinjaDeps& outputs) const
{
- return LocalGenerators;
+ outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE));
}
int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; }
- void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target);
+ void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target,
+ const std::string& config);
void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
@@ -335,11 +367,39 @@ public:
std::vector<std::string> const& linked_target_dirs,
std::string const& arg_lang);
+ virtual std::string BuildAlias(const std::string& alias,
+ const std::string& /*config*/) const
+ {
+ return alias;
+ }
+
+ virtual std::string ConfigDirectory(const std::string& /*config*/) const
+ {
+ return "";
+ }
+
+ cmNinjaDeps& GetByproductsForCleanTarget()
+ {
+ return this->ByproductsForCleanTarget;
+ }
+
+ cmNinjaDeps& GetByproductsForCleanTarget(const std::string& config)
+ {
+ return this->Configs[config].ByproductsForCleanTarget;
+ }
+
protected:
void Generate() override;
bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const override { return true; }
+ virtual bool OpenBuildFileStreams();
+ virtual void CloseBuildFileStreams();
+ virtual bool WriteDefaultBuildFile() { return true; }
+
+ bool OpenFileStream(std::unique_ptr<cmGeneratedFileStream>& stream,
+ const std::string& name);
+
private:
std::string GetEditCacheCommand() const override;
bool FindMakeProgram(cmMakefile* mf) override;
@@ -348,9 +408,6 @@ private:
cmMakefile* mf) const override;
bool CheckFortran(cmMakefile* mf) const;
- bool OpenBuildFileStream();
- void CloseBuildFileStream();
-
void CloseCompileCommandsStream();
bool OpenRulesFileStream();
@@ -395,9 +452,6 @@ private:
bool UsingGCCOnWindows = false;
- /// The set of custom commands we have seen.
- std::set<cmCustomCommand const*> CustomCommands;
-
/// The set of custom command outputs we have seen.
std::set<std::string> CustomCommandOutputs;
@@ -416,11 +470,14 @@ private:
/// The mapping from source file to assumed dependencies.
std::map<std::string, std::set<std::string>> AssumedSourceDependencies;
- using TargetAliasMap = std::map<std::string, cmGeneratorTarget*>;
+ struct TargetAlias
+ {
+ cmGeneratorTarget* GeneratorTarget;
+ std::string Config;
+ };
+ using TargetAliasMap = std::map<std::string, TargetAlias>;
TargetAliasMap TargetAliases;
- std::map<cmGeneratorTarget const*, cmNinjaOuts> TargetDependsClosures;
-
/// the local cache for calls to ConvertToNinjaPath
mutable std::unordered_map<std::string, std::string> ConvertToNinjaPathCache;
@@ -438,7 +495,101 @@ private:
std::string OutputPathPrefix;
std::string TargetAll;
std::string CMakeCacheFile;
- std::set<std::string> AdditionalCleanFiles;
+
+ struct ByConfig
+ {
+ std::set<std::string> AdditionalCleanFiles;
+
+ /// The set of custom commands we have seen.
+ std::set<cmCustomCommand const*> CustomCommands;
+
+ std::map<cmGeneratorTarget const*, cmNinjaOuts> TargetDependsClosures;
+
+ TargetAliasMap TargetAliases;
+
+ cmNinjaDeps ByproductsForCleanTarget;
+ };
+ std::map<std::string, ByConfig> Configs;
+
+ cmNinjaDeps ByproductsForCleanTarget;
+};
+
+class cmGlobalNinjaMultiGenerator : public cmGlobalNinjaGenerator
+{
+public:
+ /// The default name of Ninja's common file. Typically: common.ninja.
+ static const char* NINJA_COMMON_FILE;
+ /// The default file extension to use for per-config Ninja files.
+ static const char* NINJA_FILE_EXTENSION;
+
+ cmGlobalNinjaMultiGenerator(cmake* cm);
+ bool IsMultiConfig() const override { return true; }
+ static cmGlobalGeneratorFactory* NewFactory()
+ {
+ return new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaMultiGenerator>();
+ }
+
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ std::string GetName() const override
+ {
+ return cmGlobalNinjaMultiGenerator::GetActualName();
+ }
+
+ static std::string GetActualName() { return "Ninja Multi-Config"; }
+
+ std::string BuildAlias(const std::string& alias,
+ const std::string& config) const override
+ {
+ if (config.empty()) {
+ return alias;
+ }
+ return cmStrCat(alias, ":", config);
+ }
+
+ std::string ConfigDirectory(const std::string& config) const override
+ {
+ if (!config.empty()) {
+ return cmStrCat('/', config);
+ }
+ return "";
+ }
+
+ const char* GetCMakeCFGIntDir() const override { return "${CONFIGURATION}"; }
+
+ std::string ExpandCFGIntDir(const std::string& str,
+ const std::string& config) const override;
+
+ cmGeneratedFileStream* GetConfigFileStream(
+ const std::string& config) const override
+ {
+ return this->ConfigFileStreams.at(config).get();
+ }
+
+ cmGeneratedFileStream* GetCommonFileStream() const override
+ {
+ return this->CommonFileStream.get();
+ }
+
+ void AppendNinjaFileArgument(GeneratedMakeCommand& command,
+ const std::string& config) const override;
+
+ static std::string GetNinjaFilename(const std::string& config);
+
+ void AddRebuildManifestOutputs(cmNinjaDeps& outputs) const override;
+
+ void GetQtAutoGenConfigs(std::vector<std::string>& configs) const override;
+
+ bool WriteDefaultBuildFile() override;
+
+protected:
+ bool OpenBuildFileStreams() override;
+ void CloseBuildFileStreams() override;
+
+private:
+ std::map<std::string, std::unique_ptr<cmGeneratedFileStream>>
+ ConfigFileStreams;
+ std::unique_ptr<cmGeneratedFileStream> CommonFileStream;
};
#endif // ! cmGlobalNinjaGenerator_h
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index dfc495e..fe8c3f4 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -8,6 +8,7 @@
#include <utility>
#include <cm/memory>
+#include <cmext/memory>
#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
@@ -61,10 +62,11 @@ void cmGlobalUnixMakefileGenerator3::EnableLanguage(
}
//! Create a local generator appropriate to this Global Generator
-cmLocalGenerator* cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(
- cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator>
+cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(cmMakefile* mf)
{
- return new cmLocalUnixMakefileGenerator3(this, mf);
+ return std::unique_ptr<cmLocalGenerator>(
+ cm::make_unique<cmLocalUnixMakefileGenerator3>(this, mf));
}
void cmGlobalUnixMakefileGenerator3::GetDocumentation(
@@ -144,11 +146,11 @@ void cmGlobalUnixMakefileGenerator3::Generate()
for (auto& pmi : this->ProgressMap) {
pmi.second.WriteProgressVariables(total, current);
}
- for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (const auto& lg : this->LocalGenerators) {
std::string markFileName =
cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles/progress.marks");
cmGeneratedFileStream markFile(markFileName);
- markFile << this->CountProgressMarksInAll(lg) << "\n";
+ markFile << this->CountProgressMarksInAll(*lg) << "\n";
}
// write the main makefile
@@ -203,11 +205,11 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
}
// get a local generator for some useful methods
- cmLocalUnixMakefileGenerator3* lg =
- static_cast<cmLocalUnixMakefileGenerator3*>(this->LocalGenerators[0]);
+ auto& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(
+ this->LocalGenerators[0]);
// Write the do not edit header.
- lg->WriteDisclaimer(makefileStream);
+ lg.WriteDisclaimer(makefileStream);
// Write the main entry point target. This must be the VERY first
// target so that make with no arguments will run it.
@@ -217,10 +219,10 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
depends.emplace_back("all");
// Write the rule.
- lg->WriteMakeRule(makefileStream,
- "Default target executed when no arguments are "
- "given to make.",
- "default_target", depends, no_commands, true);
+ lg.WriteMakeRule(makefileStream,
+ "Default target executed when no arguments are "
+ "given to make.",
+ "default_target", depends, no_commands, true);
depends.clear();
@@ -231,7 +233,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
}
// Write out the "special" stuff
- lg->WriteSpecialTargetsTop(makefileStream);
+ lg.WriteSpecialTargetsTop(makefileStream);
// Write the directory level rules.
for (auto const& it : this->ComputeDirectoryTargets()) {
@@ -239,13 +241,14 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
}
// Write the target convenience rules
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
this->WriteConvenienceRules2(
- makefileStream, static_cast<cmLocalUnixMakefileGenerator3*>(localGen));
+ makefileStream,
+ cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(localGen));
}
// Write special bottom targets
- lg->WriteSpecialTargetsBottom(makefileStream);
+ lg.WriteSpecialTargetsBottom(makefileStream);
}
void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
@@ -268,12 +271,14 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
std::string makefileName =
cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), "/Makefile");
- // get a local generator for some useful methods
- cmLocalUnixMakefileGenerator3* lg =
- static_cast<cmLocalUnixMakefileGenerator3*>(this->LocalGenerators[0]);
+ {
+ // get a local generator for some useful methods
+ auto& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(
+ this->LocalGenerators[0]);
- // Write the do not edit header.
- lg->WriteDisclaimer(cmakefileStream);
+ // Write the do not edit header.
+ lg.WriteDisclaimer(cmakefileStream);
+ }
// Save the generator name
cmakefileStream << "# The generator used is:\n"
@@ -282,7 +287,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
// for each cmMakefile get its list of dependencies
std::vector<std::string> lfiles;
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (const auto& localGen : this->LocalGenerators) {
// Get the list of files contributing to this generation step.
cmAppend(lfiles, localGen->GetMakefile()->GetListFiles());
}
@@ -300,59 +305,61 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
lfiles.erase(new_end, lfiles.end());
#endif
- // reset lg to the first makefile
- lg = static_cast<cmLocalUnixMakefileGenerator3*>(this->LocalGenerators[0]);
-
- std::string currentBinDir = lg->GetCurrentBinaryDirectory();
- // Save the list to the cmake file.
- cmakefileStream
- << "# The top level Makefile was generated from the following files:\n"
- << "set(CMAKE_MAKEFILE_DEPENDS\n"
- << " \"CMakeCache.txt\"\n";
- for (std::string const& f : lfiles) {
- cmakefileStream << " \""
- << lg->MaybeConvertToRelativePath(currentBinDir, f)
- << "\"\n";
- }
- cmakefileStream << " )\n\n";
-
- // Build the path to the cache check file.
- std::string check =
- cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
- "/CMakeFiles/cmake.check_cache");
-
- // Set the corresponding makefile in the cmake file.
- cmakefileStream << "# The corresponding makefile is:\n"
- << "set(CMAKE_MAKEFILE_OUTPUTS\n"
- << " \""
- << lg->MaybeConvertToRelativePath(currentBinDir,
- makefileName)
- << "\"\n"
- << " \""
- << lg->MaybeConvertToRelativePath(currentBinDir, check)
- << "\"\n";
- cmakefileStream << " )\n\n";
-
- const std::string binDir = lg->GetBinaryDirectory();
-
- // CMake must rerun if a byproduct is missing.
{
- cmakefileStream << "# Byproducts of CMake generate step:\n"
- << "set(CMAKE_MAKEFILE_PRODUCTS\n";
- for (std::string const& outfile : lg->GetMakefile()->GetOutputFiles()) {
+ // reset lg to the first makefile
+ const auto& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(
+ this->LocalGenerators[0]);
+
+ const std::string& currentBinDir = lg.GetCurrentBinaryDirectory();
+ // Save the list to the cmake file.
+ cmakefileStream
+ << "# The top level Makefile was generated from the following files:\n"
+ << "set(CMAKE_MAKEFILE_DEPENDS\n"
+ << " \"CMakeCache.txt\"\n";
+ for (std::string const& f : lfiles) {
cmakefileStream << " \""
- << lg->MaybeConvertToRelativePath(binDir, outfile)
+ << lg.MaybeConvertToRelativePath(currentBinDir, f)
<< "\"\n";
}
+ cmakefileStream << " )\n\n";
+
+ // Build the path to the cache check file.
+ std::string check =
+ cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
+ "/CMakeFiles/cmake.check_cache");
+
+ // Set the corresponding makefile in the cmake file.
+ cmakefileStream << "# The corresponding makefile is:\n"
+ << "set(CMAKE_MAKEFILE_OUTPUTS\n"
+ << " \""
+ << lg.MaybeConvertToRelativePath(currentBinDir,
+ makefileName)
+ << "\"\n"
+ << " \""
+ << lg.MaybeConvertToRelativePath(currentBinDir, check)
+ << "\"\n";
+ cmakefileStream << " )\n\n";
+
+ const std::string& binDir = lg.GetBinaryDirectory();
+
+ // CMake must rerun if a byproduct is missing.
+ {
+ cmakefileStream << "# Byproducts of CMake generate step:\n"
+ << "set(CMAKE_MAKEFILE_PRODUCTS\n";
+ for (std::string const& outfile : lg.GetMakefile()->GetOutputFiles()) {
+ cmakefileStream << " \""
+ << lg.MaybeConvertToRelativePath(binDir, outfile)
+ << "\"\n";
+ }
+ }
// add in all the directory information files
std::string tmpStr;
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
- lg = static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
- tmpStr = cmStrCat(lg->GetCurrentBinaryDirectory(),
+ for (const auto& localGen : this->LocalGenerators) {
+ tmpStr = cmStrCat(localGen->GetCurrentBinaryDirectory(),
"/CMakeFiles/CMakeDirectoryInformation.cmake");
cmakefileStream << " \""
- << lg->MaybeConvertToRelativePath(binDir, tmpStr)
+ << localGen->MaybeConvertToRelativePath(binDir, tmpStr)
<< "\"\n";
}
cmakefileStream << " )\n\n";
@@ -364,24 +371,23 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules(
cmGeneratedFileStream& cmakefileStream,
- std::vector<cmLocalGenerator*>& lGenerators)
+ std::vector<std::unique_ptr<cmLocalGenerator>>& lGenerators)
{
- cmLocalUnixMakefileGenerator3* lg;
-
// now list all the target info files
cmakefileStream << "# Dependency information for all targets:\n";
cmakefileStream << "set(CMAKE_DEPEND_INFO_FILES\n";
- for (cmLocalGenerator* lGenerator : lGenerators) {
- lg = static_cast<cmLocalUnixMakefileGenerator3*>(lGenerator);
+ for (const auto& lGenerator : lGenerators) {
+ const auto& lg =
+ cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(lGenerator);
// for all of out targets
- for (const auto& tgt : lg->GetGeneratorTargets()) {
+ for (const auto& tgt : lg.GetGeneratorTargets()) {
if ((tgt->GetType() == cmStateEnums::EXECUTABLE) ||
(tgt->GetType() == cmStateEnums::STATIC_LIBRARY) ||
(tgt->GetType() == cmStateEnums::SHARED_LIBRARY) ||
(tgt->GetType() == cmStateEnums::MODULE_LIBRARY) ||
(tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) ||
(tgt->GetType() == cmStateEnums::UTILITY)) {
- std::string tname = cmStrCat(lg->GetRelativeTargetDirectory(tgt.get()),
+ std::string tname = cmStrCat(lg.GetRelativeTargetDirectory(tgt.get()),
"/DependInfo.cmake");
cmSystemTools::ConvertToUnixSlashes(tname);
cmakefileStream << " \"" << tname << "\"\n";
@@ -544,11 +550,11 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
}
// write the target convenience rules
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
- cmLocalUnixMakefileGenerator3* lg =
- static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
+ for (const auto& localGen : this->LocalGenerators) {
+ auto& lg =
+ cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(localGen);
// for each target Generate the rule files for each target.
- for (const auto& gtarget : lg->GetGeneratorTargets()) {
+ for (const auto& gtarget : lg.GetGeneratorTargets()) {
// Don't emit the same rule twice (e.g. two targets with the same
// simple name)
int type = gtarget->GetType();
@@ -563,23 +569,23 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
(type == cmStateEnums::OBJECT_LIBRARY) ||
(type == cmStateEnums::UTILITY))) {
// Add a rule to build the target by name.
- lg->WriteDivider(ruleFileStream);
+ lg.WriteDivider(ruleFileStream);
ruleFileStream << "# Target rules for targets named " << name
<< "\n\n";
// Write the rule.
commands.clear();
std::string tmp = "CMakeFiles/Makefile2";
- commands.push_back(lg->GetRecursiveMakeCall(tmp, name));
+ commands.push_back(lg.GetRecursiveMakeCall(tmp, name));
depends.clear();
if (regenerate) {
depends.emplace_back("cmake_check_build_system");
}
- lg->WriteMakeRule(ruleFileStream, "Build rule for target.", name,
- depends, commands, true);
+ lg.WriteMakeRule(ruleFileStream, "Build rule for target.", name,
+ depends, commands, true);
// Add a fast rule to build the target
- std::string localName = lg->GetRelativeTargetDirectory(gtarget.get());
+ std::string localName = lg.GetRelativeTargetDirectory(gtarget.get());
std::string makefileName;
makefileName = cmStrCat(localName, "/build.make");
depends.clear();
@@ -587,23 +593,23 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
std::string makeTargetName = cmStrCat(localName, "/build");
localName = cmStrCat(name, "/fast");
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName, makeTargetName));
- lg->WriteMakeRule(ruleFileStream, "fast build rule for target.",
- localName, depends, commands, true);
+ lg.GetRecursiveMakeCall(makefileName, makeTargetName));
+ lg.WriteMakeRule(ruleFileStream, "fast build rule for target.",
+ localName, depends, commands, true);
// Add a local name for the rule to relink the target before
// installation.
- if (gtarget->NeedRelinkBeforeInstall(lg->GetConfigName())) {
+ if (gtarget->NeedRelinkBeforeInstall(lg.GetConfigName())) {
makeTargetName = cmStrCat(
- lg->GetRelativeTargetDirectory(gtarget.get()), "/preinstall");
+ lg.GetRelativeTargetDirectory(gtarget.get()), "/preinstall");
localName = cmStrCat(name, "/preinstall");
depends.clear();
commands.clear();
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName, makeTargetName));
- lg->WriteMakeRule(ruleFileStream,
- "Manual pre-install relink rule for target.",
- localName, depends, commands, true);
+ lg.GetRecursiveMakeCall(makefileName, makeTargetName));
+ lg.WriteMakeRule(ruleFileStream,
+ "Manual pre-install relink rule for target.",
+ localName, depends, commands, true);
}
}
}
@@ -611,7 +617,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
}
void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
- std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg)
+ std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3& lg)
{
std::vector<std::string> depends;
std::vector<std::string> commands;
@@ -624,7 +630,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
}
// for each target Generate the rule files for each target.
- for (const auto& gtarget : lg->GetGeneratorTargets()) {
+ for (const auto& gtarget : lg.GetGeneratorTargets()) {
int type = gtarget->GetType();
std::string name = gtarget->GetName();
if (!name.empty() &&
@@ -636,27 +642,27 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
(type == cmStateEnums::UTILITY))) {
std::string makefileName;
// Add a rule to build the target by name.
- localName = lg->GetRelativeTargetDirectory(gtarget.get());
+ localName = lg.GetRelativeTargetDirectory(gtarget.get());
makefileName = cmStrCat(localName, "/build.make");
- lg->WriteDivider(ruleFileStream);
+ lg.WriteDivider(ruleFileStream);
ruleFileStream << "# Target rules for target " << localName << "\n\n";
commands.clear();
makeTargetName = cmStrCat(localName, "/depend");
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName, makeTargetName));
+ lg.GetRecursiveMakeCall(makefileName, makeTargetName));
makeTargetName = cmStrCat(localName, "/build");
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName, makeTargetName));
+ lg.GetRecursiveMakeCall(makefileName, makeTargetName));
// Write the rule.
localName += "/all";
depends.clear();
cmLocalUnixMakefileGenerator3::EchoProgress progress;
- progress.Dir = cmStrCat(lg->GetBinaryDirectory(), "/CMakeFiles");
+ progress.Dir = cmStrCat(lg.GetBinaryDirectory(), "/CMakeFiles");
{
std::ostringstream progressArg;
const char* sep = "";
@@ -675,13 +681,13 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
}
if (targetMessages) {
- lg->AppendEcho(commands, "Built target " + name,
- cmLocalUnixMakefileGenerator3::EchoNormal, &progress);
+ lg.AppendEcho(commands, "Built target " + name,
+ cmLocalUnixMakefileGenerator3::EchoNormal, &progress);
}
this->AppendGlobalTargetDepends(depends, gtarget.get());
- lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
- localName, depends, commands, true);
+ lg.WriteMakeRule(ruleFileStream, "All Build rule for target.", localName,
+ depends, commands, true);
// Write the rule.
commands.clear();
@@ -691,7 +697,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
std::ostringstream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
// # in target
- progCmd << lg->ConvertToOutputFormat(
+ progCmd << lg.ConvertToOutputFormat(
cmSystemTools::CollapseFullPath(progress.Dir),
cmOutputConverter::SHELL);
//
@@ -701,11 +707,11 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
commands.push_back(progCmd.str());
}
std::string tmp = "CMakeFiles/Makefile2";
- commands.push_back(lg->GetRecursiveMakeCall(tmp, localName));
+ commands.push_back(lg.GetRecursiveMakeCall(tmp, localName));
{
std::ostringstream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
- progCmd << lg->ConvertToOutputFormat(
+ progCmd << lg.ConvertToOutputFormat(
cmSystemTools::CollapseFullPath(progress.Dir),
cmOutputConverter::SHELL);
progCmd << " 0";
@@ -716,39 +722,38 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
depends.emplace_back("cmake_check_build_system");
}
localName =
- cmStrCat(lg->GetRelativeTargetDirectory(gtarget.get()), "/rule");
- lg->WriteMakeRule(ruleFileStream,
- "Build rule for subdir invocation for target.",
- localName, depends, commands, true);
+ cmStrCat(lg.GetRelativeTargetDirectory(gtarget.get()), "/rule");
+ lg.WriteMakeRule(ruleFileStream,
+ "Build rule for subdir invocation for target.",
+ localName, depends, commands, true);
// Add a target with the canonical name (no prefix, suffix or path).
commands.clear();
depends.clear();
depends.push_back(localName);
- lg->WriteMakeRule(ruleFileStream, "Convenience name for target.", name,
- depends, commands, true);
+ lg.WriteMakeRule(ruleFileStream, "Convenience name for target.", name,
+ depends, commands, true);
// Add rules to prepare the target for installation.
- if (gtarget->NeedRelinkBeforeInstall(lg->GetConfigName())) {
- localName = cmStrCat(lg->GetRelativeTargetDirectory(gtarget.get()),
+ if (gtarget->NeedRelinkBeforeInstall(lg.GetConfigName())) {
+ localName = cmStrCat(lg.GetRelativeTargetDirectory(gtarget.get()),
"/preinstall");
depends.clear();
commands.clear();
- commands.push_back(lg->GetRecursiveMakeCall(makefileName, localName));
- lg->WriteMakeRule(ruleFileStream,
- "Pre-install relink rule for target.", localName,
- depends, commands, true);
+ commands.push_back(lg.GetRecursiveMakeCall(makefileName, localName));
+ lg.WriteMakeRule(ruleFileStream, "Pre-install relink rule for target.",
+ localName, depends, commands, true);
}
// add the clean rule
- localName = lg->GetRelativeTargetDirectory(gtarget.get());
+ localName = lg.GetRelativeTargetDirectory(gtarget.get());
makeTargetName = cmStrCat(localName, "/clean");
depends.clear();
commands.clear();
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName, makeTargetName));
- lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
- makeTargetName, depends, commands, true);
+ lg.GetRecursiveMakeCall(makefileName, makeTargetName));
+ lg.WriteMakeRule(ruleFileStream, "clean rule for target.",
+ makeTargetName, depends, commands, true);
commands.clear();
}
}
@@ -760,7 +765,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
{
this->DirectoryTargetsMap.clear();
// Loop over all targets in all local generators.
- for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (const auto& lg : this->LocalGenerators) {
for (const auto& gt : lg->GetGeneratorTargets()) {
cmLocalGenerator* tlg = gt->GetLocalGenerator();
@@ -810,12 +815,12 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInTarget(
}
size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll(
- cmLocalGenerator* lg)
+ const cmLocalGenerator& lg)
{
size_t count = 0;
std::set<cmGeneratorTarget const*> emitted;
for (cmGeneratorTarget const* target :
- this->DirectoryTargetsMap[lg->GetStateSnapshot()]) {
+ this->DirectoryTargetsMap[lg.GetStateSnapshot()]) {
count += this->CountProgressMarksInTarget(target, emitted);
}
return count;
@@ -889,14 +894,14 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
std::set<std::string> emittedTargets;
// for each local generator
- for (cmLocalGenerator* localGen : this->LocalGenerators) {
- cmLocalUnixMakefileGenerator3* lg2 =
- static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
+ for (const auto& localGen : this->LocalGenerators) {
+ const auto& lg2 =
+ cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(localGen);
// for the passed in makefile or if this is the top Makefile wripte out
// the targets
- if (lg2 == lg || lg->IsRootMakefile()) {
+ if (&lg2 == lg || lg->IsRootMakefile()) {
// for each target Generate the rule files for each target.
- for (const auto& target : lg2->GetGeneratorTargets()) {
+ for (const auto& target : lg2.GetGeneratorTargets()) {
cmStateEnums::TargetType type = target->GetType();
if ((type == cmStateEnums::EXECUTABLE) ||
(type == cmStateEnums::STATIC_LIBRARY) ||
diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h
index 79db30e..5608baf 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.h
+++ b/Source/cmGlobalUnixMakefileGenerator3.h
@@ -8,6 +8,7 @@
#include <cstddef>
#include <iosfwd>
#include <map>
+#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -89,7 +90,8 @@ public:
/** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry);
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
/**
* Try to determine system information such as shared library
@@ -107,8 +109,9 @@ public:
*/
void Generate() override;
- void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
- std::vector<cmLocalGenerator*>&);
+ void WriteMainCMakefileLanguageRules(
+ cmGeneratedFileStream& cmakefileStream,
+ std::vector<std::unique_ptr<cmLocalGenerator>>&);
// write out the help rule listing the valid targets
void WriteHelpRule(std::ostream& ruleFileStream,
@@ -161,7 +164,7 @@ protected:
void WriteMainCMakefile();
void WriteConvenienceRules2(std::ostream& ruleFileStream,
- cmLocalUnixMakefileGenerator3*);
+ cmLocalUnixMakefileGenerator3&);
void WriteDirectoryRule2(std::ostream& ruleFileStream,
DirectoryTarget const& dt, const char* pass,
@@ -227,7 +230,7 @@ protected:
size_t CountProgressMarksInTarget(
cmGeneratorTarget const* target,
std::set<cmGeneratorTarget const*>& emitted);
- size_t CountProgressMarksInAll(cmLocalGenerator* lg);
+ size_t CountProgressMarksInAll(const cmLocalGenerator& lg);
cmGeneratedFileStream* CommandDatabase;
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index 5b83e2f..bdf4cf2 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -4,6 +4,8 @@
#include <algorithm>
+#include <cm/memory>
+
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
@@ -574,10 +576,11 @@ std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
}
//! Create a local generator appropriate to this Global Generator
-cmLocalGenerator* cmGlobalVisualStudio10Generator::CreateLocalGenerator(
- cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator>
+cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmMakefile* mf)
{
- return new cmLocalVisualStudio10Generator(this, mf);
+ return std::unique_ptr<cmLocalGenerator>(
+ cm::make_unique<cmLocalVisualStudio10Generator>(this, mf));
}
void cmGlobalVisualStudio10Generator::Generate()
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index 8a76047..c991c76 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -3,6 +3,8 @@
#ifndef cmGlobalVisualStudio10Generator_h
#define cmGlobalVisualStudio10Generator_h
+#include <memory>
+
#include "cmGlobalVisualStudio8Generator.h"
#include "cmVisualStudio10ToolsetOptions.h"
@@ -31,7 +33,8 @@ public:
std::vector<std::string>()) override;
//! create the correct local generator
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
/**
* Try to determine system information such as shared library
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index 40b214c..04ec7b3 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -2,8 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalVisualStudio7Generator.h"
+#include <utility>
#include <vector>
+#include <cm/memory>
#include <cm/string_view>
#include <windows.h>
@@ -263,12 +265,11 @@ cmGlobalVisualStudio7Generator::GenerateBuildCommand(
}
//! Create a local generator appropriate to this Global Generator
-cmLocalGenerator* cmGlobalVisualStudio7Generator::CreateLocalGenerator(
- cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator>
+cmGlobalVisualStudio7Generator::CreateLocalGenerator(cmMakefile* mf)
{
- cmLocalVisualStudio7Generator* lg =
- new cmLocalVisualStudio7Generator(this, mf);
- return lg;
+ auto lg = cm::make_unique<cmLocalVisualStudio7Generator>(this, mf);
+ return std::unique_ptr<cmLocalGenerator>(std::move(lg));
}
#if !defined(CMAKE_BOOTSTRAP)
@@ -300,7 +301,7 @@ void cmGlobalVisualStudio7Generator::Generate()
if (!cmSystemTools::GetErrorOccuredFlag() &&
!this->LocalGenerators.empty()) {
this->CallVisualStudioMacro(MacroReload,
- GetSLNFile(this->LocalGenerators[0]));
+ GetSLNFile(this->LocalGenerators[0].get()));
}
}
diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h
index 7a9fcef..974bb1d 100644
--- a/Source/cmGlobalVisualStudio7Generator.h
+++ b/Source/cmGlobalVisualStudio7Generator.h
@@ -3,6 +3,8 @@
#ifndef cmGlobalVisualStudio7Generator_h
#define cmGlobalVisualStudio7Generator_h
+#include <memory>
+
#include "cmGlobalGeneratorFactory.h"
#include "cmGlobalVisualStudioGenerator.h"
@@ -20,7 +22,8 @@ public:
~cmGlobalVisualStudio7Generator();
//! Create a local generator appropriate to this Global Generator
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
#if !defined(CMAKE_BOOTSTRAP)
Json::Value GetJson() const override;
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index ea603b0..6e89fc4 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -3,6 +3,7 @@
#include "cmGlobalVisualStudio8Generator.h"
#include <cm/memory>
+#include <cmext/memory>
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
@@ -98,21 +99,22 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
return false;
}
- std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
- cmLocalVisualStudio7Generator* lg =
- static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
+ std::vector<std::unique_ptr<cmLocalGenerator>> const& generators =
+ this->LocalGenerators;
+ auto& lg =
+ cm::static_reference_cast<cmLocalVisualStudio7Generator>(generators[0]);
const char* no_working_directory = nullptr;
std::vector<std::string> no_byproducts;
std::vector<std::string> no_depends;
cmCustomCommandLines no_commands;
- cmTarget* tgt = lg->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
- no_working_directory, no_byproducts,
- no_depends, no_commands);
+ cmTarget* tgt = lg.AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
+ no_working_directory, no_byproducts,
+ no_depends, no_commands);
- auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, lg);
+ auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, &lg);
auto gt = ptr.get();
- lg->AddGeneratorTarget(std::move(ptr));
+ lg.AddGeneratorTarget(std::move(ptr));
// Organize in the "predefined targets" folder:
//
@@ -130,7 +132,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
stampList);
std::string stampFile;
cmGeneratedFileStream fout(stampListFile.c_str());
- for (cmLocalGenerator const* gi : generators) {
+ for (const auto& gi : generators) {
stampFile = cmStrCat(gi->GetMakefile()->GetCurrentBinaryDirectory(),
"/CMakeFiles/generate.stamp");
fout << stampFile << "\n";
@@ -143,7 +145,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// Collect the input files used to generate all targets in this
// project.
std::vector<std::string> listFiles;
- for (cmLocalGenerator* gen : generators) {
+ for (const auto& gen : generators) {
cmAppend(listFiles, gen->GetMakefile()->GetListFiles());
}
@@ -155,7 +157,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
std::vector<std::string> byproducts;
byproducts.push_back(cm->GetGlobVerifyStamp());
- lg->AddCustomCommandToTarget(
+ lg.AddCustomCommandToTarget(
CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, no_depends,
verifyCommandLines, cmCustomCommandType::PRE_BUILD,
"Checking File Globs", no_working_directory, false);
@@ -173,10 +175,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
listFiles.erase(new_end, listFiles.end());
// Create a rule to re-run CMake.
- std::string argS = cmStrCat("-S", lg->GetSourceDirectory());
- std::string argB = cmStrCat("-B", lg->GetBinaryDirectory());
+ std::string argS = cmStrCat("-S", lg.GetSourceDirectory());
+ std::string argB = cmStrCat("-B", lg.GetBinaryDirectory());
std::string const sln =
- lg->GetBinaryDirectory() + "/" + lg->GetProjectName() + ".sln";
+ lg.GetBinaryDirectory() + "/" + lg.GetProjectName() + ".sln";
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list",
stampList, "--vs-solution-file", sln });
@@ -187,7 +189,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// (this could be avoided with per-target source files)
std::string no_main_dependency;
cmImplicitDependsList no_implicit_depends;
- if (cmSourceFile* file = lg->AddCustomCommandToOutput(
+ if (cmSourceFile* file = lg.AddCustomCommandToOutput(
stamps, no_byproducts, listFiles, no_main_dependency,
no_implicit_depends, commandLines, "Checking Build System",
no_working_directory, true, false)) {
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index 1eca1f6..a371633 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -6,6 +6,7 @@
#include "cmDocumentationEntry.h"
#include "cmLocalVisualStudio10Generator.h"
#include "cmMakefile.h"
+#include "cmStringAlgorithms.h"
#include "cmVSSetupHelper.h"
#include "cmake.h"
@@ -388,15 +389,19 @@ std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const
if (version) {
std::string instancePath;
GetVSInstance(instancePath);
- std::stringstream path;
- path << instancePath;
- path << "/VC/Auxiliary/Build";
- path << (cmSystemTools::VersionCompareGreaterEq(version, "14.20") ? '.'
- : '/');
- path << version;
- path << "/Microsoft.VCToolsVersion." << version << ".props";
-
- std::string toolsetPath = path.str();
+ std::string toolsetDir = instancePath + "/VC/Auxiliary/Build";
+ char sep = '/';
+ if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) {
+ std::string toolsetDot =
+ cmStrCat(toolsetDir, '.', version, "/Microsoft.VCToolsVersion.",
+ version, ".props");
+ if (cmSystemTools::PathExists(toolsetDot)) {
+ sep = '.';
+ }
+ }
+ std::string toolsetPath =
+ cmStrCat(toolsetDir, sep, version, "/Microsoft.VCToolsVersion.", version,
+ ".props");
cmSystemTools::ConvertToUnixSlashes(toolsetPath);
return toolsetPath;
}
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index d75c489..37717f4 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -392,9 +392,11 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
}
//! Create a local generator appropriate to this Global Generator
-cmLocalGenerator* cmGlobalXCodeGenerator::CreateLocalGenerator(cmMakefile* mf)
+std::unique_ptr<cmLocalGenerator> cmGlobalXCodeGenerator::CreateLocalGenerator(
+ cmMakefile* mf)
{
- return new cmLocalXCodeGenerator(this, mf);
+ return std::unique_ptr<cmLocalGenerator>(
+ cm::make_unique<cmLocalXCodeGenerator>(this, mf));
}
void cmGlobalXCodeGenerator::AddExtraIDETargets()
@@ -1363,7 +1365,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget(
void cmGlobalXCodeGenerator::ForceLinkerLanguages()
{
- for (auto localGenerator : this->LocalGenerators) {
+ for (const auto& localGenerator : this->LocalGenerators) {
// All targets depend on the build-system check target.
for (const auto& tgt : localGenerator->GetGeneratorTargets()) {
// This makes sure all targets link using the proper language.
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index f60ea72..a12021d 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -7,6 +7,7 @@
#include <iosfwd>
#include <map>
+#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -47,7 +48,8 @@ public:
static void GetDocumentation(cmDocumentationEntry& entry);
//! Create a local generator appropriate to this Global Generator
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
+ std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
+ cmMakefile* mf) override;
/**
* Try to determine system information such as shared library
diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx
index 9c1a924..f48789a 100644
--- a/Source/cmGraphVizWriter.cxx
+++ b/Source/cmGraphVizWriter.cxx
@@ -277,7 +277,7 @@ void cmGraphVizWriter::Write()
std::set<cmGeneratorTarget const*, cmGeneratorTarget::StrictTargetComparison>
sortedGeneratorTargets;
- for (cmLocalGenerator const* lg : gg->GetLocalGenerators()) {
+ for (const auto& lg : gg->GetLocalGenerators()) {
for (const auto& gt : lg->GetGeneratorTargets()) {
// Reserved targets have inconsistent names across platforms (e.g. 'all'
// vs. 'ALL_BUILD'), which can disrupt the traversal ordering.
diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx
index 0dc6236..4320010 100644
--- a/Source/cmLinkLineComputer.cxx
+++ b/Source/cmLinkLineComputer.cxx
@@ -23,6 +23,7 @@ cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
, OutputConverter(outputConverter)
, ForResponse(false)
, UseWatcomQuote(false)
+ , UseNinjaMulti(false)
, Relink(false)
{
}
@@ -34,6 +35,11 @@ void cmLinkLineComputer::SetUseWatcomQuote(bool useWatcomQuote)
this->UseWatcomQuote = useWatcomQuote;
}
+void cmLinkLineComputer::SetUseNinjaMulti(bool useNinjaMulti)
+{
+ this->UseNinjaMulti = useNinjaMulti;
+}
+
void cmLinkLineComputer::SetForResponse(bool forResponse)
{
this->ForResponse = forResponse;
@@ -106,10 +112,14 @@ void cmLinkLineComputer::ComputeLinkLibs(
std::string cmLinkLineComputer::ConvertToOutputFormat(std::string const& input)
{
- cmOutputConverter::OutputFormat shellFormat = (this->ForResponse)
- ? cmOutputConverter::RESPONSE
- : ((this->UseWatcomQuote) ? cmOutputConverter::WATCOMQUOTE
- : cmOutputConverter::SHELL);
+ cmOutputConverter::OutputFormat shellFormat = cmOutputConverter::SHELL;
+ if (this->ForResponse) {
+ shellFormat = cmOutputConverter::RESPONSE;
+ } else if (this->UseWatcomQuote) {
+ shellFormat = cmOutputConverter::WATCOMQUOTE;
+ } else if (this->UseNinjaMulti) {
+ shellFormat = cmOutputConverter::NINJAMULTI;
+ }
return this->OutputConverter->ConvertToOutputFormat(input, shellFormat);
}
@@ -117,10 +127,14 @@ std::string cmLinkLineComputer::ConvertToOutputFormat(std::string const& input)
std::string cmLinkLineComputer::ConvertToOutputForExisting(
std::string const& input)
{
- cmOutputConverter::OutputFormat shellFormat = (this->ForResponse)
- ? cmOutputConverter::RESPONSE
- : ((this->UseWatcomQuote) ? cmOutputConverter::WATCOMQUOTE
- : cmOutputConverter::SHELL);
+ cmOutputConverter::OutputFormat shellFormat = cmOutputConverter::SHELL;
+ if (this->ForResponse) {
+ shellFormat = cmOutputConverter::RESPONSE;
+ } else if (this->UseWatcomQuote) {
+ shellFormat = cmOutputConverter::WATCOMQUOTE;
+ } else if (this->UseNinjaMulti) {
+ shellFormat = cmOutputConverter::NINJAMULTI;
+ }
return this->OutputConverter->ConvertToOutputForExisting(input, shellFormat);
}
diff --git a/Source/cmLinkLineComputer.h b/Source/cmLinkLineComputer.h
index f426976..df42468 100644
--- a/Source/cmLinkLineComputer.h
+++ b/Source/cmLinkLineComputer.h
@@ -28,6 +28,7 @@ public:
cmLinkLineComputer& operator=(cmLinkLineComputer const&) = delete;
void SetUseWatcomQuote(bool useWatcomQuote);
+ void SetUseNinjaMulti(bool useNinjaMulti);
void SetForResponse(bool forResponse);
void SetRelink(bool relink);
@@ -69,6 +70,7 @@ protected:
bool ForResponse;
bool UseWatcomQuote;
+ bool UseNinjaMulti;
bool Relink;
};
diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx
index f86955d..025ef7e 100644
--- a/Source/cmLocalCommonGenerator.cxx
+++ b/Source/cmLocalCommonGenerator.cxx
@@ -17,13 +17,9 @@ cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg,
: cmLocalGenerator(gg, mf)
, WorkingDirectory(std::move(wd))
{
- // Store the configuration name that will be generated.
- if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
- // Use the build type given by the user.
- this->ConfigName = config;
- } else {
- // No configuration type given.
- this->ConfigName.clear();
+ this->Makefile->GetConfigurations(this->ConfigNames);
+ if (this->ConfigNames.empty()) {
+ this->ConfigNames.emplace_back();
}
}
diff --git a/Source/cmLocalCommonGenerator.h b/Source/cmLocalCommonGenerator.h
index eaef6ab..378ca63 100644
--- a/Source/cmLocalCommonGenerator.h
+++ b/Source/cmLocalCommonGenerator.h
@@ -7,6 +7,7 @@
#include <map>
#include <string>
+#include <vector>
#include "cmLocalGenerator.h"
@@ -25,7 +26,10 @@ public:
std::string wd);
~cmLocalCommonGenerator() override;
- std::string const& GetConfigName() const { return this->ConfigName; }
+ std::vector<std::string> const& GetConfigNames() const
+ {
+ return this->ConfigNames;
+ }
std::string GetWorkingDirectory() const { return this->WorkingDirectory; }
@@ -39,7 +43,7 @@ public:
protected:
std::string WorkingDirectory;
- std::string ConfigName;
+ std::vector<std::string> ConfigNames;
friend class cmCommonTargetGenerator;
};
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 303009e..18e43bf 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -696,11 +696,12 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures()
using LanguagePair = std::pair<std::string, std::string>;
std::vector<LanguagePair> pairedLanguages{ { "OBJC", "C" },
- { "OBJCXX", "CXX" } };
- std::set<LanguagePair> objcEnabledLanguages;
+ { "OBJCXX", "CXX" },
+ { "CUDA", "CXX" } };
+ std::set<LanguagePair> inferredEnabledLanguages;
for (auto const& lang : pairedLanguages) {
if (this->Makefile->GetState()->GetLanguageEnabled(lang.first)) {
- objcEnabledLanguages.insert(lang);
+ inferredEnabledLanguages.insert(lang);
}
}
@@ -739,12 +740,17 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures()
target->GetProperty(cmStrCat(lang.second, property)));
}
};
- for (auto const& lang : objcEnabledLanguages) {
+ for (auto const& lang : pairedLanguages) {
if (copyStandardToObjLang(lang)) {
copyPropertyToObjLang(lang, "_STANDARD_REQUIRED");
copyPropertyToObjLang(lang, "_EXTENSIONS");
}
}
+ if (const char* standard = target->GetProperty("CUDA_STANDARD")) {
+ if (std::string{ standard } == "98") {
+ target->Target->SetProperty("CUDA_STANDARD", "03");
+ }
+ }
}
}
@@ -2108,17 +2114,22 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
langStdMap["OBJC"].emplace_back("99");
langStdMap["OBJC"].emplace_back("90");
+ langStdMap["CUDA"].emplace_back("20");
+ langStdMap["CUDA"].emplace_back("17");
langStdMap["CUDA"].emplace_back("14");
langStdMap["CUDA"].emplace_back("11");
- langStdMap["CUDA"].emplace_back("98");
+ langStdMap["CUDA"].emplace_back("03");
}
std::string standard(standardProp);
-
+ if (lang == "CUDA" && standard == "98") {
+ standard = "03";
+ }
std::vector<std::string>& stds = langStdMap[lang];
auto stdIt = std::find(stds.begin(), stds.end(), standard);
if (stdIt == stds.end()) {
+
std::string e =
lang + "_STANDARD is set to invalid value '" + standard + "'";
this->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
@@ -2399,7 +2410,9 @@ void cmLocalGenerator::AppendFlags(
void cmLocalGenerator::AppendFlagEscape(std::string& flags,
const std::string& rawFlag) const
{
- this->AppendFlags(flags, this->EscapeForShell(rawFlag));
+ this->AppendFlags(
+ flags,
+ this->EscapeForShell(rawFlag, false, false, false, this->IsNinjaMulti()));
}
void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
@@ -2411,6 +2424,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
}
const std::string buildType = cmSystemTools::UpperCase(config);
+ // FIXME: Refactor collection of sources to not evaluate object libraries.
std::vector<cmSourceFile*> sources;
target->GetSourceFiles(sources, buildType);
@@ -2485,9 +2499,25 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
target->GetLocalGenerator()->GetCurrentBinaryDirectory(), "/",
target->GetName(), ".dir/${PDB_PREFIX}");
- file << "if (EXISTS \"" << from_file << "\")\n";
+ const std::string to_file =
+ cmStrCat(to_dir, pchReuseFrom, extension);
+
+ std::string dest_file = to_file;
+
+ const std::string prefix = target->GetSafeProperty("PREFIX");
+ if (!prefix.empty()) {
+ dest_file = cmStrCat(to_dir, prefix, pchReuseFrom, extension);
+ }
+
+ file << "if (EXISTS \"" << from_file << "\" AND \"" << from_file
+ << "\" IS_NEWER_THAN \"" << dest_file << "\")\n";
file << " file(COPY \"" << from_file << "\""
<< " DESTINATION \"" << to_dir << "\")\n";
+ if (!prefix.empty()) {
+ file << " file(REMOVE \"" << dest_file << "\")\n";
+ file << " file(RENAME \"" << to_file << "\" \"" << dest_file
+ << "\")\n";
+ }
file << "endif()\n";
}
@@ -2567,6 +2597,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/",
target->GetName(), ".dir/Unity/");
+ // FIXME: Refactor collection of sources to not evaluate object libraries.
std::vector<cmSourceFile*> sources;
target->GetSourceFiles(sources, buildType);
@@ -2616,12 +2647,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
for (; begin != end; ++begin) {
cmSourceFile* sf = filtered_sources[begin];
- // Only in Visual Studio generator we keep the source files
- // for explicit processing.
- if (!this->GetGlobalGenerator()->IsMultiConfig() ||
- this->GetGlobalGenerator()->IsXcode()) {
- target->AddSourceFileToUnityBatch(sf->ResolveFullPath());
- }
+ target->AddSourceFileToUnityBatch(sf->ResolveFullPath());
sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str());
if (beforeInclude) {
@@ -3201,6 +3227,11 @@ bool cmLocalGenerator::IsNMake() const
return this->GetState()->UseNMake();
}
+bool cmLocalGenerator::IsNinjaMulti() const
+{
+ return this->GetState()->UseNinjaMulti();
+}
+
std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
const cmSourceFile& source, std::string const& dir_max,
bool* hasSourceExtension, char const* customOutputExtension)
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 8788c2f..b91d5f7 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -466,6 +466,7 @@ public:
bool IsWatcomWMake() const;
bool IsMinGWMake() const;
bool IsNMake() const;
+ bool IsNinjaMulti() const;
void IssueMessage(MessageType t, std::string const& text) const;
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index ea500ac..6967097 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -29,6 +29,7 @@
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
+#include "cmTarget.h"
#include "cmake.h"
cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
@@ -61,7 +62,12 @@ void cmLocalNinjaGenerator::Generate()
this->HomeRelativeOutputPath.clear();
}
- this->WriteProcessedMakefile(this->GetBuildFileStream());
+ if (this->GetGlobalGenerator()->IsMultiConfig()) {
+ for (auto const& config : this->GetConfigNames()) {
+ this->WriteProcessedMakefile(this->GetConfigFileStream(config));
+ }
+ }
+ this->WriteProcessedMakefile(this->GetCommonFileStream());
#ifdef NINJA_GEN_VERBOSE_FILES
this->WriteProcessedMakefile(this->GetRulesFileStream());
#endif
@@ -88,12 +94,20 @@ void cmLocalNinjaGenerator::Generate()
}
auto tg = cmNinjaTargetGenerator::New(target.get());
if (tg) {
- tg->Generate();
+ if (target->Target->IsPerConfig()) {
+ for (auto const& config : this->GetConfigNames()) {
+ tg->Generate(config);
+ }
+ } else {
+ tg->Generate("");
+ }
}
}
- this->WriteCustomCommandBuildStatements();
- this->AdditionalCleanFiles();
+ for (auto const& config : this->GetConfigNames()) {
+ this->WriteCustomCommandBuildStatements(config);
+ this->AdditionalCleanFiles(config);
+ }
}
// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it.
@@ -140,9 +154,15 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
// Private methods.
-cmGeneratedFileStream& cmLocalNinjaGenerator::GetBuildFileStream() const
+cmGeneratedFileStream& cmLocalNinjaGenerator::GetConfigFileStream(
+ const std::string& config) const
{
- return *this->GetGlobalNinjaGenerator()->GetBuildFileStream();
+ return *this->GetGlobalNinjaGenerator()->GetConfigFileStream(config);
+}
+
+cmGeneratedFileStream& cmLocalNinjaGenerator::GetCommonFileStream() const
+{
+ return *this->GetGlobalNinjaGenerator()->GetCommonFileStream();
}
cmGeneratedFileStream& cmLocalNinjaGenerator::GetRulesFileStream() const
@@ -162,10 +182,22 @@ cmake* cmLocalNinjaGenerator::GetCMakeInstance()
void cmLocalNinjaGenerator::WriteBuildFileTop()
{
- // For the build file.
- this->WriteProjectHeader(this->GetBuildFileStream());
- this->WriteNinjaRequiredVersion(this->GetBuildFileStream());
- this->WriteNinjaFilesInclusion(this->GetBuildFileStream());
+ this->WriteProjectHeader(this->GetCommonFileStream());
+
+ if (this->GetGlobalGenerator()->IsMultiConfig()) {
+ for (auto const& config : this->GetConfigNames()) {
+ auto& stream = this->GetConfigFileStream(config);
+ this->WriteProjectHeader(stream);
+ this->WriteNinjaRequiredVersion(stream);
+ this->WriteNinjaConfigurationVariable(stream, config);
+ this->WriteNinjaFilesInclusionConfig(stream);
+ }
+ } else {
+ this->WriteNinjaRequiredVersion(this->GetCommonFileStream());
+ this->WriteNinjaConfigurationVariable(this->GetCommonFileStream(),
+ this->GetConfigNames().front());
+ }
+ this->WriteNinjaFilesInclusionCommon(this->GetCommonFileStream());
// For the rule file.
this->WriteProjectHeader(this->GetRulesFileStream());
@@ -175,7 +207,8 @@ void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
os << "# Project: " << this->GetProjectName() << std::endl
- << "# Configuration: " << this->ConfigName << std::endl;
+ << "# Configurations: " << cmJoin(this->GetConfigNames(), ", ")
+ << std::endl;
cmGlobalNinjaGenerator::WriteDivider(os);
}
@@ -206,6 +239,14 @@ void cmLocalNinjaGenerator::WriteNinjaRequiredVersion(std::ostream& os)
<< std::endl;
}
+void cmLocalNinjaGenerator::WriteNinjaConfigurationVariable(
+ std::ostream& os, const std::string& config)
+{
+ cmGlobalNinjaGenerator::WriteVariable(
+ os, "CONFIGURATION", config,
+ "Set configuration variable for custom commands.");
+}
+
void cmLocalNinjaGenerator::WritePools(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
@@ -235,7 +276,21 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os)
}
}
-void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
+void cmLocalNinjaGenerator::WriteNinjaFilesInclusionConfig(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << "# Include auxiliary files.\n"
+ << "\n";
+ cmGlobalNinjaGenerator* ng = this->GetGlobalNinjaGenerator();
+ std::string const ninjaCommonFile =
+ ng->NinjaOutputPath(cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE);
+ std::string const commonFilePath = ng->EncodePath(ninjaCommonFile);
+ cmGlobalNinjaGenerator::WriteInclude(os, commonFilePath,
+ "Include common file.");
+ os << "\n";
+}
+
+void cmLocalNinjaGenerator::WriteNinjaFilesInclusionCommon(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
os << "# Include auxiliary files.\n"
@@ -263,25 +318,30 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
}
void cmLocalNinjaGenerator::AppendTargetOutputs(cmGeneratorTarget* target,
- cmNinjaDeps& outputs)
+ cmNinjaDeps& outputs,
+ const std::string& config)
{
- this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
+ this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs,
+ config);
}
void cmLocalNinjaGenerator::AppendTargetDepends(cmGeneratorTarget* target,
cmNinjaDeps& outputs,
+ const std::string& config,
+ const std::string& fileConfig,
cmNinjaTargetDepends depends)
{
- this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs,
- depends);
+ this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs, config,
+ fileConfig, depends);
}
void cmLocalNinjaGenerator::AppendCustomCommandDeps(
- cmCustomCommandGenerator const& ccg, cmNinjaDeps& ninjaDeps)
+ cmCustomCommandGenerator const& ccg, cmNinjaDeps& ninjaDeps,
+ const std::string& config)
{
for (std::string const& i : ccg.GetDepends()) {
std::string dep;
- if (this->GetRealDependency(i, this->GetConfigName(), dep)) {
+ if (this->GetRealDependency(i, config, dep)) {
ninjaDeps.push_back(
this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep));
}
@@ -416,6 +476,8 @@ std::string cmLocalNinjaGenerator::BuildCommandLine(
void cmLocalNinjaGenerator::AppendCustomCommandLines(
cmCustomCommandGenerator const& ccg, std::vector<std::string>& cmdLines)
{
+ auto* gg = this->GetGlobalNinjaGenerator();
+
if (ccg.GetNumberOfCommands() > 0) {
std::string wd = ccg.GetWorkingDirectory();
if (wd.empty()) {
@@ -437,8 +499,10 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(
for (unsigned i = 0; i != ccg.GetNumberOfCommands(); ++i) {
cmdLines.push_back(launcher +
- this->ConvertToOutputFormat(ccg.GetCommand(i),
- cmOutputConverter::SHELL));
+ this->ConvertToOutputFormat(
+ ccg.GetCommand(i),
+ gg->IsMultiConfig() ? cmOutputConverter::NINJAMULTI
+ : cmOutputConverter::SHELL));
std::string& cmd = cmdLines.back();
ccg.AppendArguments(i, cmd);
@@ -446,14 +510,15 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(
}
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
- cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps)
+ cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps,
+ const std::string& config)
{
cmGlobalNinjaGenerator* gg = this->GetGlobalNinjaGenerator();
- if (gg->SeenCustomCommand(cc)) {
+ if (gg->SeenCustomCommand(cc, config)) {
return;
}
- cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this);
+ cmCustomCommandGenerator ccg(*cc, config, this);
const std::vector<std::string>& outputs = ccg.GetOutputs();
const std::vector<std::string>& byproducts = ccg.GetByproducts();
@@ -484,7 +549,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
}
cmNinjaDeps ninjaDeps;
- this->AppendCustomCommandDeps(ccg, ninjaDeps);
+ this->AppendCustomCommandDeps(ccg, ninjaDeps, config);
std::vector<std::string> cmdLines;
this->AppendCustomCommandLines(ccg, cmdLines);
@@ -495,7 +560,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
build.Outputs = std::move(ninjaOutputs);
build.ExplicitDeps = std::move(ninjaDeps);
build.OrderOnlyDeps = orderOnlyDeps;
- gg->WriteBuild(this->GetBuildFileStream(), build);
+ gg->WriteBuild(this->GetConfigFileStream(config), build);
} else {
std::string customStep = cmSystemTools::GetFilenameName(ninjaOutputs[0]);
// Hash full path to make unique.
@@ -507,8 +572,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
this->BuildCommandLine(cmdLines, customStep),
this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0],
cc->GetDepfile(), cc->GetJobPool(), cc->GetUsesTerminal(),
- /*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps,
- orderOnlyDeps);
+ /*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, config,
+ ninjaDeps, orderOnlyDeps);
}
}
@@ -524,7 +589,8 @@ void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
ins.first->second.insert(target);
}
-void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
+void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements(
+ const std::string& config)
{
for (cmCustomCommand const* customCommand : this->CustomCommands) {
auto i = this->CustomCommandTargets.find(customCommand);
@@ -542,15 +608,16 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
auto j = i->second.begin();
assert(j != i->second.end());
std::vector<std::string> ccTargetDeps;
- this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j,
- ccTargetDeps);
+ this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(
+ *j, ccTargetDeps, config);
std::sort(ccTargetDeps.begin(), ccTargetDeps.end());
++j;
for (; j != i->second.end(); ++j) {
std::vector<std::string> jDeps;
std::vector<std::string> depsIntersection;
- this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, jDeps);
+ this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, jDeps,
+ config);
std::sort(jDeps.begin(), jDeps.end());
std::set_intersection(ccTargetDeps.begin(), ccTargetDeps.end(),
jDeps.begin(), jDeps.end(),
@@ -558,7 +625,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
ccTargetDeps = depsIntersection;
}
- this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps);
+ this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps, config);
}
}
@@ -599,15 +666,13 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
return launcher;
}
-void cmLocalNinjaGenerator::AdditionalCleanFiles()
+void cmLocalNinjaGenerator::AdditionalCleanFiles(const std::string& config)
{
if (const char* prop_value =
this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
std::vector<std::string> cleanFiles;
{
- cmExpandList(cmGeneratorExpression::Evaluate(
- prop_value, this,
- this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")),
+ cmExpandList(cmGeneratorExpression::Evaluate(prop_value, this, config),
cleanFiles);
}
std::string const& binaryDir = this->GetCurrentBinaryDirectory();
@@ -615,7 +680,7 @@ void cmLocalNinjaGenerator::AdditionalCleanFiles()
for (std::string const& cleanFile : cleanFiles) {
// Support relative paths
gg->AddAdditionalCleanFile(
- cmSystemTools::CollapseFullPath(cleanFile, binaryDir));
+ cmSystemTools::CollapseFullPath(cleanFile, binaryDir), config);
}
}
}
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
index f64534c..0445879 100644
--- a/Source/cmLocalNinjaGenerator.h
+++ b/Source/cmLocalNinjaGenerator.h
@@ -64,9 +64,11 @@ public:
std::string const& customStep = std::string(),
cmGeneratorTarget const* target = nullptr) const;
- void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
+ void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs,
+ const std::string& config);
void AppendTargetDepends(
- cmGeneratorTarget* target, cmNinjaDeps& outputs,
+ cmGeneratorTarget* target, cmNinjaDeps& outputs, const std::string& config,
+ const std::string& fileConfig,
cmNinjaTargetDepends depends = DependOnTargetArtifact);
void AddCustomCommandTarget(cmCustomCommand const* cc,
@@ -74,7 +76,8 @@ public:
void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
std::vector<std::string>& cmdLines);
void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
- cmNinjaDeps& ninjaDeps);
+ cmNinjaDeps& ninjaDeps,
+ const std::string& config);
protected:
std::string ConvertToIncludeReference(
@@ -83,20 +86,25 @@ protected:
bool forceFullPaths = false) override;
private:
- cmGeneratedFileStream& GetBuildFileStream() const;
+ cmGeneratedFileStream& GetConfigFileStream(const std::string& config) const;
+ cmGeneratedFileStream& GetCommonFileStream() const;
cmGeneratedFileStream& GetRulesFileStream() const;
void WriteBuildFileTop();
void WriteProjectHeader(std::ostream& os);
void WriteNinjaRequiredVersion(std::ostream& os);
- void WriteNinjaFilesInclusion(std::ostream& os);
+ void WriteNinjaConfigurationVariable(std::ostream& os,
+ const std::string& config);
+ void WriteNinjaFilesInclusionConfig(std::ostream& os);
+ void WriteNinjaFilesInclusionCommon(std::ostream& os);
void WriteProcessedMakefile(std::ostream& os);
void WritePools(std::ostream& os);
void WriteCustomCommandBuildStatement(cmCustomCommand const* cc,
- const cmNinjaDeps& orderOnlyDeps);
+ const cmNinjaDeps& orderOnlyDeps,
+ const std::string& config);
- void WriteCustomCommandBuildStatements();
+ void WriteCustomCommandBuildStatements(const std::string& config);
std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
@@ -104,7 +112,7 @@ private:
std::string const& customStep,
cmGeneratorTarget const* target) const;
- void AdditionalCleanFiles();
+ void AdditionalCleanFiles(const std::string& config);
std::string HomeRelativeOutputPath;
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 7b6d0f3..2912604 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -3,6 +3,7 @@
#include "cmLocalUnixMakefileGenerator3.h"
#include <algorithm>
+#include <cassert>
#include <cstdio>
#include <sstream>
#include <utility>
@@ -106,6 +107,13 @@ cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3(
cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3() = default;
+std::string cmLocalUnixMakefileGenerator3::GetConfigName() const
+{
+ auto const& configNames = this->GetConfigNames();
+ assert(configNames.size() == 1);
+ return configNames.front();
+}
+
void cmLocalUnixMakefileGenerator3::Generate()
{
// Record whether some options are enabled to avoid checking many
@@ -162,7 +170,7 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
continue;
}
std::vector<cmSourceFile const*> objectSources;
- gt->GetObjectSources(objectSources, this->ConfigName);
+ gt->GetObjectSources(objectSources, this->GetConfigName());
// Compute full path to object file directory for this target.
std::string dir = cmStrCat(gt->LocalGenerator->GetCurrentBinaryDirectory(),
'/', this->GetTargetDirectory(gt.get()), '/');
@@ -401,7 +409,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
// Add a local name for the rule to relink the target before
// installation.
- if (target->NeedRelinkBeforeInstall(this->ConfigName)) {
+ if (target->NeedRelinkBeforeInstall(this->GetConfigName())) {
makeTargetName = cmStrCat(
this->GetRelativeTargetDirectory(target.get()), "/preinstall");
localName = cmStrCat(target->GetName(), "/preinstall");
@@ -858,7 +866,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomDepends(
std::vector<std::string>& depends, const std::vector<cmCustomCommand>& ccs)
{
for (cmCustomCommand const& cc : ccs) {
- cmCustomCommandGenerator ccg(cc, this->ConfigName, this);
+ cmCustomCommandGenerator ccg(cc, this->GetConfigName(), this);
this->AppendCustomDepend(depends, ccg);
}
}
@@ -869,7 +877,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomDepend(
for (std::string const& d : ccg.GetDepends()) {
// Lookup the real name of the dependency in case it is a CMake target.
std::string dep;
- if (this->GetRealDependency(d, this->ConfigName, dep)) {
+ if (this->GetRealDependency(d, this->GetConfigName(), dep)) {
depends.push_back(std::move(dep));
}
}
@@ -880,7 +888,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommands(
cmGeneratorTarget* target, std::string const& relative)
{
for (cmCustomCommand const& cc : ccs) {
- cmCustomCommandGenerator ccg(cc, this->ConfigName, this);
+ cmCustomCommandGenerator ccg(cc, this->GetConfigName(), this);
this->AppendCustomCommand(commands, ccg, target, relative, true);
}
}
@@ -1094,8 +1102,7 @@ void cmLocalUnixMakefileGenerator3::AppendDirectoryCleanCommand(
return;
}
- cmLocalGenerator* rootLG =
- this->GetGlobalGenerator()->GetLocalGenerators().at(0);
+ const auto& rootLG = this->GetGlobalGenerator()->GetLocalGenerators().at(0);
std::string const& binaryDir = rootLG->GetCurrentBinaryDirectory();
std::string const& currentBinaryDir = this->GetCurrentBinaryDirectory();
std::string cleanfile =
@@ -1840,7 +1847,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
// Build a list of preprocessor definitions for the target.
std::set<std::string> defines;
- this->GetTargetDefines(target, this->ConfigName, implicitLang.first,
+ this->GetTargetDefines(target, this->GetConfigName(), implicitLang.first,
defines);
if (!defines.empty()) {
/* clang-format off */
@@ -1864,7 +1871,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
std::vector<std::string> includes;
this->GetIncludeDirectories(includes, target, implicitLang.first,
- this->ConfigName);
+ this->GetConfigName());
std::string binaryDir = this->GetState()->GetBinaryDirectory();
if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) {
std::string const& sourceDir = this->GetState()->GetSourceDirectory();
diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h
index f12ae8b..1629e63 100644
--- a/Source/cmLocalUnixMakefileGenerator3.h
+++ b/Source/cmLocalUnixMakefileGenerator3.h
@@ -33,6 +33,8 @@ public:
cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmMakefile* mf);
~cmLocalUnixMakefileGenerator3() override;
+ std::string GetConfigName() const;
+
void ComputeHomeRelativeOutputPath() override;
/**
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index dc0b50f..6c5db75 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1992,7 +1992,8 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type,
{
auto it =
this->Targets
- .emplace(name, cmTarget(name, type, cmTarget::VisibilityNormal, this))
+ .emplace(name,
+ cmTarget(name, type, cmTarget::VisibilityNormal, this, true))
.first;
this->OrderedTargets.push_back(&it->second);
this->GetGlobalGenerator()->IndexTarget(&it->second);
@@ -4162,7 +4163,7 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name,
new cmTarget(name, type,
global ? cmTarget::VisibilityImportedGlobally
: cmTarget::VisibilityImported,
- this));
+ this, true));
// Add to the set of available imported targets.
this->ImportedTargets[name] = target.get();
@@ -4535,10 +4536,14 @@ static const char* const C_FEATURES[] = { nullptr FOR_EACH_C_FEATURE(
static const char* const CXX_FEATURES[] = { nullptr FOR_EACH_CXX_FEATURE(
FEATURE_STRING) };
+
+static const char* const CUDA_FEATURES[] = { nullptr FOR_EACH_CUDA_FEATURE(
+ FEATURE_STRING) };
#undef FEATURE_STRING
static const char* const C_STANDARDS[] = { "90", "99", "11" };
static const char* const CXX_STANDARDS[] = { "98", "11", "14", "17", "20" };
+static const char* const CUDA_STANDARDS[] = { "03", "11", "14", "17", "20" };
bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
const std::string& feature,
@@ -4578,9 +4583,13 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
target->AppendProperty("COMPILE_FEATURES", feature.c_str());
- return lang == "C" || lang == "OBJC"
- ? this->AddRequiredTargetCFeature(target, feature, lang, error)
- : this->AddRequiredTargetCxxFeature(target, feature, lang, error);
+ if (lang == "C" || lang == "OBJC") {
+ return this->AddRequiredTargetCFeature(target, feature, lang, error);
+ }
+ if (lang == "CUDA") {
+ return this->AddRequiredTargetCudaFeature(target, feature, lang, error);
+ }
+ return this->AddRequiredTargetCxxFeature(target, feature, lang, error);
}
bool cmMakefile::CompileFeatureKnown(cmTarget const* target,
@@ -4604,6 +4613,13 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target,
lang = "CXX";
return true;
}
+ bool isCudaFeature =
+ std::find_if(cm::cbegin(CUDA_FEATURES) + 1, cm::cend(CUDA_FEATURES),
+ cmStrCmp(feature)) != cm::cend(CUDA_FEATURES);
+ if (isCudaFeature) {
+ lang = "CUDA";
+ return true;
+ }
std::ostringstream e;
if (error) {
e << "specified";
@@ -4672,9 +4688,13 @@ bool cmMakefile::HaveStandardAvailable(cmTarget const* target,
std::string const& lang,
const std::string& feature) const
{
- return lang == "C" || lang == "OBJC"
- ? this->HaveCStandardAvailable(target, feature, lang)
- : this->HaveCxxStandardAvailable(target, feature, lang);
+ if (lang == "C" || lang == "OBJC") {
+ return this->HaveCStandardAvailable(target, feature, lang);
+ }
+ if (lang == "CUDA") {
+ return this->HaveCudaStandardAvailable(target, feature, lang);
+ }
+ return this->HaveCxxStandardAvailable(target, feature, lang);
}
bool cmMakefile::HaveCStandardAvailable(cmTarget const* target,
@@ -4757,6 +4777,14 @@ bool cmMakefile::IsLaterStandard(std::string const& lang,
return std::find_if(rhsIt, cm::cend(C_STANDARDS), cmStrCmp(lhs)) !=
cm::cend(C_STANDARDS);
}
+ if (lang == "CUDA") {
+ const char* const* rhsIt = std::find_if(
+ cm::cbegin(CUDA_STANDARDS), cm::cend(CUDA_STANDARDS), cmStrCmp(rhs));
+
+ return std::find_if(rhsIt, cm::cend(CUDA_STANDARDS), cmStrCmp(lhs)) !=
+ cm::cend(CUDA_STANDARDS);
+ }
+
const char* const* rhsIt = std::find_if(
cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), cmStrCmp(rhs));
@@ -4901,27 +4929,6 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target,
}
}
- const char* existingCudaStandard = target->GetProperty("CUDA_STANDARD");
- const char* const* existingCudaLevel = nullptr;
- if (existingCudaStandard) {
- existingCudaLevel =
- std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS),
- cmStrCmp(existingCudaStandard));
- if (existingCudaLevel == cm::cend(CXX_STANDARDS)) {
- std::ostringstream e;
- e << "The CUDA_STANDARD property on target \"" << target->GetName()
- << "\" contained an invalid value: \"" << existingCudaStandard
- << "\".";
- if (error) {
- *error = e.str();
- } else {
- this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
- e.str(), this->Backtrace);
- }
- return false;
- }
- }
-
/* clang-format off */
const char* const* needCxxLevel =
needCxx20 ? &CXX_STANDARDS[4]
@@ -4938,11 +4945,164 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target,
if (!existingCxxLevel || existingCxxLevel < needCxxLevel) {
target->SetProperty(cmStrCat(lang, "_STANDARD"), *needCxxLevel);
}
+ }
+
+ return true;
+}
+
+bool cmMakefile::HaveCudaStandardAvailable(cmTarget const* target,
+ const std::string& feature,
+ std::string const& lang) const
+{
+ const char* defaultCudaStandard =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "_STANDARD_DEFAULT"));
+ if (!defaultCudaStandard) {
+ this->IssueMessage(
+ MessageType::INTERNAL_ERROR,
+ cmStrCat("CMAKE_", lang,
+ "_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
+ "not fully configured for this compiler."));
+ // Return true so the caller does not try to lookup the default standard.
+ return true;
+ }
+ if (std::find_if(cm::cbegin(CUDA_STANDARDS), cm::cend(CUDA_STANDARDS),
+ cmStrCmp(defaultCudaStandard)) ==
+ cm::cend(CUDA_STANDARDS)) {
+ const std::string e =
+ cmStrCat("The CMAKE_", lang, "_STANDARD_DEFAULT variable contains an ",
+ "invalid value: \"", defaultCudaStandard, "\".");
+ this->IssueMessage(MessageType::INTERNAL_ERROR, e);
+ return false;
+ }
+
+ bool needCuda03 = false;
+ bool needCuda11 = false;
+ bool needCuda14 = false;
+ bool needCuda17 = false;
+ bool needCuda20 = false;
+ this->CheckNeededCudaLanguage(feature, lang, needCuda03, needCuda11,
+ needCuda14, needCuda17, needCuda20);
+
+ const char* existingCudaStandard =
+ target->GetProperty(cmStrCat(lang, "_STANDARD"));
+ if (!existingCudaStandard) {
+ existingCudaStandard = defaultCudaStandard;
+ }
+ const char* const* existingCudaLevel =
+ std::find_if(cm::cbegin(CUDA_STANDARDS), cm::cend(CUDA_STANDARDS),
+ cmStrCmp(existingCudaStandard));
+ if (existingCudaLevel == cm::cend(CUDA_STANDARDS)) {
+ const std::string e = cmStrCat(
+ "The ", lang, "_STANDARD property on target \"", target->GetName(),
+ "\" contained an invalid value: \"", existingCudaStandard, "\".");
+ this->IssueMessage(MessageType::FATAL_ERROR, e);
+ return false;
+ }
+
+ /* clang-format off */
+ const char* const* needCudaLevel =
+ needCuda20 ? &CUDA_STANDARDS[4]
+ : needCuda17 ? &CUDA_STANDARDS[3]
+ : needCuda14 ? &CUDA_STANDARDS[2]
+ : needCuda11 ? &CUDA_STANDARDS[1]
+ : needCuda03 ? &CUDA_STANDARDS[0]
+ : nullptr;
+ /* clang-format on */
+
+ return !needCudaLevel || needCudaLevel <= existingCudaLevel;
+}
+
+void cmMakefile::CheckNeededCudaLanguage(const std::string& feature,
+ std::string const& lang,
+ bool& needCuda03, bool& needCuda11,
+ bool& needCuda14, bool& needCuda17,
+ bool& needCuda20) const
+{
+ if (const char* propCuda03 =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "03_COMPILE_FEATURES"))) {
+ std::vector<std::string> props = cmExpandedList(propCuda03);
+ needCuda03 = cmContains(props, feature);
+ }
+ if (const char* propCuda11 =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "11_COMPILE_FEATURES"))) {
+ std::vector<std::string> props = cmExpandedList(propCuda11);
+ needCuda11 = cmContains(props, feature);
+ }
+ if (const char* propCuda14 =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "14_COMPILE_FEATURES"))) {
+ std::vector<std::string> props = cmExpandedList(propCuda14);
+ needCuda14 = cmContains(props, feature);
+ }
+ if (const char* propCuda17 =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "17_COMPILE_FEATURES"))) {
+ std::vector<std::string> props = cmExpandedList(propCuda17);
+ needCuda17 = cmContains(props, feature);
+ }
+ if (const char* propCuda20 =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "20_COMPILE_FEATURES"))) {
+ std::vector<std::string> props = cmExpandedList(propCuda20);
+ needCuda20 = cmContains(props, feature);
+ }
+}
+
+bool cmMakefile::AddRequiredTargetCudaFeature(cmTarget* target,
+ const std::string& feature,
+ std::string const& lang,
+ std::string* error) const
+{
+ bool needCuda03 = false;
+ bool needCuda11 = false;
+ bool needCuda14 = false;
+ bool needCuda17 = false;
+ bool needCuda20 = false;
+
+ this->CheckNeededCudaLanguage(feature, lang, needCuda03, needCuda11,
+ needCuda14, needCuda17, needCuda20);
+
+ const char* existingCudaStandard =
+ target->GetProperty(cmStrCat(lang, "_STANDARD"));
+ if (existingCudaStandard == nullptr) {
+ const char* defaultCudaStandard =
+ this->GetDefinition(cmStrCat("CMAKE_", lang, "_STANDARD_DEFAULT"));
+ if (defaultCudaStandard && *defaultCudaStandard) {
+ existingCudaStandard = defaultCudaStandard;
+ }
+ }
+ const char* const* existingCudaLevel = nullptr;
+ if (existingCudaStandard) {
+ existingCudaLevel =
+ std::find_if(cm::cbegin(CUDA_STANDARDS), cm::cend(CUDA_STANDARDS),
+ cmStrCmp(existingCudaStandard));
+ if (existingCudaLevel == cm::cend(CUDA_STANDARDS)) {
+ const std::string e = cmStrCat(
+ "The ", lang, "_STANDARD property on target \"", target->GetName(),
+ "\" contained an invalid value: \"", existingCudaStandard, "\".");
+ if (error) {
+ *error = e;
+ } else {
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e,
+ this->Backtrace);
+ }
+ return false;
+ }
+ }
+
+ /* clang-format off */
+ const char* const* needCudaLevel =
+ needCuda20 ? &CUDA_STANDARDS[4]
+ : needCuda17 ? &CUDA_STANDARDS[3]
+ : needCuda14 ? &CUDA_STANDARDS[2]
+ : needCuda11 ? &CUDA_STANDARDS[1]
+ : needCuda03 ? &CUDA_STANDARDS[0]
+ : nullptr;
+ /* clang-format on */
+
+ if (needCudaLevel) {
// Ensure the CUDA language level is high enough to support
- // the needed C++ features.
- if (!existingCudaLevel || existingCudaLevel < needCxxLevel) {
- target->SetProperty("CUDA_STANDARD", *needCxxLevel);
+ // the needed CUDA features.
+ if (!existingCudaLevel || existingCudaLevel < needCudaLevel) {
+ target->SetProperty("CUDA_STANDARD", *needCudaLevel);
}
}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index d0dceb9..672244e 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -1138,11 +1138,14 @@ private:
bool AddRequiredTargetCFeature(cmTarget* target, const std::string& feature,
std::string const& lang,
std::string* error = nullptr) const;
-
bool AddRequiredTargetCxxFeature(cmTarget* target,
const std::string& feature,
std::string const& lang,
std::string* error = nullptr) const;
+ bool AddRequiredTargetCudaFeature(cmTarget* target,
+ const std::string& feature,
+ std::string const& lang,
+ std::string* error = nullptr) const;
void CheckNeededCLanguage(const std::string& feature,
std::string const& lang, bool& needC90,
@@ -1151,6 +1154,10 @@ private:
std::string const& lang, bool& needCxx98,
bool& needCxx11, bool& needCxx14,
bool& needCxx17, bool& needCxx20) const;
+ void CheckNeededCudaLanguage(const std::string& feature,
+ std::string const& lang, bool& needCuda03,
+ bool& needCuda11, bool& needCuda14,
+ bool& needCuda17, bool& needCuda20) const;
bool HaveCStandardAvailable(cmTarget const* target,
const std::string& feature,
@@ -1158,6 +1165,9 @@ private:
bool HaveCxxStandardAvailable(cmTarget const* target,
const std::string& feature,
std::string const& lang) const;
+ bool HaveCudaStandardAvailable(cmTarget const* target,
+ const std::string& feature,
+ std::string const& lang) const;
void CheckForUnusedVariables() const;
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 40265ff..ff8682c 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -35,10 +35,9 @@ cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator(
{
this->CustomCommandDriver = OnDepends;
this->TargetNames =
- this->GeneratorTarget->GetExecutableNames(this->ConfigName);
+ this->GeneratorTarget->GetExecutableNames(this->GetConfigName());
- this->OSXBundleGenerator =
- cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
+ this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
@@ -64,7 +63,7 @@ void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
// write the link rules
this->WriteExecutableRule(false);
- if (this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName)) {
+ if (this->GeneratorTarget->NeedRelinkBeforeInstall(this->GetConfigName())) {
// Write rules to link an installable version of the target.
this->WriteExecutableRule(true);
}
@@ -85,7 +84,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
{
#ifndef CMAKE_BOOTSTRAP
const bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
if (!requiresDeviceLinking) {
return;
}
@@ -141,10 +140,10 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
// Add language feature flags.
this->LocalGenerator->AddLanguageFlagsForLinking(
- flags, this->GeneratorTarget, linkLanguage, this->ConfigName);
+ flags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
- this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
- linkLanguage, this->ConfigName);
+ this->LocalGenerator->AddArchitectureFlags(
+ flags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
// Add target-specific linker flags.
this->GetTargetLinkFlags(linkFlags, linkLanguage);
@@ -213,7 +212,8 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetOutputReal),
output);
- std::string targetFullPathCompilePDB = this->ComputeTargetCompilePDB();
+ std::string targetFullPathCompilePDB =
+ this->ComputeTargetCompilePDB(this->GetConfigName());
std::string targetOutPathCompilePDB =
this->LocalGenerator->ConvertToOutputFormat(targetFullPathCompilePDB,
cmOutputConverter::SHELL);
@@ -287,12 +287,14 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Get the name of the executable to generate.
cmGeneratorTarget::Names targetNames =
- this->GeneratorTarget->GetExecutableNames(this->ConfigName);
+ this->GeneratorTarget->GetExecutableNames(this->GetConfigName());
// Construct the full path version of the names.
- std::string outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
+ std::string outpath =
+ this->GeneratorTarget->GetDirectory(this->GetConfigName());
if (this->GeneratorTarget->IsAppBundleOnApple()) {
- this->OSXBundleGenerator->CreateAppBundle(targetNames.Output, outpath);
+ this->OSXBundleGenerator->CreateAppBundle(targetNames.Output, outpath,
+ this->GetConfigName());
}
outpath += '/';
std::string outpathImp;
@@ -308,18 +310,18 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
cmSystemTools::MakeDirectory(outpath);
if (!targetNames.ImportLibrary.empty()) {
outpathImp = this->GeneratorTarget->GetDirectory(
- this->ConfigName, cmStateEnums::ImportLibraryArtifact);
+ this->GetConfigName(), cmStateEnums::ImportLibraryArtifact);
cmSystemTools::MakeDirectory(outpathImp);
outpathImp += '/';
}
}
std::string compilePdbOutputPath =
- this->GeneratorTarget->GetCompilePDBDirectory(this->ConfigName);
+ this->GeneratorTarget->GetCompilePDBDirectory(this->GetConfigName());
cmSystemTools::MakeDirectory(compilePdbOutputPath);
std::string pdbOutputPath =
- this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
+ this->GeneratorTarget->GetPDBDirectory(this->GetConfigName());
cmSystemTools::MakeDirectory(pdbOutputPath);
pdbOutputPath += '/';
@@ -347,7 +349,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Get the language to use for linking this executable.
std::string linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
// Make sure we have a link language.
if (linkLanguage.empty()) {
@@ -380,7 +382,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Add flags to create an executable.
this->LocalGenerator->AddConfigVariableFlags(
- linkFlags, "CMAKE_EXE_LINKER_FLAGS", this->ConfigName);
+ linkFlags, "CMAKE_EXE_LINKER_FLAGS", this->GetConfigName());
if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
this->LocalGenerator->AppendFlags(
@@ -409,10 +411,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Add language feature flags.
this->LocalGenerator->AddLanguageFlagsForLinking(
- flags, this->GeneratorTarget, linkLanguage, this->ConfigName);
+ flags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
- this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
- linkLanguage, this->ConfigName);
+ this->LocalGenerator->AddArchitectureFlags(
+ flags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
// Add target-specific linker flags.
this->GetTargetLinkFlags(linkFlags, linkLanguage);
@@ -423,11 +425,12 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
- this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags);
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags,
+ this->GetConfigName());
}
- this->LocalGenerator->AppendIPOLinkerFlags(linkFlags, this->GeneratorTarget,
- this->ConfigName, linkLanguage);
+ this->LocalGenerator->AppendIPOLinkerFlags(
+ linkFlags, this->GeneratorTarget, this->GetConfigName(), linkLanguage);
// Construct a list of files associated with this executable that
// may need to be cleaned.
@@ -451,7 +454,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
targetFullPathImport));
std::string implib;
if (this->GeneratorTarget->GetImplibGNUtoMS(
- this->ConfigName, targetFullPathImport, implib)) {
+ this->GetConfigName(), targetFullPathImport, implib)) {
exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), implib));
}
@@ -479,7 +482,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Construct the main link rule.
std::vector<std::string> real_link_commands;
std::string linkRuleVar = this->GeneratorTarget->GetCreateRuleVariable(
- linkLanguage, this->ConfigName);
+ linkLanguage, this->GetConfigName());
std::string linkRule = this->GetLinkRule(linkRuleVar);
std::vector<std::string> commands1;
cmExpandList(linkRule, real_link_commands);
@@ -536,7 +539,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// maybe create .def file from list of objects
this->GenDefFile(real_link_commands);
- std::string manifests = this->GetManifests();
+ std::string manifests = this->GetManifests(this->GetConfigName());
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GeneratorTarget->GetName().c_str();
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index 54a6606..872521c 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -36,11 +36,10 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator(
this->CustomCommandDriver = OnDepends;
if (this->GeneratorTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
this->TargetNames =
- this->GeneratorTarget->GetLibraryNames(this->ConfigName);
+ this->GeneratorTarget->GetLibraryNames(this->GetConfigName());
}
- this->OSXBundleGenerator =
- cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
+ this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
@@ -69,14 +68,16 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
break;
case cmStateEnums::SHARED_LIBRARY:
this->WriteSharedLibraryRules(false);
- if (this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName)) {
+ if (this->GeneratorTarget->NeedRelinkBeforeInstall(
+ this->GetConfigName())) {
// Write rules to link an installable version of the target.
this->WriteSharedLibraryRules(true);
}
break;
case cmStateEnums::MODULE_LIBRARY:
this->WriteModuleLibraryRules(false);
- if (this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName)) {
+ if (this->GeneratorTarget->NeedRelinkBeforeInstall(
+ this->GetConfigName())) {
// Write rules to link an installable version of the target.
this->WriteModuleLibraryRules(true);
}
@@ -126,21 +127,21 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
{
const bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
if (requiresDeviceLinking) {
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
this->WriteDeviceLibraryRules(linkRuleVar, false);
}
std::string linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
std::string linkRuleVar = this->GeneratorTarget->GetCreateRuleVariable(
- linkLanguage, this->ConfigName);
+ linkLanguage, this->GetConfigName());
std::string extraFlags;
this->LocalGenerator->GetStaticLibraryFlags(
- extraFlags, cmSystemTools::UpperCase(this->ConfigName), linkLanguage,
+ extraFlags, cmSystemTools::UpperCase(this->GetConfigName()), linkLanguage,
this->GeneratorTarget);
this->WriteLibraryRules(linkRuleVar, extraFlags, false);
}
@@ -154,7 +155,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
if (!relink) {
const bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
if (requiresDeviceLinking) {
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
this->WriteDeviceLibraryRules(linkRuleVar, relink);
@@ -162,21 +163,22 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
}
std::string linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
std::string linkRuleVar =
cmStrCat("CMAKE_", linkLanguage, "_CREATE_SHARED_LIBRARY");
std::string extraFlags;
this->GetTargetLinkFlags(extraFlags, linkLanguage);
this->LocalGenerator->AddConfigVariableFlags(
- extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName);
+ extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->GetConfigName());
std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
- this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags,
+ this->GetConfigName());
if (this->GeneratorTarget->GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
this->LocalGenerator->AppendFlags(extraFlags, " -Wl,--no-as-needed");
@@ -188,7 +190,7 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
{
if (!relink) {
const bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
if (requiresDeviceLinking) {
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
this->WriteDeviceLibraryRules(linkRuleVar, relink);
@@ -196,21 +198,22 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
}
std::string linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
std::string linkRuleVar =
cmStrCat("CMAKE_", linkLanguage, "_CREATE_SHARED_MODULE");
std::string extraFlags;
this->GetTargetLinkFlags(extraFlags, linkLanguage);
this->LocalGenerator->AddConfigVariableFlags(
- extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName);
+ extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->GetConfigName());
std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
- this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags,
+ this->GetConfigName());
this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
}
@@ -218,14 +221,14 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
{
std::string linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
std::string linkRuleVar =
cmStrCat("CMAKE_", linkLanguage, "_CREATE_MACOSX_FRAMEWORK");
std::string extraFlags;
this->GetTargetLinkFlags(extraFlags, linkLanguage);
this->LocalGenerator->AddConfigVariableFlags(
- extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->ConfigName);
+ extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->GetConfigName());
this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
}
@@ -331,7 +334,8 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetOutputReal),
output);
- std::string targetFullPathCompilePDB = this->ComputeTargetCompilePDB();
+ std::string targetFullPathCompilePDB =
+ this->ComputeTargetCompilePDB(this->GetConfigName());
std::string targetOutPathCompilePDB =
this->LocalGenerator->ConvertToOutputFormat(targetFullPathCompilePDB,
cmOutputConverter::SHELL);
@@ -347,7 +351,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
// Add language-specific flags.
std::string langFlags;
this->LocalGenerator->AddLanguageFlagsForLinking(
- langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
+ langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
vars.LanguageCompileFlags = langFlags.c_str();
@@ -420,7 +424,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Get the language to use for linking this library.
std::string linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
// Make sure we have a link language.
if (linkLanguage.empty()) {
@@ -439,8 +443,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Create set of linking flags.
std::string linkFlags;
this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
- this->LocalGenerator->AppendIPOLinkerFlags(linkFlags, this->GeneratorTarget,
- this->ConfigName, linkLanguage);
+ this->LocalGenerator->AppendIPOLinkerFlags(
+ linkFlags, this->GeneratorTarget, this->GetConfigName(), linkLanguage);
// Add OSX version flags, if any.
if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
@@ -450,20 +454,20 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
}
// Construct the name of the library.
- this->GeneratorTarget->GetLibraryNames(this->ConfigName);
+ this->GeneratorTarget->GetLibraryNames(this->GetConfigName());
// Construct the full path version of the names.
std::string outpath;
std::string outpathImp;
if (this->GeneratorTarget->IsFrameworkOnApple()) {
- outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
+ outpath = this->GeneratorTarget->GetDirectory(this->GetConfigName());
this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output,
- outpath);
+ outpath, this->GetConfigName());
outpath += '/';
} else if (this->GeneratorTarget->IsCFBundleOnApple()) {
- outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
- this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output,
- outpath);
+ outpath = this->GeneratorTarget->GetDirectory(this->GetConfigName());
+ this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output, outpath,
+ this->GetConfigName());
outpath += '/';
} else if (relink) {
outpath = cmStrCat(this->Makefile->GetCurrentBinaryDirectory(),
@@ -474,23 +478,23 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
outpathImp = outpath;
}
} else {
- outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
+ outpath = this->GeneratorTarget->GetDirectory(this->GetConfigName());
cmSystemTools::MakeDirectory(outpath);
outpath += '/';
if (!this->TargetNames.ImportLibrary.empty()) {
outpathImp = this->GeneratorTarget->GetDirectory(
- this->ConfigName, cmStateEnums::ImportLibraryArtifact);
+ this->GetConfigName(), cmStateEnums::ImportLibraryArtifact);
cmSystemTools::MakeDirectory(outpathImp);
outpathImp += '/';
}
}
std::string compilePdbOutputPath =
- this->GeneratorTarget->GetCompilePDBDirectory(this->ConfigName);
+ this->GeneratorTarget->GetCompilePDBDirectory(this->GetConfigName());
cmSystemTools::MakeDirectory(compilePdbOutputPath);
std::string pdbOutputPath =
- this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
+ this->GeneratorTarget->GetPDBDirectory(this->GetConfigName());
cmSystemTools::MakeDirectory(pdbOutputPath);
pdbOutputPath += "/";
@@ -586,7 +590,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
targetFullPathImport));
std::string implib;
if (this->GeneratorTarget->GetImplibGNUtoMS(
- this->ConfigName, targetFullPathImport, implib)) {
+ this->GetConfigName(), targetFullPathImport, implib)) {
libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), implib));
}
@@ -638,7 +642,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_CREATE");
arCreateVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- arCreateVar, linkLanguage, this->ConfigName);
+ arCreateVar, linkLanguage, this->GetConfigName());
if (const char* rule = this->Makefile->GetDefinition(arCreateVar)) {
cmExpandList(rule, archiveCreateCommands);
@@ -647,7 +651,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_APPEND");
arAppendVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- arAppendVar, linkLanguage, this->ConfigName);
+ arAppendVar, linkLanguage, this->GetConfigName());
if (const char* rule = this->Makefile->GetDefinition(arAppendVar)) {
cmExpandList(rule, archiveAppendCommands);
@@ -656,7 +660,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_FINISH");
arFinishVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- arFinishVar, linkLanguage, this->ConfigName);
+ arFinishVar, linkLanguage, this->GetConfigName());
if (const char* rule = this->Makefile->GetDefinition(arFinishVar)) {
cmExpandList(rule, archiveFinishCommands);
@@ -726,7 +730,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// maybe create .def file from list of objects
this->GenDefFile(real_link_commands);
- std::string manifests = this->GetManifests();
+ std::string manifests = this->GetManifests(this->GetConfigName());
cmRulePlaceholderExpander::RuleVariables vars;
vars.TargetPDB = targetOutPathPDB.c_str();
@@ -771,7 +775,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
vars.Target = target.c_str();
vars.LinkLibraries = linkLibs.c_str();
vars.ObjectsQuoted = buildObjs.c_str();
- if (this->GeneratorTarget->HasSOName(this->ConfigName)) {
+ if (this->GeneratorTarget->HasSOName(this->GetConfigName())) {
vars.SONameFlag = this->Makefile->GetSONameFlag(linkLanguage);
vars.TargetSOName = this->TargetNames.SharedObject.c_str();
}
@@ -783,8 +787,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
std::string install_name_dir;
if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY) {
// Get the install_name directory for the build tree.
- install_name_dir =
- this->GeneratorTarget->GetInstallNameDirForBuildTree(this->ConfigName);
+ install_name_dir = this->GeneratorTarget->GetInstallNameDirForBuildTree(
+ this->GetConfigName());
// Set the rule variable replacement value.
if (install_name_dir.empty()) {
@@ -800,10 +804,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Add language-specific flags.
std::string langFlags;
this->LocalGenerator->AddLanguageFlagsForLinking(
- langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
+ langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
this->LocalGenerator->AddArchitectureFlags(
- langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
+ langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
vars.LanguageCompileFlags = langFlags.c_str();
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 767f4e0..436503b 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMakefileTargetGenerator.h"
+#include <cassert>
#include <cstdio>
#include <memory>
#include <sstream>
@@ -85,6 +86,13 @@ cmMakefileTargetGenerator* cmMakefileTargetGenerator::New(
return result;
}
+std::string cmMakefileTargetGenerator::GetConfigName()
+{
+ auto const& configNames = this->LocalGenerator->GetConfigNames();
+ assert(configNames.size() == 1);
+ return configNames.front();
+}
+
void cmMakefileTargetGenerator::GetTargetLinkFlags(
std::string& flags, const std::string& linkLanguage)
{
@@ -92,17 +100,18 @@ void cmMakefileTargetGenerator::GetTargetLinkFlags(
flags, this->GeneratorTarget->GetSafeProperty("LINK_FLAGS"));
std::string linkFlagsConfig =
- cmStrCat("LINK_FLAGS_", cmSystemTools::UpperCase(this->ConfigName));
+ cmStrCat("LINK_FLAGS_", cmSystemTools::UpperCase(this->GetConfigName()));
this->LocalGenerator->AppendFlags(
flags, this->GeneratorTarget->GetSafeProperty(linkFlagsConfig));
std::vector<std::string> opts;
- this->GeneratorTarget->GetLinkOptions(opts, this->ConfigName, linkLanguage);
+ this->GeneratorTarget->GetLinkOptions(opts, this->GetConfigName(),
+ linkLanguage);
// LINK_OPTIONS are escaped.
this->LocalGenerator->AppendCompileOptions(flags, opts);
this->LocalGenerator->AppendPositionIndependentLinkerFlags(
- flags, this->GeneratorTarget, this->ConfigName, linkLanguage);
+ flags, this->GeneratorTarget, this->GetConfigName(), linkLanguage);
}
void cmMakefileTargetGenerator::CreateRuleFile()
@@ -154,10 +163,10 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
auto evaluatedFiles =
[this](const char* prop_value) -> std::vector<std::string> {
std::vector<std::string> files;
- cmExpandList(
- cmGeneratorExpression::Evaluate(prop_value, this->LocalGenerator,
- this->ConfigName, this->GeneratorTarget),
- files);
+ cmExpandList(cmGeneratorExpression::Evaluate(
+ prop_value, this->LocalGenerator, this->GetConfigName(),
+ this->GeneratorTarget),
+ files);
return files;
};
@@ -187,12 +196,13 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
// First generate the object rule files. Save a list of all object
// files for this target.
std::vector<cmSourceFile const*> customCommands;
- this->GeneratorTarget->GetCustomCommands(customCommands, this->ConfigName);
+ this->GeneratorTarget->GetCustomCommands(customCommands,
+ this->GetConfigName());
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
for (cmSourceFile const* sf : customCommands) {
- cmCustomCommandGenerator ccg(*sf->GetCustomCommand(), this->ConfigName,
- this->LocalGenerator);
+ cmCustomCommandGenerator ccg(*sf->GetCustomCommand(),
+ this->GetConfigName(), this->LocalGenerator);
this->GenerateCustomRuleFile(ccg);
if (clean) {
const std::vector<std::string>& outputs = ccg.GetOutputs();
@@ -220,7 +230,8 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
this->GeneratorTarget->GetPostBuildCommands());
for (const auto& be : buildEventCommands) {
- cmCustomCommandGenerator beg(be, this->ConfigName, this->LocalGenerator);
+ cmCustomCommandGenerator beg(be, this->GetConfigName(),
+ this->LocalGenerator);
const std::vector<std::string>& byproducts = beg.GetByproducts();
for (std::string const& byproduct : byproducts) {
this->CleanFiles.insert(
@@ -230,17 +241,19 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
}
}
std::vector<cmSourceFile const*> headerSources;
- this->GeneratorTarget->GetHeaderSources(headerSources, this->ConfigName);
+ this->GeneratorTarget->GetHeaderSources(headerSources,
+ this->GetConfigName());
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
- headerSources, this->MacOSXContentGenerator);
+ headerSources, this->MacOSXContentGenerator, this->GetConfigName());
std::vector<cmSourceFile const*> extraSources;
- this->GeneratorTarget->GetExtraSources(extraSources, this->ConfigName);
+ this->GeneratorTarget->GetExtraSources(extraSources, this->GetConfigName());
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
- extraSources, this->MacOSXContentGenerator);
+ extraSources, this->MacOSXContentGenerator, this->GetConfigName());
const char* pchExtension =
this->Makefile->GetDefinition("CMAKE_PCH_EXTENSION");
std::vector<cmSourceFile const*> externalObjects;
- this->GeneratorTarget->GetExternalObjects(externalObjects, this->ConfigName);
+ this->GeneratorTarget->GetExternalObjects(externalObjects,
+ this->GetConfigName());
for (cmSourceFile const* sf : externalObjects) {
auto const& objectFileName = sf->GetFullPath();
if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) {
@@ -248,7 +261,8 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
}
}
std::vector<cmSourceFile const*> objectSources;
- this->GeneratorTarget->GetObjectSources(objectSources, this->ConfigName);
+ this->GeneratorTarget->GetObjectSources(objectSources,
+ this->GetConfigName());
for (cmSourceFile const* sf : objectSources) {
// Generate this object file's rule file.
this->WriteObjectRuleFiles(*sf);
@@ -334,9 +348,9 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
}
for (std::string const& language : languages) {
- std::string flags = this->GetFlags(language);
- std::string defines = this->GetDefines(language);
- std::string includes = this->GetIncludes(language);
+ std::string flags = this->GetFlags(language, this->GetConfigName());
+ std::string defines = this->GetDefines(language, this->GetConfigName());
+ std::string includes = this->GetIncludes(language, this->GetConfigName());
// Escape comment characters so they do not terminate assignment.
cmSystemTools::ReplaceString(flags, "#", "\\#");
cmSystemTools::ReplaceString(defines, "#", "\\#");
@@ -348,7 +362,7 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
}
void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
- cmSourceFile const& source, const char* pkgloc)
+ cmSourceFile const& source, const char* pkgloc, const std::string& config)
{
// Skip OS X content when not building a Framework or Bundle.
if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
@@ -356,7 +370,8 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
}
std::string macdir =
- this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
+ this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc,
+ config);
// Get the input file location.
std::string const& input = source.GetFullPath();
@@ -451,7 +466,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
// generate the depend scanning rule
this->WriteObjectDependRules(source, depends);
- std::string config = this->LocalGenerator->GetConfigName();
+ std::string config = this->GetConfigName();
std::string configUpper = cmSystemTools::UpperCase(config);
// Add precompile headers dependencies
@@ -593,16 +608,17 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
{
std::string targetFullPathReal;
std::string targetFullPathPDB;
- std::string targetFullPathCompilePDB = this->ComputeTargetCompilePDB();
+ std::string targetFullPathCompilePDB =
+ this->ComputeTargetCompilePDB(this->GetConfigName());
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
targetFullPathReal = this->GeneratorTarget->GetFullPath(
- this->ConfigName, cmStateEnums::RuntimeBinaryArtifact, true);
- targetFullPathPDB =
- cmStrCat(this->GeneratorTarget->GetPDBDirectory(this->ConfigName), '/',
- this->GeneratorTarget->GetPDBName(this->ConfigName));
+ this->GetConfigName(), cmStateEnums::RuntimeBinaryArtifact, true);
+ targetFullPathPDB = cmStrCat(
+ this->GeneratorTarget->GetPDBDirectory(this->GetConfigName()), '/',
+ this->GeneratorTarget->GetPDBName(this->GetConfigName()));
}
targetOutPathReal = this->LocalGenerator->ConvertToOutputFormat(
@@ -708,13 +724,15 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
std::string workingDirectory = cmSystemTools::CollapseFullPath(
this->LocalGenerator->GetCurrentBinaryDirectory());
compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
- this->GetFlags(lang));
+ this->GetFlags(lang, this->GetConfigName()));
std::string langDefines = std::string("$(") + lang + "_DEFINES)";
compileCommand.replace(compileCommand.find(langDefines),
- langDefines.size(), this->GetDefines(lang));
+ langDefines.size(),
+ this->GetDefines(lang, this->GetConfigName()));
std::string langIncludes = std::string("$(") + lang + "_INCLUDES)";
compileCommand.replace(compileCommand.find(langIncludes),
- langIncludes.size(), this->GetIncludes(lang));
+ langIncludes.size(),
+ this->GetIncludes(lang, this->GetConfigName()));
const char* eliminate[] = {
this->Makefile->GetDefinition("CMAKE_START_TEMP_FILE"),
@@ -1068,7 +1086,8 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
<< "# Targets to which this target links.\n"
<< "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
/* clang-format on */
- std::vector<std::string> dirs = this->GetLinkedTargetDirectories();
+ std::vector<std::string> dirs =
+ this->GetLinkedTargetDirectories(this->GetConfigName());
for (std::string const& d : dirs) {
*this->InfoFileStream << " \"" << d << "/DependInfo.cmake\"\n";
}
@@ -1171,7 +1190,7 @@ void cmMakefileTargetGenerator::DriveCustomCommands(
sources, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (cmSourceFile* source : sources) {
if (cmCustomCommand* cc = source->GetCustomCommand()) {
- cmCustomCommandGenerator ccg(*cc, this->ConfigName,
+ cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
this->LocalGenerator);
cmAppend(depends, ccg.GetOutputs());
}
@@ -1429,7 +1448,7 @@ void cmMakefileTargetGenerator::AppendTargetDepends(
}
// Loop over all library dependencies.
- const std::string& cfg = this->LocalGenerator->GetConfigName();
+ const std::string& cfg = this->GetConfigName();
if (cmComputeLinkInformation* cli =
this->GeneratorTarget->GetLinkInformation(cfg)) {
cmAppend(depends, cli->GetDepends());
@@ -1474,13 +1493,13 @@ void cmMakefileTargetGenerator::AppendLinkDepends(
// Add a dependency on user-specified manifest files, if any.
std::vector<cmSourceFile const*> manifest_srcs;
- this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
+ this->GeneratorTarget->GetManifests(manifest_srcs, this->GetConfigName());
for (cmSourceFile const* manifest_src : manifest_srcs) {
depends.push_back(manifest_src->GetFullPath());
}
// Add user-specified dependencies.
- this->GeneratorTarget->GetLinkDepends(depends, this->ConfigName,
+ this->GeneratorTarget->GetLinkDepends(depends, this->GetConfigName(),
linkLanguage);
}
@@ -1488,10 +1507,11 @@ std::string cmMakefileTargetGenerator::GetLinkRule(
const std::string& linkRuleVar)
{
std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
- if (this->GeneratorTarget->HasImplibGNUtoMS(this->ConfigName)) {
- std::string ruleVar = cmStrCat(
- "CMAKE_", this->GeneratorTarget->GetLinkerLanguage(this->ConfigName),
- "_GNUtoMS_RULE");
+ if (this->GeneratorTarget->HasImplibGNUtoMS(this->GetConfigName())) {
+ std::string ruleVar =
+ cmStrCat("CMAKE_",
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName()),
+ "_GNUtoMS_RULE");
if (const char* rule = this->Makefile->GetDefinition(ruleVar)) {
linkRule += rule;
}
@@ -1630,7 +1650,7 @@ void cmMakefileTargetGenerator::CreateLinkLibs(
std::string frameworkPath;
std::string linkPath;
cmComputeLinkInformation* pcli =
- this->GeneratorTarget->GetLinkInformation(this->ConfigName);
+ this->GeneratorTarget->GetLinkInformation(this->GetConfigName());
this->LocalGenerator->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath);
linkLibs = frameworkPath + linkPath + linkLibs;
@@ -1638,9 +1658,10 @@ void cmMakefileTargetGenerator::CreateLinkLibs(
if (useResponseFile &&
linkLibs.find_first_not_of(' ') != std::string::npos) {
// Lookup the response file reference flag.
- std::string responseFlagVar = cmStrCat(
- "CMAKE_", this->GeneratorTarget->GetLinkerLanguage(this->ConfigName),
- "_RESPONSE_FILE_LINK_FLAG");
+ std::string responseFlagVar =
+ cmStrCat("CMAKE_",
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName()),
+ "_RESPONSE_FILE_LINK_FLAG");
const char* responseFlag = this->Makefile->GetDefinition(responseFlagVar);
if (!responseFlag) {
responseFlag = "@";
@@ -1675,9 +1696,10 @@ void cmMakefileTargetGenerator::CreateObjectLists(
this->WriteObjectsStrings(object_strings, responseFileLimit);
// Lookup the response file reference flag.
- std::string responseFlagVar = cmStrCat(
- "CMAKE_", this->GeneratorTarget->GetLinkerLanguage(this->ConfigName),
- "_RESPONSE_FILE_LINK_FLAG");
+ std::string responseFlagVar =
+ cmStrCat("CMAKE_",
+ this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName()),
+ "_RESPONSE_FILE_LINK_FLAG");
const char* responseFlag = this->Makefile->GetDefinition(responseFlagVar);
if (!responseFlag) {
responseFlag = "@";
@@ -1716,7 +1738,8 @@ void cmMakefileTargetGenerator::CreateObjectLists(
}
void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
- const std::string& lang)
+ const std::string& lang,
+ const std::string& /*config*/)
{
std::string responseVar =
cmStrCat("CMAKE_", lang, "_USE_RESPONSE_FILE_FOR_INCLUDES");
@@ -1724,11 +1747,11 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
std::vector<std::string> includes;
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
- lang, this->ConfigName);
+ lang, this->GetConfigName());
std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
includes, this->GeneratorTarget, lang, false, useResponseFile,
- this->ConfigName);
+ this->GetConfigName());
if (includeFlags.empty()) {
return;
}
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
index 7b9c7a5..710ef89 100644
--- a/Source/cmMakefileTargetGenerator.h
+++ b/Source/cmMakefileTargetGenerator.h
@@ -52,6 +52,8 @@ public:
cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
+ std::string GetConfigName();
+
protected:
void GetTargetLinkFlags(std::string& flags, const std::string& linkLanguage);
@@ -81,7 +83,8 @@ protected:
{
}
- void operator()(cmSourceFile const& source, const char* pkgloc) override;
+ void operator()(cmSourceFile const& source, const char* pkgloc,
+ const std::string& config) override;
private:
cmMakefileTargetGenerator* Generator;
@@ -163,7 +166,8 @@ protected:
/** Add commands for generate def files */
void GenDefFile(std::vector<std::string>& real_link_commands);
- void AddIncludeFlags(std::string& flags, const std::string& lang) override;
+ void AddIncludeFlags(std::string& flags, const std::string& lang,
+ const std::string& config) override;
virtual void CloseFileStreams();
cmLocalUnixMakefileGenerator3* LocalGenerator;
diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx
index 1625e4f..6c18e48 100644
--- a/Source/cmMakefileUtilityTargetGenerator.cxx
+++ b/Source/cmMakefileUtilityTargetGenerator.cxx
@@ -22,8 +22,7 @@ cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator(
: cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnUtility;
- this->OSXBundleGenerator =
- cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
+ this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 72bef21..5a12855 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -41,33 +41,25 @@
cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
cmGeneratorTarget* target)
: cmNinjaTargetGenerator(target)
- , TargetLinkLanguage("")
{
- this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
- if (target->GetType() == cmStateEnums::EXECUTABLE) {
- this->TargetNames = this->GetGeneratorTarget()->GetExecutableNames(
- GetLocalGenerator()->GetConfigName());
- } else {
- this->TargetNames = this->GetGeneratorTarget()->GetLibraryNames(
- GetLocalGenerator()->GetConfigName());
- }
-
if (target->GetType() != cmStateEnums::OBJECT_LIBRARY) {
// on Windows the output dir is already needed at compile time
// ensure the directory exists (OutDir test)
- EnsureDirectoryExists(target->GetDirectory(this->GetConfigName()));
+ for (auto const& config : this->GetConfigNames()) {
+ EnsureDirectoryExists(target->GetDirectory(config));
+ }
}
- this->OSXBundleGenerator =
- cm::make_unique<cmOSXBundleGenerator>(target, this->GetConfigName());
+ this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() = default;
-void cmNinjaNormalTargetGenerator::Generate()
+void cmNinjaNormalTargetGenerator::Generate(const std::string& config)
{
- if (this->TargetLinkLanguage.empty()) {
+ std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
+ if (this->TargetLinkLanguage(config).empty()) {
cmSystemTools::Error("CMake can not determine linker language for "
"target: " +
this->GetGeneratorTarget()->GetName());
@@ -75,25 +67,36 @@ void cmNinjaNormalTargetGenerator::Generate()
}
// Write the rules for each language.
- this->WriteLanguagesRules();
+ this->WriteLanguagesRules(config);
// Write the build statements
- this->WriteObjectBuildStatements();
+ bool firstForConfig = true;
+ for (auto const& fileConfig : this->GetConfigNames()) {
+ this->WriteObjectBuildStatements(config, fileConfig, firstForConfig);
+ firstForConfig = false;
+ }
if (this->GetGeneratorTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- this->WriteObjectLibStatement();
+ this->WriteObjectLibStatement(config);
} else {
// If this target has cuda language link inputs, and we need to do
// device linking
- this->WriteDeviceLinkStatement();
- this->WriteLinkStatement();
+ this->WriteDeviceLinkStatement(config);
+ firstForConfig = true;
+ for (auto const& fileConfig : this->GetConfigNames()) {
+ this->WriteLinkStatement(config, fileConfig, firstForConfig);
+ firstForConfig = false;
+ }
}
+ this->GetGlobalGenerator()->AddTargetAlias(
+ this->GetTargetName(), this->GetGeneratorTarget(), "all");
// Find ADDITIONAL_CLEAN_FILES
- this->AdditionalCleanFiles();
+ this->AdditionalCleanFiles(config);
}
-void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
+void cmNinjaNormalTargetGenerator::WriteLanguagesRules(
+ const std::string& config)
{
#ifdef NINJA_GEN_VERBOSE_FILES
cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
@@ -106,8 +109,7 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
// Write rules for languages compiled in this target.
std::set<std::string> languages;
std::vector<cmSourceFile const*> sourceFiles;
- this->GetGeneratorTarget()->GetObjectSources(
- sourceFiles, this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ this->GetGeneratorTarget()->GetObjectSources(sourceFiles, config);
for (cmSourceFile const* sf : sourceFiles) {
std::string const lang = sf->GetLanguage();
if (!lang.empty()) {
@@ -115,7 +117,7 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
}
}
for (std::string const& language : languages) {
- this->WriteLanguageRules(language);
+ this->WriteLanguageRules(language, config);
}
}
@@ -139,22 +141,26 @@ const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
}
}
-std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule() const
+std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule(
+ const std::string& config) const
{
- return this->TargetLinkLanguage + "_" +
+ return this->TargetLinkLanguage(config) + "_" +
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
"_LINKER__" +
cmGlobalNinjaGenerator::EncodeRuleName(
- this->GetGeneratorTarget()->GetName());
+ this->GetGeneratorTarget()->GetName()) +
+ "_" + config;
}
-std::string cmNinjaNormalTargetGenerator::LanguageLinkerDeviceRule() const
+std::string cmNinjaNormalTargetGenerator::LanguageLinkerDeviceRule(
+ const std::string& config) const
{
- return this->TargetLinkLanguage + "_" +
+ return this->TargetLinkLanguage(config) + "_" +
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
"_DEVICE_LINKER__" +
cmGlobalNinjaGenerator::EncodeRuleName(
- this->GetGeneratorTarget()->GetName());
+ this->GetGeneratorTarget()->GetName()) +
+ "_" + config;
}
struct cmNinjaRemoveNoOpCommands
@@ -165,9 +171,10 @@ struct cmNinjaRemoveNoOpCommands
}
};
-void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
+void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(
+ bool useResponseFile, const std::string& config)
{
- cmNinjaRule rule(this->LanguageLinkerDeviceRule());
+ cmNinjaRule rule(this->LanguageLinkerDeviceRule(config));
if (!this->GetGlobalGenerator()->HasRule(rule.Name)) {
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
@@ -241,30 +248,34 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds);
// Write the linker rule with response file if needed.
- rule.Comment = cmStrCat("Rule for linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), '.');
- rule.Description = cmStrCat("Linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), " $TARGET_FILE");
+ rule.Comment =
+ cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), '.');
+ rule.Description =
+ cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), " $TARGET_FILE");
rule.Restat = "$RESTAT";
this->GetGlobalGenerator()->AddRule(rule);
}
}
-void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
+void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
+ const std::string& config)
{
cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
- std::string linkRuleName = this->LanguageLinkerRule();
+ std::string linkRuleName = this->LanguageLinkerRule(config);
if (!this->GetGlobalGenerator()->HasRule(linkRuleName)) {
cmNinjaRule rule(std::move(linkRuleName));
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
vars.CMTargetType = cmState::GetTargetTypeName(targetType);
- vars.Language = this->TargetLinkLanguage.c_str();
+ std::string lang = this->TargetLinkLanguage(config);
+ vars.Language = config.c_str();
- if (this->TargetLinkLanguage == "Swift") {
+ if (this->TargetLinkLanguage(config) == "Swift") {
vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME";
vars.SwiftModule = "$SWIFT_MODULE";
vars.SwiftModuleName = "$SWIFT_MODULE_NAME";
@@ -278,7 +289,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
std::string responseFlag;
- std::string cmakeVarLang = cmStrCat("CMAKE_", this->TargetLinkLanguage);
+ std::string cmakeVarLang =
+ cmStrCat("CMAKE_", this->TargetLinkLanguage(config));
// build response file name
std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
@@ -286,7 +298,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
if (flag) {
responseFlag = flag;
- } else if (this->TargetLinkLanguage != "CUDA") {
+ } else if (this->TargetLinkLanguage(config) != "CUDA") {
responseFlag = "@";
}
@@ -304,7 +316,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
rule.RspContent = "$in_newline";
}
rule.RspContent += " $LINK_PATH $LINK_LIBRARIES";
- if (this->TargetLinkLanguage == "Swift") {
+ if (this->TargetLinkLanguage(config) == "Swift") {
vars.SwiftSources = responseFlag.c_str();
} else {
vars.Objects = responseFlag.c_str();
@@ -359,7 +371,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
// Rule for linking library/executable.
- std::vector<std::string> linkCmds = this->ComputeLinkCmd();
+ std::vector<std::string> linkCmds = this->ComputeLinkCmd(config);
for (std::string& linkCmd : linkCmds) {
linkCmd = cmStrCat(launcher, linkCmd);
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
@@ -374,15 +386,18 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds);
// Write the linker rule with response file if needed.
- rule.Comment = cmStrCat("Rule for linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), '.');
- rule.Description = cmStrCat("Linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), " $TARGET_FILE");
+ rule.Comment =
+ cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), '.');
+ rule.Description =
+ cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), " $TARGET_FILE");
rule.Restat = "$RESTAT";
this->GetGlobalGenerator()->AddRule(rule);
}
- if (this->TargetNames.Output != this->TargetNames.Real &&
+ auto const tgtNames = this->TargetNames(config);
+ if (tgtNames.Output != tgtNames.Real &&
!this->GetGeneratorTarget()->IsFrameworkOnApple()) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -441,7 +456,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeDeviceLinkCmd()
return linkCmds;
}
-std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
+std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd(
+ const std::string& config)
{
std::vector<std::string> linkCmds;
cmMakefile* mf = this->GetMakefile();
@@ -450,14 +466,14 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
// this occurs when things like IPO is enabled, and we need to use the
// CMAKE_<lang>_CREATE_STATIC_LIBRARY_IPO define instead.
std::string linkCmdVar = this->GetGeneratorTarget()->GetCreateRuleVariable(
- this->TargetLinkLanguage, this->GetConfigName());
+ this->TargetLinkLanguage(config), config);
const char* linkCmd = mf->GetDefinition(linkCmdVar);
if (linkCmd) {
std::string linkCmdStr = linkCmd;
- if (this->GetGeneratorTarget()->HasImplibGNUtoMS(this->ConfigName)) {
- std::string ruleVar = cmStrCat(
- "CMAKE_", this->GeneratorTarget->GetLinkerLanguage(this->ConfigName),
- "_GNUtoMS_RULE");
+ if (this->GetGeneratorTarget()->HasImplibGNUtoMS(config)) {
+ std::string ruleVar =
+ cmStrCat("CMAKE_", this->GeneratorTarget->GetLinkerLanguage(config),
+ "_GNUtoMS_RULE");
if (const char* rule = this->Makefile->GetDefinition(ruleVar)) {
linkCmdStr += rule;
}
@@ -469,9 +485,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL),
" -E __run_co_compile --lwyu=");
cmGeneratorTarget& gt = *this->GetGeneratorTarget();
- const std::string cfgName = this->GetConfigName();
std::string targetOutputReal = this->ConvertToNinjaPath(
- gt.GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
+ gt.GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact,
/*realname=*/true));
cmakeCommand += targetOutputReal;
linkCmds.push_back(std::move(cmakeCommand));
@@ -490,21 +505,21 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
}
// TODO: Use ARCHIVE_APPEND for archives over a certain size.
{
- std::string linkCmdVar =
- cmStrCat("CMAKE_", this->TargetLinkLanguage, "_ARCHIVE_CREATE");
+ std::string linkCmdVar = cmStrCat(
+ "CMAKE_", this->TargetLinkLanguage(config), "_ARCHIVE_CREATE");
linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- linkCmdVar, this->TargetLinkLanguage, this->GetConfigName());
+ linkCmdVar, this->TargetLinkLanguage(config), config);
std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
cmExpandList(linkCmd, linkCmds);
}
{
- std::string linkCmdVar =
- cmStrCat("CMAKE_", this->TargetLinkLanguage, "_ARCHIVE_FINISH");
+ std::string linkCmdVar = cmStrCat(
+ "CMAKE_", this->TargetLinkLanguage(config), "_ARCHIVE_FINISH");
linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- linkCmdVar, this->TargetLinkLanguage, this->GetConfigName());
+ linkCmdVar, this->TargetLinkLanguage(config), config);
std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
cmExpandList(linkCmd, linkCmds);
@@ -535,7 +550,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
return std::vector<std::string>();
}
-void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
+void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement(
+ const std::string& config)
{
cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
if (!globalGen->GetLanguageEnabled("CUDA")) {
@@ -545,7 +561,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->GetLocalGenerator(), this->ConfigName);
+ *this->GeneratorTarget, *this->GetLocalGenerator(), config);
if (!requiresDeviceLinking) {
return;
}
@@ -558,24 +574,23 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
std::string const& objExt =
this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
- std::string const cfgName = this->GetConfigName();
std::string const targetOutputReal = ConvertToNinjaPath(
genTarget->ObjectDirectory + "cmake_device_link" + objExt);
std::string const targetOutputImplib = ConvertToNinjaPath(
- genTarget->GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
+ genTarget->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
this->DeviceLinkObject = targetOutputReal;
// Write comments.
- cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
+ cmGlobalNinjaGenerator::WriteDivider(this->GetCommonFileStream());
const cmStateEnums::TargetType targetType = genTarget->GetType();
- this->GetBuildFileStream() << "# Device Link build statements for "
- << cmState::GetTargetTypeName(targetType)
- << " target " << this->GetTargetName() << "\n\n";
+ this->GetCommonFileStream() << "# Device Link build statements for "
+ << cmState::GetTargetTypeName(targetType)
+ << " target " << this->GetTargetName() << "\n\n";
// Compute the comment.
- cmNinjaBuild build(this->LanguageLinkerDeviceRule());
+ cmNinjaBuild build(this->LanguageLinkerDeviceRule(config));
build.Comment =
cmStrCat("Link the ", this->GetVisibleTypeName(), ' ', targetOutputReal);
@@ -584,14 +599,15 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// Compute outputs.
build.Outputs.push_back(targetOutputReal);
// Compute specific libraries to link with.
- build.ExplicitDeps = this->GetObjects();
- build.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);
+ build.ExplicitDeps = this->GetObjects(config);
+ build.ImplicitDeps =
+ this->ComputeLinkDeps(this->TargetLinkLanguage(config), config);
std::string frameworkPath;
std::string linkPath;
- std::string createRule = genTarget->GetCreateRuleVariable(
- this->TargetLinkLanguage, this->GetConfigName());
+ std::string createRule =
+ genTarget->GetCreateRuleVariable(this->TargetLinkLanguage(config), config);
const bool useWatcomQuote =
this->GetMakefile()->IsOn(createRule + "_USE_WATCOM_QUOTE");
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
@@ -605,17 +621,17 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(),
globalGen));
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
+ linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig());
localGen.GetTargetFlags(
- linkLineComputer.get(), this->GetConfigName(), vars["LINK_LIBRARIES"],
- vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, genTarget);
+ linkLineComputer.get(), config, vars["LINK_LIBRARIES"], vars["FLAGS"],
+ vars["LINK_FLAGS"], frameworkPath, linkPath, genTarget);
this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars);
- vars["LINK_FLAGS"] =
- cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]);
+ vars["LINK_FLAGS"] = globalGen->EncodeLiteral(vars["LINK_FLAGS"]);
- vars["MANIFESTS"] = this->GetManifests();
+ vars["MANIFESTS"] = this->GetManifests(config);
vars["LINK_PATH"] = frameworkPath + linkPath;
@@ -624,24 +640,25 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// code between the Makefile executable and library generators.
if (targetType == cmStateEnums::EXECUTABLE) {
std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, config);
vars["FLAGS"] = t;
} else {
std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, config);
vars["ARCH_FLAGS"] = t;
t.clear();
localGen.AddLanguageFlagsForLinking(t, genTarget, cudaLinkLanguage,
- cfgName);
+ config);
vars["LANGUAGE_COMPILE_FLAGS"] = t;
}
- if (genTarget->HasSOName(cfgName)) {
+ auto const tgtNames = this->TargetNames(config);
+ if (genTarget->HasSOName(config)) {
vars["SONAME_FLAG"] =
- this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage);
- vars["SONAME"] = this->TargetNames.SharedObject;
+ this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage(config));
+ vars["SONAME"] = tgtNames.SharedObject;
if (targetType == cmStateEnums::SHARED_LIBRARY) {
std::string install_dir =
- this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName);
+ this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(config);
if (!install_dir.empty()) {
vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
install_dir, cmOutputConverter::SHELL);
@@ -649,25 +666,28 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
}
}
- if (!this->TargetNames.ImportLibrary.empty()) {
+ if (!tgtNames.ImportLibrary.empty()) {
const std::string impLibPath = localGen.ConvertToOutputFormat(
targetOutputImplib, cmOutputConverter::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
EnsureParentDirectoryExists(impLibPath);
}
- const std::string objPath = GetGeneratorTarget()->GetSupportDirectory();
+ const std::string objPath =
+ cmStrCat(GetGeneratorTarget()->GetSupportDirectory(),
+ globalGen->ConfigDirectory(config));
+
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
EnsureDirectoryExists(objPath);
- this->SetMsvcTargetPdbVariable(vars);
+ this->SetMsvcTargetPdbVariable(vars, config);
+ std::string& linkLibraries = vars["LINK_LIBRARIES"];
+ std::string& link_path = vars["LINK_PATH"];
if (globalGen->IsGCCOnWindows()) {
// ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
- std::string& linkLibraries = vars["LINK_LIBRARIES"];
std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
- std::string& link_path = vars["LINK_PATH"];
std::replace(link_path.begin(), link_path.end(), '\\', '/');
}
@@ -675,65 +695,88 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// do not check if the user has explicitly forced a response file.
int const commandLineLengthLimit =
static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
- globalGen->GetRuleCmdLength(this->LanguageLinkerDeviceRule());
+ globalGen->GetRuleCmdLength(this->LanguageLinkerDeviceRule(config));
build.RspFile = this->ConvertToNinjaPath(std::string("CMakeFiles/") +
genTarget->GetName() + ".rsp");
// Gather order-only dependencies.
- this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
- build.OrderOnlyDeps);
+ this->GetLocalGenerator()->AppendTargetDepends(
+ this->GetGeneratorTarget(), build.OrderOnlyDeps, config, config);
// Write the build statement for this target.
bool usedResponseFile = false;
- globalGen->WriteBuild(this->GetBuildFileStream(), build,
+ globalGen->WriteBuild(this->GetCommonFileStream(), build,
commandLineLengthLimit, &usedResponseFile);
- this->WriteDeviceLinkRule(usedResponseFile);
+ this->WriteDeviceLinkRule(usedResponseFile, config);
}
-void cmNinjaNormalTargetGenerator::WriteLinkStatement()
+void cmNinjaNormalTargetGenerator::WriteLinkStatement(
+ const std::string& config, const std::string& fileConfig,
+ bool firstForConfig)
{
cmMakefile* mf = this->GetMakefile();
cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
cmGeneratorTarget* gt = this->GetGeneratorTarget();
- const std::string cfgName = this->GetConfigName();
- std::string targetOutput = ConvertToNinjaPath(gt->GetFullPath(cfgName));
+ std::string targetOutput = ConvertToNinjaPath(gt->GetFullPath(config));
std::string targetOutputReal = ConvertToNinjaPath(
- gt->GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
+ gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact,
/*realname=*/true));
std::string targetOutputImplib = ConvertToNinjaPath(
- gt->GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
+ gt->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
+ if (config != fileConfig) {
+ if (targetOutput == ConvertToNinjaPath(gt->GetFullPath(fileConfig))) {
+ return;
+ }
+ if (targetOutputReal ==
+ ConvertToNinjaPath(gt->GetFullPath(fileConfig,
+ cmStateEnums::RuntimeBinaryArtifact,
+ /*realname=*/true))) {
+ return;
+ }
+ if (!gt->GetFullName(config, cmStateEnums::ImportLibraryArtifact)
+ .empty() &&
+ !gt->GetFullName(fileConfig, cmStateEnums::ImportLibraryArtifact)
+ .empty() &&
+ targetOutputImplib ==
+ ConvertToNinjaPath(gt->GetFullPath(
+ fileConfig, cmStateEnums::ImportLibraryArtifact))) {
+ return;
+ }
+ }
+
+ auto const tgtNames = this->TargetNames(config);
if (gt->IsAppBundleOnApple()) {
// Create the app bundle
- std::string outpath = gt->GetDirectory(cfgName);
- this->OSXBundleGenerator->CreateAppBundle(this->TargetNames.Output,
- outpath);
+ std::string outpath = gt->GetDirectory(config);
+ this->OSXBundleGenerator->CreateAppBundle(tgtNames.Output, outpath,
+ config);
// Calculate the output path
- targetOutput = cmStrCat(outpath, '/', this->TargetNames.Output);
+ targetOutput = cmStrCat(outpath, '/', tgtNames.Output);
targetOutput = this->ConvertToNinjaPath(targetOutput);
- targetOutputReal = cmStrCat(outpath, '/', this->TargetNames.Real);
+ targetOutputReal = cmStrCat(outpath, '/', tgtNames.Real);
targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
} else if (gt->IsFrameworkOnApple()) {
// Create the library framework.
- this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output,
- gt->GetDirectory(cfgName));
+ this->OSXBundleGenerator->CreateFramework(
+ tgtNames.Output, gt->GetDirectory(config), config);
} else if (gt->IsCFBundleOnApple()) {
// Create the core foundation bundle.
- this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output,
- gt->GetDirectory(cfgName));
+ this->OSXBundleGenerator->CreateCFBundle(tgtNames.Output,
+ gt->GetDirectory(config), config);
}
// Write comments.
- cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
+ cmGlobalNinjaGenerator::WriteDivider(this->GetConfigFileStream(fileConfig));
const cmStateEnums::TargetType targetType = gt->GetType();
- this->GetBuildFileStream()
+ this->GetConfigFileStream(fileConfig)
<< "# Link build statements for " << cmState::GetTargetTypeName(targetType)
<< " target " << this->GetTargetName() << "\n\n";
- cmNinjaBuild linkBuild(this->LanguageLinkerRule());
+ cmNinjaBuild linkBuild(this->LanguageLinkerRule(config));
cmNinjaVars& vars = linkBuild.Variables;
// Compute the comment.
@@ -742,11 +785,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Compute outputs.
linkBuild.Outputs.push_back(targetOutputReal);
+ if (firstForConfig) {
+ globalGen->GetByproductsForCleanTarget(config).push_back(targetOutputReal);
+ }
- if (this->TargetLinkLanguage == "Swift") {
- vars["SWIFT_LIBRARY_NAME"] = [this]() -> std::string {
+ if (this->TargetLinkLanguage(config) == "Swift") {
+ vars["SWIFT_LIBRARY_NAME"] = [this, config]() -> std::string {
cmGeneratorTarget::Names targetNames =
- this->GetGeneratorTarget()->GetLibraryNames(this->GetConfigName());
+ this->GetGeneratorTarget()->GetLibraryNames(config);
return targetNames.Base;
}();
@@ -782,12 +828,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
"/output-file-map.json"),
cmOutputConverter::SHELL);
- vars["SWIFT_SOURCES"] = [this]() -> std::string {
+ vars["SWIFT_SOURCES"] = [this, config]() -> std::string {
std::vector<cmSourceFile const*> sources;
std::stringstream oss;
- this->GetGeneratorTarget()->GetObjectSources(sources,
- this->GetConfigName());
+ this->GetGeneratorTarget()->GetObjectSources(sources, config);
cmLocalGenerator const* LocalGen = this->GetLocalGenerator();
for (const auto& source : sources) {
oss << " "
@@ -801,27 +846,28 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Since we do not perform object builds, compute the
// defines/flags/includes here so that they can be passed along
// appropriately.
- vars["DEFINES"] = this->GetDefines("Swift");
- vars["FLAGS"] = this->GetFlags("Swift");
- vars["INCLUDES"] = this->GetIncludes("Swift");
+ vars["DEFINES"] = this->GetDefines("Swift", config);
+ vars["FLAGS"] = this->GetFlags("Swift", config);
+ vars["INCLUDES"] = this->GetIncludes("Swift", config);
}
// Compute specific libraries to link with.
- if (this->TargetLinkLanguage == "Swift") {
+ if (this->TargetLinkLanguage(config) == "Swift") {
std::vector<cmSourceFile const*> sources;
- gt->GetObjectSources(sources, this->GetConfigName());
+ gt->GetObjectSources(sources, config);
for (const auto& source : sources) {
linkBuild.Outputs.push_back(
- this->ConvertToNinjaPath(this->GetObjectFilePath(source)));
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)));
linkBuild.ExplicitDeps.push_back(
this->ConvertToNinjaPath(this->GetSourceFilePath(source)));
}
linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]);
} else {
- linkBuild.ExplicitDeps = this->GetObjects();
+ linkBuild.ExplicitDeps = this->GetObjects(config);
}
- linkBuild.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);
+ linkBuild.ImplicitDeps =
+ this->ComputeLinkDeps(this->TargetLinkLanguage(config), config);
if (!this->DeviceLinkObject.empty()) {
linkBuild.ExplicitDeps.push_back(this->DeviceLinkObject);
@@ -831,7 +877,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
std::string linkPath;
std::string createRule =
- gt->GetCreateRuleVariable(this->TargetLinkLanguage, this->GetConfigName());
+ gt->GetCreateRuleVariable(this->TargetLinkLanguage(config), config);
bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE");
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
@@ -843,27 +889,29 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetLocalGenerator(),
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
+ linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig());
- localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(),
+ localGen.GetTargetFlags(linkLineComputer.get(), config,
vars["LINK_LIBRARIES"], vars["FLAGS"],
vars["LINK_FLAGS"], frameworkPath, linkPath, gt);
// Add OS X version flags, if any.
if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
- this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage,
- "COMPATIBILITY", true);
- this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage,
- "CURRENT", false);
+ this->AppendOSXVerFlag(vars["LINK_FLAGS"],
+ this->TargetLinkLanguage(config), "COMPATIBILITY",
+ true);
+ this->AppendOSXVerFlag(vars["LINK_FLAGS"],
+ this->TargetLinkLanguage(config), "CURRENT", false);
}
this->addPoolNinjaVariable("JOB_POOL_LINK", gt, vars);
- this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"]);
- vars["LINK_FLAGS"] =
- cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]);
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"],
+ config);
+ vars["LINK_FLAGS"] = globalGen->EncodeLiteral(vars["LINK_FLAGS"]);
- vars["MANIFESTS"] = this->GetManifests();
+ vars["MANIFESTS"] = this->GetManifests(config);
vars["LINK_PATH"] = frameworkPath + linkPath;
std::string lwyuFlags;
@@ -876,23 +924,26 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// code between the Makefile executable and library generators.
if (targetType == cmStateEnums::EXECUTABLE) {
std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, gt, TargetLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, gt, this->TargetLinkLanguage(config),
+ config);
t += lwyuFlags;
vars["FLAGS"] = t;
} else {
std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, gt, TargetLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, gt, this->TargetLinkLanguage(config),
+ config);
vars["ARCH_FLAGS"] = t;
t.clear();
t += lwyuFlags;
- localGen.AddLanguageFlagsForLinking(t, gt, TargetLinkLanguage, cfgName);
+ localGen.AddLanguageFlagsForLinking(
+ t, gt, this->TargetLinkLanguage(config), config);
vars["LANGUAGE_COMPILE_FLAGS"] = t;
}
- if (gt->HasSOName(cfgName)) {
- vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage);
- vars["SONAME"] = this->TargetNames.SharedObject;
+ if (gt->HasSOName(config)) {
+ vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage(config));
+ vars["SONAME"] = tgtNames.SharedObject;
if (targetType == cmStateEnums::SHARED_LIBRARY) {
- std::string install_dir = gt->GetInstallNameDirForBuildTree(cfgName);
+ std::string install_dir = gt->GetInstallNameDirForBuildTree(config);
if (!install_dir.empty()) {
vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
install_dir, cmOutputConverter::SHELL);
@@ -902,17 +953,21 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmNinjaDeps byproducts;
- if (!this->TargetNames.ImportLibrary.empty()) {
+ if (!tgtNames.ImportLibrary.empty()) {
const std::string impLibPath = localGen.ConvertToOutputFormat(
targetOutputImplib, cmOutputConverter::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
EnsureParentDirectoryExists(impLibPath);
- if (gt->HasImportLibrary(cfgName)) {
+ if (gt->HasImportLibrary(config)) {
byproducts.push_back(targetOutputImplib);
+ if (firstForConfig) {
+ globalGen->GetByproductsForCleanTarget(config).push_back(
+ targetOutputImplib);
+ }
}
}
- if (!this->SetMsvcTargetPdbVariable(vars)) {
+ if (!this->SetMsvcTargetPdbVariable(vars, config)) {
// It is common to place debug symbols at a specific place,
// so we need a plain target name in the rule available.
std::string prefix;
@@ -927,16 +982,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
vars["TARGET_PDB"] = base + suffix + dbg_suffix;
}
- const std::string objPath = gt->GetSupportDirectory();
+ const std::string objPath =
+ cmStrCat(gt->GetSupportDirectory(), globalGen->ConfigDirectory(config));
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
EnsureDirectoryExists(objPath);
+ std::string& linkLibraries = vars["LINK_LIBRARIES"];
+ std::string& link_path = vars["LINK_PATH"];
if (globalGen->IsGCCOnWindows()) {
// ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
- std::string& linkLibraries = vars["LINK_LIBRARIES"];
std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
- std::string& link_path = vars["LINK_PATH"];
std::replace(link_path.begin(), link_path.end(), '\\', '/');
}
@@ -947,23 +1003,30 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
std::vector<std::string> preLinkCmdLines;
std::vector<std::string> postBuildCmdLines;
- std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines,
- &preLinkCmdLines,
- &postBuildCmdLines };
-
- for (unsigned i = 0; i != 3; ++i) {
- for (cmCustomCommand const& cc : *cmdLists[i]) {
- cmCustomCommandGenerator ccg(cc, cfgName, this->GetLocalGenerator());
- localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
- std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
- std::transform(ccByproducts.begin(), ccByproducts.end(),
- std::back_inserter(byproducts), MapToNinjaPath());
+
+ if (config == fileConfig) {
+ std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines,
+ &preLinkCmdLines,
+ &postBuildCmdLines };
+
+ for (unsigned i = 0; i != 3; ++i) {
+ for (cmCustomCommand const& cc : *cmdLists[i]) {
+ cmCustomCommandGenerator ccg(cc, config, this->GetLocalGenerator());
+ localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
+ std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
+ std::transform(ccByproducts.begin(), ccByproducts.end(),
+ std::back_inserter(byproducts), MapToNinjaPath());
+ std::transform(
+ ccByproducts.begin(), ccByproducts.end(),
+ std::back_inserter(globalGen->GetByproductsForCleanTarget()),
+ MapToNinjaPath());
+ }
}
}
// maybe create .def file from list of objects
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- gt->GetModuleDefinitionInfo(this->GetConfigName());
+ gt->GetModuleDefinitionInfo(config);
if (mdi && mdi->DefFileGenerated) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -989,7 +1052,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmGeneratedFileStream fout(obj_list_file);
if (mdi->WindowsExportAllSymbols) {
- cmNinjaDeps objs = this->GetObjects();
+ cmNinjaDeps objs = this->GetObjects(config);
for (std::string const& obj : objs) {
if (cmHasLiteralSuffix(obj, ".obj")) {
fout << obj << "\n";
@@ -1024,7 +1087,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
symlinkVars["POST_BUILD"] = postBuildCmdLine;
}
- std::string cmakeVarLang = cmStrCat("CMAKE_", this->TargetLinkLanguage);
+ std::string cmakeVarLang =
+ cmStrCat("CMAKE_", this->TargetLinkLanguage(config));
// build response file name
std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
@@ -1032,8 +1096,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
const char* flag = GetMakefile()->GetDefinition(cmakeLinkVar);
bool const lang_supports_response =
- !(this->TargetLinkLanguage == "RC" ||
- (this->TargetLinkLanguage == "CUDA" && !flag));
+ !(this->TargetLinkLanguage(config) == "RC" ||
+ (this->TargetLinkLanguage(config) == "CUDA" && !flag));
int commandLineLengthLimit = -1;
if (!lang_supports_response || !this->ForceResponseFile()) {
commandLineLengthLimit =
@@ -1045,18 +1109,19 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
gt->GetName() + ".rsp");
// Gather order-only dependencies.
- this->GetLocalGenerator()->AppendTargetDepends(gt, linkBuild.OrderOnlyDeps);
+ this->GetLocalGenerator()->AppendTargetDepends(gt, linkBuild.OrderOnlyDeps,
+ config, fileConfig);
// Add order-only dependencies on versioning symlinks of shared libs we link.
if (!this->GeneratorTarget->IsDLLPlatform()) {
if (cmComputeLinkInformation* cli =
- this->GeneratorTarget->GetLinkInformation(this->GetConfigName())) {
+ this->GeneratorTarget->GetLinkInformation(config)) {
for (auto const& item : cli->GetItems()) {
if (item.Target &&
item.Target->GetType() == cmStateEnums::SHARED_LIBRARY &&
!item.Target->IsFrameworkOnApple()) {
- std::string const& lib = this->ConvertToNinjaPath(
- item.Target->GetFullPath(this->GetConfigName()));
+ std::string const& lib =
+ this->ConvertToNinjaPath(item.Target->GetFullPath(config));
if (std::find(linkBuild.ImplicitDeps.begin(),
linkBuild.ImplicitDeps.end(),
lib) == linkBuild.ImplicitDeps.end()) {
@@ -1077,24 +1142,27 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Write the build statement for this target.
bool usedResponseFile = false;
- globalGen->WriteBuild(this->GetBuildFileStream(), linkBuild,
+ globalGen->WriteBuild(this->GetConfigFileStream(fileConfig), linkBuild,
commandLineLengthLimit, &usedResponseFile);
- this->WriteLinkRule(usedResponseFile);
+ this->WriteLinkRule(usedResponseFile, config);
if (symlinkNeeded) {
if (targetType == cmStateEnums::EXECUTABLE) {
cmNinjaBuild build("CMAKE_SYMLINK_EXECUTABLE");
build.Comment = "Create executable symlink " + targetOutput;
build.Outputs.push_back(targetOutput);
+ if (firstForConfig) {
+ globalGen->GetByproductsForCleanTarget(config).push_back(targetOutput);
+ }
build.ExplicitDeps.push_back(targetOutputReal);
build.Variables = std::move(symlinkVars);
- globalGen->WriteBuild(this->GetBuildFileStream(), build);
+ globalGen->WriteBuild(this->GetConfigFileStream(fileConfig), build);
} else {
cmNinjaBuild build("CMAKE_SYMLINK_LIBRARY");
build.Comment = "Create library symlink " + targetOutput;
std::string const soName = this->ConvertToNinjaPath(
- this->GetTargetFilePath(this->TargetNames.SharedObject));
+ this->GetTargetFilePath(tgtNames.SharedObject, config));
// If one link has to be created.
if (targetOutputReal == soName || targetOutput == soName) {
symlinkVars["SONAME"] =
@@ -1103,33 +1171,58 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
} else {
symlinkVars["SONAME"].clear();
build.Outputs.push_back(soName);
+ if (firstForConfig) {
+ globalGen->GetByproductsForCleanTarget(config).push_back(soName);
+ }
}
build.Outputs.push_back(targetOutput);
+ if (firstForConfig) {
+ globalGen->GetByproductsForCleanTarget(config).push_back(targetOutput);
+ }
build.ExplicitDeps.push_back(targetOutputReal);
build.Variables = std::move(symlinkVars);
- globalGen->WriteBuild(this->GetBuildFileStream(), build);
+ globalGen->WriteBuild(this->GetConfigFileStream(fileConfig), build);
}
}
// Add aliases for the file name and the target name.
- globalGen->AddTargetAlias(this->TargetNames.Output, gt);
- globalGen->AddTargetAlias(this->GetTargetName(), gt);
+ globalGen->AddTargetAlias(tgtNames.Output, gt, config);
+ globalGen->AddTargetAlias(this->GetTargetName(), gt, config);
}
-void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
+void cmNinjaNormalTargetGenerator::WriteObjectLibStatement(
+ const std::string& config)
{
// Write a phony output that depends on all object files.
{
cmNinjaBuild build("phony");
build.Comment = "Object library " + this->GetTargetName();
this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
- build.Outputs);
- build.ExplicitDeps = this->GetObjects();
- this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
+ build.Outputs, config);
+ this->GetLocalGenerator()->AppendTargetOutputs(
+ this->GetGeneratorTarget(),
+ this->GetGlobalGenerator()->GetByproductsForCleanTarget(config), config);
+ build.ExplicitDeps = this->GetObjects(config);
+ this->GetGlobalGenerator()->WriteBuild(this->GetCommonFileStream(), build);
}
// Add aliases for the target name.
- this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
- this->GetGeneratorTarget());
+ this->GetGlobalGenerator()->AddTargetAlias(
+ this->GetTargetName(), this->GetGeneratorTarget(), config);
+}
+
+cmGeneratorTarget::Names cmNinjaNormalTargetGenerator::TargetNames(
+ const std::string& config) const
+{
+ if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
+ return this->GeneratorTarget->GetExecutableNames(config);
+ }
+ return this->GeneratorTarget->GetLibraryNames(config);
+}
+
+std::string cmNinjaNormalTargetGenerator::TargetLinkLanguage(
+ const std::string& config) const
+{
+ return this->GeneratorTarget->GetLinkerLanguage(config);
}
diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h
index ebc1268..cda76d8 100644
--- a/Source/cmNinjaNormalTargetGenerator.h
+++ b/Source/cmNinjaNormalTargetGenerator.h
@@ -17,30 +17,31 @@ public:
cmNinjaNormalTargetGenerator(cmGeneratorTarget* target);
~cmNinjaNormalTargetGenerator() override;
- void Generate() override;
+ void Generate(const std::string& config) override;
private:
- std::string LanguageLinkerRule() const;
- std::string LanguageLinkerDeviceRule() const;
+ std::string LanguageLinkerRule(const std::string& config) const;
+ std::string LanguageLinkerDeviceRule(const std::string& config) const;
const char* GetVisibleTypeName() const;
- void WriteLanguagesRules();
+ void WriteLanguagesRules(const std::string& config);
- void WriteLinkRule(bool useResponseFile);
- void WriteDeviceLinkRule(bool useResponseFile);
+ void WriteLinkRule(bool useResponseFile, const std::string& config);
+ void WriteDeviceLinkRule(bool useResponseFile, const std::string& config);
- void WriteLinkStatement();
- void WriteDeviceLinkStatement();
+ void WriteLinkStatement(const std::string& config,
+ const std::string& fileConfig, bool firstForConfig);
+ void WriteDeviceLinkStatement(const std::string& config);
- void WriteObjectLibStatement();
+ void WriteObjectLibStatement(const std::string& config);
- std::vector<std::string> ComputeLinkCmd();
+ std::vector<std::string> ComputeLinkCmd(const std::string& config);
std::vector<std::string> ComputeDeviceLinkCmd();
private:
// Target name info.
- cmGeneratorTarget::Names TargetNames;
- std::string TargetLinkLanguage;
+ cmGeneratorTarget::Names TargetNames(const std::string& config) const;
+ std::string TargetLinkLanguage(const std::string& config) const;
std::string DeviceLinkObject;
};
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 919a5db..ee1163a 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -68,9 +68,15 @@ cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default;
-cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const
+cmGeneratedFileStream& cmNinjaTargetGenerator::GetConfigFileStream(
+ const std::string& config) const
{
- return *this->GetGlobalGenerator()->GetBuildFileStream();
+ return *this->GetGlobalGenerator()->GetConfigFileStream(config);
+}
+
+cmGeneratedFileStream& cmNinjaTargetGenerator::GetCommonFileStream() const
+{
+ return *this->GetGlobalGenerator()->GetCommonFileStream();
}
cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
@@ -84,17 +90,19 @@ cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
}
std::string cmNinjaTargetGenerator::LanguageCompilerRule(
- const std::string& lang) const
+ const std::string& lang, const std::string& config) const
{
return lang + "_COMPILER__" +
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
+ cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()) +
+ "_" + config;
}
std::string cmNinjaTargetGenerator::LanguagePreprocessRule(
- std::string const& lang) const
+ std::string const& lang, const std::string& config) const
{
return lang + "_PREPROCESS__" +
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
+ cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()) +
+ "_" + config;
}
bool cmNinjaTargetGenerator::NeedExplicitPreprocessing(
@@ -117,10 +125,11 @@ bool cmNinjaTargetGenerator::CompilePreprocessedSourceWithDefines(
}
std::string cmNinjaTargetGenerator::LanguageDyndepRule(
- const std::string& lang) const
+ const std::string& lang, const std::string& config) const
{
return lang + "_DYNDEP__" +
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
+ cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()) +
+ "_" + config;
}
bool cmNinjaTargetGenerator::NeedDyndep(std::string const& lang) const
@@ -128,9 +137,11 @@ bool cmNinjaTargetGenerator::NeedDyndep(std::string const& lang) const
return lang == "Fortran";
}
-std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget()
+std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget(
+ const std::string& config)
{
- return "cmake_object_order_depends_target_" + this->GetTargetName();
+ return cmGlobalNinjaGenerator::OrderDependsTargetForTarget(
+ this->GeneratorTarget, config);
}
// TODO: Most of the code is picked up from
@@ -138,10 +149,10 @@ std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget()
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
// Refactor it.
std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
- cmSourceFile const* source, const std::string& language)
+ cmSourceFile const* source, const std::string& language,
+ const std::string& config)
{
- std::string flags = this->GetFlags(language);
- const std::string configName = this->LocalGenerator->GetConfigName();
+ std::string flags = this->GetFlags(language, config);
// Add Fortran format flags.
if (language == "Fortran") {
@@ -150,7 +161,7 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
// Add source file specific flags.
cmGeneratorExpressionInterpreter genexInterpreter(
- this->LocalGenerator, configName, this->GeneratorTarget, language);
+ this->LocalGenerator, config, this->GeneratorTarget, language);
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
@@ -166,16 +177,16 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
// Add precompile headers compile options.
const std::string pchSource =
- this->GeneratorTarget->GetPchSource(configName, language);
+ this->GeneratorTarget->GetPchSource(config, language);
if (!pchSource.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
std::string pchOptions;
if (source->GetFullPath() == pchSource) {
- pchOptions = this->GeneratorTarget->GetPchCreateCompileOptions(
- configName, language);
+ pchOptions =
+ this->GeneratorTarget->GetPchCreateCompileOptions(config, language);
} else {
pchOptions =
- this->GeneratorTarget->GetPchUseCompileOptions(configName, language);
+ this->GeneratorTarget->GetPchUseCompileOptions(config, language);
}
this->LocalGenerator->AppendCompileOptions(
@@ -186,16 +197,17 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
}
void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
- std::string const& language)
+ std::string const& language,
+ const std::string& config)
{
std::vector<std::string> includes;
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
- language, this->GetConfigName());
+ language, config);
// Add include directory flags.
std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
includes, this->GeneratorTarget, language,
language == "RC", // full include paths for RC needed by cmcldeps
- false, this->GetConfigName());
+ false, config);
if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
std::replace(includeFlags.begin(), includeFlags.end(), '\\', '/');
}
@@ -232,13 +244,18 @@ bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
// TODO: Refactor with
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
- const std::string& language)
+ const std::string& language,
+ const std::string& config)
{
std::set<std::string> defines;
- const std::string config = this->LocalGenerator->GetConfigName();
cmGeneratorExpressionInterpreter genexInterpreter(
this->LocalGenerator, config, this->GeneratorTarget, language);
+ // Seriously??
+ if (this->GetGlobalGenerator()->IsMultiConfig()) {
+ defines.insert(cmStrCat("CMAKE_INTDIR=\"", config, '"'));
+ }
+
const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
this->LocalGenerator->AppendDefines(
@@ -253,17 +270,17 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
genexInterpreter.Evaluate(config_compile_defs, COMPILE_DEFINITIONS));
}
- std::string definesString = this->GetDefines(language);
+ std::string definesString = this->GetDefines(language, config);
this->LocalGenerator->JoinDefines(defines, definesString, language);
return definesString;
}
std::string cmNinjaTargetGenerator::ComputeIncludes(
- cmSourceFile const* source, const std::string& language)
+ cmSourceFile const* source, const std::string& language,
+ const std::string& config)
{
std::vector<std::string> includes;
- const std::string config = this->LocalGenerator->GetConfigName();
cmGeneratorExpressionInterpreter genexInterpreter(
this->LocalGenerator, config, this->GeneratorTarget, language);
@@ -277,13 +294,13 @@ std::string cmNinjaTargetGenerator::ComputeIncludes(
std::string includesString = this->LocalGenerator->GetIncludeFlags(
includes, this->GeneratorTarget, language, true, false, config);
this->LocalGenerator->AppendFlags(includesString,
- this->GetIncludes(language));
+ this->GetIncludes(language, config));
return includesString;
}
cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
- const std::string& linkLanguage) const
+ const std::string& linkLanguage, const std::string& config) const
{
// Static libraries never depend on other targets for linking.
if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
@@ -292,7 +309,7 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
}
cmComputeLinkInformation* cli =
- this->GeneratorTarget->GetLinkInformation(this->GetConfigName());
+ this->GeneratorTarget->GetLinkInformation(config);
if (!cli) {
return cmNinjaDeps();
}
@@ -303,8 +320,7 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
// Add a dependency on the link definitions file, if any.
if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- this->GeneratorTarget->GetModuleDefinitionInfo(
- this->GetConfigName())) {
+ this->GeneratorTarget->GetModuleDefinitionInfo(config)) {
for (cmSourceFile const* src : mdi->Sources) {
result.push_back(this->ConvertToNinjaPath(src->GetFullPath()));
}
@@ -312,15 +328,14 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
// Add a dependency on user-specified manifest files, if any.
std::vector<cmSourceFile const*> manifest_srcs;
- this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
+ this->GeneratorTarget->GetManifests(manifest_srcs, config);
for (cmSourceFile const* manifest_src : manifest_srcs) {
result.push_back(this->ConvertToNinjaPath(manifest_src->GetFullPath()));
}
// Add user-specified dependencies.
std::vector<std::string> linkDeps;
- this->GeneratorTarget->GetLinkDepends(linkDeps, this->ConfigName,
- linkLanguage);
+ this->GeneratorTarget->GetLinkDepends(linkDeps, config, linkLanguage);
std::transform(linkDeps.begin(), linkDeps.end(), std::back_inserter(result),
MapToNinjaPath());
@@ -334,7 +349,7 @@ std::string cmNinjaTargetGenerator::GetSourceFilePath(
}
std::string cmNinjaTargetGenerator::GetObjectFilePath(
- cmSourceFile const* source) const
+ cmSourceFile const* source, const std::string& config) const
{
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
if (!path.empty()) {
@@ -342,13 +357,14 @@ std::string cmNinjaTargetGenerator::GetObjectFilePath(
}
std::string const& objectName = this->GeneratorTarget->GetObjectName(source);
path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ path += this->GetGlobalGenerator()->ConfigDirectory(config);
path += "/";
path += objectName;
return path;
}
std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
- cmSourceFile const* source) const
+ cmSourceFile const* source, const std::string& config) const
{
// Choose an extension to compile already-preprocessed source.
std::string ppExt = source->GetExtension();
@@ -378,19 +394,21 @@ std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
path += "/";
}
path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ path += this->GetGlobalGenerator()->ConfigDirectory(config);
path += "/";
path += ppName;
return path;
}
std::string cmNinjaTargetGenerator::GetDyndepFilePath(
- std::string const& lang) const
+ std::string const& lang, const std::string& config) const
{
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
if (!path.empty()) {
path += "/";
}
path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ path += this->GetGlobalGenerator()->ConfigDirectory(config);
path += "/";
path += lang;
path += ".dd";
@@ -398,25 +416,27 @@ std::string cmNinjaTargetGenerator::GetDyndepFilePath(
}
std::string cmNinjaTargetGenerator::GetTargetDependInfoPath(
- std::string const& lang) const
+ std::string const& lang, const std::string& config) const
{
std::string path =
cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
- '/', lang, "DependInfo.json");
+ this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang,
+ "DependInfo.json");
return path;
}
-std::string cmNinjaTargetGenerator::GetTargetOutputDir() const
+std::string cmNinjaTargetGenerator::GetTargetOutputDir(
+ const std::string& config) const
{
- std::string dir = this->GeneratorTarget->GetDirectory(this->GetConfigName());
+ std::string dir = this->GeneratorTarget->GetDirectory(config);
return ConvertToNinjaPath(dir);
}
std::string cmNinjaTargetGenerator::GetTargetFilePath(
- const std::string& name) const
+ const std::string& name, const std::string& config) const
{
- std::string path = this->GetTargetOutputDir();
+ std::string path = this->GetTargetOutputDir(config);
if (path.empty() || path == ".") {
return name;
}
@@ -430,21 +450,21 @@ std::string cmNinjaTargetGenerator::GetTargetName() const
return this->GeneratorTarget->GetName();
}
-bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
+bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(
+ cmNinjaVars& vars, const std::string& config) const
{
cmMakefile* mf = this->GetMakefile();
if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID") ||
mf->GetDefinition("MSVC_CUDA_ARCHITECTURE_ID")) {
std::string pdbPath;
- std::string compilePdbPath = this->ComputeTargetCompilePDB();
+ std::string compilePdbPath = this->ComputeTargetCompilePDB(config);
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
- pdbPath = cmStrCat(
- this->GeneratorTarget->GetPDBDirectory(this->GetConfigName()), '/',
- this->GeneratorTarget->GetPDBName(this->GetConfigName()));
+ pdbPath = cmStrCat(this->GeneratorTarget->GetPDBDirectory(config), '/',
+ this->GeneratorTarget->GetPDBName(config));
}
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -460,15 +480,17 @@ bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
return false;
}
-void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language)
+void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language,
+ const std::string& config)
{
#ifdef NINJA_GEN_VERBOSE_FILES
this->GetRulesFileStream() << "# Rules for language " << language << "\n\n";
#endif
- this->WriteCompileRule(language);
+ this->WriteCompileRule(language, config);
}
-void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
+void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
+ const std::string& config)
{
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
@@ -509,7 +531,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
- ConvertToNinjaPath(this->GetTargetDependInfoPath(lang)),
+ ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config)),
cmLocalGenerator::SHELL);
std::string launcher;
@@ -524,7 +546,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
if (explicitPP) {
- cmNinjaRule rule(this->LanguagePreprocessRule(lang));
+ cmNinjaRule rule(this->LanguagePreprocessRule(lang, config));
// Explicit preprocessing always uses a depfile.
rule.DepType = ""; // no deps= for multiple outputs
rule.DepFile = "$DEP_FILE";
@@ -604,7 +626,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
if (needDyndep) {
// Write the rule for ninja dyndep file generation.
- cmNinjaRule rule(this->LanguageDyndepRule(lang));
+ cmNinjaRule rule(this->LanguageDyndepRule(lang, config));
// Command line length is almost always limited -> use response file for
// dyndep rules
rule.RspFile = "$out.rsp";
@@ -628,7 +650,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
this->GetGlobalGenerator()->AddRule(rule);
}
- cmNinjaRule rule(this->LanguageCompilerRule(lang));
+ cmNinjaRule rule(this->LanguageCompilerRule(lang, config));
// If using a response file, move defines, includes, and flags into it.
if (!responseFlag.empty()) {
rule.RspFile = "$RSP_FILE";
@@ -787,50 +809,52 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
this->GetGlobalGenerator()->AddRule(rule);
}
-void cmNinjaTargetGenerator::WriteObjectBuildStatements()
+void cmNinjaTargetGenerator::WriteObjectBuildStatements(
+ const std::string& config, const std::string& fileConfig,
+ bool firstForConfig)
{
// Write comments.
- cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
- this->GetBuildFileStream()
+ cmGlobalNinjaGenerator::WriteDivider(this->GetConfigFileStream(fileConfig));
+ this->GetConfigFileStream(fileConfig)
<< "# Object build statements for "
<< cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
<< " target " << this->GetTargetName() << "\n\n";
{
std::vector<cmSourceFile const*> customCommands;
- this->GeneratorTarget->GetCustomCommands(customCommands, this->ConfigName);
+ this->GeneratorTarget->GetCustomCommands(customCommands, config);
for (cmSourceFile const* sf : customCommands) {
cmCustomCommand const* cc = sf->GetCustomCommand();
this->GetLocalGenerator()->AddCustomCommandTarget(
cc, this->GetGeneratorTarget());
// Record the custom commands for this target. The container is used
// in WriteObjectBuildStatement when called in a loop below.
- this->CustomCommands.push_back(cc);
+ this->Configs[config].CustomCommands.push_back(cc);
}
}
{
std::vector<cmSourceFile const*> headerSources;
- this->GeneratorTarget->GetHeaderSources(headerSources, this->ConfigName);
+ this->GeneratorTarget->GetHeaderSources(headerSources, config);
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
- headerSources, this->MacOSXContentGenerator.get());
+ headerSources, this->MacOSXContentGenerator.get(), config);
}
{
std::vector<cmSourceFile const*> extraSources;
- this->GeneratorTarget->GetExtraSources(extraSources, this->ConfigName);
+ this->GeneratorTarget->GetExtraSources(extraSources, config);
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
- extraSources, this->MacOSXContentGenerator.get());
+ extraSources, this->MacOSXContentGenerator.get(), config);
}
- {
+ if (firstForConfig) {
const char* pchExtension =
GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
std::vector<cmSourceFile const*> externalObjects;
- this->GeneratorTarget->GetExternalObjects(externalObjects,
- this->ConfigName);
+ this->GeneratorTarget->GetExternalObjects(externalObjects, config);
for (cmSourceFile const* sf : externalObjects) {
- const auto objectFileName = this->GetSourceFilePath(sf);
+ auto objectFileName = this->GetGlobalGenerator()->ExpandCFGIntDir(
+ this->GetSourceFilePath(sf), config);
if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) {
- this->Objects.push_back(objectFileName);
+ this->Configs[config].Objects.push_back(objectFileName);
}
}
}
@@ -838,19 +862,19 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements()
{
cmNinjaBuild build("phony");
build.Comment = "Order-only phony target for " + this->GetTargetName();
- build.Outputs.push_back(this->OrderDependsTargetForTarget());
+ build.Outputs.push_back(this->OrderDependsTargetForTarget(config));
cmNinjaDeps& orderOnlyDeps = build.OrderOnlyDeps;
this->GetLocalGenerator()->AppendTargetDepends(
- this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering);
+ this->GeneratorTarget, orderOnlyDeps, config, fileConfig,
+ DependOnTargetOrdering);
// Add order-only dependencies on other files associated with the target.
- cmAppend(orderOnlyDeps, this->ExtraFiles);
+ cmAppend(orderOnlyDeps, this->Configs[config].ExtraFiles);
// Add order-only dependencies on custom command outputs.
- for (cmCustomCommand const* cc : this->CustomCommands) {
- cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
- this->GetLocalGenerator());
+ for (cmCustomCommand const* cc : this->Configs[config].CustomCommands) {
+ cmCustomCommandGenerator ccg(*cc, config, this->GetLocalGenerator());
const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
const std::vector<std::string>& ccbyproducts = ccg.GetByproducts();
std::transform(ccoutputs.begin(), ccoutputs.end(),
@@ -876,26 +900,27 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements()
orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
}
- this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
+ this->GetGlobalGenerator()->WriteBuild(
+ this->GetConfigFileStream(fileConfig), build);
}
{
std::vector<cmSourceFile const*> objectSources;
- this->GeneratorTarget->GetObjectSources(objectSources, this->ConfigName);
+ this->GeneratorTarget->GetObjectSources(objectSources, config);
for (cmSourceFile const* sf : objectSources) {
- this->WriteObjectBuildStatement(sf);
+ this->WriteObjectBuildStatement(sf, config, fileConfig, firstForConfig);
}
}
- for (auto const& langDDIFiles : this->DDIFiles) {
+ for (auto const& langDDIFiles : this->Configs[config].DDIFiles) {
std::string const& language = langDDIFiles.first;
cmNinjaDeps const& ddiFiles = langDDIFiles.second;
- cmNinjaBuild build(this->LanguageDyndepRule(language));
- build.Outputs.push_back(this->GetDyndepFilePath(language));
+ cmNinjaBuild build(this->LanguageDyndepRule(language, config));
+ build.Outputs.push_back(this->GetDyndepFilePath(language, config));
build.ExplicitDeps = ddiFiles;
- this->WriteTargetDependInfo(language);
+ this->WriteTargetDependInfo(language, config);
// Make sure dyndep files for all our dependencies have already
// been generated so that the '<LANG>Modules.json' files they
@@ -906,46 +931,51 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements()
// refactoring the Ninja generator to generate targets in
// dependency order so that we can collect the needed information.
this->GetLocalGenerator()->AppendTargetDepends(
- this->GeneratorTarget, build.OrderOnlyDeps, DependOnTargetArtifact);
+ this->GeneratorTarget, build.OrderOnlyDeps, config, fileConfig,
+ DependOnTargetArtifact);
- this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
+ this->GetGlobalGenerator()->WriteBuild(
+ this->GetConfigFileStream(fileConfig), build);
}
- this->GetBuildFileStream() << "\n";
+ this->GetConfigFileStream(fileConfig) << "\n";
- if (!this->SwiftOutputMap.empty()) {
+ if (!this->Configs[config].SwiftOutputMap.empty()) {
std::string const mapFilePath =
this->GeneratorTarget->GetSupportDirectory() + "/output-file-map.json";
- std::string const targetSwiftDepsPath = [this]() -> std::string {
+ std::string const targetSwiftDepsPath = [this, config]() -> std::string {
cmGeneratorTarget const* target = this->GeneratorTarget;
if (const char* name = target->GetProperty("Swift_DEPENDENCIES_FILE")) {
return name;
}
return this->ConvertToNinjaPath(target->GetSupportDirectory() + "/" +
- target->GetName() + ".swiftdeps");
+ config + "/" + target->GetName() +
+ ".swiftdeps");
}();
// build the global target dependencies
// https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
Json::Value deps(Json::objectValue);
deps["swift-dependencies"] = targetSwiftDepsPath;
- this->SwiftOutputMap[""] = deps;
+ this->Configs[config].SwiftOutputMap[""] = deps;
cmGeneratedFileStream output(mapFilePath);
- output << this->SwiftOutputMap;
+ output << this->Configs[config].SwiftOutputMap;
}
}
void cmNinjaTargetGenerator::WriteObjectBuildStatement(
- cmSourceFile const* source)
+ cmSourceFile const* source, const std::string& config,
+ const std::string& fileConfig, bool firstForConfig)
{
std::string const language = source->GetLanguage();
std::string const sourceFileName =
language == "RC" ? source->GetFullPath() : this->GetSourceFilePath(source);
- std::string const objectDir =
- this->ConvertToNinjaPath(this->GeneratorTarget->GetSupportDirectory());
+ std::string const objectDir = this->ConvertToNinjaPath(
+ cmStrCat(this->GeneratorTarget->GetSupportDirectory(),
+ this->GetGlobalGenerator()->ConfigDirectory(config)));
std::string const objectFileName =
- this->ConvertToNinjaPath(this->GetObjectFilePath(source));
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
std::string const objectFileDir =
cmSystemTools::GetFilenamePath(objectFileName);
@@ -961,11 +991,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
int const commandLineLengthLimit =
((lang_supports_response && this->ForceResponseFile())) ? -1 : 0;
- cmNinjaBuild objBuild(this->LanguageCompilerRule(language));
+ cmNinjaBuild objBuild(this->LanguageCompilerRule(language, config));
cmNinjaVars& vars = objBuild.Variables;
- vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
- vars["DEFINES"] = this->ComputeDefines(source, language);
- vars["INCLUDES"] = this->ComputeIncludes(source, language);
+ vars["FLAGS"] = this->ComputeFlagsForObject(source, language, config);
+ vars["DEFINES"] = this->ComputeDefines(source, language, config);
+ vars["INCLUDES"] = this->ComputeIncludes(source, language, config);
if (!this->NeedDepTypeMSVC(language)) {
bool replaceExt(false);
@@ -993,11 +1023,13 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"]);
objBuild.Outputs.push_back(objectFileName);
- const char* pchExtension =
- this->GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
- if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) {
- // Add this object to the list of object files.
- this->Objects.push_back(objectFileName);
+ if (firstForConfig) {
+ const char* pchExtension =
+ this->GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
+ if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) {
+ // Add this object to the list of object files.
+ this->Configs[config].Objects.push_back(objectFileName);
+ }
}
objBuild.ExplicitDeps.push_back(sourceFileName);
@@ -1006,13 +1038,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
std::vector<std::string> depList;
const std::string pchSource =
- this->GeneratorTarget->GetPchSource(this->GetConfigName(), language);
+ this->GeneratorTarget->GetPchSource(config, language);
if (!pchSource.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
- depList.push_back(
- this->GeneratorTarget->GetPchHeader(this->GetConfigName(), language));
+ depList.push_back(this->GeneratorTarget->GetPchHeader(config, language));
if (source->GetFullPath() != pchSource) {
- depList.push_back(
- this->GeneratorTarget->GetPchFile(this->GetConfigName(), language));
+ depList.push_back(this->GeneratorTarget->GetPchFile(config, language));
}
}
@@ -1033,7 +1063,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
MapToNinjaPath());
}
- objBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget());
+ objBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget(config));
// If the source file is GENERATED and does not have a custom command
// (either attached to this source file or another one), assume that one of
@@ -1053,10 +1083,10 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
// For some cases we do an explicit preprocessor invocation.
bool const explicitPP = this->NeedExplicitPreprocessing(language);
if (explicitPP) {
- cmNinjaBuild ppBuild(this->LanguagePreprocessRule(language));
+ cmNinjaBuild ppBuild(this->LanguagePreprocessRule(language, config));
std::string const ppFileName =
- this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source));
+ this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source, config));
ppBuild.Outputs.push_back(ppFileName);
ppBuild.RspFile = ppFileName + ".rsp";
@@ -1114,7 +1144,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
sourceDirectory, this->GeneratorTarget, language, false, false,
- this->GetConfigName());
+ config);
vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"];
}
@@ -1138,17 +1168,19 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
std::string const ddiFile = objectFileName + ".ddi";
ppBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile;
ppBuild.ImplicitOuts.push_back(ddiFile);
- this->DDIFiles[language].push_back(ddiFile);
+ if (firstForConfig) {
+ this->Configs[config].DDIFiles[language].push_back(ddiFile);
+ }
}
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
ppBuild.Variables);
- this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), ppBuild,
- commandLineLengthLimit);
+ this->GetGlobalGenerator()->WriteBuild(
+ this->GetConfigFileStream(fileConfig), ppBuild, commandLineLengthLimit);
}
if (needDyndep) {
- std::string const dyndep = this->GetDyndepFilePath(language);
+ std::string const dyndep = this->GetDyndepFilePath(language, config);
objBuild.OrderOnlyDeps.push_back(dyndep);
vars["dyndep"] = dyndep;
}
@@ -1163,15 +1195,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
vars);
- this->SetMsvcTargetPdbVariable(vars);
+ this->SetMsvcTargetPdbVariable(vars, config);
objBuild.RspFile = objectFileName + ".rsp";
if (language == "Swift") {
- this->EmitSwiftDependencyInfo(source);
+ this->EmitSwiftDependencyInfo(source, config);
} else {
- this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
- objBuild, commandLineLengthLimit);
+ this->GetGlobalGenerator()->WriteBuild(
+ this->GetConfigFileStream(fileConfig), objBuild, commandLineLengthLimit);
}
if (const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
@@ -1181,11 +1213,13 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
std::transform(build.Outputs.begin(), build.Outputs.end(),
build.Outputs.begin(), MapToNinjaPath());
build.ExplicitDeps = objBuild.Outputs;
- this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
+ this->GetGlobalGenerator()->WriteBuild(
+ this->GetConfigFileStream(fileConfig), build);
}
}
-void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang)
+void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang,
+ const std::string& config)
{
Json::Value tdi(Json::objectValue);
tdi["language"] = lang;
@@ -1213,7 +1247,7 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang)
Json::Value& tdi_include_dirs = tdi["include-dirs"] = Json::arrayValue;
std::vector<std::string> includes;
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
- lang, this->GetConfigName());
+ lang, config);
for (std::string const& i : includes) {
// Convert the include directories the same way we do for -I flags.
// See upstream ninja issue 1251.
@@ -1222,22 +1256,22 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang)
Json::Value& tdi_linked_target_dirs = tdi["linked-target-dirs"] =
Json::arrayValue;
- for (std::string const& l : this->GetLinkedTargetDirectories()) {
+ for (std::string const& l : this->GetLinkedTargetDirectories(config)) {
tdi_linked_target_dirs.append(l);
}
- std::string const tdin = this->GetTargetDependInfoPath(lang);
+ std::string const tdin = this->GetTargetDependInfoPath(lang, config);
cmGeneratedFileStream tdif(tdin);
tdif << tdi;
}
void cmNinjaTargetGenerator::EmitSwiftDependencyInfo(
- cmSourceFile const* source)
+ cmSourceFile const* source, const std::string& config)
{
std::string const sourceFilePath =
this->ConvertToNinjaPath(this->GetSourceFilePath(source));
std::string const objectFilePath =
- this->ConvertToNinjaPath(this->GetObjectFilePath(source));
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
std::string const swiftDepsPath = [source, objectFilePath]() -> std::string {
if (const char* name = source->GetProperty("Swift_DEPENDENCIES_FILE")) {
return name;
@@ -1250,10 +1284,10 @@ void cmNinjaTargetGenerator::EmitSwiftDependencyInfo(
}
return objectFilePath + ".dia";
}();
- std::string const makeDepsPath = [this, source]() -> std::string {
+ std::string const makeDepsPath = [this, source, config]() -> std::string {
cmLocalNinjaGenerator const* local = this->GetLocalGenerator();
std::string const objectFileName =
- this->ConvertToNinjaPath(this->GetObjectFilePath(source));
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
std::string const objectFileDir =
cmSystemTools::GetFilenamePath(objectFileName);
@@ -1274,7 +1308,7 @@ void cmNinjaTargetGenerator::EmitSwiftDependencyInfo(
entry["dependencies"] = makeDepsPath;
entry["swift-dependencies"] = swiftDepsPath;
entry["diagnostics"] = swiftDiaPath;
- SwiftOutputMap[sourceFilePath] = entry;
+ this->Configs[config].SwiftOutputMap[sourceFilePath] = entry;
}
void cmNinjaTargetGenerator::ExportObjectCompileCommand(
@@ -1349,27 +1383,34 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName);
}
-void cmNinjaTargetGenerator::AdditionalCleanFiles()
+void cmNinjaTargetGenerator::AdditionalCleanFiles(const std::string& config)
{
if (const char* prop_value =
this->GeneratorTarget->GetProperty("ADDITIONAL_CLEAN_FILES")) {
cmLocalNinjaGenerator* lg = this->LocalGenerator;
std::vector<std::string> cleanFiles;
- cmExpandList(cmGeneratorExpression::Evaluate(
- prop_value, lg,
- this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"),
- this->GeneratorTarget),
+ cmExpandList(cmGeneratorExpression::Evaluate(prop_value, lg, config,
+ this->GeneratorTarget),
cleanFiles);
std::string const& binaryDir = lg->GetCurrentBinaryDirectory();
cmGlobalNinjaGenerator* gg = lg->GetGlobalNinjaGenerator();
for (std::string const& cleanFile : cleanFiles) {
// Support relative paths
gg->AddAdditionalCleanFile(
- cmSystemTools::CollapseFullPath(cleanFile, binaryDir));
+ cmSystemTools::CollapseFullPath(cleanFile, binaryDir), config);
}
}
}
+cmNinjaDeps cmNinjaTargetGenerator::GetObjects(const std::string& config) const
+{
+ auto const it = this->Configs.find(config);
+ if (it != this->Configs.end()) {
+ return it->second.Objects;
+ }
+ return {};
+}
+
void cmNinjaTargetGenerator::EnsureDirectoryExists(
const std::string& path) const
{
@@ -1392,7 +1433,7 @@ void cmNinjaTargetGenerator::EnsureParentDirectoryExists(
}
void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
- cmSourceFile const& source, const char* pkgloc)
+ cmSourceFile const& source, const char* pkgloc, const std::string& config)
{
// Skip OS X content when not building a Framework or Bundle.
if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
@@ -1400,7 +1441,8 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
}
std::string macdir =
- this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
+ this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc,
+ config);
// Get the input file location.
std::string input = source.GetFullPath();
@@ -1412,11 +1454,11 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
output = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(output);
// Write a build statement to copy the content into the bundle.
- this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
- output);
+ this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input, output,
+ config);
// Add as a dependency to the target so that it gets called.
- this->Generator->ExtraFiles.push_back(std::move(output));
+ this->Generator->Configs[config].ExtraFiles.push_back(std::move(output));
}
void cmNinjaTargetGenerator::addPoolNinjaVariable(
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index 4627bcd..22dd7b8 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -38,16 +38,17 @@ public:
/// Destructor.
~cmNinjaTargetGenerator() override;
- virtual void Generate() = 0;
+ virtual void Generate(const std::string& config) = 0;
std::string GetTargetName() const;
bool NeedDepTypeMSVC(const std::string& lang) const;
protected:
- bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
+ bool SetMsvcTargetPdbVariable(cmNinjaVars&, const std::string& config) const;
- cmGeneratedFileStream& GetBuildFileStream() const;
+ cmGeneratedFileStream& GetConfigFileStream(const std::string& config) const;
+ cmGeneratedFileStream& GetCommonFileStream() const;
cmGeneratedFileStream& GetRulesFileStream() const;
cmGeneratorTarget* GetGeneratorTarget() const
@@ -64,15 +65,18 @@ protected:
cmMakefile* GetMakefile() const { return this->Makefile; }
- std::string LanguageCompilerRule(const std::string& lang) const;
- std::string LanguagePreprocessRule(std::string const& lang) const;
+ std::string LanguageCompilerRule(const std::string& lang,
+ const std::string& config) const;
+ std::string LanguagePreprocessRule(std::string const& lang,
+ const std::string& config) const;
bool NeedExplicitPreprocessing(std::string const& lang) const;
- std::string LanguageDyndepRule(std::string const& lang) const;
+ std::string LanguageDyndepRule(std::string const& lang,
+ const std::string& config) const;
bool NeedDyndep(std::string const& lang) const;
bool UsePreprocessedSource(std::string const& lang) const;
bool CompilePreprocessedSourceWithDefines(std::string const& lang) const;
- std::string OrderDependsTargetForTarget();
+ std::string OrderDependsTargetForTarget(const std::string& config);
std::string ComputeOrderDependsForTarget();
@@ -82,15 +86,19 @@ protected:
* by LanguageFlagsVarName().
*/
std::string ComputeFlagsForObject(cmSourceFile const* source,
- const std::string& language);
+ const std::string& language,
+ const std::string& config);
- void AddIncludeFlags(std::string& flags, std::string const& lang) override;
+ void AddIncludeFlags(std::string& flags, std::string const& lang,
+ const std::string& config) override;
std::string ComputeDefines(cmSourceFile const* source,
- const std::string& language);
+ const std::string& language,
+ const std::string& config);
std::string ComputeIncludes(cmSourceFile const* source,
- const std::string& language);
+ const std::string& language,
+ const std::string& config);
std::string ConvertToNinjaPath(const std::string& path) const
{
@@ -102,36 +110,51 @@ protected:
}
/// @return the list of link dependency for the given target @a target.
- cmNinjaDeps ComputeLinkDeps(const std::string& linkLanguage) const;
+ cmNinjaDeps ComputeLinkDeps(const std::string& linkLanguage,
+ const std::string& config) const;
/// @return the source file path for the given @a source.
std::string GetSourceFilePath(cmSourceFile const* source) const;
/// @return the object file path for the given @a source.
- std::string GetObjectFilePath(cmSourceFile const* source) const;
+ std::string GetObjectFilePath(cmSourceFile const* source,
+ const std::string& config) const;
/// @return the preprocessed source file path for the given @a source.
- std::string GetPreprocessedFilePath(cmSourceFile const* source) const;
+ std::string GetPreprocessedFilePath(cmSourceFile const* source,
+ const std::string& config) const;
/// @return the dyndep file path for this target.
- std::string GetDyndepFilePath(std::string const& lang) const;
+ std::string GetDyndepFilePath(std::string const& lang,
+ const std::string& config) const;
/// @return the target dependency scanner info file path
- std::string GetTargetDependInfoPath(std::string const& lang) const;
+ std::string GetTargetDependInfoPath(std::string const& lang,
+ const std::string& config) const;
/// @return the file path where the target named @a name is generated.
- std::string GetTargetFilePath(const std::string& name) const;
+ std::string GetTargetFilePath(const std::string& name,
+ const std::string& config) const;
/// @return the output path for the target.
- virtual std::string GetTargetOutputDir() const;
-
- void WriteLanguageRules(const std::string& language);
- void WriteCompileRule(const std::string& language);
- void WriteObjectBuildStatements();
- void WriteObjectBuildStatement(cmSourceFile const* source);
- void WriteTargetDependInfo(std::string const& lang);
-
- void EmitSwiftDependencyInfo(cmSourceFile const* source);
+ virtual std::string GetTargetOutputDir(const std::string& config) const;
+
+ void WriteLanguageRules(const std::string& language,
+ const std::string& config);
+ void WriteCompileRule(const std::string& language,
+ const std::string& config);
+ void WriteObjectBuildStatements(const std::string& config,
+ const std::string& fileConfig,
+ bool firstForConfig);
+ void WriteObjectBuildStatement(cmSourceFile const* source,
+ const std::string& config,
+ const std::string& fileConfig,
+ bool firstForConfig);
+ void WriteTargetDependInfo(std::string const& lang,
+ const std::string& config);
+
+ void EmitSwiftDependencyInfo(cmSourceFile const* source,
+ const std::string& config);
void ExportObjectCompileCommand(
std::string const& language, std::string const& sourceFileName,
@@ -139,9 +162,9 @@ protected:
std::string const& objectFileDir, std::string const& flags,
std::string const& defines, std::string const& includes);
- void AdditionalCleanFiles();
+ void AdditionalCleanFiles(const std::string& config);
- cmNinjaDeps GetObjects() const { return this->Objects; }
+ cmNinjaDeps GetObjects(const std::string& config) const;
void EnsureDirectoryExists(const std::string& dir) const;
void EnsureParentDirectoryExists(const std::string& path) const;
@@ -155,7 +178,8 @@ protected:
{
}
- void operator()(cmSourceFile const& source, const char* pkgloc) override;
+ void operator()(cmSourceFile const& source, const char* pkgloc,
+ const std::string& config) override;
private:
cmNinjaTargetGenerator* Generator;
@@ -174,14 +198,20 @@ protected:
private:
cmLocalNinjaGenerator* LocalGenerator;
- /// List of object files for this target.
- cmNinjaDeps Objects;
- // Fortran Support
- std::map<std::string, cmNinjaDeps> DDIFiles;
- // Swift Support
- Json::Value SwiftOutputMap;
- std::vector<cmCustomCommand const*> CustomCommands;
- cmNinjaDeps ExtraFiles;
+
+ struct ByConfig
+ {
+ /// List of object files for this target.
+ cmNinjaDeps Objects;
+ // Fortran Support
+ std::map<std::string, cmNinjaDeps> DDIFiles;
+ // Swift Support
+ Json::Value SwiftOutputMap;
+ std::vector<cmCustomCommand const*> CustomCommands;
+ cmNinjaDeps ExtraFiles;
+ };
+
+ std::map<std::string, ByConfig> Configs;
};
#endif // ! cmNinjaTargetGenerator_h
diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx
index 5259037..0cddb12 100644
--- a/Source/cmNinjaUtilityTargetGenerator.cxx
+++ b/Source/cmNinjaUtilityTargetGenerator.cxx
@@ -15,13 +15,13 @@
#include "cmGeneratorTarget.h"
#include "cmGlobalNinjaGenerator.h"
#include "cmLocalNinjaGenerator.h"
-#include "cmMakefile.h"
#include "cmNinjaTypes.h"
#include "cmOutputConverter.h"
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
+#include "cmTarget.h"
cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
cmGeneratorTarget* target)
@@ -31,14 +31,18 @@ cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
cmNinjaUtilityTargetGenerator::~cmNinjaUtilityTargetGenerator() = default;
-void cmNinjaUtilityTargetGenerator::Generate()
+void cmNinjaUtilityTargetGenerator::Generate(const std::string& config)
{
cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
cmLocalNinjaGenerator* lg = this->GetLocalGenerator();
cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
+ std::string configDir;
+ if (genTarget->Target->IsPerConfig()) {
+ configDir = gg->ConfigDirectory(config);
+ }
std::string utilCommandName =
- cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles/",
+ cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles", configDir, "/",
this->GetTargetName(), ".util");
utilCommandName = this->ConvertToNinjaPath(utilCommandName);
@@ -55,8 +59,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
for (std::vector<cmCustomCommand> const* cmdList : cmdLists) {
for (cmCustomCommand const& ci : *cmdList) {
- cmCustomCommandGenerator ccg(ci, this->GetConfigName(), lg);
- lg->AppendCustomCommandDeps(ccg, deps);
+ cmCustomCommandGenerator ccg(ci, config, lg);
+ lg->AppendCustomCommandDeps(ccg, deps, config);
lg->AppendCustomCommandLines(ccg, commands);
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
std::transform(ccByproducts.begin(), ccByproducts.end(),
@@ -69,13 +73,11 @@ void cmNinjaUtilityTargetGenerator::Generate()
}
{
- std::string const& config =
- this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
std::vector<cmSourceFile*> sources;
genTarget->GetSourceFiles(sources, config);
for (cmSourceFile const* source : sources) {
if (cmCustomCommand const* cc = source->GetCustomCommand()) {
- cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), lg);
+ cmCustomCommandGenerator ccg(*cc, config, lg);
lg->AddCustomCommandTarget(cc, genTarget);
// Depend on all custom command outputs.
@@ -89,13 +91,21 @@ void cmNinjaUtilityTargetGenerator::Generate()
}
}
- lg->AppendTargetOutputs(genTarget, phonyBuild.Outputs);
- lg->AppendTargetDepends(genTarget, deps);
+ std::string outputConfig;
+ if (genTarget->Target->IsPerConfig()) {
+ outputConfig = config;
+ }
+ lg->AppendTargetOutputs(genTarget, phonyBuild.Outputs, outputConfig);
+ if (genTarget->Target->GetType() != cmStateEnums::GLOBAL_TARGET) {
+ lg->AppendTargetOutputs(genTarget, gg->GetByproductsForCleanTarget(),
+ config);
+ }
+ lg->AppendTargetDepends(genTarget, deps, config, config);
if (commands.empty()) {
phonyBuild.Comment = "Utility command for " + this->GetTargetName();
phonyBuild.ExplicitDeps = std::move(deps);
- gg->WriteBuild(this->GetBuildFileStream(), phonyBuild);
+ gg->WriteBuild(this->GetCommonFileStream(), phonyBuild);
} else {
std::string command =
lg->BuildCommandLine(commands, "utility", this->GeneratorTarget);
@@ -118,6 +128,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
cmOutputConverter::SHELL));
cmSystemTools::ReplaceString(command, "$(ARGS)", "");
+ command = gg->ExpandCFGIntDir(command, config);
if (command.find('$') != std::string::npos) {
return;
@@ -127,22 +138,32 @@ void cmNinjaUtilityTargetGenerator::Generate()
gg->SeenCustomCommandOutput(util_output);
}
+ std::string ccConfig;
+ if (genTarget->Target->IsPerConfig() &&
+ genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) {
+ ccConfig = config;
+ }
gg->WriteCustomCommandBuild(command, desc,
"Utility command for " + this->GetTargetName(),
/*depfile*/ "", /*job_pool*/ "", uses_terminal,
- /*restat*/ true, util_outputs, deps);
+ /*restat*/ true, util_outputs, ccConfig, deps);
phonyBuild.ExplicitDeps.push_back(utilCommandName);
- gg->WriteBuild(this->GetBuildFileStream(), phonyBuild);
+ gg->WriteBuild(this->GetCommonFileStream(), phonyBuild);
}
// Find ADDITIONAL_CLEAN_FILES
- this->AdditionalCleanFiles();
+ this->AdditionalCleanFiles(config);
// Add an alias for the logical target name regardless of what directory
// contains it. Skip this for GLOBAL_TARGET because they are meant to
// be per-directory and have one at the top-level anyway.
if (genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) {
- gg->AddTargetAlias(this->GetTargetName(), genTarget);
+ gg->AddTargetAlias(this->GetTargetName(), genTarget, config);
+ } else if (gg->IsMultiConfig() && genTarget->Target->IsPerConfig()) {
+ cmNinjaBuild phonyAlias("phony");
+ gg->AppendTargetOutputs(genTarget, phonyAlias.Outputs, "");
+ phonyAlias.ExplicitDeps = phonyBuild.Outputs;
+ gg->WriteBuild(this->GetConfigFileStream(config), phonyAlias);
}
}
diff --git a/Source/cmNinjaUtilityTargetGenerator.h b/Source/cmNinjaUtilityTargetGenerator.h
index 01cc459..ca3f0a4 100644
--- a/Source/cmNinjaUtilityTargetGenerator.h
+++ b/Source/cmNinjaUtilityTargetGenerator.h
@@ -5,6 +5,8 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include <string>
+
#include "cmNinjaTargetGenerator.h"
class cmGeneratorTarget;
@@ -15,7 +17,7 @@ public:
cmNinjaUtilityTargetGenerator(cmGeneratorTarget* target);
~cmNinjaUtilityTargetGenerator() override;
- void Generate() override;
+ void Generate(const std::string& config) override;
};
#endif // ! cmNinjaUtilityTargetGenerator_h
diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx
index a6f4e51..382b563 100644
--- a/Source/cmOSXBundleGenerator.cxx
+++ b/Source/cmOSXBundleGenerator.cxx
@@ -3,7 +3,6 @@
#include "cmOSXBundleGenerator.h"
#include <cassert>
-#include <utility>
#include "cmGeneratorTarget.h"
#include "cmLocalGenerator.h"
@@ -15,12 +14,10 @@
class cmSourceFile;
-cmOSXBundleGenerator::cmOSXBundleGenerator(cmGeneratorTarget* target,
- std::string configName)
+cmOSXBundleGenerator::cmOSXBundleGenerator(cmGeneratorTarget* target)
: GT(target)
, Makefile(target->Target->GetMakefile())
, LocalGenerator(target->GetLocalGenerator())
- , ConfigName(std::move(configName))
, MacContentFolders(nullptr)
{
if (this->MustSkip()) {
@@ -34,34 +31,34 @@ bool cmOSXBundleGenerator::MustSkip()
}
void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName,
- std::string& outpath)
+ std::string& outpath,
+ const std::string& config)
{
if (this->MustSkip()) {
return;
}
// Compute bundle directory names.
- std::string out =
- cmStrCat(outpath, '/',
- this->GT->GetAppBundleDirectory(this->ConfigName,
- cmGeneratorTarget::FullLevel));
+ std::string out = cmStrCat(
+ outpath, '/',
+ this->GT->GetAppBundleDirectory(config, cmGeneratorTarget::FullLevel));
cmSystemTools::MakeDirectory(out);
this->Makefile->AddCMakeOutputFile(out);
// Configure the Info.plist file. Note that it needs the executable name
// to be set.
- std::string plist =
- cmStrCat(outpath, '/',
- this->GT->GetAppBundleDirectory(this->ConfigName,
- cmGeneratorTarget::ContentLevel),
- "/Info.plist");
+ std::string plist = cmStrCat(
+ outpath, '/',
+ this->GT->GetAppBundleDirectory(config, cmGeneratorTarget::ContentLevel),
+ "/Info.plist");
this->LocalGenerator->GenerateAppleInfoPList(this->GT, targetName, plist);
this->Makefile->AddCMakeOutputFile(plist);
outpath = out;
}
void cmOSXBundleGenerator::CreateFramework(const std::string& targetName,
- const std::string& outpath)
+ const std::string& outpath,
+ const std::string& config)
{
if (this->MustSkip()) {
return;
@@ -70,15 +67,13 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName,
assert(this->MacContentFolders);
// Compute the location of the top-level foo.framework directory.
- std::string contentdir =
- cmStrCat(outpath, '/',
- this->GT->GetFrameworkDirectory(this->ConfigName,
- cmGeneratorTarget::ContentLevel),
- '/');
+ std::string contentdir = cmStrCat(
+ outpath, '/',
+ this->GT->GetFrameworkDirectory(config, cmGeneratorTarget::ContentLevel),
+ '/');
std::string newoutpath = outpath + "/" +
- this->GT->GetFrameworkDirectory(this->ConfigName,
- cmGeneratorTarget::FullLevel);
+ this->GT->GetFrameworkDirectory(config, cmGeneratorTarget::FullLevel);
std::string frameworkVersion = this->GT->GetFrameworkVersion();
@@ -156,27 +151,26 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName,
}
void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
- const std::string& root)
+ const std::string& root,
+ const std::string& config)
{
if (this->MustSkip()) {
return;
}
// Compute bundle directory names.
- std::string out =
- cmStrCat(root, '/',
- this->GT->GetCFBundleDirectory(this->ConfigName,
- cmGeneratorTarget::FullLevel));
+ std::string out = cmStrCat(
+ root, '/',
+ this->GT->GetCFBundleDirectory(config, cmGeneratorTarget::FullLevel));
cmSystemTools::MakeDirectory(out);
this->Makefile->AddCMakeOutputFile(out);
// Configure the Info.plist file. Note that it needs the executable name
// to be set.
- std::string plist =
- cmStrCat(root, '/',
- this->GT->GetCFBundleDirectory(this->ConfigName,
- cmGeneratorTarget::ContentLevel),
- "/Info.plist");
+ std::string plist = cmStrCat(
+ root, '/',
+ this->GT->GetCFBundleDirectory(config, cmGeneratorTarget::ContentLevel),
+ "/Info.plist");
std::string name = cmSystemTools::GetFilenameName(targetName);
this->LocalGenerator->GenerateAppleInfoPList(this->GT, name, plist);
this->Makefile->AddCMakeOutputFile(plist);
@@ -184,7 +178,7 @@ void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
void cmOSXBundleGenerator::GenerateMacOSXContentStatements(
std::vector<cmSourceFile const*> const& sources,
- MacOSXContentGeneratorType* generator)
+ MacOSXContentGeneratorType* generator, const std::string& config)
{
if (this->MustSkip()) {
return;
@@ -194,20 +188,19 @@ void cmOSXBundleGenerator::GenerateMacOSXContentStatements(
cmGeneratorTarget::SourceFileFlags tsFlags =
this->GT->GetTargetSourceFileFlags(source);
if (tsFlags.Type != cmGeneratorTarget::SourceFileTypeNormal) {
- (*generator)(*source, tsFlags.MacFolder);
+ (*generator)(*source, tsFlags.MacFolder, config);
}
}
}
std::string cmOSXBundleGenerator::InitMacOSXContentDirectory(
- const char* pkgloc)
+ const char* pkgloc, const std::string& config)
{
// Construct the full path to the content subdirectory.
- std::string macdir =
- cmStrCat(this->GT->GetMacContentDirectory(
- this->ConfigName, cmStateEnums::RuntimeBinaryArtifact),
- '/', pkgloc);
+ std::string macdir = cmStrCat(this->GT->GetMacContentDirectory(
+ config, cmStateEnums::RuntimeBinaryArtifact),
+ '/', pkgloc);
cmSystemTools::MakeDirectory(macdir);
// Record use of this content location. Only the first level
diff --git a/Source/cmOSXBundleGenerator.h b/Source/cmOSXBundleGenerator.h
index 3dea6cc..232be48 100644
--- a/Source/cmOSXBundleGenerator.h
+++ b/Source/cmOSXBundleGenerator.h
@@ -17,29 +17,33 @@ class cmSourceFile;
class cmOSXBundleGenerator
{
public:
- cmOSXBundleGenerator(cmGeneratorTarget* target, std::string configName);
+ cmOSXBundleGenerator(cmGeneratorTarget* target);
// create an app bundle at a given root, and return
// the directory within the bundle that contains the executable
- void CreateAppBundle(const std::string& targetName, std::string& root);
+ void CreateAppBundle(const std::string& targetName, std::string& root,
+ const std::string& config);
// create a framework at a given root
- void CreateFramework(const std::string& targetName, const std::string& root);
+ void CreateFramework(const std::string& targetName, const std::string& root,
+ const std::string& config);
// create a cf bundle at a given root
- void CreateCFBundle(const std::string& targetName, const std::string& root);
+ void CreateCFBundle(const std::string& targetName, const std::string& root,
+ const std::string& config);
struct MacOSXContentGeneratorType
{
virtual ~MacOSXContentGeneratorType() = default;
- virtual void operator()(cmSourceFile const& source,
- const char* pkgloc) = 0;
+ virtual void operator()(cmSourceFile const& source, const char* pkgloc,
+ const std::string& config) = 0;
};
void GenerateMacOSXContentStatements(
std::vector<cmSourceFile const*> const& sources,
- MacOSXContentGeneratorType* generator);
- std::string InitMacOSXContentDirectory(const char* pkgloc);
+ MacOSXContentGeneratorType* generator, const std::string& config);
+ std::string InitMacOSXContentDirectory(const char* pkgloc,
+ const std::string& config);
void SetMacContentFolders(std::set<std::string>* macContentFolders)
{
@@ -53,7 +57,6 @@ private:
cmGeneratorTarget* GT;
cmMakefile* Makefile;
cmLocalGenerator* LocalGenerator;
- std::string ConfigName;
std::set<std::string>* MacContentFolders;
};
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index e602a6d..1c6fad1 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -43,9 +43,10 @@ std::string cmOutputConverter::ConvertToOutputFormat(cm::string_view source,
{
std::string result(source);
// Convert it to an output path.
- if (output == SHELL || output == WATCOMQUOTE) {
+ if (output == SHELL || output == WATCOMQUOTE || output == NINJAMULTI) {
result = this->ConvertDirectorySeparatorsForShell(source);
- result = this->EscapeForShell(result, true, false, output == WATCOMQUOTE);
+ result = this->EscapeForShell(result, true, false, output == WATCOMQUOTE,
+ output == NINJAMULTI);
} else if (output == RESPONSE) {
result = this->EscapeForShell(result, false, false, false);
}
@@ -79,9 +80,9 @@ static bool cmOutputConverterIsShellOperator(cm::string_view str)
return (shellOperators.count(str) != 0);
}
-std::string cmOutputConverter::EscapeForShell(cm::string_view str,
- bool makeVars, bool forEcho,
- bool useWatcomQuote) const
+std::string cmOutputConverter::EscapeForShell(
+ cm::string_view str, bool makeVars, bool forEcho, bool useWatcomQuote,
+ bool unescapeNinjaConfiguration) const
{
// Do not escape shell operators.
if (cmOutputConverterIsShellOperator(str)) {
@@ -95,6 +96,9 @@ std::string cmOutputConverter::EscapeForShell(cm::string_view str,
} else if (!this->LinkScriptShell) {
flags |= Shell_Flag_Make;
}
+ if (unescapeNinjaConfiguration) {
+ flags |= Shell_Flag_UnescapeNinjaConfiguration;
+ }
if (makeVars) {
flags |= Shell_Flag_AllowMakeVariables;
}
@@ -511,5 +515,14 @@ std::string cmOutputConverter::Shell__GetArgument(cm::string_view in,
}
}
+ if (flags & Shell_Flag_UnescapeNinjaConfiguration) {
+ std::string ninjaConfigReplace;
+ if (flags & Shell_Flag_IsUnix) {
+ ninjaConfigReplace += '\\';
+ }
+ ninjaConfigReplace += "$${CONFIGURATION}";
+ cmSystemTools::ReplaceString(out, ninjaConfigReplace, "${CONFIGURATION}");
+ }
+
return out;
}
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index 349a069..6583ab5 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -22,6 +22,7 @@ public:
{
SHELL,
WATCOMQUOTE,
+ NINJAMULTI,
RESPONSE
};
std::string ConvertToOutputFormat(cm::string_view source,
@@ -70,12 +71,14 @@ public:
/** The target shell quoting uses extra single Quotes for Watcom tools. */
Shell_Flag_WatcomQuote = (1 << 7),
- Shell_Flag_IsUnix = (1 << 8)
+ Shell_Flag_IsUnix = (1 << 8),
+
+ Shell_Flag_UnescapeNinjaConfiguration = (1 << 9),
};
std::string EscapeForShell(cm::string_view str, bool makeVars = false,
- bool forEcho = false,
- bool useWatcomQuote = false) const;
+ bool forEcho = false, bool useWatcomQuote = false,
+ bool unescapeNinjaConfiguration = false) const;
static std::string EscapeForCMake(cm::string_view str);
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index da32204..ecf892b 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -293,7 +293,11 @@ class cmMakefile;
3, 16, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0098, \
"FindFLEX runs flex in CMAKE_CURRENT_BINARY_DIR when executing.", 3, \
- 17, 0, cmPolicies::WARN)
+ 17, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0099, \
+ "Link properties are transitive over private dependency on static " \
+ "libraries.", \
+ 3, 17, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@@ -322,7 +326,8 @@ class cmMakefile;
F(CMP0076) \
F(CMP0081) \
F(CMP0083) \
- F(CMP0095)
+ F(CMP0095) \
+ F(CMP0099)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies
diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx
index ef70fce..db5a8ba 100644
--- a/Source/cmQtAutoGenGlobalInitializer.cxx
+++ b/Source/cmQtAutoGenGlobalInitializer.cxx
@@ -40,9 +40,9 @@ cmQtAutoGenGlobalInitializer::Keywords::Keywords()
}
cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
- std::vector<cmLocalGenerator*> const& localGenerators)
+ std::vector<std::unique_ptr<cmLocalGenerator>> const& localGenerators)
{
- for (cmLocalGenerator* localGen : localGenerators) {
+ for (const auto& localGen : localGenerators) {
// Detect global autogen and autorcc target names
bool globalAutoGenTarget = false;
bool globalAutoRccTarget = false;
@@ -55,7 +55,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
if (targetName.empty()) {
targetName = "autogen";
}
- GlobalAutoGenTargets_.emplace(localGen, std::move(targetName));
+ GlobalAutoGenTargets_.emplace(localGen.get(), std::move(targetName));
globalAutoGenTarget = true;
}
@@ -66,7 +66,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
if (targetName.empty()) {
targetName = "autorcc";
}
- GlobalAutoRccTargets_.emplace(localGen, std::move(targetName));
+ GlobalAutoRccTargets_.emplace(localGen.get(), std::move(targetName));
globalAutoRccTarget = true;
}
}
diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h
index 806725a..2f6e581 100644
--- a/Source/cmQtAutoGenGlobalInitializer.h
+++ b/Source/cmQtAutoGenGlobalInitializer.h
@@ -48,7 +48,7 @@ public:
public:
cmQtAutoGenGlobalInitializer(
- std::vector<cmLocalGenerator*> const& localGenerators);
+ std::vector<std::unique_ptr<cmLocalGenerator>> const& localGenerators);
~cmQtAutoGenGlobalInitializer();
Keywords const& kw() const { return Keywords_; };
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 42979af..fc65756 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -1042,9 +1042,16 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
}
// Compose command lines
- cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
- { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen",
- this->AutogenTarget.InfoFile, "$<CONFIGURATION>" });
+ // TODO: Refactor autogen to output a per-config mocs_compilation.cpp instead
+ // of fiddling with the include directories
+ std::vector<std::string> configs;
+ this->GlobalGen->GetQtAutoGenConfigs(configs);
+ cmCustomCommandLines commandLines;
+ for (auto const& config : configs) {
+ commandLines.push_back(cmMakeCommandLine(
+ { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen",
+ this->AutogenTarget.InfoFile, config }));
+ }
// Use PRE_BUILD on demand
bool usePRE_BUILD = false;
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index f9b5ed1..72f663d 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -615,6 +615,9 @@ const char* cmState::GetGlobalProperty(const std::string& prop)
if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
return &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1];
}
+ if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
+ return &FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
#undef STRING_LIST_ELEMENT
return this->GlobalProperties.GetPropertyValue(prop);
@@ -712,6 +715,16 @@ bool cmState::UseMSYSShell() const
return this->MSYSShell;
}
+void cmState::SetNinjaMulti(bool ninjaMulti)
+{
+ this->NinjaMulti = ninjaMulti;
+}
+
+bool cmState::UseNinjaMulti() const
+{
+ return this->NinjaMulti;
+}
+
unsigned int cmState::GetCacheMajorVersion() const
{
return this->CacheManager->GetCacheMajorVersion();
diff --git a/Source/cmState.h b/Source/cmState.h
index a7ca015..cd871b9 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -190,6 +190,8 @@ public:
bool UseNMake() const;
void SetMSYSShell(bool mSYSShell);
bool UseMSYSShell() const;
+ void SetNinjaMulti(bool ninjaMulti);
+ bool UseNinjaMulti() const;
unsigned int GetCacheMajorVersion() const;
unsigned int GetCacheMinorVersion() const;
@@ -245,6 +247,7 @@ private:
bool MinGWMake = false;
bool NMake = false;
bool MSYSShell = false;
+ bool NinjaMulti = false;
Mode CurrentMode = Unknown;
};
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index b9bf7a5..6441c0e 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -176,6 +176,7 @@ public:
bool IsImportedTarget;
bool ImportedGloballyVisible;
bool BuildInterfaceIncludesAppended;
+ bool PerConfig;
std::set<BT<std::string>> Utilities;
std::vector<cmCustomCommand> PreBuildCommands;
std::vector<cmCustomCommand> PreLinkCommands;
@@ -213,7 +214,7 @@ public:
};
cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
- Visibility vis, cmMakefile* mf)
+ Visibility vis, cmMakefile* mf, bool perConfig)
: impl(cm::make_unique<cmTargetInternals>())
{
assert(mf);
@@ -229,6 +230,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
(vis == VisibilityImported || vis == VisibilityImportedGlobally);
impl->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
impl->BuildInterfaceIncludesAppended = false;
+ impl->PerConfig = perConfig;
// Check whether this is a DLL platform.
impl->IsDLLPlatform =
@@ -1800,6 +1802,11 @@ bool cmTarget::IsImportedGloballyVisible() const
return impl->ImportedGloballyVisible;
}
+bool cmTarget::IsPerConfig() const
+{
+ return impl->PerConfig;
+}
+
const char* cmTarget::GetSuffixVariableInternal(
cmStateEnums::ArtifactType artifact) const
{
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 65a1ce3..1bfa3ce 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -44,7 +44,7 @@ public:
};
cmTarget(std::string const& name, cmStateEnums::TargetType type,
- Visibility vis, cmMakefile* mf);
+ Visibility vis, cmMakefile* mf, bool perConfig);
cmTarget(cmTarget const&) = delete;
cmTarget(cmTarget&&) noexcept;
@@ -186,6 +186,7 @@ public:
bool IsImported() const;
bool IsImportedGloballyVisible() const;
+ bool IsPerConfig() const;
bool GetMappedConfig(std::string const& desired_config, const char** loc,
const char** imp, std::string& suffix) const;
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 5ffa576..66cf683 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -2160,7 +2160,6 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
this->WriteExtraSource(e1, si.Source);
break;
case cmGeneratorTarget::SourceKindHeader:
- case cmGeneratorTarget::SourceKindUnityBatched:
this->WriteHeaderSource(e1, si.Source);
break;
case cmGeneratorTarget::SourceKindIDL:
@@ -2172,6 +2171,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
case cmGeneratorTarget::SourceKindModuleDefinition:
tool = "None";
break;
+ case cmGeneratorTarget::SourceKindUnityBatched:
case cmGeneratorTarget::SourceKindObjectSource: {
const std::string& lang = si.Source->GetLanguage();
if (lang == "C" || lang == "CXX") {
@@ -2418,6 +2418,9 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
clOptions.AppendFlag("DisableSpecificWarnings",
"%(DisableSpecificWarnings)");
}
+ if (clOptions.HasFlag("ForcedIncludeFiles")) {
+ clOptions.AppendFlag("ForcedIncludeFiles", "%(ForcedIncludeFiles)");
+ }
if (configDependentDefines) {
clOptions.AddDefines(
genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index b1c6e8f..6bfb37e 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -538,7 +538,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
std::vector<std::string> includeDirs = cmExpandedList(includes);
gg->CreateGenerationObjects();
- cmLocalGenerator* lg = gg->LocalGenerators[0];
+ const auto& lg = gg->LocalGenerators[0];
std::string includeFlags =
lg->GetIncludeFlags(includeDirs, nullptr, language);
@@ -1919,6 +1919,7 @@ void cmake::AddDefaultGenerators()
this->Generators.push_back(cmGlobalGhsMultiGenerator::NewFactory());
# endif
this->Generators.push_back(cmGlobalNinjaGenerator::NewFactory());
+ this->Generators.push_back(cmGlobalNinjaMultiGenerator::NewFactory());
#endif
#if defined(CMAKE_USE_WMAKE)
this->Generators.push_back(cmGlobalWatcomWMakeGenerator::NewFactory());
@@ -2169,7 +2170,7 @@ int cmake::CheckBuildSystem()
if (ggd) {
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot());
- std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mfd));
+ auto lgd = ggd->CreateLocalGenerator(&mfd);
lgd->ClearDependencies(&mfd, verbose);
}
}
diff --git a/Source/cmake.h b/Source/cmake.h
index 9e78436..02de4c1 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -746,4 +746,11 @@ private:
FOR_EACH_CXX11_FEATURE(F) \
FOR_EACH_CXX14_FEATURE(F)
+#define FOR_EACH_CUDA_FEATURE(F) \
+ F(cuda_std_03) \
+ F(cuda_std_11) \
+ F(cuda_std_14) \
+ F(cuda_std_17) \
+ F(cuda_std_20)
+
#endif
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index c2fbb43..9f4463c 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -21,16 +21,15 @@
#if !defined(CMAKE_BOOTSTRAP)
# include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
+# include "cmFileTime.h"
# include "cmServer.h"
# include "cmServerConnection.h"
+
+# include "bindexplib.h"
#endif
#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32)
# include "cmsys/ConsoleBuf.hxx"
-
-# include "cmFileTime.h"
-
-# include "bindexplib.h"
#endif
#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) && !defined(__CYGWIN__)
@@ -581,11 +580,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
return 0;
}
-#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
- else if (args[1] == "__create_def") {
+#if !defined(CMAKE_BOOTSTRAP)
+ if (args[1] == "__create_def") {
if (args.size() < 4) {
std::cerr << "__create_def Usage: -E __create_def outfile.def "
- "objlistfile [-nm=nm-path]\n";
+ "objlistfile [--nm=nm-path]\n";
return 1;
}
cmsys::ifstream fin(args[3].c_str(), std::ios::in | std::ios::binary);
@@ -612,7 +611,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
return 0;
}
}
- FILE* fout = cmsys::SystemTools::Fopen(args[2].c_str(), "w+");
+ FILE* fout = cmsys::SystemTools::Fopen(args[2], "w+");
if (!fout) {
std::cerr << "could not open output .def file: " << args[2].c_str()
<< "\n";
@@ -1085,7 +1084,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
snapshot.GetDirectory().SetCurrentBinary(startOutDir);
snapshot.GetDirectory().SetCurrentSource(startDir);
cmMakefile mf(ggd, snapshot);
- std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mf));
+ auto lgd = ggd->CreateLocalGenerator(&mf);
// Actually scan dependencies.
return lgd->UpdateDependencies(depInfo, verbose, color) ? 0 : 2;