diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2018-04-19 12:58:49 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-04-20 13:28:13 (GMT) |
commit | cb83314e659ccb6396b897d8c7301f758b415fc1 (patch) | |
tree | d739605b4d2f44844f20b2a47d4beaae1abe2e1a /Source | |
parent | 38d854dccff6ddeb69c217252dd9ed9f87fe1b19 (diff) | |
download | CMake-cb83314e659ccb6396b897d8c7301f758b415fc1.zip CMake-cb83314e659ccb6396b897d8c7301f758b415fc1.tar.gz CMake-cb83314e659ccb6396b897d8c7301f758b415fc1.tar.bz2 |
add_compile_definitions: add new command
This command manages preprocessor definitions at directory level and
supports generator expressions.
Fixes: #15374
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. */ |