diff options
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 2 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 17 | ||||
-rw-r--r-- | Source/cmSourceGroupCommand.cxx | 15 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.h | 2 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsSpectreMitigation-check.cmake | 30 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsSpectreMitigation.cmake | 8 | ||||
-rw-r--r-- | Tests/SwiftOnly/CMakeLists.txt | 3 |
9 files changed, 67 insertions, 25 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 6083358..02bc14b 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -138,7 +138,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(_variant "") if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang") - if(CMAKE_HOST_WIN32 AND "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") + if("x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") if(CMAKE_GENERATOR MATCHES "Visual Studio") set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC") else() diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 4eba4ff..9afc15a 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -339,15 +339,16 @@ bool cmGlobalGenerator::CheckTargetsForType() const bool failed = false; for (cmLocalGenerator* generator : this->LocalGenerators) { for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) { - std::vector<std::string> configs; - target->Makefile->GetConfigurations(configs); - if (configs.empty()) { - configs.emplace_back(); - } + if (target->GetType() == cmStateEnums::EXECUTABLE && + target->GetPropertyAsBool("WIN32_EXECUTABLE")) { + std::vector<std::string> configs; + target->Makefile->GetConfigurations(configs); + if (configs.empty()) { + configs.emplace_back(); + } - for (std::string const& config : configs) { - if (target->GetLinkerLanguage(config) == "Swift") { - if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { + for (std::string const& config : configs) { + if (target->GetLinkerLanguage(config) == "Swift") { this->GetCMakeInstance()->IssueMessage( MessageType::FATAL_ERROR, "WIN32_EXECUTABLE property is not supported on Swift " diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 5cdacaa..04b4d72 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -63,15 +63,6 @@ bool rootIsPrefix(const std::string& root, return true; } -std::string prepareFilePathForTree(const std::string& path, - const std::string& currentSourceDir) -{ - if (!cmSystemTools::FileIsFullPath(path)) { - return cmSystemTools::CollapseFullPath(currentSourceDir + "/" + path); - } - return cmSystemTools::CollapseFullPath(path); -} - std::vector<std::string> prepareFilesPathsForTree( const std::vector<std::string>& filesPaths, const std::string& currentSourceDir) @@ -80,9 +71,11 @@ std::vector<std::string> prepareFilesPathsForTree( prepared.reserve(filesPaths.size()); for (auto const& filePath : filesPaths) { + std::string fullPath = + cmSystemTools::CollapseFullPath(filePath, currentSourceDir); // If provided file path is actually not a file, silently ignore it. - if (cmSystemTools::FileExists(filePath, /*isFile=*/true)) { - prepared.push_back(prepareFilePathForTree(filePath, currentSourceDir)); + if (cmSystemTools::FileExists(fullPath, /*isFile=*/true)) { + prepared.emplace_back(std::move(fullPath)); } } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 8c6ba4e..7d25713 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1229,8 +1229,11 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues( if (this->IPOEnabledConfigurations.count(config) > 0) { e1.Element("WholeProgramOptimization", "true"); } - if (this->SpectreMitigationConfigurations.count(config) > 0) { - e1.Element("SpectreMitigation", "Spectre"); + { + auto s = this->SpectreMitigation.find(config); + if (s != this->SpectreMitigation.end()) { + e1.Element("SpectreMitigation", s->second); + } } } @@ -2760,8 +2763,8 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } } - if (clOptions.HasFlag("SpectreMitigation")) { - this->SpectreMitigationConfigurations.insert(configName); + if (const char* s = clOptions.GetFlag("SpectreMitigation")) { + this->SpectreMitigation[configName] = s; clOptions.RemoveFlag("SpectreMitigation"); } diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 860b809..6607e77 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -215,7 +215,7 @@ private: unsigned int NsightTegraVersion[4]; bool TargetCompileAsWinRT; std::set<std::string> IPOEnabledConfigurations; - std::set<std::string> SpectreMitigationConfigurations; + std::map<std::string, std::string> SpectreMitigation; cmGlobalVisualStudio10Generator* const GlobalGenerator; cmLocalVisualStudio10Generator* const LocalGenerator; std::set<std::string> CSharpCustomCommandNames; diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 55ca9ea..27b81b7 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -26,3 +26,7 @@ run_cmake(VsPackageReferences) if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05) run_cmake(VsJustMyCode) endif() + +if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.20) + run_cmake(VsSpectreMitigation) +endif() diff --git a/Tests/RunCMake/VS10Project/VsSpectreMitigation-check.cmake b/Tests/RunCMake/VS10Project/VsSpectreMitigation-check.cmake new file mode 100644 index 0000000..6117763 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsSpectreMitigation-check.cmake @@ -0,0 +1,30 @@ +macro(VsSpectreMitigation_check tgt spectre_expect) + set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/${tgt}.vcxproj") + if(NOT EXISTS "${vcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not exist.") + return() + endif() + + set(HAVE_SpectreMitigation 0) + + file(STRINGS "${vcProjectFile}" lines) + foreach(line IN LISTS lines) + if(line MATCHES "^ *<SpectreMitigation>([^<>]+)</SpectreMitigation>") + set(spectre_actual "${CMAKE_MATCH_1}") + if(NOT "${spectre_actual}" STREQUAL "${spectre_expect}") + set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has <SpectreMitigation> '${spectre_actual}', not '${spectre_expect}'.") + return() + endif() + set(HAVE_SpectreMitigation 1) + break() + endif() + endforeach() + + if(NOT HAVE_SpectreMitigation AND NOT "${spectre_expect}" STREQUAL "") + set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <SpectreMitigation> field.") + return() + endif() +endmacro() + +VsSpectreMitigation_check(SpectreMitigationOn-C "Spectre") +VsSpectreMitigation_check(SpectreMitigationOff-C "false") diff --git a/Tests/RunCMake/VS10Project/VsSpectreMitigation.cmake b/Tests/RunCMake/VS10Project/VsSpectreMitigation.cmake new file mode 100644 index 0000000..b3779d7 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsSpectreMitigation.cmake @@ -0,0 +1,8 @@ +set(CMAKE_CONFIGURATION_TYPES Debug) +enable_language(C) + +add_library(SpectreMitigationOn-C empty.c) +target_compile_options(SpectreMitigationOn-C PRIVATE -Qspectre) + +add_library(SpectreMitigationOff-C empty.c) +target_compile_options(SpectreMitigationOff-C PRIVATE -Qspectre-) diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt index e5f8588..f4cbac2 100644 --- a/Tests/SwiftOnly/CMakeLists.txt +++ b/Tests/SwiftOnly/CMakeLists.txt @@ -8,3 +8,6 @@ elseif(NOT XCODE_VERSION VERSION_LESS 8.0) endif() add_executable(SwiftOnly main.swift) + +# Dummy to make sure generation works with such targets. +add_library(SwiftIface INTERFACE) |