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/CursesDialog/CMakeLists.txt36
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.cxx81
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.h17
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx174
-rw-r--r--Source/CursesDialog/cmCursesMainForm.h13
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.cxx32
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.h5
-rw-r--r--Source/cmAddCustomCommandCommand.cxx10
-rw-r--r--Source/cmAddCustomTargetCommand.cxx3
-rw-r--r--Source/cmCPluginAPI.cxx14
-rw-r--r--Source/cmCommands.cxx27
-rw-r--r--Source/cmCustomCommandTypes.h39
-rw-r--r--Source/cmFileAPICodemodel.cxx66
-rw-r--r--Source/cmGlobalGenerator.cxx2
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx20
-rw-r--r--Source/cmGlobalVisualStudioGenerator.cxx7
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx23
-rw-r--r--Source/cmLocalGenerator.cxx3
-rw-r--r--Source/cmMakefile.cxx298
-rw-r--r--Source/cmMakefile.h85
-rw-r--r--Source/cmQtAutoGenGlobalInitializer.cxx3
-rw-r--r--Source/cmQtAutoGenInitializer.cxx10
-rw-r--r--Source/cmSourceFile.cxx78
-rw-r--r--Source/cmSourceFile.h22
-rw-r--r--Source/cmTarget.cxx15
-rw-r--r--Source/cmTarget.h10
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.cxx70
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.h34
-rw-r--r--Source/cmTargetCompileFeaturesCommand.cxx65
-rw-r--r--Source/cmTargetCompileFeaturesCommand.h26
-rw-r--r--Source/cmTargetCompileOptionsCommand.cxx56
-rw-r--r--Source/cmTargetCompileOptionsCommand.h34
-rw-r--r--Source/cmTargetIncludeDirectoriesCommand.cxx57
-rw-r--r--Source/cmTargetIncludeDirectoriesCommand.h38
-rw-r--r--Source/cmTargetLinkDirectoriesCommand.cxx53
-rw-r--r--Source/cmTargetLinkDirectoriesCommand.h34
-rw-r--r--Source/cmTargetLinkOptionsCommand.cxx55
-rw-r--r--Source/cmTargetLinkOptionsCommand.h34
-rw-r--r--Source/cmTargetPrecompileHeadersCommand.cxx98
-rw-r--r--Source/cmTargetPrecompileHeadersCommand.h38
-rw-r--r--Source/cmTargetPropCommandBase.cxx12
-rw-r--r--Source/cmTargetPropCommandBase.h14
-rw-r--r--Source/cmTargetSourcesCommand.cxx81
-rw-r--r--Source/cmTargetSourcesCommand.h44
46 files changed, 981 insertions, 960 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 71a7dbd..4e3e842 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -195,6 +195,7 @@ set(SRCS
cmCustomCommandGenerator.h
cmCustomCommandLines.cxx
cmCustomCommandLines.h
+ cmCustomCommandTypes.h
cmDefinitions.cxx
cmDefinitions.h
cmDepends.cxx
@@ -1144,7 +1145,7 @@ target_link_libraries(cpack CPackLib)
# Curses GUI
if(BUILD_CursesDialog)
- include(${CMake_SOURCE_DIR}/Source/CursesDialog/CMakeLists.txt)
+ add_subdirectory(CursesDialog)
endif()
# Qt GUI
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index d9ca09b..2196243 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 20190927)
+set(CMake_VERSION_PATCH 20190930)
#set(CMake_VERSION_RC 0)
set(CMake_VERSION_IS_DIRTY 0)
diff --git a/Source/CursesDialog/CMakeLists.txt b/Source/CursesDialog/CMakeLists.txt
index 270b07e..7009717 100644
--- a/Source/CursesDialog/CMakeLists.txt
+++ b/Source/CursesDialog/CMakeLists.txt
@@ -1,26 +1,22 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-set( CURSES_SRCS
- CursesDialog/cmCursesOptionsWidget.cxx
- CursesDialog/cmCursesBoolWidget.cxx
- CursesDialog/cmCursesCacheEntryComposite.cxx
- CursesDialog/cmCursesDummyWidget.cxx
- CursesDialog/cmCursesFilePathWidget.cxx
- CursesDialog/cmCursesForm.cxx
- CursesDialog/cmCursesLabelWidget.cxx
- CursesDialog/cmCursesLongMessageForm.cxx
- CursesDialog/cmCursesMainForm.cxx
- CursesDialog/cmCursesPathWidget.cxx
- CursesDialog/cmCursesStringWidget.cxx
- CursesDialog/cmCursesWidget.cxx
- CursesDialog/ccmake.cxx
- )
-
-include_directories(${CURSES_INCLUDE_PATH})
-
-
-add_executable(ccmake ${CURSES_SRCS} )
+add_executable(ccmake
+ ccmake.cxx
+ cmCursesBoolWidget.cxx
+ cmCursesCacheEntryComposite.cxx
+ cmCursesDummyWidget.cxx
+ cmCursesFilePathWidget.cxx
+ cmCursesForm.cxx
+ cmCursesLabelWidget.cxx
+ cmCursesLongMessageForm.cxx
+ cmCursesMainForm.cxx
+ cmCursesOptionsWidget.cxx
+ cmCursesPathWidget.cxx
+ cmCursesStringWidget.cxx
+ cmCursesWidget.cxx
+ )
+target_include_directories(ccmake PRIVATE ${CURSES_INCLUDE_PATH})
target_link_libraries(ccmake CMakeLib)
if(CMAKE_USE_SYSTEM_FORM)
find_path(CURSES_FORM_INCLUDE_DIR NAMES form.h HINTS ${CURSES_INCLUDE_PATH} ${CURSES_INCLUDE_PATH}/ncurses)
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
index 47fe84c..561784c 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
@@ -13,9 +13,11 @@
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
-#include "cmake.h"
+
+#include <cm/memory>
#include <cassert>
+#include <utility>
#include <vector>
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
@@ -24,61 +26,65 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
, LabelWidth(labelwidth)
, EntryWidth(entrywidth)
{
- this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
- this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
- this->Entry = nullptr;
- this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
+ this->Label =
+ cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
+ this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
+ this->Entry =
+ cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
}
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
- const std::string& key, cmake* cm, bool isNew, int labelwidth,
+ const std::string& key, cmState* state, bool isNew, int labelwidth,
int entrywidth)
: Key(key)
, LabelWidth(labelwidth)
, EntryWidth(entrywidth)
{
- this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
+ this->Label =
+ cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
if (isNew) {
- this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
+ this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, "*");
} else {
- this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
+ this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
}
- this->Entry = nullptr;
- const char* value = cm->GetState()->GetCacheEntryValue(key);
+ const char* value = state->GetCacheEntryValue(key);
assert(value);
- switch (cm->GetState()->GetCacheEntryType(key)) {
- case cmStateEnums::BOOL:
- this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
- if (cmIsOn(value)) {
- static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
- } else {
- static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
- }
+ switch (state->GetCacheEntryType(key)) {
+ case cmStateEnums::BOOL: {
+ auto bw = cm::make_unique<cmCursesBoolWidget>(this->EntryWidth, 1, 1, 1);
+ bw->SetValueAsBool(cmIsOn(value));
+ this->Entry = std::move(bw);
break;
- case cmStateEnums::PATH:
- this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
- static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
+ }
+ case cmStateEnums::PATH: {
+ auto pw = cm::make_unique<cmCursesPathWidget>(this->EntryWidth, 1, 1, 1);
+ pw->SetString(value);
+ this->Entry = std::move(pw);
break;
- case cmStateEnums::FILEPATH:
- this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
- static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
+ }
+ case cmStateEnums::FILEPATH: {
+ auto fpw =
+ cm::make_unique<cmCursesFilePathWidget>(this->EntryWidth, 1, 1, 1);
+ fpw->SetString(value);
+ this->Entry = std::move(fpw);
break;
+ }
case cmStateEnums::STRING: {
- const char* stringsProp =
- cm->GetState()->GetCacheEntryProperty(key, "STRINGS");
+ const char* stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProp) {
- cmCursesOptionsWidget* ow =
- new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
- this->Entry = ow;
- std::vector<std::string> options = cmExpandedList(stringsProp);
- for (auto const& opt : options) {
+ auto ow =
+ cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1);
+ for (std::string const& opt : cmExpandedList(stringsProp)) {
ow->AddOption(opt);
}
ow->SetOption(value);
+ this->Entry = std::move(ow);
} else {
- this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
- static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
+ auto sw =
+ cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
+ sw->SetString(value);
+ this->Entry = std::move(sw);
}
break;
}
@@ -91,12 +97,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
}
}
-cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
-{
- delete this->Label;
- delete this->IsNewLabel;
- delete this->Entry;
-}
+cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() = default;
const char* cmCursesCacheEntryComposite::GetValue()
{
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h
index 0a69d3a..a711363 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.h
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h
@@ -5,33 +5,38 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include <memory>
#include <string>
class cmCursesLabelWidget;
class cmCursesWidget;
-class cmake;
+class cmState;
class cmCursesCacheEntryComposite
{
public:
cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
int entrywidth);
- cmCursesCacheEntryComposite(const std::string& key, cmake* cm, bool isNew,
- int labelwidth, int entrywidth);
+ cmCursesCacheEntryComposite(const std::string& key, cmState* state,
+ bool isNew, int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite();
cmCursesCacheEntryComposite(cmCursesCacheEntryComposite const&) = delete;
cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite const&) =
delete;
+ cmCursesCacheEntryComposite(cmCursesCacheEntryComposite&&) = default;
+ cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite&&) =
+ default;
+
const char* GetValue();
friend class cmCursesMainForm;
protected:
- cmCursesLabelWidget* Label;
- cmCursesLabelWidget* IsNewLabel;
- cmCursesWidget* Entry;
+ std::unique_ptr<cmCursesLabelWidget> Label;
+ std::unique_ptr<cmCursesLabelWidget> IsNewLabel;
+ std::unique_ptr<cmCursesWidget> Entry;
std::string Key;
int LabelWidth;
int EntryWidth;
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 5f8a19e..219771b 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesMainForm.h"
-#include "cmAlgorithms.h"
#include "cmCursesCacheEntryComposite.h"
#include "cmCursesDummyWidget.h"
#include "cmCursesForm.h"
@@ -18,6 +17,8 @@
#include "cmVersion.h"
#include "cmake.h"
+#include <cm/memory>
+
#include <algorithm>
#include <cstdio>
#include <cstring>
@@ -34,8 +35,6 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args,
, InitialWidth(initWidth)
{
this->NumberOfPages = 0;
- this->Fields = nullptr;
- this->Entries = nullptr;
this->AdvancedMode = false;
this->NumberOfVisibleEntries = 0;
this->OkToGenerate = false;
@@ -43,7 +42,8 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args,
"Welcome to ccmake, curses based user interface for CMake.");
this->HelpMessage.emplace_back();
this->HelpMessage.emplace_back(s_ConstHelpMessage);
- this->CMakeInstance = new cmake(cmake::RoleProject, cmState::Project);
+ this->CMakeInstance =
+ cm::make_unique<cmake>(cmake::RoleProject, cmState::Project);
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeCursesCommand());
@@ -52,8 +52,6 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args,
cmStrCat(cmSystemTools::GetProgramPath(this->Args[0]), "/cmake");
this->Args[0] = whereCMake;
this->CMakeInstance->SetArgs(this->Args);
- this->SearchString = "";
- this->OldSearchString = "";
this->SearchMode = false;
}
@@ -64,27 +62,15 @@ cmCursesMainForm::~cmCursesMainForm()
free_form(this->Form);
this->Form = nullptr;
}
- delete[] this->Fields;
-
- // Clean-up composites
- if (this->Entries) {
- cmDeleteAll(*this->Entries);
- }
- delete this->Entries;
- if (this->CMakeInstance) {
- delete this->CMakeInstance;
- this->CMakeInstance = nullptr;
- }
}
// See if a cache entry is in the list of entries in the ui.
bool cmCursesMainForm::LookForCacheEntry(const std::string& key)
{
- return this->Entries &&
- std::any_of(this->Entries->begin(), this->Entries->end(),
- [&key](cmCursesCacheEntryComposite* entry) {
- return key == entry->Key;
- });
+ return std::any_of(this->Entries.begin(), this->Entries.end(),
+ [&key](cmCursesCacheEntryComposite const& entry) {
+ return key == entry.Key;
+ });
}
// Create new cmCursesCacheEntryComposite entries from the cache
@@ -92,11 +78,10 @@ void cmCursesMainForm::InitializeUI()
{
// Create a vector of cmCursesCacheEntryComposite's
// which contain labels, entries and new entry markers
- std::vector<cmCursesCacheEntryComposite*>* newEntries =
- new std::vector<cmCursesCacheEntryComposite*>;
+ std::vector<cmCursesCacheEntryComposite> newEntries;
std::vector<std::string> cacheKeys =
this->CMakeInstance->GetState()->GetCacheEntryKeys();
- newEntries->reserve(cacheKeys.size());
+ newEntries.reserve(cacheKeys.size());
// Count non-internal and non-static entries
int count = 0;
@@ -112,13 +97,12 @@ void cmCursesMainForm::InitializeUI()
int entrywidth = this->InitialWidth - 35;
- cmCursesCacheEntryComposite* comp;
if (count == 0) {
// If cache is empty, display a label saying so and a
// dummy entry widget (does not respond to input)
- comp = new cmCursesCacheEntryComposite("EMPTY CACHE", 30, 30);
- comp->Entry = new cmCursesDummyWidget(1, 1, 1, 1);
- newEntries->push_back(comp);
+ cmCursesCacheEntryComposite comp("EMPTY CACHE", 30, 30);
+ comp.Entry = cm::make_unique<cmCursesDummyWidget>(1, 1, 1, 1);
+ newEntries.emplace_back(std::move(comp));
} else {
// Create the composites.
@@ -132,8 +116,8 @@ void cmCursesMainForm::InitializeUI()
}
if (!this->LookForCacheEntry(key)) {
- newEntries->push_back(new cmCursesCacheEntryComposite(
- key, this->CMakeInstance, true, 30, entrywidth));
+ newEntries.emplace_back(key, this->CMakeInstance->GetState(), true, 30,
+ entrywidth);
this->OkToGenerate = false;
}
}
@@ -148,18 +132,14 @@ void cmCursesMainForm::InitializeUI()
}
if (this->LookForCacheEntry(key)) {
- newEntries->push_back(new cmCursesCacheEntryComposite(
- key, this->CMakeInstance, false, 30, entrywidth));
+ newEntries.emplace_back(key, this->CMakeInstance->GetState(), false,
+ 30, entrywidth);
}
}
}
- // Clean old entries
- if (this->Entries) {
- cmDeleteAll(*this->Entries);
- }
- delete this->Entries;
- this->Entries = newEntries;
+ // Replace old entries
+ this->Entries = std::move(newEntries);
// Compute fields from composites
this->RePost();
@@ -173,18 +153,18 @@ void cmCursesMainForm::RePost()
free_form(this->Form);
this->Form = nullptr;
}
- delete[] this->Fields;
+ this->Fields.clear();
if (this->AdvancedMode) {
- this->NumberOfVisibleEntries = this->Entries->size();
+ this->NumberOfVisibleEntries = this->Entries.size();
} else {
// If normal mode, count only non-advanced entries
this->NumberOfVisibleEntries = 0;
- for (cmCursesCacheEntryComposite* entry : *this->Entries) {
+ for (cmCursesCacheEntryComposite& entry : this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- entry->GetValue(), "ADVANCED");
+ entry.GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
@@ -197,38 +177,32 @@ void cmCursesMainForm::RePost()
}
// Assign the fields: 3 for each entry: label, new entry marker
// ('*' or ' ') and entry widget
- this->Fields = new FIELD*[3 * this->NumberOfVisibleEntries + 1];
- size_t cc;
- for (cc = 0; cc < 3 * this->NumberOfVisibleEntries + 1; cc++) {
- this->Fields[cc] = nullptr;
- }
+ this->Fields.reserve(3 * this->NumberOfVisibleEntries + 1);
// Assign fields
- int j = 0;
- for (cmCursesCacheEntryComposite* entry : *this->Entries) {
+ for (cmCursesCacheEntryComposite& entry : this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- entry->GetValue(), "ADVANCED");
+ entry.GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
- this->Fields[3 * j] = entry->Label->Field;
- this->Fields[3 * j + 1] = entry->IsNewLabel->Field;
- this->Fields[3 * j + 2] = entry->Entry->Field;
- j++;
+ this->Fields.push_back(entry.Label->Field);
+ this->Fields.push_back(entry.IsNewLabel->Field);
+ this->Fields.push_back(entry.Entry->Field);
}
// if no cache entries there should still be one dummy field
- if (j == 0) {
- const auto& front = *this->Entries->front();
- this->Fields[0] = front.Label->Field;
- this->Fields[1] = front.IsNewLabel->Field;
- this->Fields[2] = front.Entry->Field;
+ if (this->Fields.empty()) {
+ const auto& front = this->Entries.front();
+ this->Fields.push_back(front.Label->Field);
+ this->Fields.push_back(front.IsNewLabel->Field);
+ this->Fields.push_back(front.Entry->Field);
this->NumberOfVisibleEntries = 1;
}
// Has to be null terminated.
- this->Fields[3 * this->NumberOfVisibleEntries] = nullptr;
+ this->Fields.push_back(nullptr);
}
void cmCursesMainForm::Render(int left, int top, int width, int height)
@@ -261,16 +235,16 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
height -= 7;
if (this->AdvancedMode) {
- this->NumberOfVisibleEntries = this->Entries->size();
+ this->NumberOfVisibleEntries = this->Entries.size();
} else {
// If normal, display only non-advanced entries
this->NumberOfVisibleEntries = 0;
- for (cmCursesCacheEntryComposite* entry : *this->Entries) {
+ for (cmCursesCacheEntryComposite& entry : this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- entry->GetValue(), "ADVANCED");
+ entry.GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
@@ -283,12 +257,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
if (height > 0) {
bool isNewPage;
int i = 0;
- for (cmCursesCacheEntryComposite* entry : *this->Entries) {
+ for (cmCursesCacheEntryComposite& entry : this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- entry->GetValue(), "ADVANCED");
+ entry.GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
@@ -299,16 +273,16 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
if (isNewPage) {
this->NumberOfPages++;
}
- entry->Label->Move(left, top + row - 1, isNewPage);
- entry->IsNewLabel->Move(left + 32, top + row - 1, false);
- entry->Entry->Move(left + 33, top + row - 1, false);
- entry->Entry->SetPage(this->NumberOfPages);
+ entry.Label->Move(left, top + row - 1, isNewPage);
+ entry.IsNewLabel->Move(left + 32, top + row - 1, false);
+ entry.Entry->Move(left + 33, top + row - 1, false);
+ entry.Entry->SetPage(this->NumberOfPages);
i++;
}
}
// Post the form
- this->Form = new_form(this->Fields);
+ this->Form = new_form(this->Fields.data());
post_form(this->Form);
// Update toolbar
this->UpdateStatusBar();
@@ -655,28 +629,28 @@ void cmCursesMainForm::RemoveEntry(const char* value)
}
auto removeIt =
- std::find_if(this->Entries->begin(), this->Entries->end(),
- [value](cmCursesCacheEntryComposite* entry) -> bool {
- const char* val = entry->GetValue();
+ std::find_if(this->Entries.begin(), this->Entries.end(),
+ [value](cmCursesCacheEntryComposite& entry) -> bool {
+ const char* val = entry.GetValue();
return val != nullptr && !strcmp(value, val);
});
- if (removeIt != this->Entries->end()) {
+ if (removeIt != this->Entries.end()) {
this->CMakeInstance->UnwatchUnusedCli(value);
- this->Entries->erase(removeIt);
+ this->Entries.erase(removeIt);
}
}
// copy from the list box to the cache manager
void cmCursesMainForm::FillCacheManagerFromUI()
{
- for (cmCursesCacheEntryComposite* entry : *this->Entries) {
- const std::string& cacheKey = entry->Key;
+ for (cmCursesCacheEntryComposite& entry : this->Entries) {
+ const std::string& cacheKey = entry.Key;
const char* existingValue =
this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey);
if (existingValue) {
std::string oldValue = existingValue;
- std::string newValue = entry->Entry->GetValue();
+ std::string newValue = entry.Entry->GetValue();
std::string fixedOldValue;
std::string fixedNewValue;
cmStateEnums::CacheEntryType t =
@@ -762,7 +736,7 @@ void cmCursesMainForm::HandleInput()
this->JumpToCacheEntry(this->SearchString.c_str());
this->OldSearchString = this->SearchString;
}
- this->SearchString = "";
+ this->SearchString.clear();
}
/*
else if ( key == KEY_ESCAPE )
@@ -778,7 +752,7 @@ void cmCursesMainForm::HandleInput()
}
} else if (key == ctrl('h') || key == KEY_BACKSPACE || key == KEY_DC) {
if (!this->SearchString.empty()) {
- this->SearchString.resize(this->SearchString.size() - 1);
+ this->SearchString.pop_back();
}
}
} else if (currentWidget && !this->SearchMode) {
@@ -867,17 +841,9 @@ void cmCursesMainForm::HandleInput()
curField, "HELPSTRING");
}
if (helpString) {
- char* message = new char
- [strlen(curField) + strlen(helpString) +
- strlen(
- "Current option is: \n Help string for this option is: \n") +
- 10];
- sprintf(
- message,
- "Current option is: %s\nHelp string for this option is: %s\n",
- curField, helpString);
- this->HelpMessage[1] = message;
- delete[] message;
+ this->HelpMessage[1] =
+ cmStrCat("Current option is: ", curField, '\n',
+ "Help string for this option is: ", helpString, '\n');
} else {
this->HelpMessage[1] = "";
}
@@ -973,14 +939,14 @@ void cmCursesMainForm::HandleInput()
if (nextCur) {
// make the next or prev. current field after deletion
- auto nextEntryIt =
- std::find_if(this->Entries->begin(), this->Entries->end(),
- [&nextVal](cmCursesCacheEntryComposite* entry) {
- return nextVal == entry->Key;
- });
-
- if (nextEntryIt != this->Entries->end()) {
- set_current_field(this->Form, (*nextEntryIt)->Entry->Field);
+ auto nextEntryIt = std::find_if(
+ this->Entries.begin(), this->Entries.end(),
+ [&nextVal](cmCursesCacheEntryComposite const& entry) {
+ return nextVal == entry.Key;
+ });
+
+ if (nextEntryIt != this->Entries.end()) {
+ set_current_field(this->Form, nextEntryIt->Entry->Field);
}
}
}
diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h
index f3194ab..48d1791 100644
--- a/Source/CursesDialog/cmCursesMainForm.h
+++ b/Source/CursesDialog/cmCursesMainForm.h
@@ -5,15 +5,16 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmCursesCacheEntryComposite.h"
#include "cmCursesForm.h"
#include "cmCursesStandardIncludes.h"
#include "cmStateTypes.h"
#include <cstddef>
+#include <memory>
#include <string>
#include <vector>
-class cmCursesCacheEntryComposite;
class cmake;
/** \class cmCursesMainForm
@@ -122,7 +123,7 @@ protected:
void JumpToCacheEntry(const char* str);
// Copies of cache entries stored in the user interface
- std::vector<cmCursesCacheEntryComposite*>* Entries;
+ std::vector<cmCursesCacheEntryComposite> Entries;
// Errors produced during last run of cmake
std::vector<std::string> Errors;
// Command line arguments to be passed to cmake each time
@@ -136,11 +137,7 @@ protected:
static const char* s_ConstHelpMessage;
// Fields displayed. Includes labels, new entry markers, entries
- FIELD** Fields;
- // Where is source of current project
- std::string WhereSource;
- // Where is cmake executable
- std::string WhereCMake;
+ std::vector<FIELD*> Fields;
// Number of entries shown (depends on mode -normal or advanced-)
size_t NumberOfVisibleEntries;
bool AdvancedMode;
@@ -150,7 +147,7 @@ protected:
int NumberOfPages;
int InitialWidth;
- cmake* CMakeInstance;
+ std::unique_ptr<cmake> CMakeInstance;
std::string SearchString;
std::string OldSearchString;
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx
index 3fc1858..d3a05e8 100644
--- a/Source/CursesDialog/cmCursesStringWidget.cxx
+++ b/Source/CursesDialog/cmCursesStringWidget.cxx
@@ -9,7 +9,6 @@
#include "cmStateTypes.h"
#include <cstdio>
-#include <cstring>
inline int ctrl(int z)
{
@@ -35,13 +34,13 @@ void cmCursesStringWidget::OnTab(cmCursesMainForm* /*unused*/,
void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/)
{
- FORM* form = fm->GetForm();
if (this->InEdit) {
cmCursesForm::LogMessage("String widget leaving edit.");
this->InEdit = false;
fm->PrintKeys();
- delete[] this->OriginalString;
+ this->OriginalString.clear();
// trick to force forms to update the field buffer
+ FORM* form = fm->GetForm();
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
this->Done = true;
@@ -49,9 +48,7 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/)
cmCursesForm::LogMessage("String widget entering edit.");
this->InEdit = true;
fm->PrintKeys();
- char* buf = field_buffer(this->Field, 0);
- this->OriginalString = new char[strlen(buf) + 1];
- strcpy(this->OriginalString, buf);
+ this->OriginalString = field_buffer(this->Field, 0);
}
}
@@ -75,7 +72,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
return false;
}
- this->OriginalString = nullptr;
+ this->OriginalString.clear();
this->Done = false;
char debugMessage[128];
@@ -113,7 +110,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') ||
key == KEY_PPAGE || key == ctrl('u')) {
this->InEdit = false;
- delete[] this->OriginalString;
+ this->OriginalString.clear();
// trick to force forms to update the field buffer
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
@@ -125,7 +122,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
this->InEdit = false;
fm->PrintKeys();
this->SetString(this->OriginalString);
- delete[] this->OriginalString;
+ this->OriginalString.clear();
touchwin(w);
wrefresh(w);
return true;
@@ -188,23 +185,18 @@ bool cmCursesStringWidget::PrintKeys()
}
if (this->InEdit) {
char fmt_s[] = "%s";
- char firstLine[512];
// Clean the toolbar
- memset(firstLine, ' ', sizeof(firstLine));
- firstLine[511] = '\0';
curses_move(y - 4, 0);
- printw(fmt_s, firstLine);
- curses_move(y - 3, 0);
- printw(fmt_s, firstLine);
- curses_move(y - 2, 0);
- printw(fmt_s, firstLine);
- curses_move(y - 1, 0);
- printw(fmt_s, firstLine);
-
+ clrtoeol();
curses_move(y - 3, 0);
printw(fmt_s, "Editing option, press [enter] to confirm");
+ clrtoeol();
curses_move(y - 2, 0);
printw(fmt_s, " press [esc] to cancel");
+ clrtoeol();
+ curses_move(y - 1, 0);
+ clrtoeol();
+
return true;
}
return false;
diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h
index 021515b..a41f0e8 100644
--- a/Source/CursesDialog/cmCursesStringWidget.h
+++ b/Source/CursesDialog/cmCursesStringWidget.h
@@ -23,9 +23,6 @@ class cmCursesStringWidget : public cmCursesWidget
public:
cmCursesStringWidget(int width, int height, int left, int top);
- cmCursesStringWidget(cmCursesStringWidget const&) = delete;
- cmCursesStringWidget& operator=(cmCursesStringWidget const&) = delete;
-
/**
* Handle user input. Called by the container of this widget
* when this widget has focus. Returns true if the input was
@@ -65,7 +62,7 @@ public:
protected:
// true if the widget is in edit mode
bool InEdit;
- char* OriginalString;
+ std::string OriginalString;
bool Done;
};
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
index 94de851..6e04ce5 100644
--- a/Source/cmAddCustomCommandCommand.cxx
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -8,6 +8,7 @@
#include "cmCheckCustomOutputs.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
+#include "cmCustomCommandTypes.h"
#include "cmExecutionStatus.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
@@ -15,7 +16,6 @@
#include "cmPolicies.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
-#include "cmTarget.h"
bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
@@ -55,7 +55,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
// Save all command lines.
cmCustomCommandLines commandLines;
- cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
+ cmCustomCommandType cctype = cmCustomCommandType::POST_BUILD;
enum tdoing
{
@@ -139,11 +139,11 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
currentLine.clear();
}
} else if (copy == keyPRE_BUILD) {
- cctype = cmTarget::PRE_BUILD;
+ cctype = cmCustomCommandType::PRE_BUILD;
} else if (copy == keyPRE_LINK) {
- cctype = cmTarget::PRE_LINK;
+ cctype = cmCustomCommandType::PRE_LINK;
} else if (copy == keyPOST_BUILD) {
- cctype = cmTarget::POST_BUILD;
+ cctype = cmCustomCommandType::POST_BUILD;
} else if (copy == keyVERBATIM) {
verbatim = true;
} else if (copy == keyAPPEND) {
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx
index b580c43..e27b126 100644
--- a/Source/cmAddCustomTargetCommand.cxx
+++ b/Source/cmAddCustomTargetCommand.cxx
@@ -6,6 +6,7 @@
#include "cmCheckCustomOutputs.h"
#include "cmCustomCommandLines.h"
+#include "cmCustomCommandTypes.h"
#include "cmExecutionStatus.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
@@ -214,7 +215,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
// Add the utility target to the makefile.
bool escapeOldStyle = !verbatim;
cmTarget* target = mf.AddUtilityCommand(
- targetName, cmMakefile::TargetOrigin::Project, excludeFromAll,
+ targetName, cmCommandOrigin::Project, excludeFromAll,
working_directory.c_str(), byproducts, depends, commandLines,
escapeOldStyle, comment, uses_terminal, command_expand_lists, job_pool);
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx
index 1eaf48b..78a232e 100644
--- a/Source/cmCPluginAPI.cxx
+++ b/Source/cmCPluginAPI.cxx
@@ -220,8 +220,10 @@ void CCONV cmAddUtilityCommand(void* arg, const char* utilityName,
}
// Pass the call to the makefile instance.
- mf->AddUtilityCommand(utilityName, cmMakefile::TargetOrigin::Project,
- (all ? false : true), nullptr, depends2, commandLines);
+ std::vector<std::string> no_byproducts;
+ mf->AddUtilityCommand(utilityName, cmCommandOrigin::Project,
+ (all ? false : true), nullptr, no_byproducts, depends2,
+ commandLines);
}
void CCONV cmAddCustomCommand(void* arg, const char* source,
const char* command, int numArgs,
@@ -319,16 +321,16 @@ void CCONV cmAddCustomCommandToTarget(void* arg, const char* target,
commandLines.push_back(commandLine);
// Select the command type.
- cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
+ cmCustomCommandType cctype = cmCustomCommandType::POST_BUILD;
switch (commandType) {
case CM_PRE_BUILD:
- cctype = cmTarget::PRE_BUILD;
+ cctype = cmCustomCommandType::PRE_BUILD;
break;
case CM_PRE_LINK:
- cctype = cmTarget::PRE_LINK;
+ cctype = cmCustomCommandType::PRE_LINK;
break;
case CM_POST_BUILD:
- cctype = cmTarget::POST_BUILD;
+ cctype = cmCustomCommandType::POST_BUILD;
break;
}
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 88d17f1..b1f7db7 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -246,26 +246,22 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("set_tests_properties",
cmSetTestsPropertiesCommand);
state->AddBuiltinCommand("subdirs", cmSubdirCommand);
- state->AddBuiltinCommand(
- "target_compile_definitions",
- cm::make_unique<cmTargetCompileDefinitionsCommand>());
+ state->AddBuiltinCommand("target_compile_definitions",
+ cmTargetCompileDefinitionsCommand);
state->AddBuiltinCommand("target_compile_features",
- cm::make_unique<cmTargetCompileFeaturesCommand>());
+ cmTargetCompileFeaturesCommand);
state->AddBuiltinCommand("target_compile_options",
- cm::make_unique<cmTargetCompileOptionsCommand>());
- state->AddBuiltinCommand(
- "target_include_directories",
- cm::make_unique<cmTargetIncludeDirectoriesCommand>());
+ cmTargetCompileOptionsCommand);
+ state->AddBuiltinCommand("target_include_directories",
+ cmTargetIncludeDirectoriesCommand);
state->AddBuiltinCommand("target_link_libraries",
cmTargetLinkLibrariesCommand);
- state->AddBuiltinCommand("target_sources",
- cm::make_unique<cmTargetSourcesCommand>());
+ state->AddBuiltinCommand("target_sources", cmTargetSourcesCommand);
state->AddBuiltinCommand("try_compile",
cm::make_unique<cmTryCompileCommand>());
state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>());
- state->AddBuiltinCommand(
- "target_precompile_headers",
- cm::make_unique<cmTargetPrecompileHeadersCommand>());
+ state->AddBuiltinCommand("target_precompile_headers",
+ cmTargetPrecompileHeadersCommand);
#if !defined(CMAKE_BOOTSTRAP)
state->AddBuiltinCommand("add_compile_definitions",
@@ -280,10 +276,9 @@ 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",
- cm::make_unique<cmTargetLinkOptionsCommand>());
+ state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand);
state->AddBuiltinCommand("target_link_directories",
- cm::make_unique<cmTargetLinkDirectoriesCommand>());
+ cmTargetLinkDirectoriesCommand);
state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand);
diff --git a/Source/cmCustomCommandTypes.h b/Source/cmCustomCommandTypes.h
new file mode 100644
index 0000000..d4bf1f9
--- /dev/null
+++ b/Source/cmCustomCommandTypes.h
@@ -0,0 +1,39 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#ifndef cmCustomCommandTypes_h
+#define cmCustomCommandTypes_h
+
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include <string>
+
+/** Target custom command type */
+enum class cmCustomCommandType
+{
+ PRE_BUILD,
+ PRE_LINK,
+ POST_BUILD
+};
+
+/** Where the command originated from. */
+enum class cmCommandOrigin
+{
+ Project,
+ Generator
+};
+
+/** How to handle custom commands for object libraries */
+enum class cmObjectLibraryCommands
+{
+ Reject,
+ Accept
+};
+
+/** Utility target output source file name. */
+struct cmUtilityOutput
+{
+ std::string Name;
+ std::string NameCMP0049;
+};
+
+#endif
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx
index 96ea071..fbdb975 100644
--- a/Source/cmFileAPICodemodel.cxx
+++ b/Source/cmFileAPICodemodel.cxx
@@ -858,47 +858,69 @@ CompileData Target::BuildCompileData(cmSourceFile* sf)
fd.Flags.emplace_back(std::move(flags), JBTIndex());
}
const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
- if (const char* coptions = sf->GetProperty(COMPILE_OPTIONS)) {
- std::string flags;
- lg->AppendCompileOptions(
- flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
- fd.Flags.emplace_back(std::move(flags), JBTIndex());
+ for (BT<std::string> tmpOpt : sf->GetCompileOptions()) {
+ tmpOpt.Value = genexInterpreter.Evaluate(tmpOpt.Value, COMPILE_OPTIONS);
+ // After generator evaluation we need to use the AppendCompileOptions
+ // method so we handle situations where backtrace entries have lists
+ // and properly escape flags.
+ std::string tmp;
+ lg->AppendCompileOptions(tmp, tmpOpt.Value);
+ BT<std::string> opt(tmp, tmpOpt.Backtrace);
+ fd.Flags.emplace_back(this->ToJBT(opt));
}
// Add include directories from source file properties.
{
- std::vector<std::string> includes;
const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
- if (const char* cincludes = sf->GetProperty(INCLUDE_DIRECTORIES)) {
- const std::string& evaluatedIncludes =
- genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES);
- lg->AppendIncludeDirectories(includes, evaluatedIncludes, *sf);
-
- for (std::string const& include : includes) {
- bool const isSystemInclude = this->GT->IsSystemIncludeDirectory(
- include, this->Config, fd.Language);
- fd.Includes.emplace_back(include, isSystemInclude);
+ for (BT<std::string> tmpInclude : sf->GetIncludeDirectories()) {
+ tmpInclude.Value =
+ genexInterpreter.Evaluate(tmpInclude.Value, INCLUDE_DIRECTORIES);
+
+ // After generator evaluation we need to use the AppendIncludeDirectories
+ // method so we handle situations where backtrace entries have lists.
+ std::vector<std::string> tmp;
+ lg->AppendIncludeDirectories(tmp, tmpInclude.Value, *sf);
+ for (std::string& i : tmp) {
+ bool const isSystemInclude =
+ this->GT->IsSystemIncludeDirectory(i, this->Config, fd.Language);
+ BT<std::string> include(i, tmpInclude.Backtrace);
+ fd.Includes.emplace_back(this->ToJBT(include), isSystemInclude);
}
}
}
const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
- std::set<std::string> fileDefines;
- if (const char* defs = sf->GetProperty(COMPILE_DEFINITIONS)) {
- lg->AppendDefines(fileDefines,
- genexInterpreter.Evaluate(defs, COMPILE_DEFINITIONS));
+ std::set<BT<std::string>> fileDefines;
+ for (BT<std::string> tmpDef : sf->GetCompileDefinitions()) {
+ tmpDef.Value =
+ genexInterpreter.Evaluate(tmpDef.Value, COMPILE_DEFINITIONS);
+
+ // After generator evaluation we need to use the AppendDefines method
+ // so we handle situations where backtrace entries have lists.
+ std::set<std::string> tmp;
+ lg->AppendDefines(tmp, tmpDef.Value);
+ for (const std::string& i : tmp) {
+ BT<std::string> def(i, tmpDef.Backtrace);
+ fileDefines.insert(def);
+ }
}
+ std::set<std::string> configFileDefines;
const std::string defPropName =
"COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(this->Config);
if (const char* config_defs = sf->GetProperty(defPropName)) {
lg->AppendDefines(
- fileDefines,
+ configFileDefines,
genexInterpreter.Evaluate(config_defs, COMPILE_DEFINITIONS));
}
- fd.Defines.reserve(fileDefines.size());
- for (std::string const& d : fileDefines) {
+ fd.Defines.reserve(fileDefines.size() + configFileDefines.size());
+
+ for (BT<std::string> const& def : fileDefines) {
+ fd.Defines.emplace_back(this->ToJBT(def));
+ }
+
+ for (std::string const& d : configFileDefines) {
fd.Defines.emplace_back(d, JBTIndex());
}
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 2273c50..c4974f3 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -2582,7 +2582,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti,
cmCustomCommand cc(nullptr, no_outputs, no_byproducts, no_depends,
gti.CommandLines, nullptr, gti.WorkingDir.c_str());
cc.SetUsesTerminal(gti.UsesTerminal);
- target.AddPostBuildCommand(cc);
+ target.AddPostBuildCommand(std::move(cc));
if (!gti.Message.empty()) {
target.SetProperty("EchoString", gti.Message.c_str());
}
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index f25d2e2..8e6125b 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -96,17 +96,18 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
return false;
}
- const char* no_working_directory = nullptr;
- std::vector<std::string> no_depends;
std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
cmLocalVisualStudio7Generator* lg =
static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
cmMakefile* mf = lg->GetMakefile();
- cmCustomCommandLines noCommandLines;
+ const char* no_working_directory = nullptr;
+ std::vector<std::string> no_byproducts;
+ std::vector<std::string> no_depends;
+ cmCustomCommandLines no_commands;
cmTarget* tgt = mf->AddUtilityCommand(
- CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
- false, no_working_directory, no_depends, noCommandLines);
+ CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, false,
+ no_working_directory, no_byproducts, no_depends, no_commands);
cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg);
lg->AddGeneratorTarget(gt);
@@ -152,10 +153,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
std::vector<std::string> byproducts;
byproducts.push_back(cm->GetGlobVerifyStamp());
- mf->AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts,
- no_depends, verifyCommandLines,
- cmTarget::PRE_BUILD, "Checking File Globs",
- no_working_directory, false);
+ mf->AddCustomCommandToTarget(
+ CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, no_depends,
+ verifyCommandLines, cmCustomCommandType::PRE_BUILD,
+ "Checking File Globs", no_working_directory, false);
// Ensure ZERO_CHECK always runs in Visual Studio using MSBuild,
// otherwise the prebuild command will not be run.
@@ -182,7 +183,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// file as the main dependency because it would get
// overwritten by the CreateVCProjBuildRule.
// (this could be avoided with per-target source files)
- std::vector<std::string> no_byproducts;
std::string no_main_dependency;
cmImplicitDependsList no_implicit_depends;
if (cmSourceFile* file = mf->AddCustomCommandToOutput(
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 7a564ed..0bc08a5 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -183,7 +183,8 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
{
// Add a special target that depends on ALL projects for easy build
// of one configuration only.
- const char* no_working_dir = 0;
+ const char* no_working_dir = nullptr;
+ std::vector<std::string> no_byproducts;
std::vector<std::string> no_depends;
cmCustomCommandLines no_commands;
for (auto const& it : this->ProjectMap) {
@@ -193,8 +194,8 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
// Use no actual command lines so that the target itself is not
// considered always out of date.
cmTarget* allBuild = gen[0]->GetMakefile()->AddUtilityCommand(
- "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_working_dir,
- no_depends, no_commands, false, "Build all projects");
+ "ALL_BUILD", cmCommandOrigin::Generator, true, no_working_dir,
+ no_byproducts, no_depends, no_commands, false, "Build all projects");
cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
gen[0]->AddGeneratorTarget(gt);
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 2c3d3ad..4202175 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -497,12 +497,14 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
{
cmMakefile* mf = root->GetMakefile();
- // Add ALL_BUILD
const char* no_working_directory = nullptr;
+ std::vector<std::string> no_byproducts;
std::vector<std::string> no_depends;
+
+ // Add ALL_BUILD
cmTarget* allbuild = mf->AddUtilityCommand(
- "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true,
- no_working_directory, no_depends,
+ "ALL_BUILD", cmCommandOrigin::Generator, true, no_working_directory,
+ no_byproducts, no_depends,
cmMakeSingleCommandLine({ "echo", "Build all projects" }));
cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
@@ -526,8 +528,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile);
cmSystemTools::ReplaceString(file, "\\ ", " ");
cmTarget* check = mf->AddUtilityCommand(
- CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
- true, no_working_directory, no_depends,
+ CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, true,
+ no_working_directory, no_byproducts, no_depends,
cmMakeSingleCommandLine({ "make", "-f", file }));
cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
@@ -542,9 +544,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
continue;
}
- std::string targetName = target->GetName();
-
- if (regenerate && (targetName != CMAKE_CHECK_BUILD_SYSTEM_TARGET)) {
+ if (regenerate &&
+ (target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET)) {
target->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
}
@@ -555,11 +556,11 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
commandLines.front().back() = // fill placeholder
this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)");
- std::vector<std::string> no_byproducts;
gen->GetMakefile()->AddCustomCommandToTarget(
target->GetName(), no_byproducts, no_depends, commandLines,
- cmTarget::POST_BUILD, "Depend check for xcode", dir.c_str(), true,
- false, "", "", false, cmMakefile::AcceptObjectLibraryCommands);
+ cmCustomCommandType::POST_BUILD, "Depend check for xcode",
+ dir.c_str(), true, false, "", "", false,
+ cmObjectLibraryCommands::Accept);
}
if (!this->IsExcluded(target)) {
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 93e074d..7af3da5 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -7,6 +7,7 @@
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmCustomCommandLines.h"
+#include "cmCustomCommandTypes.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionEvaluationFile.h"
@@ -2356,7 +2357,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target,
if (this->GetGlobalGenerator()->IsMultiConfig()) {
this->Makefile->AddCustomCommandToTarget(
target->GetName(), outputs, no_deps, commandLines,
- cmTarget::PRE_BUILD, no_message, no_current_dir);
+ cmCustomCommandType::PRE_BUILD, no_message, no_current_dir);
} else {
cmImplicitDependsList no_implicit_depends;
cmSourceFile* copy_rule = this->Makefile->AddCustomCommandToOutput(
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 34081ed..a528fc6 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -39,6 +39,7 @@
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
+#include "cmTarget.h"
#include "cmTargetLinkLibraryType.h"
#include "cmTest.h"
#include "cmTestGenerator.h" // IWYU pragma: keep
@@ -837,13 +838,8 @@ bool cmMakefile::ValidateCustomCommand(
return true;
}
-cmTarget* cmMakefile::AddCustomCommandToTarget(
- const std::string& target, const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
- const char* comment, const char* workingDir, bool escapeOldStyle,
- bool uses_terminal, const std::string& depfile, const std::string& job_pool,
- bool command_expand_lists, ObjectLibraryCommands objLibraryCommands)
+cmTarget* cmMakefile::GetCustomCommandTarget(
+ const std::string& target, cmObjectLibraryCommands objLibCommands) const
{
// Find the target to which to add the custom command.
auto ti = this->Targets.find(target);
@@ -884,7 +880,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget(
}
cmTarget* t = &ti->second;
- if (objLibraryCommands == RejectObjectLibraryCommands &&
+ if (objLibCommands == cmObjectLibraryCommands::Reject &&
t->GetType() == cmStateEnums::OBJECT_LIBRARY) {
std::ostringstream e;
e << "Target \"" << target
@@ -902,8 +898,21 @@ cmTarget* cmMakefile::AddCustomCommandToTarget(
return nullptr;
}
+ return t;
+}
+
+cmTarget* cmMakefile::AddCustomCommandToTarget(
+ const std::string& target, const std::vector<std::string>& byproducts,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines, cmCustomCommandType type,
+ const char* comment, const char* workingDir, bool escapeOldStyle,
+ bool uses_terminal, const std::string& depfile, const std::string& job_pool,
+ bool command_expand_lists, cmObjectLibraryCommands objLibCommands)
+{
+ cmTarget* t = this->GetCustomCommandTarget(target, objLibCommands);
+
// Validate custom commands.
- if (!this->ValidateCustomCommand(commandLines)) {
+ if (!t || !this->ValidateCustomCommand(commandLines)) {
return t;
}
@@ -920,7 +929,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget(
void cmMakefile::CommitCustomCommandToTarget(
cmTarget* target, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
+ const cmCustomCommandLines& commandLines, cmCustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle,
bool uses_terminal, const std::string& depfile, const std::string& job_pool,
bool command_expand_lists)
@@ -936,47 +945,18 @@ void cmMakefile::CommitCustomCommandToTarget(
cc.SetDepfile(depfile);
cc.SetJobPool(job_pool);
switch (type) {
- case cmTarget::PRE_BUILD:
- target->AddPreBuildCommand(cc);
+ case cmCustomCommandType::PRE_BUILD:
+ target->AddPreBuildCommand(std::move(cc));
break;
- case cmTarget::PRE_LINK:
- target->AddPreLinkCommand(cc);
+ case cmCustomCommandType::PRE_LINK:
+ target->AddPreLinkCommand(std::move(cc));
break;
- case cmTarget::POST_BUILD:
- target->AddPostBuildCommand(cc);
+ case cmCustomCommandType::POST_BUILD:
+ target->AddPostBuildCommand(std::move(cc));
break;
}
- this->UpdateOutputToSourceMap(byproducts, target);
-}
-
-void cmMakefile::UpdateOutputToSourceMap(
- std::vector<std::string> const& byproducts, cmTarget* target)
-{
- for (std::string const& o : byproducts) {
- this->UpdateOutputToSourceMap(o, target);
- }
-}
-
-void cmMakefile::UpdateOutputToSourceMap(std::string const& byproduct,
- cmTarget* target)
-{
- SourceEntry entry;
- entry.Sources.Target = target;
- auto pr = this->OutputToSource.emplace(byproduct, entry);
- if (!pr.second) {
- SourceEntry& current = pr.first->second;
- // Has the target already been set?
- if (!current.Sources.Target) {
- current.Sources.Target = target;
- } else {
- // Multiple custom commands/targets produce the same output (source file
- // or target). See also comment in other UpdateOutputToSourceMap
- // overload.
- //
- // TODO: Warn the user about this case.
- }
- }
+ this->AddTargetByproducts(target, byproducts);
}
cmSourceFile* cmMakefile::AddCustomCommandToOutput(
@@ -1102,47 +1082,10 @@ cmSourceFile* cmMakefile::CommitCustomCommandToOutput(
cc->SetDepfile(depfile);
cc->SetJobPool(job_pool);
file->SetCustomCommand(std::move(cc));
- this->UpdateOutputToSourceMap(outputs, file, false);
- this->UpdateOutputToSourceMap(byproducts, file, true);
- }
- return file;
-}
-
-void cmMakefile::UpdateOutputToSourceMap(
- std::vector<std::string> const& outputs, cmSourceFile* source,
- bool byproduct)
-{
- for (std::string const& o : outputs) {
- this->UpdateOutputToSourceMap(o, source, byproduct);
- }
-}
-
-void cmMakefile::UpdateOutputToSourceMap(std::string const& output,
- cmSourceFile* source, bool byproduct)
-{
- SourceEntry entry;
- entry.Sources.Source = source;
- entry.Sources.SourceIsByproduct = byproduct;
- auto pr = this->OutputToSource.emplace(output, entry);
- if (!pr.second) {
- SourceEntry& current = pr.first->second;
- // Outputs take precedence over byproducts
- if (!current.Sources.Source ||
- (current.Sources.SourceIsByproduct && !byproduct)) {
- current.Sources.Source = source;
- current.Sources.SourceIsByproduct = false;
- } else {
- // Multiple custom commands produce the same output but may
- // be attached to a different source file (MAIN_DEPENDENCY).
- // LinearGetSourceFileWithOutput would return the first one,
- // so keep the mapping for the first one.
- //
- // TODO: Warn the user about this case. However, the VS 8 generator
- // triggers it for separate generate.stamp rules in ZERO_CHECK and
- // individual targets.
- }
+ this->AddSourceOutputs(file, outputs, byproducts);
}
+ return file;
}
void cmMakefile::AddCustomCommandOldStyle(
@@ -1157,9 +1100,9 @@ void cmMakefile::AddCustomCommandOldStyle(
// same then it added a post-build rule to the target. Preserve
// this behavior.
std::vector<std::string> no_byproducts;
- this->AddCustomCommandToTarget(target, no_byproducts, depends,
- commandLines, cmTarget::POST_BUILD, comment,
- nullptr);
+ this->AddCustomCommandToTarget(
+ target, no_byproducts, depends, commandLines,
+ cmCustomCommandType::POST_BUILD, comment, nullptr);
return;
}
@@ -1247,85 +1190,73 @@ void cmMakefile::CommitAppendCustomCommandToOutput(
}
}
-cmTarget* cmMakefile::AddUtilityCommand(
- const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
- const char* workingDirectory, const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines, bool escapeOldStyle,
- const char* comment, bool uses_terminal, bool command_expand_lists,
- const std::string& job_pool)
+cmUtilityOutput cmMakefile::GetUtilityOutput(cmTarget* target)
{
- std::vector<std::string> no_byproducts;
- return this->AddUtilityCommand(
- utilityName, origin, excludeFromAll, workingDirectory, no_byproducts,
- depends, commandLines, escapeOldStyle, comment, uses_terminal,
- command_expand_lists, job_pool);
+ std::string force = cmStrCat(this->GetCurrentBinaryDirectory(),
+ "/CMakeFiles/", target->GetName());
+ std::string forceCMP0049 = target->GetSourceCMP0049(force);
+ {
+ cmSourceFile* sf = nullptr;
+ if (!forceCMP0049.empty()) {
+ sf = this->GetOrCreateSource(forceCMP0049, false,
+ cmSourceFileLocationKind::Known);
+ }
+ // The output is not actually created so mark it symbolic.
+ if (sf) {
+ sf->SetProperty("SYMBOLIC", "1");
+ } else {
+ cmSystemTools::Error("Could not get source file entry for " + force);
+ }
+ }
+ return { std::move(force), std::move(forceCMP0049) };
}
cmTarget* cmMakefile::AddUtilityCommand(
- const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
+ const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle,
const char* comment, bool uses_terminal, bool command_expand_lists,
const std::string& job_pool)
{
- // Create a target instance for this utility.
- cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName);
- target->SetIsGeneratorProvided(origin == TargetOrigin::Generator);
- if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
- target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
- }
+ cmTarget* target =
+ this->AddNewUtilityTarget(utilityName, origin, excludeFromAll);
// Validate custom commands.
- if (!this->ValidateCustomCommand(commandLines) ||
- (commandLines.empty() && depends.empty())) {
+ if ((commandLines.empty() && depends.empty()) ||
+ !this->ValidateCustomCommand(commandLines)) {
return target;
}
+ // Get the output name of the utility target and mark it generated.
+ cmUtilityOutput force = this->GetUtilityOutput(target);
+ this->GetOrCreateGeneratedSource(force.Name);
+
// Always create the byproduct sources and mark them generated.
this->CreateGeneratedSources(byproducts);
- std::string force =
- cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", utilityName);
- this->CreateGeneratedSource(force);
- std::string forceCMP0049 = target->GetSourceCMP0049(force);
- {
- cmSourceFile* sf = nullptr;
- if (!forceCMP0049.empty()) {
- sf = this->GetOrCreateSource(forceCMP0049, false,
- cmSourceFileLocationKind::Known);
- }
- // The output is not actually created so mark it symbolic.
- if (sf) {
- sf->SetProperty("SYMBOLIC", "1");
- } else {
- cmSystemTools::Error("Could not get source file entry for " + force);
- }
- }
-
if (!comment) {
// Use an empty comment to avoid generation of default comment.
comment = "";
}
- this->CommitUtilityCommand(target, force, forceCMP0049, workingDirectory,
- byproducts, depends, commandLines, escapeOldStyle,
- comment, uses_terminal, command_expand_lists,
- job_pool);
+ this->CommitUtilityCommand(target, force, workingDirectory, byproducts,
+ depends, commandLines, escapeOldStyle, comment,
+ uses_terminal, command_expand_lists, job_pool);
return target;
}
void cmMakefile::CommitUtilityCommand(
- cmTarget* target, const std::string& force, const std::string& forceCMP0049,
- const char* workingDirectory, const std::vector<std::string>& byproducts,
+ cmTarget* target, const cmUtilityOutput& force, const char* workingDirectory,
+ const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle,
const char* comment, bool uses_terminal, bool command_expand_lists,
const std::string& job_pool)
{
std::vector<std::string> forced;
- forced.push_back(force);
+ forced.push_back(force.Name);
std::string no_main_dependency;
cmImplicitDependsList no_implicit_depends;
bool no_replace = false;
@@ -1333,11 +1264,11 @@ void cmMakefile::CommitUtilityCommand(
forced, byproducts, depends, no_main_dependency, no_implicit_depends,
commandLines, comment, workingDirectory, no_replace, escapeOldStyle,
uses_terminal, command_expand_lists, /*depfile=*/"", job_pool);
- if (!forceCMP0049.empty()) {
- target->AddSource(forceCMP0049);
+ if (!force.NameCMP0049.empty()) {
+ target->AddSource(force.NameCMP0049);
}
if (sf) {
- this->UpdateOutputToSourceMap(byproducts, target);
+ this->AddTargetByproducts(target, byproducts);
}
}
@@ -2156,6 +2087,18 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type,
return &it->second;
}
+cmTarget* cmMakefile::AddNewUtilityTarget(const std::string& utilityName,
+ cmCommandOrigin origin,
+ bool excludeFromAll)
+{
+ cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName);
+ target->SetIsGeneratorProvided(origin == cmCommandOrigin::Generator);
+ if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
+ target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
+ }
+ return target;
+}
+
namespace {
bool AnyOutputMatches(const std::string& name,
const std::vector<std::string>& outputs)
@@ -2286,6 +2229,76 @@ bool cmMakefile::MightHaveCustomCommand(const std::string& name) const
return false;
}
+void cmMakefile::AddTargetByproducts(
+ cmTarget* target, const std::vector<std::string>& byproducts)
+{
+ for (std::string const& o : byproducts) {
+ this->UpdateOutputToSourceMap(o, target);
+ }
+}
+
+void cmMakefile::AddSourceOutputs(cmSourceFile* source,
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& byproducts)
+{
+ for (std::string const& o : outputs) {
+ this->UpdateOutputToSourceMap(o, source, false);
+ }
+ for (std::string const& o : byproducts) {
+ this->UpdateOutputToSourceMap(o, source, true);
+ }
+}
+
+void cmMakefile::UpdateOutputToSourceMap(std::string const& byproduct,
+ cmTarget* target)
+{
+ SourceEntry entry;
+ entry.Sources.Target = target;
+
+ auto pr = this->OutputToSource.emplace(byproduct, entry);
+ if (!pr.second) {
+ SourceEntry& current = pr.first->second;
+ // Has the target already been set?
+ if (!current.Sources.Target) {
+ current.Sources.Target = target;
+ } else {
+ // Multiple custom commands/targets produce the same output (source file
+ // or target). See also comment in other UpdateOutputToSourceMap
+ // overload.
+ //
+ // TODO: Warn the user about this case.
+ }
+ }
+}
+
+void cmMakefile::UpdateOutputToSourceMap(std::string const& output,
+ cmSourceFile* source, bool byproduct)
+{
+ SourceEntry entry;
+ entry.Sources.Source = source;
+ entry.Sources.SourceIsByproduct = byproduct;
+
+ auto pr = this->OutputToSource.emplace(output, entry);
+ if (!pr.second) {
+ SourceEntry& current = pr.first->second;
+ // Outputs take precedence over byproducts
+ if (!current.Sources.Source ||
+ (current.Sources.SourceIsByproduct && !byproduct)) {
+ current.Sources.Source = source;
+ current.Sources.SourceIsByproduct = false;
+ } else {
+ // Multiple custom commands produce the same output but may
+ // be attached to a different source file (MAIN_DEPENDENCY).
+ // LinearGetSourceFileWithOutput would return the first one,
+ // so keep the mapping for the first one.
+ //
+ // TODO: Warn the user about this case. However, the VS 8 generator
+ // triggers it for separate generate.stamp rules in ZERO_CHECK and
+ // individual targets.
+ }
+ }
+}
+
#if !defined(CMAKE_BOOTSTRAP)
cmSourceGroup* cmMakefile::GetSourceGroup(
const std::vector<std::string>& name) const
@@ -3530,19 +3543,20 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
return this->CreateSource(sourceName, generated, kind);
}
-void cmMakefile::CreateGeneratedSource(const std::string& output)
+cmSourceFile* cmMakefile::GetOrCreateGeneratedSource(
+ const std::string& sourceName)
{
- if (cmSourceFile* out = this->GetOrCreateSource(
- output, true, cmSourceFileLocationKind::Known)) {
- out->SetProperty("GENERATED", "1");
- }
+ cmSourceFile* sf =
+ this->GetOrCreateSource(sourceName, true, cmSourceFileLocationKind::Known);
+ sf->SetProperty("GENERATED", "1");
+ return sf;
}
void cmMakefile::CreateGeneratedSources(
const std::vector<std::string>& outputs)
{
for (std::string const& output : outputs) {
- this->CreateGeneratedSource(output);
+ this->GetOrCreateGeneratedSource(output);
}
}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index db37477..bb88bed 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -20,6 +20,7 @@
#include <cm/string_view>
#include "cmAlgorithms.h"
+#include "cmCustomCommandTypes.h"
#include "cmListFileCache.h"
#include "cmMessageType.h"
#include "cmNewLineStyle.h"
@@ -28,7 +29,10 @@
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
-#include "cmTarget.h"
+
+// IWYU does not see that 'std::unordered_map<std::string, cmTarget>'
+// will not compile without the complete type.
+#include "cmTarget.h" // IWYU pragma: keep
#if !defined(CMAKE_BOOTSTRAP)
# include "cmSourceGroup.h"
@@ -164,22 +168,21 @@ public:
*/
void FinalPass();
- /** How to handle custom commands for object libraries */
- enum ObjectLibraryCommands
- {
- RejectObjectLibraryCommands,
- AcceptObjectLibraryCommands
- };
+ /**
+ * Get the target for PRE_BUILD, PRE_LINK, or POST_BUILD commands.
+ */
+ cmTarget* GetCustomCommandTarget(
+ const std::string& target, cmObjectLibraryCommands objLibCommands) const;
/** Add a custom command to the build. */
cmTarget* AddCustomCommandToTarget(
const std::string& target, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
+ const cmCustomCommandLines& commandLines, cmCustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle = true,
bool uses_terminal = false, const std::string& depfile = "",
const std::string& job_pool = "", bool command_expand_lists = false,
- ObjectLibraryCommands objLibraryCommands = RejectObjectLibraryCommands);
+ cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject);
cmSourceFile* AddCustomCommandToOutput(
const std::string& output, const std::vector<std::string>& depends,
const std::string& main_dependency,
@@ -209,6 +212,19 @@ public:
const cmCustomCommandLines& commandLines);
/**
+ * Add target byproducts.
+ */
+ void AddTargetByproducts(cmTarget* target,
+ const std::vector<std::string>& byproducts);
+
+ /**
+ * Add source file outputs.
+ */
+ void AddSourceOutputs(cmSourceFile* source,
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& byproducts);
+
+ /**
* Add a define flag to the build.
*/
void AddDefineFlag(std::string const& definition);
@@ -225,6 +241,10 @@ public:
cmTarget* AddNewTarget(cmStateEnums::TargetType type,
const std::string& name);
+ /** Create a target instance for the utility. */
+ cmTarget* AddNewUtilityTarget(const std::string& utilityName,
+ cmCommandOrigin origin, bool excludeFromAll);
+
/**
* Add an executable to the build.
*/
@@ -232,26 +252,19 @@ public:
const std::vector<std::string>& srcs,
bool excludeFromAll = false);
- /** Where the target originated from. */
- enum class TargetOrigin
- {
- Project,
- Generator
- };
+ /**
+ * Return the utility target output source file name and the CMP0049 name.
+ */
+ cmUtilityOutput GetUtilityOutput(cmTarget* target);
/**
* Add a utility to the build. A utility target is a command that
* is run every time the target is built.
*/
cmTarget* AddUtilityCommand(
- const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
- const char* workingDirectory, const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
- const char* comment = nullptr, bool uses_terminal = false,
- bool command_expand_lists = false, const std::string& job_pool = "");
- cmTarget* AddUtilityCommand(
- const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
- const char* workingDirectory, const std::vector<std::string>& byproducts,
+ const std::string& utilityName, cmCommandOrigin origin,
+ bool excludeFromAll, const char* workingDirectory,
+ const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
const char* comment = nullptr, bool uses_terminal = false,
@@ -455,6 +468,12 @@ public:
const std::string& sourceName, bool generated = false,
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
+ /** Get a cmSourceFile pointer for a given source name and always mark the
+ * file as generated, if the name is not found, then create the source file
+ * and return it.
+ */
+ cmSourceFile* GetOrCreateGeneratedSource(const std::string& sourceName);
+
void AddTargetObject(std::string const& tgtName, std::string const& objFile);
/**
@@ -1036,13 +1055,12 @@ private:
friend bool cmCMakePolicyCommand(std::vector<std::string> const& args,
cmExecutionStatus& status);
class IncludeScope;
-
friend class IncludeScope;
- class ListFileScope;
+ class ListFileScope;
friend class ListFileScope;
- class BuildsystemFileScope;
+ class BuildsystemFileScope;
friend class BuildsystemFileScope;
// CMP0053 == old
@@ -1061,10 +1079,12 @@ private:
bool ValidateCustomCommand(const cmCustomCommandLines& commandLines) const;
+ void CreateGeneratedSources(const std::vector<std::string>& outputs);
+
void CommitCustomCommandToTarget(
cmTarget* target, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
+ const cmCustomCommandLines& commandLines, cmCustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle,
bool uses_terminal, const std::string& depfile,
const std::string& job_pool, bool command_expand_lists);
@@ -1083,8 +1103,7 @@ private:
const cmImplicitDependsList& implicit_depends,
const cmCustomCommandLines& commandLines);
- void CommitUtilityCommand(cmTarget* target, const std::string& force,
- const std::string& forceCMP0049,
+ void CommitUtilityCommand(cmTarget* target, const cmUtilityOutput& force,
const char* workingDirectory,
const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
@@ -1093,9 +1112,6 @@ private:
bool uses_terminal, bool command_expand_lists,
const std::string& job_pool);
- void CreateGeneratedSource(const std::string& output);
- void CreateGeneratedSources(const std::vector<std::string>& outputs);
-
/**
* See LinearGetSourceFileWithOutput for background information
*/
@@ -1120,12 +1136,7 @@ private:
using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>;
OutputToSourceMap OutputToSource;
- void UpdateOutputToSourceMap(std::vector<std::string> const& byproducts,
- cmTarget* target);
void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target);
-
- void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
- cmSourceFile* source, bool byproduct);
void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source,
bool byproduct);
diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx
index 576a034..751ad50 100644
--- a/Source/cmQtAutoGenGlobalInitializer.cxx
+++ b/Source/cmQtAutoGenGlobalInitializer.cxx
@@ -3,6 +3,7 @@
#include "cmQtAutoGenGlobalInitializer.h"
#include "cmCustomCommandLines.h"
+#include "cmCustomCommandTypes.h"
#include "cmDuration.h"
#include "cmGeneratorTarget.h"
#include "cmLocalGenerator.h"
@@ -154,7 +155,7 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget(
// Create utility target
cmTarget* target = makefile->AddUtilityCommand(
- name, cmMakefile::TargetOrigin::Generator, true,
+ name, cmCommandOrigin::Generator, true,
makefile->GetHomeOutputDirectory().c_str() /*work dir*/,
std::vector<std::string>() /*output*/,
std::vector<std::string>() /*depends*/, cmCustomCommandLines(), false,
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 0d56fe1..d7b9fa2 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -8,6 +8,7 @@
#include "cmAlgorithms.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
+#include "cmCustomCommandTypes.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
@@ -1085,7 +1086,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
this->Dir.Work.c_str());
cc.SetEscapeOldStyle(false);
cc.SetEscapeAllowMakeVars(true);
- this->GenTarget->Target->AddPreBuildCommand(cc);
+ this->GenTarget->Target->AddPreBuildCommand(std::move(cc));
} else {
// Add link library target dependencies to the autogen target
@@ -1117,7 +1118,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
// Create autogen target
cmTarget* autogenTarget = this->Makefile->AddUtilityCommand(
- this->AutogenTarget.Name, cmMakefile::TargetOrigin::Generator, true,
+ this->AutogenTarget.Name, cmCommandOrigin::Generator, true,
this->Dir.Work.c_str(), /*byproducts=*/autogenProvides,
std::vector<std::string>(this->AutogenTarget.DependFiles.begin(),
this->AutogenTarget.DependFiles.end()),
@@ -1199,9 +1200,8 @@ bool cmQtAutoGenInitializer::InitRccTargets()
}
cmTarget* autoRccTarget = this->Makefile->AddUtilityCommand(
- ccName, cmMakefile::TargetOrigin::Generator, true,
- this->Dir.Work.c_str(), ccOutput, ccDepends, commandLines, false,
- ccComment.c_str());
+ ccName, cmCommandOrigin::Generator, true, this->Dir.Work.c_str(),
+ ccOutput, ccDepends, commandLines, false, ccComment.c_str());
// Create autogen generator target
this->LocalGen->AddGeneratorTarget(
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index bd68d04..2a345eb 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -6,6 +6,7 @@
#include <utility>
#include "cmGlobalGenerator.h"
+#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmProperty.h"
@@ -28,6 +29,11 @@ std::string const& cmSourceFile::GetExtension() const
const std::string cmSourceFile::propLANGUAGE = "LANGUAGE";
const std::string cmSourceFile::propLOCATION = "LOCATION";
const std::string cmSourceFile::propGENERATED = "GENERATED";
+const std::string cmSourceFile::propCOMPILE_DEFINITIONS =
+ "COMPILE_DEFINITIONS";
+const std::string cmSourceFile::propCOMPILE_OPTIONS = "COMPILE_OPTIONS";
+const std::string cmSourceFile::propINCLUDE_DIRECTORIES =
+ "INCLUDE_DIRECTORIES";
void cmSourceFile::SetObjectLibrary(std::string const& objlib)
{
@@ -226,7 +232,27 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc)
void cmSourceFile::SetProperty(const std::string& prop, const char* value)
{
- this->Properties.SetProperty(prop, value);
+ if (prop == propINCLUDE_DIRECTORIES) {
+ this->IncludeDirectories.clear();
+ if (value) {
+ cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
+ this->IncludeDirectories.emplace_back(value, lfbt);
+ }
+ } else if (prop == propCOMPILE_OPTIONS) {
+ this->CompileOptions.clear();
+ if (value) {
+ cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
+ this->CompileOptions.emplace_back(value, lfbt);
+ }
+ } else if (prop == propCOMPILE_DEFINITIONS) {
+ this->CompileDefinitions.clear();
+ if (value) {
+ cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
+ this->CompileDefinitions.emplace_back(value, lfbt);
+ }
+ } else {
+ this->Properties.SetProperty(prop, value);
+ }
// Update IsGenerated flag
if (prop == propGENERATED) {
@@ -237,7 +263,24 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value)
void cmSourceFile::AppendProperty(const std::string& prop, const char* value,
bool asString)
{
- this->Properties.AppendProperty(prop, value, asString);
+ if (prop == propINCLUDE_DIRECTORIES) {
+ if (value && *value) {
+ cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
+ this->IncludeDirectories.emplace_back(value, lfbt);
+ }
+ } else if (prop == propCOMPILE_OPTIONS) {
+ if (value && *value) {
+ cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
+ this->CompileOptions.emplace_back(value, lfbt);
+ }
+ } else if (prop == propCOMPILE_DEFINITIONS) {
+ if (value && *value) {
+ cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
+ this->CompileDefinitions.emplace_back(value, lfbt);
+ }
+ } else {
+ this->Properties.AppendProperty(prop, value, asString);
+ }
// Update IsGenerated flag
if (prop == propGENERATED) {
@@ -287,6 +330,37 @@ const char* cmSourceFile::GetProperty(const std::string& prop) const
return this->FullPath.c_str();
}
+ // Check for the properties with backtraces.
+ if (prop == propINCLUDE_DIRECTORIES) {
+ if (this->IncludeDirectories.empty()) {
+ return nullptr;
+ }
+
+ static std::string output;
+ output = cmJoin(this->IncludeDirectories, ";");
+ return output.c_str();
+ }
+
+ if (prop == propCOMPILE_OPTIONS) {
+ if (this->CompileOptions.empty()) {
+ return nullptr;
+ }
+
+ static std::string output;
+ output = cmJoin(this->CompileOptions, ";");
+ return output.c_str();
+ }
+
+ if (prop == propCOMPILE_DEFINITIONS) {
+ if (this->CompileDefinitions.empty()) {
+ return nullptr;
+ }
+
+ static std::string output;
+ output = cmJoin(this->CompileDefinitions, ";");
+ return output.c_str();
+ }
+
const char* retVal = this->Properties.GetPropertyValue(prop);
if (!retVal) {
cmMakefile const* mf = this->Location.GetMakefile();
diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h
index 3b18fdb..6ef4167 100644
--- a/Source/cmSourceFile.h
+++ b/Source/cmSourceFile.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCustomCommand.h"
+#include "cmListFileCache.h"
#include "cmPropertyMap.h"
#include "cmSourceFileLocation.h"
#include "cmSourceFileLocationKind.h"
@@ -57,6 +58,21 @@ public:
/// @return Equivalent to GetPropertyAsBool("GENERATED")
bool GetIsGenerated() const { return this->IsGenerated; }
+ const std::vector<BT<std::string>>& GetCompileOptions() const
+ {
+ return this->CompileOptions;
+ }
+
+ const std::vector<BT<std::string>>& GetCompileDefinitions() const
+ {
+ return this->CompileDefinitions;
+ }
+
+ const std::vector<BT<std::string>>& GetIncludeDirectories() const
+ {
+ return this->IncludeDirectories;
+ }
+
/**
* Resolves the full path to the file. Attempts to locate the file on disk
* and finalizes its location.
@@ -116,6 +132,9 @@ private:
std::string FullPath;
std::string ObjectLibrary;
std::vector<std::string> Depends;
+ std::vector<BT<std::string>> CompileOptions;
+ std::vector<BT<std::string>> CompileDefinitions;
+ std::vector<BT<std::string>> IncludeDirectories;
bool FindFullPathFailed = false;
bool IsGenerated = false;
@@ -126,6 +145,9 @@ private:
static const std::string propLANGUAGE;
static const std::string propLOCATION;
static const std::string propGENERATED;
+ static const std::string propCOMPILE_DEFINITIONS;
+ static const std::string propCOMPILE_OPTIONS;
+ static const std::string propINCLUDE_DIRECTORIES;
};
// TODO: Factor out into platform information modules.
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 1b88db6..ae77d9e 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -604,6 +604,11 @@ void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
impl->PreBuildCommands.push_back(cmd);
}
+void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd)
+{
+ impl->PreBuildCommands.push_back(std::move(cmd));
+}
+
std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
{
return impl->PreLinkCommands;
@@ -614,6 +619,11 @@ void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
impl->PreLinkCommands.push_back(cmd);
}
+void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd)
+{
+ impl->PreLinkCommands.push_back(std::move(cmd));
+}
+
std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
{
return impl->PostBuildCommands;
@@ -624,6 +634,11 @@ void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
impl->PostBuildCommands.push_back(cmd);
}
+void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd)
+{
+ impl->PostBuildCommands.push_back(std::move(cmd));
+}
+
void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
{
if (!srcs.empty()) {
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index f4726d3..65a1ce3 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -43,13 +43,6 @@ public:
VisibilityImportedGlobally
};
- enum CustomCommandType
- {
- PRE_BUILD,
- PRE_LINK,
- POST_BUILD
- };
-
cmTarget(std::string const& name, cmStateEnums::TargetType type,
Visibility vis, cmMakefile* mf);
@@ -91,14 +84,17 @@ public:
//! Get the list of the PRE_BUILD custom commands for this target
std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
void AddPreBuildCommand(cmCustomCommand const& cmd);
+ void AddPreBuildCommand(cmCustomCommand&& cmd);
//! Get the list of the PRE_LINK custom commands for this target
std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
void AddPreLinkCommand(cmCustomCommand const& cmd);
+ void AddPreLinkCommand(cmCustomCommand&& cmd);
//! Get the list of the POST_BUILD custom commands for this target
std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
void AddPostBuildCommand(cmCustomCommand const& cmd);
+ void AddPostBuildCommand(cmCustomCommand&& cmd);
//! Add sources to the target.
void AddSources(std::vector<std::string> const& srcs);
diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx
index 94e249f..edee167 100644
--- a/Source/cmTargetCompileDefinitionsCommand.cxx
+++ b/Source/cmTargetCompileDefinitionsCommand.cxx
@@ -6,43 +6,53 @@
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
+namespace {
-bool cmTargetCompileDefinitionsCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
+class TargetCompileDefinitionsImpl : public cmTargetPropCommandBase
{
- return this->HandleArguments(args, "COMPILE_DEFINITIONS");
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
- const std::string& name)
-{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify compile definitions for target \"", name,
- "\" which is not built by this project."));
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify compile definitions for target \"", name,
+ "\" which is not built by this project."));
+ }
-std::string cmTargetCompileDefinitionsCommand::Join(
- const std::vector<std::string>& content)
-{
- std::string defs;
- std::string sep;
- for (std::string const& it : content) {
- if (cmHasLiteralPrefix(it, "-D")) {
- defs += sep + it.substr(2);
- } else {
- defs += sep + it;
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool /*prepend*/, bool /*system*/) override
+ {
+ tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
+ return true; // Successfully handled.
+ }
+
+ std::string Join(const std::vector<std::string>& content) override
+ {
+ std::string defs;
+ std::string sep;
+ for (std::string const& it : content) {
+ if (cmHasLiteralPrefix(it, "-D")) {
+ defs += sep + it.substr(2);
+ } else {
+ defs += sep + it;
+ }
+ sep = ";";
}
- sep = ";";
+ return defs;
}
- return defs;
-}
+};
+
+} // namespace
-bool cmTargetCompileDefinitionsCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
+bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
- tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
- return true; // Successfully handled.
+ return TargetCompileDefinitionsImpl(status).HandleArguments(
+ args, "COMPILE_DEFINITIONS");
}
diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h
index f85dc0a..05ff092 100644
--- a/Source/cmTargetCompileDefinitionsCommand.h
+++ b/Source/cmTargetCompileDefinitionsCommand.h
@@ -8,39 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetCompileDefinitionsCommand : public cmTargetPropCommandBase
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetCompileDefinitionsCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
- std::string Join(const std::vector<std::string>& content) override;
-};
+bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx
index a22b94b..06be4f0 100644
--- a/Source/cmTargetCompileFeaturesCommand.cxx
+++ b/Source/cmTargetCompileFeaturesCommand.cxx
@@ -5,40 +5,51 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
class cmTarget;
-bool cmTargetCompileFeaturesCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
-{
- return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS);
-}
+namespace {
-void cmTargetCompileFeaturesCommand::HandleMissingTarget(
- const std::string& name)
+class TargetCompileFeaturesImpl : public cmTargetPropCommandBase
{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify compile features for target \"", name,
- "\" which is not built by this project."));
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-std::string cmTargetCompileFeaturesCommand::Join(
- const std::vector<std::string>& content)
-{
- return cmJoin(content, ";");
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify compile features for target \"", name,
+ "\" which is not built by this project."));
+ }
-bool cmTargetCompileFeaturesCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
-{
- for (std::string const& it : content) {
- std::string error;
- if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) {
- this->SetError(error);
- return false; // Not (successfully) handled.
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool /*prepend*/, bool /*system*/) override
+ {
+ for (std::string const& it : content) {
+ std::string error;
+ if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) {
+ this->SetError(error);
+ return false; // Not (successfully) handled.
+ }
}
+ return true; // Successfully handled.
+ }
+
+ std::string Join(const std::vector<std::string>& content) override
+ {
+ return cmJoin(content, ";");
}
- return true; // Successfully handled.
+};
+
+} // namespace
+
+bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return TargetCompileFeaturesImpl(status).HandleArguments(args,
+ "COMPILE_FEATURES");
}
diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h
index 39597ca..db0c04b 100644
--- a/Source/cmTargetCompileFeaturesCommand.h
+++ b/Source/cmTargetCompileFeaturesCommand.h
@@ -8,31 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase
-{
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetCompileFeaturesCommand>();
- }
-
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
- std::string Join(const std::vector<std::string>& content) override;
-};
+bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx
index ccc215a..e39b726 100644
--- a/Source/cmTargetCompileOptionsCommand.cxx
+++ b/Source/cmTargetCompileOptionsCommand.cxx
@@ -7,34 +7,44 @@
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
+namespace {
-bool cmTargetCompileOptionsCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
+class TargetCompileOptionsImpl : public cmTargetPropCommandBase
{
- return this->HandleArguments(args, "COMPILE_OPTIONS", PROCESS_BEFORE);
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-void cmTargetCompileOptionsCommand::HandleMissingTarget(
- const std::string& name)
-{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify compile options for target \"", name,
- "\" which is not built by this project."));
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify compile options for target \"", name,
+ "\" which is not built by this project."));
+ }
-std::string cmTargetCompileOptionsCommand::Join(
- const std::vector<std::string>& content)
-{
- return cmJoin(content, ";");
-}
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool /*prepend*/, bool /*system*/) override
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ tgt->InsertCompileOption(this->Join(content), lfbt);
+ return true; // Successfully handled.
+ }
+
+ std::string Join(const std::vector<std::string>& content) override
+ {
+ return cmJoin(content, ";");
+ }
+};
+
+} // namespace
-bool cmTargetCompileOptionsCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
+bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- tgt->InsertCompileOption(this->Join(content), lfbt);
- return true; // Successfully handled.
+ return TargetCompileOptionsImpl(status).HandleArguments(
+ args, "COMPILE_OPTIONS", TargetCompileOptionsImpl::PROCESS_BEFORE);
}
diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h
index b328ba2..3ab1a89 100644
--- a/Source/cmTargetCompileOptionsCommand.h
+++ b/Source/cmTargetCompileOptionsCommand.h
@@ -8,39 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetCompileOptionsCommand : public cmTargetPropCommandBase
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetCompileOptionsCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
- std::string Join(const std::vector<std::string>& content) override;
-};
+bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx
index 7801ee8..95b69f3 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.cxx
+++ b/Source/cmTargetIncludeDirectoriesCommand.cxx
@@ -11,26 +11,36 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
+namespace {
-bool cmTargetIncludeDirectoriesCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
+class TargetIncludeDirectoriesImpl : public cmTargetPropCommandBase
{
- return this->HandleArguments(args, "INCLUDE_DIRECTORIES",
- ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-void cmTargetIncludeDirectoriesCommand::HandleMissingTarget(
- const std::string& name)
-{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify include directories for target \"", name,
- "\" which is not built by this project."));
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify include directories for target \"", name,
+ "\" which is not built by this project."));
+ }
+
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool system) override;
+
+ void HandleInterfaceContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool system) override;
-std::string cmTargetIncludeDirectoriesCommand::Join(
+ std::string Join(const std::vector<std::string>& content) override;
+};
+
+std::string TargetIncludeDirectoriesImpl::Join(
const std::vector<std::string>& content)
{
std::string dirs;
@@ -48,7 +58,7 @@ std::string cmTargetIncludeDirectoriesCommand::Join(
return dirs;
}
-bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
+bool TargetIncludeDirectoriesImpl::HandleDirectContent(
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
bool system)
{
@@ -70,16 +80,27 @@ bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
return true; // Successfully handled.
}
-void cmTargetIncludeDirectoriesCommand::HandleInterfaceContent(
+void TargetIncludeDirectoriesImpl::HandleInterfaceContent(
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
bool system)
{
cmTargetPropCommandBase::HandleInterfaceContent(tgt, content, prepend,
system);
-
if (system) {
std::string joined = this->Join(content);
tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
joined.c_str());
}
}
+
+} // namespace
+
+bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return TargetIncludeDirectoriesImpl(status).HandleArguments(
+ args, "INCLUDE_DIRECTORIES",
+ TargetIncludeDirectoriesImpl::ArgumentFlags(
+ TargetIncludeDirectoriesImpl::PROCESS_BEFORE |
+ TargetIncludeDirectoriesImpl::PROCESS_SYSTEM));
+}
diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h
index f6481db..9958f41 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.h
+++ b/Source/cmTargetIncludeDirectoriesCommand.h
@@ -8,43 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetIncludeDirectoriesCommand : public cmTargetPropCommandBase
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetIncludeDirectoriesCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
-
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
- void HandleInterfaceContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
- std::string Join(const std::vector<std::string>& content) override;
-};
+bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetLinkDirectoriesCommand.cxx b/Source/cmTargetLinkDirectoriesCommand.cxx
index c2ef6c1..0c68d60 100644
--- a/Source/cmTargetLinkDirectoriesCommand.cxx
+++ b/Source/cmTargetLinkDirectoriesCommand.cxx
@@ -9,25 +9,37 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
+namespace {
-bool cmTargetLinkDirectoriesCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
+class TargetLinkDirectoriesImpl : public cmTargetPropCommandBase
{
- return this->HandleArguments(args, "LINK_DIRECTORIES", PROCESS_BEFORE);
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-void cmTargetLinkDirectoriesCommand::HandleMissingTarget(
- const std::string& name)
-{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify link directories for target \"", name,
- "\" which is not built by this project."));
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify link directories for target \"", name,
+ "\" which is not built by this project."));
+ }
+
+ std::string Join(const std::vector<std::string>& content) override;
-std::string cmTargetLinkDirectoriesCommand::Join(
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool /*system*/) override
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend);
+ return true; // Successfully handled.
+ }
+};
+
+std::string TargetLinkDirectoriesImpl::Join(
const std::vector<std::string>& content)
{
std::vector<std::string> directories;
@@ -48,12 +60,11 @@ std::string cmTargetLinkDirectoriesCommand::Join(
return cmJoin(directories, ";");
}
-bool cmTargetLinkDirectoriesCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool)
-{
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+} // namespace
- tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend);
-
- return true; // Successfully handled.
+bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return TargetLinkDirectoriesImpl(status).HandleArguments(
+ args, "LINK_DIRECTORIES", TargetLinkDirectoriesImpl::PROCESS_BEFORE);
}
diff --git a/Source/cmTargetLinkDirectoriesCommand.h b/Source/cmTargetLinkDirectoriesCommand.h
index a651d73..3724d6c 100644
--- a/Source/cmTargetLinkDirectoriesCommand.h
+++ b/Source/cmTargetLinkDirectoriesCommand.h
@@ -8,39 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetLinkDirectoriesCommand : public cmTargetPropCommandBase
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetLinkDirectoriesCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
- std::string Join(const std::vector<std::string>& content) override;
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
-};
+bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetLinkOptionsCommand.cxx b/Source/cmTargetLinkOptionsCommand.cxx
index dbd7bfe..df9416f 100644
--- a/Source/cmTargetLinkOptionsCommand.cxx
+++ b/Source/cmTargetLinkOptionsCommand.cxx
@@ -7,33 +7,44 @@
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
+namespace {
-bool cmTargetLinkOptionsCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
+class TargetLinkOptionsImpl : public cmTargetPropCommandBase
{
- return this->HandleArguments(args, "LINK_OPTIONS", PROCESS_BEFORE);
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-void cmTargetLinkOptionsCommand::HandleMissingTarget(const std::string& name)
-{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify link options for target \"", name,
- "\" which is not built by this project."));
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify link options for target \"", name,
+ "\" which is not built by this project."));
+ }
-std::string cmTargetLinkOptionsCommand::Join(
- const std::vector<std::string>& content)
-{
- return cmJoin(content, ";");
-}
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool /*system*/) override
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ tgt->InsertLinkOption(this->Join(content), lfbt, prepend);
+ return true; // Successfully handled.
+ }
+
+ std::string Join(const std::vector<std::string>& content) override
+ {
+ return cmJoin(content, ";");
+ }
+};
+
+} // namespace
-bool cmTargetLinkOptionsCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool)
+bool cmTargetLinkOptionsCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- tgt->InsertLinkOption(this->Join(content), lfbt, prepend);
- return true; // Successfully handled.
+ return TargetLinkOptionsImpl(status).HandleArguments(
+ args, "LINK_OPTIONS", TargetLinkOptionsImpl::PROCESS_BEFORE);
}
diff --git a/Source/cmTargetLinkOptionsCommand.h b/Source/cmTargetLinkOptionsCommand.h
index 918a8d7..13fb40c 100644
--- a/Source/cmTargetLinkOptionsCommand.h
+++ b/Source/cmTargetLinkOptionsCommand.h
@@ -8,39 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetLinkOptionsCommand : public cmTargetPropCommandBase
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetLinkOptionsCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
- std::string Join(const std::vector<std::string>& content) override;
-};
+bool cmTargetLinkOptionsCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetPrecompileHeadersCommand.cxx b/Source/cmTargetPrecompileHeadersCommand.cxx
index 5751fff..887d973 100644
--- a/Source/cmTargetPrecompileHeadersCommand.cxx
+++ b/Source/cmTargetPrecompileHeadersCommand.cxx
@@ -8,51 +8,14 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
#include <utility>
-bool cmTargetPrecompileHeadersCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
-{
- return this->HandleArguments(args, "PRECOMPILE_HEADERS", PROCESS_REUSE_FROM);
-}
-
-void cmTargetPrecompileHeadersCommand::HandleInterfaceContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
- bool system)
-{
- cmTargetPropCommandBase::HandleInterfaceContent(
- tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
-}
-
-void cmTargetPrecompileHeadersCommand::HandleMissingTarget(
- const std::string& name)
-{
- const std::string e =
- cmStrCat("Cannot specify precompile headers for target \"", name,
- "\" which is not built by this project.");
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
-}
-
-std::string cmTargetPrecompileHeadersCommand::Join(
- const std::vector<std::string>& content)
-{
- return cmJoin(content, ";");
-}
-
-bool cmTargetPrecompileHeadersCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
-{
- tgt->AppendProperty(
- "PRECOMPILE_HEADERS",
- this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
- return true;
-}
+namespace {
-std::vector<std::string>
-cmTargetPrecompileHeadersCommand::ConvertToAbsoluteContent(
- cmTarget* /*tgt*/, const std::vector<std::string>& content,
- bool /*isInterfaceContent*/)
+std::vector<std::string> ConvertToAbsoluteContent(
+ const std::vector<std::string>& content, std::string const& baseDir)
{
std::vector<std::string> absoluteContent;
absoluteContent.reserve(content.size());
@@ -66,10 +29,59 @@ cmTargetPrecompileHeadersCommand::ConvertToAbsoluteContent(
cmGeneratorExpression::Find(src) == 0) {
absoluteSrc = src;
} else {
- absoluteSrc =
- cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', src);
+ absoluteSrc = cmStrCat(baseDir, '/', src);
}
absoluteContent.emplace_back(std::move(absoluteSrc));
}
return absoluteContent;
}
+
+class TargetPrecompileHeadersImpl : public cmTargetPropCommandBase
+{
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
+
+private:
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool /*prepend*/, bool /*system*/) override
+ {
+ std::string const& base = this->Makefile->GetCurrentSourceDirectory();
+ tgt->AppendProperty(
+ "PRECOMPILE_HEADERS",
+ this->Join(ConvertToAbsoluteContent(content, base)).c_str());
+ return true;
+ }
+
+ void HandleInterfaceContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool system) override
+ {
+ std::string const& base = this->Makefile->GetCurrentSourceDirectory();
+ cmTargetPropCommandBase::HandleInterfaceContent(
+ tgt, ConvertToAbsoluteContent(content, base), prepend, system);
+ }
+
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify precompile headers for target \"", name,
+ "\" which is not built by this project."));
+ }
+
+ std::string Join(const std::vector<std::string>& content) override
+ {
+ return cmJoin(content, ";");
+ }
+};
+
+} // namespace
+
+bool cmTargetPrecompileHeadersCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return TargetPrecompileHeadersImpl(status).HandleArguments(
+ args, "PRECOMPILE_HEADERS",
+ TargetPrecompileHeadersImpl::PROCESS_REUSE_FROM);
+}
diff --git a/Source/cmTargetPrecompileHeadersCommand.h b/Source/cmTargetPrecompileHeadersCommand.h
index 00dc928..8b0ac97 100644
--- a/Source/cmTargetPrecompileHeadersCommand.h
+++ b/Source/cmTargetPrecompileHeadersCommand.h
@@ -8,43 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetPrecompileHeadersCommand : public cmTargetPropCommandBase
-{
-public:
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetPrecompileHeadersCommand>();
- }
-
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-protected:
- void HandleInterfaceContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
-
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
-
- std::string Join(const std::vector<std::string>& content) override;
- std::vector<std::string> ConvertToAbsoluteContent(
- cmTarget* tgt, const std::vector<std::string>& content,
- bool isInterfaceContent);
-};
+bool cmTargetPrecompileHeadersCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx
index 4bc3125..bbc1e16 100644
--- a/Source/cmTargetPropCommandBase.cxx
+++ b/Source/cmTargetPropCommandBase.cxx
@@ -2,12 +2,24 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetPropCommandBase.h"
+#include "cmExecutionStatus.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmStateTypes.h"
#include "cmTarget.h"
#include "cmake.h"
+cmTargetPropCommandBase::cmTargetPropCommandBase(cmExecutionStatus& status)
+ : Makefile(&status.GetMakefile())
+ , Status(status)
+{
+}
+
+void cmTargetPropCommandBase::SetError(std::string const& e)
+{
+ this->Status.SetError(e);
+}
+
bool cmTargetPropCommandBase::HandleArguments(
std::vector<std::string> const& args, const std::string& prop,
ArgumentFlags flags)
diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h
index b244417..601ad01 100644
--- a/Source/cmTargetPropCommandBase.h
+++ b/Source/cmTargetPropCommandBase.h
@@ -8,13 +8,18 @@
#include <string>
#include <vector>
-#include "cmCommand.h"
-
+class cmExecutionStatus;
+class cmMakefile;
class cmTarget;
-class cmTargetPropCommandBase : public cmCommand
+class cmTargetPropCommandBase
{
public:
+ cmTargetPropCommandBase(cmExecutionStatus& status);
+ virtual ~cmTargetPropCommandBase() = default;
+
+ void SetError(std::string const& e);
+
enum ArgumentFlags
{
NO_FLAGS = 0x0,
@@ -30,6 +35,7 @@ public:
protected:
std::string Property;
cmTarget* Target = nullptr;
+ cmMakefile* Makefile;
virtual void HandleInterfaceContent(cmTarget* tgt,
const std::vector<std::string>& content,
@@ -49,6 +55,8 @@ private:
bool PopulateTargetProperies(const std::string& scope,
const std::vector<std::string>& content,
bool prepend, bool system);
+
+ cmExecutionStatus& Status;
};
#endif
diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx
index 7c9d03c..c2e0b28 100644
--- a/Source/cmTargetSourcesCommand.cxx
+++ b/Source/cmTargetSourcesCommand.cxx
@@ -11,47 +11,54 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
+#include "cmTargetPropCommandBase.h"
-class cmExecutionStatus;
+namespace {
-bool cmTargetSourcesCommand::InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus&)
+class TargetSourcesImpl : public cmTargetPropCommandBase
{
- return this->HandleArguments(args, "SOURCES");
-}
+public:
+ using cmTargetPropCommandBase::cmTargetPropCommandBase;
-void cmTargetSourcesCommand::HandleInterfaceContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
- bool system)
-{
- cmTargetPropCommandBase::HandleInterfaceContent(
- tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
-}
+protected:
+ void HandleInterfaceContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool system) override
+ {
+ cmTargetPropCommandBase::HandleInterfaceContent(
+ tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
+ }
-void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name)
-{
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("Cannot specify sources for target \"", name,
- "\" which is not built by this project."));
-}
+private:
+ void HandleMissingTarget(const std::string& name) override
+ {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Cannot specify sources for target \"", name,
+ "\" which is not built by this project."));
+ }
-std::string cmTargetSourcesCommand::Join(
- const std::vector<std::string>& content)
-{
- return cmJoin(content, ";");
-}
+ bool HandleDirectContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool /*prepend*/, bool /*system*/) override
+ {
+ tgt->AppendProperty(
+ "SOURCES",
+ this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
+ return true; // Successfully handled.
+ }
-bool cmTargetSourcesCommand::HandleDirectContent(
- cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
-{
- tgt->AppendProperty(
- "SOURCES",
- this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
- return true; // Successfully handled.
-}
+ std::string Join(const std::vector<std::string>& content) override
+ {
+ return cmJoin(content, ";");
+ }
+
+ std::vector<std::string> ConvertToAbsoluteContent(
+ cmTarget* tgt, const std::vector<std::string>& content,
+ bool isInterfaceContent);
+};
-std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent(
+std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent(
cmTarget* tgt, const std::vector<std::string>& content,
bool isInterfaceContent)
{
@@ -120,3 +127,11 @@ std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent(
return useAbsoluteContent ? absoluteContent : content;
}
+
+} // namespace
+
+bool cmTargetSourcesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return TargetSourcesImpl(status).HandleArguments(args, "SOURCES");
+}
diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h
index 1cff8c3..5eecf34 100644
--- a/Source/cmTargetSourcesCommand.h
+++ b/Source/cmTargetSourcesCommand.h
@@ -8,49 +8,9 @@
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-#include "cmTargetPropCommandBase.h"
-
class cmExecutionStatus;
-class cmTarget;
-
-class cmTargetSourcesCommand : public cmTargetPropCommandBase
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmTargetSourcesCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-protected:
- void HandleInterfaceContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
-
-private:
- void HandleMissingTarget(const std::string& name) override;
-
- bool HandleDirectContent(cmTarget* tgt,
- const std::vector<std::string>& content,
- bool prepend, bool system) override;
-
- std::string Join(const std::vector<std::string>& content) override;
- std::vector<std::string> ConvertToAbsoluteContent(
- cmTarget* tgt, const std::vector<std::string>& content,
- bool isInterfaceContent);
-};
+bool cmTargetSourcesCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif