diff options
author | Brad King <brad.king@kitware.com> | 2018-04-23 14:16:20 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-04-23 14:16:24 (GMT) |
commit | ba234392b1ca82549d57488f18e2ab622019d8f6 (patch) | |
tree | 1ac39485ef168ea304f8091e0f81ee436aab6ecd /Source | |
parent | c74539aad738e7ceddaa223b0edb622724b6a2e2 (diff) | |
parent | cb83314e659ccb6396b897d8c7301f758b415fc1 (diff) | |
download | CMake-ba234392b1ca82549d57488f18e2ab622019d8f6.zip CMake-ba234392b1ca82549d57488f18e2ab622019d8f6.tar.gz CMake-ba234392b1ca82549d57488f18e2ab622019d8f6.tar.bz2 |
Merge topic 'add_compile_definitions'
cb83314e65 add_compile_definitions: add new command
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1988
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmAddCompileDefinitionsCommand.cxx | 20 | ||||
-rw-r--r-- | Source/cmAddCompileDefinitionsCommand.h | 31 | ||||
-rw-r--r-- | Source/cmCommands.cxx | 3 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 5 | ||||
-rw-r--r-- | Source/cmMakefile.h | 1 |
6 files changed, 62 insertions, 0 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index a007098..d9e07e5 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -375,6 +375,8 @@ set(SRCS cmCommand.h cmCommands.cxx cmCommands.h + cmAddCompileDefinitionsCommand.cxx + cmAddCompileDefinitionsCommand.h cmAddCompileOptionsCommand.cxx cmAddCompileOptionsCommand.h cmAddCustomCommandCommand.cxx diff --git a/Source/cmAddCompileDefinitionsCommand.cxx b/Source/cmAddCompileDefinitionsCommand.cxx new file mode 100644 index 0000000..0474819 --- /dev/null +++ b/Source/cmAddCompileDefinitionsCommand.cxx @@ -0,0 +1,20 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmAddCompileDefinitionsCommand.h" + +#include "cmMakefile.h" + +class cmExecutionStatus; + +bool cmAddCompileDefinitionsCommand::InitialPass( + std::vector<std::string> const& args, cmExecutionStatus&) +{ + if (args.empty()) { + return true; + } + + for (std::string const& i : args) { + this->Makefile->AddCompileDefinition(i); + } + return true; +} diff --git a/Source/cmAddCompileDefinitionsCommand.h b/Source/cmAddCompileDefinitionsCommand.h new file mode 100644 index 0000000..e985dca --- /dev/null +++ b/Source/cmAddCompileDefinitionsCommand.h @@ -0,0 +1,31 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmAddCompileDefinitionsCommand_h +#define cmAddCompileDefinitionsCommand_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <string> +#include <vector> + +#include "cmCommand.h" + +class cmExecutionStatus; + +class cmAddCompileDefinitionsCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + cmCommand* Clone() override { return new cmAddCompileDefinitionsCommand; } + + /** + * 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; +}; + +#endif diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index a1de8b1..a87b450 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -4,6 +4,7 @@ #include "cmPolicies.h" #include "cmState.h" +#include "cmAddCompileDefinitionsCommand.h" #include "cmAddCustomCommandCommand.h" #include "cmAddCustomTargetCommand.h" #include "cmAddDefinitionsCommand.h" @@ -253,6 +254,8 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("try_run", new cmTryRunCommand); #if defined(CMAKE_BUILD_WITH_CMAKE) + state->AddBuiltinCommand("add_compile_definitions", + new cmAddCompileDefinitionsCommand); state->AddBuiltinCommand("add_compile_options", new cmAddCompileOptionsCommand); state->AddBuiltinCommand("aux_source_directory", diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 490d516..18ba7aa 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1195,6 +1195,11 @@ void cmMakefile::RemoveDefineFlag(std::string const& flag, } } +void cmMakefile::AddCompileDefinition(std::string const& option) +{ + this->AppendProperty("COMPILE_DEFINITIONS", option.c_str()); +} + void cmMakefile::AddCompileOption(std::string const& option) { this->AppendProperty("COMPILE_OPTIONS", option.c_str()); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 8589deb..16b2047 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -168,6 +168,7 @@ public: */ void AddDefineFlag(std::string const& definition); void RemoveDefineFlag(std::string const& definition); + void AddCompileDefinition(std::string const& definition); void AddCompileOption(std::string const& option); /** Create a new imported target with the name and type given. */ |