summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-08-29 13:37:26 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-08-29 13:38:21 (GMT)
commitfa36e2151d25358c7946a53c4440f0487210770d (patch)
tree8909e40db9d7a8c54ea047d5ea6d92f2592a3264 /Source/cmLocalGenerator.cxx
parent030570d71ff8b15a7242203f2638d3b77af755b9 (diff)
parent8da78d4efe0e4d0ef8708ecd94cf886c3f7d9ae4 (diff)
downloadCMake-fa36e2151d25358c7946a53c4440f0487210770d.zip
CMake-fa36e2151d25358c7946a53c4440f0487210770d.tar.gz
CMake-fa36e2151d25358c7946a53c4440f0487210770d.tar.bz2
Merge topic 'precompile-headers'
8da78d4efe Precompile headers: Update documentation 5772930164 Precompile headers: Add unit tests 519606704e Precompile headers: Add support for Visual Studio generators 28be170fbc Precompile headers: Add support for Xcode generator b8626261e9 Precompile headers: Add methods to generate PCH sources 375d01c680 PCH: add example/test 9b6797e71d PCH: add target_precompile_headers command 0467a2f91b PCH: add PRECOMPILE_HEADERS to special properties Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Daniel Pfeifer <daniel@pfeifer-mail.de> Acked-by: Ivan171 <heavenandhell171@gmail.com> Acked-by: Stanislav Ershov <digital.stream.of.mind@gmail.com> Acked-by: Steve Mokris <smokris@softpixel.com> Acked-by: Evgeniy Dushistov <dushistov@mail.ru> Acked-by: Danila Malyutin <flashmozzg@gmail.com> Acked-by: Viktor Kirilov <vik.kirilov@gmail.com> Acked-by: Lucas Zhao <zhaopf6@163.com> Merge-request: !3553
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx83
1 files changed, 83 insertions, 0 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 2e40543..7177694 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -18,6 +18,7 @@
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
+#include "cmSourceFileLocationKind.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
@@ -37,6 +38,7 @@
#include <algorithm>
#include <assert.h>
+#include <functional>
#include <initializer_list>
#include <iterator>
#include <memory>
@@ -2124,6 +2126,82 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags,
this->AppendFlags(flags, this->EscapeForShell(rawFlag));
}
+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;
+ }
+
+ const std::string createOptVar =
+ cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_CREATE_PCH");
+ std::string createOptionList =
+ this->Makefile->GetSafeDefinition(createOptVar);
+
+ const std::string useOptVar =
+ cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_USE_PCH");
+ std::string useOptionList = this->Makefile->GetSafeDefinition(useOptVar);
+
+ const std::string pchExtension =
+ this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION");
+
+ if (createOptionList.empty() || useOptionList.empty() ||
+ pchExtension.empty()) {
+ return;
+ }
+
+ auto pch_sf = this->Makefile->GetOrCreateSource(
+ pchSource, false, cmSourceFileLocationKind::Known);
+ std::string pchFile = pchHeader;
+
+ if (!this->GetGlobalGenerator()->IsXcode()) {
+ // Exclude the pch files from linking
+ if (this->Makefile->IsOn("CMAKE_LINK_PCH")) {
+ cmSystemTools::ReplaceString(pchFile, (lang == "C" ? ".h" : ".hxx"),
+ pchExtension);
+ pch_sf->SetProperty("OBJECT_OUTPUTS", pchFile.c_str());
+ } else {
+ pchFile += pchExtension;
+ pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str());
+ }
+
+ target->AddSource(pchSource, true);
+
+ 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());
+
+ std::vector<cmSourceFile*> sources;
+ target->GetSourceFiles(sources, buildType);
+ 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");
+ }
+ continue;
+ }
+
+ if (!this->GetGlobalGenerator()->IsXcode()) {
+ sf->SetProperty("OBJECT_DEPENDS", pchFile.c_str());
+ sf->SetProperty("COMPILE_OPTIONS", useOptionList.c_str());
+ }
+ }
+}
+
void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags,
cmGeneratorTarget* target,
const std::string& config,
@@ -2716,6 +2794,11 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
}
}
+ const char* pchExtension = source.GetProperty("PCH_EXTENSION");
+ if (pchExtension) {
+ customOutputExtension = pchExtension;
+ }
+
// Remove the source extension if it is to be replaced.
if (replaceExt || customOutputExtension) {
keptSourceExtension = false;