summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmCommands.cxx2
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.cxx57
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.h91
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt26
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/consumer.cpp18
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/main.cpp14
-rw-r--r--Tests/CMakeLists.txt1
7 files changed, 209 insertions, 0 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 6b315ea..227b226 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -28,6 +28,7 @@
#include "cmRemoveDefinitionsCommand.cxx"
#include "cmSourceGroupCommand.cxx"
#include "cmSubdirDependsCommand.cxx"
+#include "cmTargetCompileDefinitionsCommand.cxx"
#include "cmTargetIncludeDirectoriesCommand.cxx"
#include "cmTargetPropCommandBase.cxx"
#include "cmUseMangledMesaCommand.cxx"
@@ -69,6 +70,7 @@ void GetPredefinedCommands(std::list<cmCommand*>&
commands.push_back(new cmSourceGroupCommand);
commands.push_back(new cmSubdirDependsCommand);
commands.push_back(new cmTargetIncludeDirectoriesCommand);
+ commands.push_back(new cmTargetCompileDefinitionsCommand);
commands.push_back(new cmUseMangledMesaCommand);
commands.push_back(new cmUtilitySourceCommand);
commands.push_back(new cmVariableRequiresCommand);
diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx
new file mode 100644
index 0000000..492a1b7
--- /dev/null
+++ b/Source/cmTargetCompileDefinitionsCommand.cxx
@@ -0,0 +1,57 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "cmTargetCompileDefinitionsCommand.h"
+
+#include "cmMakefileIncludeDirectoriesEntry.h"
+
+bool cmTargetCompileDefinitionsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ return this->HandleArguments(args, "COMPILE_DEFINITIONS");
+}
+
+void cmTargetCompileDefinitionsCommand
+::HandleImportedTargetInvalidScope(const std::string &scope,
+ const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify " << scope << " compile definitions for imported "
+ "target \"" << tgt << "\". Compile definitions can only be "
+ "specified for an imported target in the INTERFACE mode.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+void cmTargetCompileDefinitionsCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile definitions for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+bool cmTargetCompileDefinitionsCommand
+::HandleNonTargetArg(std::string &content,
+ const std::string &sep,
+ const std::string &entry,
+ const std::string &)
+{
+ content += sep + entry;
+ return true;
+}
+
+void cmTargetCompileDefinitionsCommand
+::HandleDirectContent(cmTarget *tgt, const std::string &content,
+ bool)
+{
+ tgt->AppendProperty("COMPILE_DEFINITIONS", content.c_str());
+}
diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h
new file mode 100644
index 0000000..707610e
--- /dev/null
+++ b/Source/cmTargetCompileDefinitionsCommand.h
@@ -0,0 +1,91 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+
+#ifndef cmTargetCompileDefinitionsCommand_h
+#define cmTargetCompileDefinitionsCommand_h
+
+#include "cmTargetPropCommandBase.h"
+
+class cmTargetCompileDefinitionsCommand : public cmTargetPropCommandBase
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetCompileDefinitionsCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual const char* GetName() const { return "target_compile_definitions";}
+
+ /**
+ * Succinct documentation.
+ */
+ virtual const char* GetTerseDocumentation() const
+ {
+ return
+ "Add compile definitions to a target.";
+ }
+
+ /**
+ * More documentation.
+ */
+ virtual const char* GetFullDocumentation() const
+ {
+ return
+ " target_compile_definitions(<target> "
+ "<INTERFACE|PUBLIC|PRIVATE> [items1...]\n"
+ " [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])\n"
+ "Specify compile definitions or targets to use when compiling a given "
+ "target. "
+ "The named <target> must have been created by a command such as "
+ "add_executable or add_library. "
+ "The INTERFACE, PUBLIC and PRIVATE keywords are required to specify "
+ "the scope of the following arguments. PRIVATE and PUBLIC items will "
+ "populate the COMPILE_DEFINITIONS property of <target>. PUBLIC and "
+ "INTERFACE items will populate the INTERFACE_COMPILE_DEFINITIONS "
+ "property of <target>. "
+ "The non-scope arguments specify compile definitions or targets to use "
+ "INTERFACE_COMPILE_DEFINITIONS from. "
+ "Repeated calls for the same <target> append items in the order called."
+ "\n"
+ ;
+ }
+
+ cmTypeMacro(cmTargetCompileDefinitionsCommand, cmCommand);
+
+private:
+ virtual void HandleImportedTargetInvalidScope(const std::string &scope,
+ const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleNonTargetArg(std::string &content,
+ const std::string &sep,
+ const std::string &entry,
+ const std::string &tgt);
+
+ virtual void HandleDirectContent(cmTarget *tgt, const std::string &content,
+ bool prepend);
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
new file mode 100644
index 0000000..84a23ef
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
@@ -0,0 +1,26 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(target_compile_definitions)
+
+add_executable(target_compile_definitions
+ "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
+)
+target_compile_definitions(target_compile_definitions
+ PRIVATE MY_PRIVATE_DEFINE
+ PUBLIC MY_PUBLIC_DEFINE
+ INTERFACE MY_INTERFACE_DEFINE
+)
+
+add_library(importedlib UNKNOWN IMPORTED)
+target_compile_definitions(importedlib
+ INTERFACE MY_IMPORTEDINTERFACE_DEFINE
+)
+
+add_executable(consumer
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
+)
+
+target_compile_definitions(consumer
+ PRIVATE target_compile_definitions importedlib
+)
diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
new file mode 100644
index 0000000..e3788dd
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
@@ -0,0 +1,18 @@
+
+#ifdef MY_PRIVATE_DEFINE
+#error Unexpected MY_PRIVATE_DEFINE
+#endif
+
+#ifndef MY_PUBLIC_DEFINE
+#error Expected MY_PUBLIC_DEFINE
+#endif
+
+#ifndef MY_INTERFACE_DEFINE
+#error Expected MY_INTERFACE_DEFINE
+#endif
+
+#ifndef MY_IMPORTEDINTERFACE_DEFINE
+#error Expected MY_IMPORTEDINTERFACE_DEFINE
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_compile_definitions/main.cpp b/Tests/CMakeCommands/target_compile_definitions/main.cpp
new file mode 100644
index 0000000..addb33c
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_definitions/main.cpp
@@ -0,0 +1,14 @@
+
+#ifndef MY_PRIVATE_DEFINE
+#error Expected MY_PRIVATE_DEFINE
+#endif
+
+#ifndef MY_PUBLIC_DEFINE
+#error Expected MY_PUBLIC_DEFINE
+#endif
+
+#ifdef MY_INTERFACE_DEFINE
+#error Unexpected MY_INTERFACE_DEFINE
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 2dced5f..2f7df01 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1931,6 +1931,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries)
ADD_TEST_MACRO(CMakeCommands.target_include_directories target_include_directories)
+ ADD_TEST_MACRO(CMakeCommands.target_compile_definitions target_compile_definitions)
configure_file(
"${CMake_SOURCE_DIR}/Tests/CTestTestCrash/test.cmake.in"