diff options
30 files changed, 338 insertions, 196 deletions
diff --git a/Help/generator/Ninja.rst b/Help/generator/Ninja.rst index 51ef49b..c75d2c4 100644 --- a/Help/generator/Ninja.rst +++ b/Help/generator/Ninja.rst @@ -3,9 +3,9 @@ Ninja Generates build.ninja files. -A build.ninja file is generated into the build tree. Recent versions -of the ninja program can build the project through the ``all`` target. -An ``install`` target is also provided. +A ``build.ninja`` file is generated into the build tree. Use the ninja +program to build the project through the ``all`` target and install the +project through the ``install`` (or ``install/strip``) target. For each subdirectory ``sub/dir`` of the project, additional targets are generated: @@ -16,6 +16,13 @@ are generated: ``sub/dir/install`` Runs the install step in the subdirectory, if any. +``sub/dir/install/strip`` + Runs the install step in the subdirectory followed by a ``CMAKE_STRIP`` command, + if any. + + The ``CMAKE_STRIP`` variable will contain the platform's ``strip`` utility, which + removes symbols information from generated binaries. + ``sub/dir/test`` Runs the test step in the subdirectory, if any. diff --git a/Help/generator/Unix Makefiles.rst b/Help/generator/Unix Makefiles.rst index 1e65ee1..dfe4ecb 100644 --- a/Help/generator/Unix Makefiles.rst +++ b/Help/generator/Unix Makefiles.rst @@ -3,6 +3,29 @@ Unix Makefiles Generates standard UNIX makefiles. -A hierarchy of UNIX makefiles is generated into the build tree. Any -standard UNIX-style make program can build the project through the -default ``all`` target. An ``install`` target is also provided. +A hierarchy of UNIX makefiles is generated into the build tree. Use +any standard UNIX-style make program to build the project through +the ``all`` target and install the project through the ``install`` +(or ``install/strip``) target. + +For each subdirectory ``sub/dir`` of the project a UNIX makefile will +be created, containing the following targets: + +``all`` + Depends on all targets required by the subdirectory. + +``install`` + Runs the install step in the subdirectory, if any. + +``install/strip`` + Runs the install step in the subdirectory followed by a ``CMAKE_STRIP`` command, + if any. + + The ``CMAKE_STRIP`` variable will contain the platform's ``strip`` utility, which + removes symbols information from generated binaries. + +``test`` + Runs the test step in the subdirectory, if any. + +``package`` + Runs the package step in the subdirectory, if any. diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index 45c33fb..ea5a3b3 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -97,6 +97,9 @@ else() "\"${__ranlib}\" <TARGET>" ) + set(CMAKE_PCH_EXTENSION .pch) set(CMAKE_PCH_PROLOGUE "#pragma clang system_header") + set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Xclang -include-pch -Xclang <PCH_FILE>) + set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER>) endmacro() endif() diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake index 84b3a9b..f226553 100644 --- a/Modules/Platform/Windows-Clang.cmake +++ b/Modules/Platform/Windows-Clang.cmake @@ -83,9 +83,10 @@ macro(__windows_compiler_clang_gnu lang) string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG -Xclang -gcodeview ${__ADDED_FLAGS}") set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") - set(CMAKE_PCH_EXTENSION .gch) - set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Winvalid-pch -include <PCH_HEADER>) - set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Winvalid-pch -x ${__pch_header_${lang}} -include <PCH_HEADER>) + set(CMAKE_PCH_EXTENSION .pch) + set(CMAKE_PCH_PROLOGUE "#pragma clang system_header") + set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Xclang -include-pch -Xclang <PCH_FILE>) + set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER>) unset(__ADDED_FLAGS) unset(__ADDED_FLAGS_DEBUG) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 0515f6c..bca928e 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 15) -set(CMake_VERSION_PATCH 20191004) +set(CMake_VERSION_PATCH 20191007) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 018037c..ee9ea3c 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1381,6 +1381,11 @@ bool cmGlobalGenerator::Compute() return false; } + // Add automatically generated sources (e.g. unity build). + if (!this->AddAutomaticSources()) { + return false; + } + // Add generator specific helper commands for (cmLocalGenerator* localGen : this->LocalGenerators) { localGen->AddHelperCommands(); @@ -1548,6 +1553,19 @@ bool cmGlobalGenerator::QtAutoGen() #endif } +bool cmGlobalGenerator::AddAutomaticSources() +{ + for (cmLocalGenerator* lg : this->LocalGenerators) { + for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) { + if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + continue; + } + lg->AddUnityBuild(gt); + } + } + return true; +} + cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index b7a8ac7..9e30b8f 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -503,6 +503,8 @@ protected: /// @return true on success bool QtAutoGen(); + bool AddAutomaticSources(); + std::string SelectMakeProgram(const std::string& makeProgram, const std::string& makeDefault = "") const; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index f23e28d..8ae1e12 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2827,7 +2827,6 @@ bool cmGlobalXCodeGenerator::CreateGroups( continue; } - generator->AddUnityBuild(gtgt, ""); generator->AddPchDependencies(gtgt, ""); auto addSourceToGroup = [this, mf, gtgt, diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 154d509..ccd70a3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2254,196 +2254,216 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags, void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target, const std::string& config) { - const std::string lang = target->GetLinkerLanguage(config); const std::string buildType = cmSystemTools::UpperCase(config); - const std::string pchSource = target->GetPchSource(config, lang); - const std::string pchHeader = target->GetPchHeader(config, lang); - if (pchSource.empty() || pchHeader.empty()) { - return; - } + std::vector<cmSourceFile*> sources; + target->GetSourceFiles(sources, buildType); - const std::string createOptVar = - cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_CREATE_PCH"); - std::string createOptionList = - this->Makefile->GetSafeDefinition(createOptVar); + for (const std::string& lang : { "C", "CXX" }) { + auto langSources = + std::count_if(sources.begin(), sources.end(), [lang](cmSourceFile* sf) { + return lang == sf->GetLanguage(); + }); + if (langSources == 0) { + continue; + } - const std::string useOptVar = - cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_USE_PCH"); - std::string useOptionList = this->Makefile->GetSafeDefinition(useOptVar); + const std::string pchSource = target->GetPchSource(config, lang); + const std::string pchHeader = target->GetPchHeader(config, lang); - const std::string pchExtension = - this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION"); + if (pchSource.empty() || pchHeader.empty()) { + continue; + } - if (createOptionList.empty() || useOptionList.empty() || - pchExtension.empty()) { - return; - } + const std::string createOptVar = + cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_CREATE_PCH"); + std::string createOptionList = + this->Makefile->GetSafeDefinition(createOptVar); - const char* pchReuseFrom = - target->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); + const std::string useOptVar = + cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_USE_PCH"); + std::string useOptionList = this->Makefile->GetSafeDefinition(useOptVar); - auto pch_sf = this->Makefile->GetOrCreateSource( - pchSource, false, cmSourceFileLocationKind::Known); - std::string pchFile = pchHeader; + const std::string pchExtension = + this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION"); - if (!this->GetGlobalGenerator()->IsXcode()) { - if (!pchReuseFrom) { - target->AddSource(pchSource, true); + if (createOptionList.empty() || useOptionList.empty() || + pchExtension.empty()) { + continue; } - // Exclude the pch files from linking - if (this->Makefile->IsOn("CMAKE_LINK_PCH")) { + const char* pchReuseFrom = + target->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); - auto replaceExtension = [](const std::string& str, - const std::string& ext) -> std::string { - auto dot_pos = str.rfind('.'); - std::string result; - if (dot_pos != std::string::npos) { - result = str.substr(0, dot_pos); - } - result += ext; - return result; - }; + auto pch_sf = this->Makefile->GetOrCreateSource( + pchSource, false, cmSourceFileLocationKind::Known); + std::string pchFile = pchHeader; + if (!this->GetGlobalGenerator()->IsXcode()) { if (!pchReuseFrom) { - std::string pchSourceObj = target->GetPchFileObject(config, lang); + target->AddSource(pchSource, true); + } - pchFile = replaceExtension(pchSourceObj, pchExtension); - pch_sf->SetProperty("OBJECT_OUTPUTS", pchFile.c_str()); - } else { - auto reuseTarget = - this->GlobalGenerator->FindGeneratorTarget(pchReuseFrom); + // Exclude the pch files from linking + if (this->Makefile->IsOn("CMAKE_LINK_PCH")) { - if (this->Makefile->IsOn("CMAKE_PCH_COPY_COMPILE_PDB")) { + auto replaceExtension = [](const std::string& str, + const std::string& ext) -> std::string { + auto dot_pos = str.rfind('.'); + std::string result; + if (dot_pos != std::string::npos) { + result = str.substr(0, dot_pos); + } + result += ext; + return result; + }; - const std::string pdb_prefix = - this->GetGlobalGenerator()->IsMultiConfig() - ? cmStrCat(this->GlobalGenerator->GetCMakeCFGIntDir(), "/") - : ""; + if (!pchReuseFrom) { + std::string pchSourceObj = target->GetPchFileObject(config, lang); - const std::string target_compile_pdb_dir = - cmStrCat(target->GetLocalGenerator()->GetCurrentBinaryDirectory(), - "/", target->GetName(), ".dir/"); + pchFile = replaceExtension(pchSourceObj, pchExtension); + pch_sf->SetProperty("OBJECT_OUTPUTS", pchFile.c_str()); + } else { + auto reuseTarget = + this->GlobalGenerator->FindGeneratorTarget(pchReuseFrom); - const std::string copy_script = - cmStrCat(target_compile_pdb_dir, "copy_idb_pdb.cmake"); - cmGeneratedFileStream file(copy_script); + if (this->Makefile->IsOn("CMAKE_PCH_COPY_COMPILE_PDB")) { - file << "# CMake generated file\n"; - for (auto extension : { ".pdb", ".idb" }) { - const std::string from_file = cmStrCat( - reuseTarget->GetLocalGenerator()->GetCurrentBinaryDirectory(), - "/", pchReuseFrom, ".dir/${PDB_PREFIX}", pchReuseFrom, - extension); + const std::string pdb_prefix = + this->GetGlobalGenerator()->IsMultiConfig() + ? cmStrCat(this->GlobalGenerator->GetCMakeCFGIntDir(), "/") + : ""; - const std::string to_dir = cmStrCat( + const std::string target_compile_pdb_dir = cmStrCat( target->GetLocalGenerator()->GetCurrentBinaryDirectory(), "/", - target->GetName(), ".dir/${PDB_PREFIX}"); - - file << "if (EXISTS \"" << from_file << "\")\n"; - file << " file(COPY \"" << from_file << "\"" - << " DESTINATION \"" << to_dir << "\")\n"; - file << "endif()\n"; - } + target->GetName(), ".dir/"); + + const std::string copy_script = + cmStrCat(target_compile_pdb_dir, "copy_idb_pdb.cmake"); + cmGeneratedFileStream file(copy_script); + + file << "# CMake generated file\n"; + for (auto extension : { ".pdb", ".idb" }) { + const std::string from_file = cmStrCat( + reuseTarget->GetLocalGenerator()->GetCurrentBinaryDirectory(), + "/", pchReuseFrom, ".dir/${PDB_PREFIX}", pchReuseFrom, + extension); + + const std::string to_dir = cmStrCat( + target->GetLocalGenerator()->GetCurrentBinaryDirectory(), "/", + target->GetName(), ".dir/${PDB_PREFIX}"); + + file << "if (EXISTS \"" << from_file << "\")\n"; + file << " file(COPY \"" << from_file << "\"" + << " DESTINATION \"" << to_dir << "\")\n"; + file << "endif()\n"; + } - cmCustomCommandLines commandLines; - cmCustomCommandLine currentLine; - currentLine.push_back(cmSystemTools::GetCMakeCommand()); - currentLine.push_back(cmStrCat("-DPDB_PREFIX=", pdb_prefix)); - currentLine.push_back("-P"); - currentLine.push_back(copy_script); - commandLines.push_back(std::move(currentLine)); - - const std::string no_main_dependency; - const std::vector<std::string> no_deps; - const char* no_message = ""; - const char* no_current_dir = nullptr; - std::vector<std::string> no_byproducts; - - std::vector<std::string> outputs; - outputs.push_back(cmStrCat(target_compile_pdb_dir, pdb_prefix, - pchReuseFrom, ".pdb")); - - if (this->GetGlobalGenerator()->IsMultiConfig()) { - this->Makefile->AddCustomCommandToTarget( - target->GetName(), outputs, no_deps, commandLines, - cmCustomCommandType::PRE_BUILD, no_message, no_current_dir); - } else { - cmImplicitDependsList no_implicit_depends; - cmSourceFile* copy_rule = this->Makefile->AddCustomCommandToOutput( - outputs, no_byproducts, no_deps, no_main_dependency, - no_implicit_depends, commandLines, no_message, no_current_dir); - - if (copy_rule) { - target->AddSource(copy_rule->ResolveFullPath()); + cmCustomCommandLines commandLines; + cmCustomCommandLine currentLine; + currentLine.push_back(cmSystemTools::GetCMakeCommand()); + currentLine.push_back(cmStrCat("-DPDB_PREFIX=", pdb_prefix)); + currentLine.push_back("-P"); + currentLine.push_back(copy_script); + commandLines.push_back(std::move(currentLine)); + + const std::string no_main_dependency; + const std::vector<std::string> no_deps; + const char* no_message = ""; + const char* no_current_dir = nullptr; + std::vector<std::string> no_byproducts; + + std::vector<std::string> outputs; + outputs.push_back(cmStrCat(target_compile_pdb_dir, pdb_prefix, + pchReuseFrom, ".pdb")); + + if (this->GetGlobalGenerator()->IsMultiConfig()) { + this->Makefile->AddCustomCommandToTarget( + target->GetName(), outputs, no_deps, commandLines, + cmCustomCommandType::PRE_BUILD, no_message, no_current_dir); + } else { + cmImplicitDependsList no_implicit_depends; + cmSourceFile* copy_rule = + this->Makefile->AddCustomCommandToOutput( + outputs, no_byproducts, no_deps, no_main_dependency, + no_implicit_depends, commandLines, no_message, + no_current_dir); + + if (copy_rule) { + target->AddSource(copy_rule->ResolveFullPath()); + } } - } - target->Target->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY", - target_compile_pdb_dir.c_str()); - } + target->Target->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY", + target_compile_pdb_dir.c_str()); + } - std::string pchSourceObj = reuseTarget->GetPchFileObject(config, lang); + std::string pchSourceObj = + reuseTarget->GetPchFileObject(config, lang); - // Link to the pch object file - target->Target->SetProperty( - "LINK_FLAGS", - this->ConvertToOutputFormat(pchSourceObj, SHELL).c_str()); + // Link to the pch object file + target->Target->SetProperty( + "LINK_FLAGS", + this->ConvertToOutputFormat(pchSourceObj, SHELL).c_str()); - pchFile = replaceExtension(pchSourceObj, pchExtension); + pchFile = replaceExtension(pchSourceObj, pchExtension); + } + } else { + pchFile += pchExtension; + pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str()); } - } else { - pchFile += pchExtension; - pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str()); - } - // Add pchHeader to source files, which will - // be grouped as "Precompile Header File" - auto pchHeader_sf = this->Makefile->GetOrCreateSource( - pchHeader, false, cmSourceFileLocationKind::Known); - std::string err; - pchHeader_sf->ResolveFullPath(&err); - target->AddSource(pchHeader); - - for (auto& str : { std::ref(useOptionList), std::ref(createOptionList) }) { - cmSystemTools::ReplaceString(str, "<PCH_HEADER>", pchHeader); - cmSystemTools::ReplaceString(str, "<PCH_FILE>", pchFile); + // Add pchHeader to source files, which will + // be grouped as "Precompile Header File" + auto pchHeader_sf = this->Makefile->GetOrCreateSource( + pchHeader, false, cmSourceFileLocationKind::Known); + std::string err; + pchHeader_sf->ResolveFullPath(&err); + target->AddSource(pchHeader); + + for (auto& str : + { std::ref(useOptionList), std::ref(createOptionList) }) { + cmSystemTools::ReplaceString(str, "<PCH_HEADER>", pchHeader); + cmSystemTools::ReplaceString(str, "<PCH_FILE>", pchFile); + } } - } - pch_sf->SetProperty("COMPILE_OPTIONS", createOptionList.c_str()); + pch_sf->SetProperty("COMPILE_OPTIONS", createOptionList.c_str()); - std::vector<cmSourceFile*> sources; - target->GetSourceFiles(sources, buildType); - for (cmSourceFile* sf : sources) { - if (pch_sf == sf || sf->GetLanguage() != lang) { - continue; - } + for (cmSourceFile* sf : sources) { + if (pch_sf == sf || sf->GetLanguage() != lang) { + continue; + } - if (sf->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) { - if (this->GetGlobalGenerator()->IsXcode()) { - sf->SetProperty("COMPILE_DEFINITIONS", - "CMAKE_SKIP_PRECOMPILE_HEADERS"); + if (sf->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) { + if (this->GetGlobalGenerator()->IsXcode()) { + sf->SetProperty("COMPILE_DEFINITIONS", + "CMAKE_SKIP_PRECOMPILE_HEADERS"); + } + continue; } - continue; - } - if (!this->GetGlobalGenerator()->IsXcode()) { - sf->AppendProperty("OBJECT_DEPENDS", pchFile.c_str()); - sf->AppendProperty("OBJECT_DEPENDS", pchHeader.c_str()); - sf->SetProperty("COMPILE_OPTIONS", useOptionList.c_str()); + if (!this->GetGlobalGenerator()->IsXcode()) { + sf->AppendProperty("OBJECT_DEPENDS", pchFile.c_str()); + sf->AppendProperty("OBJECT_DEPENDS", pchHeader.c_str()); + sf->SetProperty("COMPILE_OPTIONS", useOptionList.c_str()); + } } } } -void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target, - const std::string& config) +void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) { if (!target->GetPropertyAsBool("UNITY_BUILD")) { return; } + // FIXME: Handle all configurations in multi-config generators. + std::string config; + if (!this->GetGlobalGenerator()->IsMultiConfig()) { + config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + } + const std::string buildType = cmSystemTools::UpperCase(config); std::string filename_base = diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index f150733..14d05ad 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -128,7 +128,7 @@ public: const std::string& rawFlag) const; void AddPchDependencies(cmGeneratorTarget* target, const std::string& config); - void AddUnityBuild(cmGeneratorTarget* target, const std::string& config); + void AddUnityBuild(cmGeneratorTarget* target); void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target, const std::string& config, const std::string& lang); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 6b0f802..e16e851 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1313,7 +1313,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, const std::string& libName, cmGeneratorTarget* target) { - this->AddUnityBuild(target, ""); this->AddPchDependencies(target, ""); std::vector<std::string> configs; diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 91bd47e..0b225cb 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -41,7 +41,6 @@ cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator( cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); - this->LocalGenerator->AddUnityBuild(target, this->ConfigName); this->LocalGenerator->AddPchDependencies(target, this->ConfigName); } diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index faa0d67..cf09374 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -43,7 +43,6 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator( cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); - this->LocalGenerator->AddUnityBuild(target, this->ConfigName); this->LocalGenerator->AddPchDependencies(target, this->ConfigName); } diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx index 47e2665..516f098 100644 --- a/Source/cmMakefileUtilityTargetGenerator.cxx +++ b/Source/cmMakefileUtilityTargetGenerator.cxx @@ -26,7 +26,6 @@ cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator( cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); - this->LocalGenerator->AddUnityBuild(target, this->ConfigName); this->LocalGenerator->AddPchDependencies(target, this->ConfigName); } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 38ccaa3..3f362fc 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -62,7 +62,6 @@ cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( cm::make_unique<cmOSXBundleGenerator>(target, this->GetConfigName()); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); - GetLocalGenerator()->AddUnityBuild(target, this->GetConfigName()); GetLocalGenerator()->AddPchDependencies(target, this->GetConfigName()); } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index d5f0c61..34556f9 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -251,7 +251,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() == this->Makefile->GetCurrentBinaryDirectory()); - this->LocalGenerator->AddUnityBuild(target, ""); this->LocalGenerator->AddPchDependencies(target, ""); } diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index ed20b91..32b580b 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -451,8 +451,8 @@ if(BUILD_TESTING) ADD_TEST_MACRO(StagingPrefix StagingPrefix) ADD_TEST_MACRO(ImportedSameName ImportedSameName) ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary) - if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") - set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + if(NOT _isMultiConfig) + set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=$<CONFIGURATION>) ADD_TEST_MACRO(ConfigSources ConfigSources) endif() ADD_TEST_MACRO(SourcesProperty SourcesProperty) diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt index 748aad8..f5dd276 100644 --- a/Tests/ConfigSources/CMakeLists.txt +++ b/Tests/ConfigSources/CMakeLists.txt @@ -1,17 +1,21 @@ - cmake_minimum_required(VERSION 3.0) - -project(ConfigSources) +project(ConfigSources CXX) add_library(iface INTERFACE) -set_property(TARGET iface PROPERTY INTERFACE_SOURCES +target_sources(iface INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/iface_src.cpp" "$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/iface_debug_src.cpp>" - "$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp>" -) + "$<$<NOT:$<CONFIG:Debug>>:${CMAKE_CURRENT_SOURCE_DIR}/iface_other_src.cpp>" + "$<$<CONFIG:NotAConfig>:${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp>" + ) +target_compile_definitions(iface INTERFACE + "$<$<CONFIG:Debug>:CFG_DEBUG>" + "$<$<NOT:$<CONFIG:Debug>>:CFG_OTHER>" + ) add_executable(ConfigSources - $<$<CONFIG:Debug>:main.cpp> - $<$<CONFIG:Release>:does_not_exist.cpp> -) + $<$<CONFIG:Debug>:main_debug.cpp> + $<$<NOT:$<CONFIG:Debug>>:main_other.cpp> + $<$<CONFIG:NotAConfig>:does_not_exist.cpp> + ) target_link_libraries(ConfigSources iface) diff --git a/Tests/ConfigSources/iface.h b/Tests/ConfigSources/iface.h new file mode 100644 index 0000000..810456c --- /dev/null +++ b/Tests/ConfigSources/iface.h @@ -0,0 +1,10 @@ + +int iface_src(); + +#ifdef CFG_DEBUG +int iface_debug(); +#endif + +#ifdef CFG_OTHER +int iface_other(); +#endif diff --git a/Tests/ConfigSources/iface_debug.h b/Tests/ConfigSources/iface_debug.h deleted file mode 100644 index a23d737..0000000 --- a/Tests/ConfigSources/iface_debug.h +++ /dev/null @@ -1,4 +0,0 @@ - -int iface_src(); - -int iface_debug(); diff --git a/Tests/ConfigSources/iface_debug_src.cpp b/Tests/ConfigSources/iface_debug_src.cpp index 63b22fc..010059f 100644 --- a/Tests/ConfigSources/iface_debug_src.cpp +++ b/Tests/ConfigSources/iface_debug_src.cpp @@ -1,5 +1,11 @@ +#ifndef CFG_DEBUG +# error "This source should only be compiled in a Debug configuration." +#endif +#ifdef CFG_OTHER +# error "This source should not be compiled in a non-Debug configuration." +#endif -#include "iface_debug.h" +#include "iface.h" int iface_debug() { diff --git a/Tests/ConfigSources/iface_other_src.cpp b/Tests/ConfigSources/iface_other_src.cpp new file mode 100644 index 0000000..8ffdfbb --- /dev/null +++ b/Tests/ConfigSources/iface_other_src.cpp @@ -0,0 +1,13 @@ +#ifndef CFG_OTHER +# error "This source should only be compiled in a non-Debug configuration." +#endif +#ifdef CFG_DEBUG +# error "This source should not be compiled in a Debug configuration." +#endif + +#include "iface.h" + +int iface_other() +{ + return 0; +} diff --git a/Tests/ConfigSources/main.cpp b/Tests/ConfigSources/main.cpp deleted file mode 100644 index 71af72f..0000000 --- a/Tests/ConfigSources/main.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -#include "iface_debug.h" - -int main(int argc, char** argv) -{ - return iface_src() + iface_debug(); -} diff --git a/Tests/ConfigSources/main_debug.cpp b/Tests/ConfigSources/main_debug.cpp new file mode 100644 index 0000000..9b1e68a --- /dev/null +++ b/Tests/ConfigSources/main_debug.cpp @@ -0,0 +1,13 @@ +#ifndef CFG_DEBUG +# error "This source should only be compiled in a Debug configuration." +#endif +#ifdef CFG_OTHER +# error "This source should not be compiled in a non-Debug configuration." +#endif + +#include "iface.h" + +int main(int argc, char** argv) +{ + return iface_src() + iface_debug(); +} diff --git a/Tests/ConfigSources/main_other.cpp b/Tests/ConfigSources/main_other.cpp new file mode 100644 index 0000000..3184a19 --- /dev/null +++ b/Tests/ConfigSources/main_other.cpp @@ -0,0 +1,13 @@ +#ifndef CFG_OTHER +# error "This source should only be compiled in a non-Debug configuration." +#endif +#ifdef CFG_DEBUG +# error "This source should not be compiled in a Debug configuration." +#endif + +#include "iface.h" + +int main(int argc, char** argv) +{ + return iface_src() + iface_other(); +} diff --git a/Tests/RunCMake/PrecompileHeaders/DisabledPch-check.cmake b/Tests/RunCMake/PrecompileHeaders/DisabledPch-check.cmake index fa37c2c..8cf0fc9 100644 --- a/Tests/RunCMake/PrecompileHeaders/DisabledPch-check.cmake +++ b/Tests/RunCMake/PrecompileHeaders/DisabledPch-check.cmake @@ -1,17 +1,17 @@ if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) - set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/CMakeFiles/foo.dir/cmake_pch.h") - set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.h") + set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/CMakeFiles/foo.dir/cmake_pch.h") + set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.h") else() - set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/cmake_pch.h") - set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h") + set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/cmake_pch.h") + set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h") endif() if (NOT EXISTS ${foo_pch_header}) - set(RunCMake_TEST_FAILED "Generated foo pch header ${foo_pch_header} does not exist") - return() + set(RunCMake_TEST_FAILED "Generated foo pch header ${foo_pch_header} does not exist") + return() endif() if (EXISTS ${foobar_pch_header}) - set(RunCMake_TEST_FAILED "Generated foobar pch header ${foobar_pch_header} should not exist") - return() + set(RunCMake_TEST_FAILED "Generated foobar pch header ${foobar_pch_header} should not exist") + return() endif() diff --git a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake new file mode 100644 index 0000000..44fe2da --- /dev/null +++ b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake @@ -0,0 +1,17 @@ +if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(foobar_pch_h_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.h") + set(foobar_pch_hxx_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.hxx") +else() + set(foobar_pch_h_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h") + set(foobar_pch_hxx_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.hxx") +endif() + +if (NOT EXISTS ${foobar_pch_h_header}) + set(RunCMake_TEST_FAILED "Generated foobar C pch header ${foobar_pch_h_header} does not exist") + return() +endif() + +if (NOT EXISTS ${foobar_pch_hxx_header}) + set(RunCMake_TEST_FAILED "Generated foobar C++ pch header ${foobar_pch_hxx_header} does not exist") + return() +endif() diff --git a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake new file mode 100644 index 0000000..7a837da --- /dev/null +++ b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) +project(PchMultilanguage C CXX) + +add_executable(foobar + foo.c + main.cpp +) +target_include_directories(foobar PUBLIC include) +target_precompile_headers(foobar PRIVATE "<stddef.h>") diff --git a/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue-check.cmake b/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue-check.cmake index fd82607..ba220f3 100644 --- a/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue-check.cmake +++ b/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue-check.cmake @@ -1,7 +1,7 @@ if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) - set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/CMakeFiles/main.dir/cmake_pch.hxx") + set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/CMakeFiles/main.dir/cmake_pch.hxx") else() - set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/cmake_pch.hxx") + set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/cmake_pch.hxx") endif() file(STRINGS ${main_pch_header} main_pch_header_strings) diff --git a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake index bd3b1b8..ec13663 100644 --- a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake +++ b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake @@ -18,3 +18,4 @@ run_cmake(PchPrologueEpilogue) run_test(SkipPrecompileHeaders) run_test(PchReuseFrom) run_test(PchReuseFromSubdir) +run_cmake(PchMultilanguage) |