[Cmake-commits] CMake branch, next, updated. v2.8.12.1-5066-gd07a0f4
Stephen Kelly
steveire at gmail.com
Mon Nov 11 15:02:55 EST 2013
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".
The branch, next has been updated
via d07a0f44c99bb0cbfa8c80ff05c7102858cda361 (commit)
via 76ab4ee7b2d50b74b547f97a29eaf4b38fff7657 (commit)
via e4bf7af42858a91bbb389b7bbae82033c851f254 (commit)
via 56cb5836eb63d35b73d311fd3a6015f91f5ea7f5 (commit)
via b3bbaa85c102ab1f5ea01b91b7d118be82876f1c (commit)
via 405303b35d492a71593fcd4897bb8fc75e78d0d5 (commit)
via 31fdddb09f496f3b3a1013ef102e42f60222d00b (commit)
via 30c1703d8a562e66e4befccbff07d68ae6af3b56 (commit)
via 4a2106f2b18add8c9dfd3623988cfd20c48b888f (commit)
via 5b706c62e9eb5b20bac4e0644f8c1e5c4d2ca152 (commit)
via 718551001344234775ee8155ee3478ea8877ce73 (commit)
via 4144d4b9cdb0abbef99e6d8def703a1ec04940b8 (commit)
via 231cca7df67bdc9eaf76f11c3873dcc6a892137f (commit)
from 55ec64678a04a4ec164427670e26933a9522fc48 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d07a0f44c99bb0cbfa8c80ff05c7102858cda361
commit d07a0f44c99bb0cbfa8c80ff05c7102858cda361
Merge: 55ec646 76ab4ee
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Nov 11 15:02:46 2013 -0500
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Nov 11 15:02:46 2013 -0500
Merge topic 'target_compile_features' into next
76ab4ee Base the target_compile_features command on cmTargetPropCommandBase.
e4bf7af cmTargetPropCommandBase: Change the interface to return bool.
56cb583 cmTarget: Transitively evaluate compiler features.
b3bbaa8 cmTarget: Allow populating COMPILE_FEATURES using generator expressions.
405303b cmTarget: Make COMPILE_FEATURES available as a target property.
31fdddb Add target_compile_features command.
30c1703 Record compilers capable of msvcxx_sealed feature.
4a2106f Record compilers capable of the gnuxx_typeof feature.
5b706c6 Record the compilers capable of the cxx_delegating_constructors feature.
7185510 cmTarget: Add CXX_STANDARD and CXX_EXTENSION target properties.
4144d4b Add some COMPILE_OPTIONS for specifying C++ dialect.
231cca7 Don't load Clang-CXX from AppleClang-CXX.
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=76ab4ee7b2d50b74b547f97a29eaf4b38fff7657
commit 76ab4ee7b2d50b74b547f97a29eaf4b38fff7657
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Oct 30 21:13:44 2013 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 21:00:35 2013 +0100
Base the target_compile_features command on cmTargetPropCommandBase.
This gives us 'free' handling of IMPORTED, ALIAS, INTERFACE,
non-compilable and missing targets.
diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx
index 8b48ce3..8a7e5f8 100644
--- a/Source/cmTargetCompileFeaturesCommand.cxx
+++ b/Source/cmTargetCompileFeaturesCommand.cxx
@@ -15,49 +15,56 @@ bool cmTargetCompileFeaturesCommand::InitialPass(
std::vector<std::string> const& args,
cmExecutionStatus &)
{
- if (args.size() < 3)
- {
- this->SetError("called with wrong number of arguments.");
- return false;
- }
- cmTarget *target = this->Makefile->FindTargetToUse(args[0].c_str());
+ return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS);
+}
- if(!target)
- {
- this->SetError("specified invalid target.");
- return false;
- }
+void cmTargetCompileFeaturesCommand
+::HandleImportedTarget(const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile features for imported target \""
+ << tgt << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
- if(target->IsImported())
- {
- this->SetError("may not be used with an IMPORTED target.");
- return false;
- }
+void cmTargetCompileFeaturesCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile features for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
- const bool interfaceOnly = args[1] == "INTERFACE";
- if(args[1] != "PRIVATE" && args[1] != "PUBLIC" && !interfaceOnly)
+//----------------------------------------------------------------------------
+std::string cmTargetCompileFeaturesCommand
+::Join(const std::vector<std::string> &content)
+{
+ std::string defs;
+ std::string sep;
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
{
- this->SetError("called with invalid arguments.");
- return false;
+ defs += sep + *it;
+ sep = ";";
}
+ return defs;
+}
- for (size_t i = 2; i < args.size(); ++i)
+//----------------------------------------------------------------------------
+bool cmTargetCompileFeaturesCommand
+::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
+ bool, bool)
+{
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
{
- std::string feature = args[i];
-
- if (!interfaceOnly)
- {
- if (!this->Makefile->AddRequiredTargetFeature(target, feature.c_str()))
- {
- cmOStringStream e;
- e << "specified unknown feature \"" << feature << "\".";
- this->SetError(e.str().c_str());
- return false;
- }
- }
- if (interfaceOnly || args[1] == "PUBLIC")
+ if(!this->Makefile->AddRequiredTargetFeature(tgt, it->c_str()))
{
- target->AppendProperty("INTERFACE_COMPILE_FEATURES", feature.c_str());
+ cmOStringStream e;
+ e << "specified unknown feature \"" << *it << "\".";
+ this->SetError(e.str().c_str());
+ return false;
}
}
return true;
diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h
index 63beeca..97a61ba 100644
--- a/Source/cmTargetCompileFeaturesCommand.h
+++ b/Source/cmTargetCompileFeaturesCommand.h
@@ -12,9 +12,9 @@
#ifndef cmTargetCompileFeaturesCommand_h
#define cmTargetCompileFeaturesCommand_h
-#include "cmCommand.h"
+#include "cmTargetPropCommandBase.h"
-class cmTargetCompileFeaturesCommand : public cmCommand
+class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase
{
virtual cmCommand* Clone()
{
@@ -26,7 +26,16 @@ class cmTargetCompileFeaturesCommand : public cmCommand
virtual const char* GetName() const { return "target_compile_features";}
- cmTypeMacro(cmTargetCompileFeaturesCommand, cmCommand);
+ cmTypeMacro(cmTargetCompileFeaturesCommand, cmTargetPropCommandBase);
+
+private:
+ virtual void HandleImportedTarget(const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+ virtual std::string Join(const std::vector<std::string> &content);
};
#endif
diff --git a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
index 28341c9..f2abef7 100644
--- a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
@@ -1,4 +1,11 @@
include(RunCMake)
+run_cmake(not_enough_args)
+run_cmake(alias_target)
+run_cmake(utility_target)
+run_cmake(invalid_args)
+run_cmake(invalid_args_on_interface)
+run_cmake(imported_target)
+run_cmake(no_target)
run_cmake(not_a_cxx_feature)
run_cmake(no_matching_cxx_feature)
diff --git a/Tests/RunCMake/target_compile_features/alias_target-result.txt b/Tests/RunCMake/target_compile_features/alias_target-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/alias_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
new file mode 100644
index 0000000..3321e3f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at alias_target.cmake:4 \(target_compile_features\):
+ target_compile_features can not be used on an ALIAS target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/alias_target.cmake b/Tests/RunCMake/target_compile_features/alias_target.cmake
new file mode 100644
index 0000000..d35ddba
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/alias_target.cmake
@@ -0,0 +1,4 @@
+
+add_executable(main empty.cpp)
+add_executable(Alias::Main ALIAS main)
+target_compile_features(Alias::Main PRIVATE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/imported_target-result.txt b/Tests/RunCMake/target_compile_features/imported_target-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/imported_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/imported_target-stderr.txt b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
new file mode 100644
index 0000000..95431b4
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at imported_target.cmake:3 \(target_compile_features\):
+ Cannot specify compile features for imported target "main".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/imported_target.cmake b/Tests/RunCMake/target_compile_features/imported_target.cmake
new file mode 100644
index 0000000..e248c2f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/imported_target.cmake
@@ -0,0 +1,3 @@
+
+add_library(main INTERFACE IMPORTED)
+target_compile_features(main INTERFACE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args-result.txt b/Tests/RunCMake/target_compile_features/invalid_args-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
new file mode 100644
index 0000000..1242730
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at invalid_args.cmake:3 \(target_compile_features\):
+ target_compile_features called with invalid arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args.cmake b/Tests/RunCMake/target_compile_features/invalid_args.cmake
new file mode 100644
index 0000000..1a7fb37
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args.cmake
@@ -0,0 +1,3 @@
+
+add_executable(main empty.cpp)
+target_compile_features(main INVALID cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt
new file mode 100644
index 0000000..d7f48b1
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at invalid_args_on_interface.cmake:3 \(target_compile_features\):
+ target_compile_features may only be set INTERFACE properties on INTERFACE
+ targets
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake b/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake
new file mode 100644
index 0000000..324d0f3
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake
@@ -0,0 +1,3 @@
+
+add_library(main INTERFACE)
+target_compile_features(main PRIVATE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/no_target-result.txt b/Tests/RunCMake/target_compile_features/no_target-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/no_target-stderr.txt b/Tests/RunCMake/target_compile_features/no_target-stderr.txt
new file mode 100644
index 0000000..9cd5e6b
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_target-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at no_target.cmake:2 \(target_compile_features\):
+ Cannot specify compile features for target "main" which is not built by
+ this project.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/no_target.cmake b/Tests/RunCMake/target_compile_features/no_target.cmake
new file mode 100644
index 0000000..3f0afe2
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_target.cmake
@@ -0,0 +1,2 @@
+
+target_compile_features(main INTERFACE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-result.txt b/Tests/RunCMake/target_compile_features/not_enough_args-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_enough_args-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
new file mode 100644
index 0000000..0f27a9c
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at not_enough_args.cmake:3 \(target_compile_features\):
+ target_compile_features called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args.cmake b/Tests/RunCMake/target_compile_features/not_enough_args.cmake
new file mode 100644
index 0000000..9561230
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_enough_args.cmake
@@ -0,0 +1,3 @@
+
+add_executable(main empty.cpp)
+target_compile_features(main)
diff --git a/Tests/RunCMake/target_compile_features/utility_target-result.txt b/Tests/RunCMake/target_compile_features/utility_target-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/utility_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/utility_target-stderr.txt b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
new file mode 100644
index 0000000..96b0bd7
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at utility_target.cmake:4 \(target_compile_features\):
+ target_compile_features called with non-compilable target type
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/utility_target.cmake b/Tests/RunCMake/target_compile_features/utility_target.cmake
new file mode 100644
index 0000000..8919056
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/utility_target.cmake
@@ -0,0 +1,4 @@
+
+add_custom_target(utility)
+
+target_compile_features(utility PRIVATE cxx_delegating_constructors)
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e4bf7af42858a91bbb389b7bbae82033c851f254
commit e4bf7af42858a91bbb389b7bbae82033c851f254
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Nov 9 00:18:35 2013 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 21:00:35 2013 +0100
cmTargetPropCommandBase: Change the interface to return bool.
This is needed for the target_compile_features command, which
may fail at configure time if an invalid feature is specified.
diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx
index 46c9666..2ad2405 100644
--- a/Source/cmTargetCompileDefinitionsCommand.cxx
+++ b/Source/cmTargetCompileDefinitionsCommand.cxx
@@ -58,9 +58,10 @@ std::string cmTargetCompileDefinitionsCommand
}
//----------------------------------------------------------------------------
-void cmTargetCompileDefinitionsCommand
+bool cmTargetCompileDefinitionsCommand
::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
bool, bool)
{
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
+ return true;
}
diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h
index 7405e90..eedcfbf 100644
--- a/Source/cmTargetCompileDefinitionsCommand.h
+++ b/Source/cmTargetCompileDefinitionsCommand.h
@@ -44,7 +44,7 @@ private:
virtual void HandleImportedTarget(const std::string &tgt);
virtual void HandleMissingTarget(const std::string &name);
- virtual void HandleDirectContent(cmTarget *tgt,
+ virtual bool HandleDirectContent(cmTarget *tgt,
const std::vector<std::string> &content,
bool prepend, bool system);
virtual std::string Join(const std::vector<std::string> &content);
diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx
index 254acc7..18499fd 100644
--- a/Source/cmTargetCompileOptionsCommand.cxx
+++ b/Source/cmTargetCompileOptionsCommand.cxx
@@ -51,7 +51,7 @@ std::string cmTargetCompileOptionsCommand
}
//----------------------------------------------------------------------------
-void cmTargetCompileOptionsCommand
+bool cmTargetCompileOptionsCommand
::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
bool, bool)
{
@@ -59,4 +59,5 @@ void cmTargetCompileOptionsCommand
this->Makefile->GetBacktrace(lfbt);
cmValueWithOrigin entry(this->Join(content), lfbt);
tgt->InsertCompileOption(entry);
+ return true;
}
diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h
index 3713e5a..4376ba7 100644
--- a/Source/cmTargetCompileOptionsCommand.h
+++ b/Source/cmTargetCompileOptionsCommand.h
@@ -44,7 +44,7 @@ private:
virtual void HandleImportedTarget(const std::string &tgt);
virtual void HandleMissingTarget(const std::string &name);
- virtual void HandleDirectContent(cmTarget *tgt,
+ virtual bool HandleDirectContent(cmTarget *tgt,
const std::vector<std::string> &content,
bool prepend, bool system);
virtual std::string Join(const std::vector<std::string> &content);
diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx
index e7b906c..af7fe77 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.cxx
+++ b/Source/cmTargetIncludeDirectoriesCommand.cxx
@@ -64,7 +64,7 @@ std::string cmTargetIncludeDirectoriesCommand
}
//----------------------------------------------------------------------------
-void cmTargetIncludeDirectoriesCommand
+bool cmTargetIncludeDirectoriesCommand
::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
bool prepend, bool system)
{
@@ -76,6 +76,7 @@ void cmTargetIncludeDirectoriesCommand
{
tgt->AddSystemIncludeDirectories(content);
}
+ return true;
}
//----------------------------------------------------------------------------
diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h
index 6863ee5..bb0efcd 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.h
+++ b/Source/cmTargetIncludeDirectoriesCommand.h
@@ -45,7 +45,7 @@ private:
virtual void HandleImportedTarget(const std::string &tgt);
virtual void HandleMissingTarget(const std::string &name);
- virtual void HandleDirectContent(cmTarget *tgt,
+ virtual bool HandleDirectContent(cmTarget *tgt,
const std::vector<std::string> &content,
bool prepend, bool system);
virtual void HandleInterfaceContent(cmTarget *tgt,
diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx
index e7b6999..2470b28 100644
--- a/Source/cmTargetPropCommandBase.cxx
+++ b/Source/cmTargetPropCommandBase.cxx
@@ -131,29 +131,31 @@ bool cmTargetPropCommandBase
|| args[i] == "PRIVATE"
|| args[i] == "INTERFACE" )
{
- this->PopulateTargetProperies(scope, content, prepend, system);
- return true;
+ return this->PopulateTargetProperies(scope, content, prepend, system);
}
content.push_back(args[i]);
}
- this->PopulateTargetProperies(scope, content, prepend, system);
- return true;
+ return this->PopulateTargetProperies(scope, content, prepend, system);
}
//----------------------------------------------------------------------------
-void cmTargetPropCommandBase
+bool cmTargetPropCommandBase
::PopulateTargetProperies(const std::string &scope,
const std::vector<std::string> &content,
bool prepend, bool system)
{
if (scope == "PRIVATE" || scope == "PUBLIC")
{
- this->HandleDirectContent(this->Target, content, prepend, system);
+ if (!this->HandleDirectContent(this->Target, content, prepend, system))
+ {
+ return false;
+ }
}
if (scope == "INTERFACE" || scope == "PUBLIC")
{
this->HandleInterfaceContent(this->Target, content, prepend, system);
}
+ return true;
}
//----------------------------------------------------------------------------
diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h
index c402836..67a8596 100644
--- a/Source/cmTargetPropCommandBase.h
+++ b/Source/cmTargetPropCommandBase.h
@@ -43,7 +43,7 @@ private:
virtual void HandleImportedTarget(const std::string &tgt) = 0;
virtual void HandleMissingTarget(const std::string &name) = 0;
- virtual void HandleDirectContent(cmTarget *tgt,
+ virtual bool HandleDirectContent(cmTarget *tgt,
const std::vector<std::string> &content,
bool prepend, bool system) = 0;
@@ -51,7 +51,7 @@ private:
bool ProcessContentArgs(std::vector<std::string> const& args,
unsigned int &argIndex, bool prepend, bool system);
- void PopulateTargetProperies(const std::string &scope,
+ bool PopulateTargetProperies(const std::string &scope,
const std::vector<std::string> &content,
bool prepend, bool system);
};
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=56cb5836eb63d35b73d311fd3a6015f91f5ea7f5
commit 56cb5836eb63d35b73d311fd3a6015f91f5ea7f5
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Oct 22 01:40:47 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 21:00:35 2013 +0100
cmTarget: Transitively evaluate compiler features.
Extend the interface of the target_compile_features command with
PUBLIC and INTERFACE keywords. Populate the INTERFACE_COMPILER_FEATURES
target property if they are set. Consume the INTERFACE_COMPILER_FEATURES
target property from linked dependent targets to determine the final
required compiler features and the compile flag, if needed.
diff --git a/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst
index ebd9611..e33ba4e 100644
--- a/Help/command/target_compile_features.rst
+++ b/Help/command/target_compile_features.rst
@@ -5,7 +5,7 @@ Add expected compiler features to a target.
::
- target_compile_features(<target> PRIVATE <feature> [...])
+ target_compile_features(<target> <PRIVATE|PUBLIC|INTERFACE> <feature> [...])
Specify compiler features required when compiling a given target. If the
feature is not listed in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable,
@@ -13,6 +13,12 @@ then an error will be reported by CMake. If the use of the feature requires
an additional compiler flag, such as --std=c++11, the flag will be added
automatically.
+The INTERFACE, PUBLIC and PRIVATE keywords are required to specify the
+scope of the features. PRIVATE and PUBLIC items will
+populate the :prop_tgt:`COMPILE_FEATURES` property of <target>. PUBLIC and
+INTERFACE items will populate the :prop_tgt:`INTERFACE_COMPILE_FEATURES` property
+of <target>. Repeated calls for the same <target> append items in the order called.
+
The named <target> must have been created by a command such as
add_executable or add_library and must not be an IMPORTED target.
diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx
index 92dc054..cfcaa70 100644
--- a/Source/cmGeneratorExpressionDAGChecker.cxx
+++ b/Source/cmGeneratorExpressionDAGChecker.cxx
@@ -210,3 +210,11 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingCompileOptions() const
return (strcmp(prop, "COMPILE_OPTIONS") == 0
|| strcmp(prop, "INTERFACE_COMPILE_OPTIONS") == 0 );
}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorExpressionDAGChecker::EvaluatingCompileFeatures() const
+{
+ const char *prop = this->Property.c_str();
+ return (strcmp(prop, "COMPILE_FEATURES") == 0
+ || strcmp(prop, "INTERFACE_COMPILE_FEATURES") == 0);
+}
diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h
index c8594e7..0502430 100644
--- a/Source/cmGeneratorExpressionDAGChecker.h
+++ b/Source/cmGeneratorExpressionDAGChecker.h
@@ -20,13 +20,15 @@
F(EvaluatingIncludeDirectories) \
F(EvaluatingSystemIncludeDirectories) \
F(EvaluatingCompileDefinitions) \
- F(EvaluatingCompileOptions)
+ F(EvaluatingCompileOptions) \
+ F(EvaluatingCompileFeatures)
#define CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(F) \
F(INCLUDE_DIRECTORIES) \
F(SYSTEM_INCLUDE_DIRECTORIES) \
F(COMPILE_DEFINITIONS) \
- F(COMPILE_OPTIONS)
+ F(COMPILE_OPTIONS) \
+ F(COMPILE_FEATURES)
//----------------------------------------------------------------------------
struct cmGeneratorExpressionDAGChecker
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 08b9e86..a44ce49 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1386,6 +1386,13 @@ void cmLocalGenerator::AddCompileOptions(
this->AppendFlagEscape(flags, i->c_str());
}
}
+ std::vector<std::string> features;
+ target->GetCompileFeatures(features, config);
+ for(std::vector<std::string>::const_iterator it = features.begin();
+ it != features.end(); ++it)
+ {
+ this->Makefile->AddRequiredTargetFeature(target, it->c_str());
+ }
this->AddCompilerRequirementFlag(flags, target, lang);
}
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 8a1e386..ea7dc97 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -145,10 +145,13 @@ public:
CachedLinkInterfaceCompileOptionsEntries;
mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
CachedLinkInterfaceCompileDefinitionsEntries;
+ mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
+ CachedLinkInterfaceCompileFeaturesEntries;
mutable std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone;
mutable std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone;
mutable std::map<std::string, bool> CacheLinkInterfaceCompileOptionsDone;
+ mutable std::map<std::string, bool> CacheLinkInterfaceCompileFeaturesDone;
};
//----------------------------------------------------------------------------
@@ -183,6 +186,7 @@ cmTargetInternals::~cmTargetInternals()
{
deleteAndClear(this->CachedLinkInterfaceIncludeDirectoriesEntries);
deleteAndClear(this->CachedLinkInterfaceCompileOptionsEntries);
+ deleteAndClear(this->CachedLinkInterfaceCompileFeaturesEntries);
deleteAndClear(this->CachedLinkInterfaceCompileDefinitionsEntries);
}
@@ -205,6 +209,7 @@ cmTarget::cmTarget()
this->BuildInterfaceIncludesAppended = false;
this->DebugIncludesDone = false;
this->DebugCompileOptionsDone = false;
+ this->DebugCompileFeaturesDone = false;
this->DebugCompileDefinitionsDone = false;
}
@@ -2223,6 +2228,121 @@ void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
}
//----------------------------------------------------------------------------
+static void processCompileFeatures(cmTarget const* tgt,
+ const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
+ std::vector<std::string> &options,
+ std::set<std::string> &uniqueOptions,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const char *config, bool debugOptions)
+{
+ processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
+ dagChecker, config, debugOptions, "features");
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetCompileFeatures(std::vector<std::string> &result,
+ const char *config) const
+{
+ std::set<std::string> uniqueFeatures;
+ cmListFileBacktrace lfbt;
+
+ cmGeneratorExpressionDAGChecker dagChecker(lfbt,
+ this->GetName(),
+ "COMPILE_FEATURES",
+ 0, 0);
+
+ std::vector<std::string> debugProperties;
+ const char *debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp)
+ {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugFeatures = !this->DebugCompileFeaturesDone
+ && std::find(debugProperties.begin(),
+ debugProperties.end(),
+ "COMPILE_FEATURES")
+ != debugProperties.end();
+
+ if (this->Makefile->IsGeneratingBuildSystem())
+ {
+ this->DebugCompileFeaturesDone = true;
+ }
+
+ processCompileFeatures(this,
+ this->Internal->CompileFeaturesEntries,
+ result,
+ uniqueFeatures,
+ &dagChecker,
+ config,
+ debugFeatures);
+
+ std::string configString = config ? config : "";
+ if (!this->Internal->CacheLinkInterfaceCompileFeaturesDone[configString])
+ {
+
+ for (std::vector<cmValueWithOrigin>::const_iterator
+ it = this->Internal->LinkInterfacePropertyEntries.begin(),
+ end = this->Internal->LinkInterfacePropertyEntries.end();
+ it != end; ++it)
+ {
+ if (!cmGeneratorExpression::IsValidTargetName(it->Value)
+ && cmGeneratorExpression::Find(it->Value) == std::string::npos)
+ {
+ continue;
+ }
+ {
+ cmGeneratorExpression ge(lfbt);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(it->Value);
+ std::string targetResult = cge->Evaluate(this->Makefile, config,
+ false, this, 0, 0);
+ if (!this->Makefile->FindTargetToUse(targetResult.c_str()))
+ {
+ continue;
+ }
+ }
+ std::string featureGenex = "$<TARGET_PROPERTY:" +
+ it->Value + ",INTERFACE_COMPILE_FEATURES>";
+ if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
+ {
+ // Because it->Value is a generator expression, ensure that it
+ // evaluates to the non-empty string before being used in the
+ // TARGET_PROPERTY expression.
+ featureGenex = "$<$<BOOL:" + it->Value + ">:" + featureGenex + ">";
+ }
+ cmGeneratorExpression ge(it->Backtrace);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
+ featureGenex);
+
+ this->Internal
+ ->CachedLinkInterfaceCompileFeaturesEntries[configString].push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge,
+ it->Value));
+ }
+ }
+
+ processCompileFeatures(this,
+ this->Internal->CachedLinkInterfaceCompileFeaturesEntries[configString],
+ result,
+ uniqueFeatures,
+ &dagChecker,
+ config,
+ debugFeatures);
+
+ if (!this->Makefile->IsGeneratingBuildSystem())
+ {
+ deleteAndClear(this->Internal->CachedLinkInterfaceCompileFeaturesEntries);
+ }
+ else
+ {
+ this->Internal->CacheLinkInterfaceCompileFeaturesDone[configString]
+ = true;
+ }
+}
+
+//----------------------------------------------------------------------------
void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
{
// Wipe out maps caching information affected by this property.
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index b516a0a..0dc90a4 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -524,6 +524,8 @@ public:
void GetCompileOptions(std::vector<std::string> &result,
const char *config) const;
+ void GetCompileFeatures(std::vector<std::string> &result,
+ const char *config) const;
bool IsNullImpliedByLinkLibraries(const std::string &p) const;
bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
@@ -682,6 +684,7 @@ private:
mutable bool DebugIncludesDone;
mutable bool DebugCompileOptionsDone;
mutable bool DebugCompileDefinitionsDone;
+ mutable bool DebugCompileFeaturesDone;
mutable std::set<std::string> LinkImplicitNullProperties;
bool BuildInterfaceIncludesAppended;
diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx
index f89e075..8b48ce3 100644
--- a/Source/cmTargetCompileFeaturesCommand.cxx
+++ b/Source/cmTargetCompileFeaturesCommand.cxx
@@ -34,7 +34,8 @@ bool cmTargetCompileFeaturesCommand::InitialPass(
return false;
}
- if(args[1] != "PRIVATE")
+ const bool interfaceOnly = args[1] == "INTERFACE";
+ if(args[1] != "PRIVATE" && args[1] != "PUBLIC" && !interfaceOnly)
{
this->SetError("called with invalid arguments.");
return false;
@@ -44,12 +45,19 @@ bool cmTargetCompileFeaturesCommand::InitialPass(
{
std::string feature = args[i];
- if (!this->Makefile->AddRequiredTargetFeature(target, feature.c_str()))
+ if (!interfaceOnly)
{
- cmOStringStream e;
- e << "specified unknown feature \"" << feature << "\".";
- this->SetError(e.str().c_str());
- return false;
+ if (!this->Makefile->AddRequiredTargetFeature(target, feature.c_str()))
+ {
+ cmOStringStream e;
+ e << "specified unknown feature \"" << feature << "\".";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+ }
+ if (interfaceOnly || args[1] == "PUBLIC")
+ {
+ target->AppendProperty("INTERFACE_COMPILE_FEATURES", feature.c_str());
}
}
return true;
diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
index c26ddbd..7276935 100644
--- a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
@@ -21,3 +21,11 @@ add_executable(target_compile_features main.cpp)
target_compile_features(target_compile_features
PRIVATE cxx_delegating_constructors
)
+
+add_library(lib_delegating_constructors lib_delegating_constructors.cpp)
+target_compile_features(lib_delegating_constructors
+ PUBLIC cxx_delegating_constructors
+)
+
+add_executable(lib_user lib_user.cpp)
+target_link_libraries(lib_user lib_delegating_constructors)
diff --git a/Tests/CMakeCommands/target_compile_features/lib_delegating_constructors.cpp b/Tests/CMakeCommands/target_compile_features/lib_delegating_constructors.cpp
new file mode 100644
index 0000000..e597acd
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_delegating_constructors.cpp
@@ -0,0 +1,8 @@
+
+#include "lib_delegating_constructors.h"
+
+Foo::Foo(int i)
+ : m_i(i)
+{
+
+}
diff --git a/Tests/CMakeCommands/target_compile_features/lib_delegating_constructors.h b/Tests/CMakeCommands/target_compile_features/lib_delegating_constructors.h
new file mode 100644
index 0000000..75be701
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_delegating_constructors.h
@@ -0,0 +1,17 @@
+
+#include <cstring>
+
+class Foo
+{
+public:
+ Foo(int i);
+
+ Foo(const char *a)
+ : Foo(strlen(a))
+ {
+
+ }
+
+private:
+ int m_i;
+};
diff --git a/Tests/CMakeCommands/target_compile_features/lib_user.cpp b/Tests/CMakeCommands/target_compile_features/lib_user.cpp
new file mode 100644
index 0000000..83ad51e
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_user.cpp
@@ -0,0 +1,27 @@
+
+#include "lib_delegating_constructors.h"
+
+class Bar
+{
+ Bar(int i)
+ :m_i(i)
+ {
+
+ }
+
+ Bar(const char *a)
+ : Bar(strlen(a))
+ {
+
+ }
+
+private:
+ int m_i;
+};
+
+int main(int argc, char **argv)
+{
+ Foo f("hello");
+ Foo b("world");
+ return 0;
+}
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b3bbaa85c102ab1f5ea01b91b7d118be82876f1c
commit b3bbaa85c102ab1f5ea01b91b7d118be82876f1c
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Oct 22 15:05:49 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 21:00:35 2013 +0100
cmTarget: Allow populating COMPILE_FEATURES using generator expressions.
diff --git a/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst
index aa438b2..ebd9611 100644
--- a/Help/command/target_compile_features.rst
+++ b/Help/command/target_compile_features.rst
@@ -15,3 +15,8 @@ automatically.
The named <target> must have been created by a command such as
add_executable or add_library and must not be an IMPORTED target.
+
+Arguments to target_compile_features may use "generator expressions"
+with the syntax "$<...>".
+See the :manual:`cmake-generator-expressions(7)` manual for available
+expressions.
diff --git a/Help/prop_tgt/COMPILE_FEATURES.rst b/Help/prop_tgt/COMPILE_FEATURES.rst
index b2c6145..3ef743c 100644
--- a/Help/prop_tgt/COMPILE_FEATURES.rst
+++ b/Help/prop_tgt/COMPILE_FEATURES.rst
@@ -5,3 +5,7 @@ Compiler features enabled for this target.
The list of features in this property are a subset of the features listed
in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
+
+Contents of COMPILE_FEATURES may use "generator expressions" with the
+syntax "$<...>". See the :manual:`cmake-generator-expressions(7)` manual for
+available expressions.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6f75ec4..e7c23ef 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4455,6 +4455,11 @@ static const char * const CXX_STANDARDS[] = {
bool cmMakefile::
AddRequiredTargetFeature(cmTarget *target, const char *feature) const
{
+ if (cmGeneratorExpression::Find(feature) != std::string::npos)
+ {
+ target->AppendProperty("COMPILE_FEATURES", feature);
+ return true;
+ }
bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
!= cmArrayEnd(CXX_FEATURES);
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=405303b35d492a71593fcd4897bb8fc75e78d0d5
commit 405303b35d492a71593fcd4897bb8fc75e78d0d5
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Oct 22 14:58:21 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 21:00:35 2013 +0100
cmTarget: Make COMPILE_FEATURES available as a target property.
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 55a1de2..e3a4cf8 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -96,6 +96,7 @@ Properties on Targets
/prop_tgt/COMPILE_DEFINITIONS
/prop_tgt/COMPILE_FLAGS
/prop_tgt/COMPILE_OPTIONS
+ /prop_tgt/COMPILE_FEATURES
/prop_tgt/CONFIG_OUTPUT_NAME
/prop_tgt/CONFIG_POSTFIX
/prop_tgt/CXX_STANDARD
diff --git a/Help/prop_tgt/COMPILE_FEATURES.rst b/Help/prop_tgt/COMPILE_FEATURES.rst
new file mode 100644
index 0000000..b2c6145
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_FEATURES.rst
@@ -0,0 +1,7 @@
+COMPILE_FEATURES
+----------------
+
+Compiler features enabled for this target.
+
+The list of features in this property are a subset of the features listed
+in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index b66b664..6f75ec4 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4487,6 +4487,8 @@ AddRequiredTargetFeature(cmTarget *target, const char *feature) const
return false;
}
+ target->AppendProperty("COMPILE_FEATURES", feature);
+
bool needCxx98 = true;
bool needCxx11 = false;
bool needCxxExt = false;
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 4142b2a..8a1e386 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -135,6 +135,7 @@ public:
};
std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
std::vector<TargetPropertyEntry*> CompileOptionsEntries;
+ std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
std::vector<cmValueWithOrigin> LinkInterfacePropertyEntries;
@@ -1411,6 +1412,17 @@ void cmTarget::SetProperty(const char* prop, const char* value)
new cmTargetInternals::TargetPropertyEntry(cge));
return;
}
+ if(strcmp(prop,"COMPILE_FEATURES") == 0)
+ {
+ cmListFileBacktrace lfbt;
+ this->Makefile->GetBacktrace(lfbt);
+ cmGeneratorExpression ge(lfbt);
+ deleteAndClear(this->Internal->CompileFeaturesEntries);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ this->Internal->CompileFeaturesEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge));
+ return;
+ }
if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
{
cmListFileBacktrace lfbt;
@@ -1476,6 +1488,15 @@ void cmTarget::AppendProperty(const char* prop, const char* value,
new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
return;
}
+ if(strcmp(prop,"COMPILE_FEATURES") == 0)
+ {
+ cmListFileBacktrace lfbt;
+ this->Makefile->GetBacktrace(lfbt);
+ cmGeneratorExpression ge(lfbt);
+ this->Internal->CompileFeaturesEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
+ return;
+ }
if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
{
cmListFileBacktrace lfbt;
@@ -2668,6 +2689,24 @@ const char *cmTarget::GetProperty(const char* prop,
}
return output.c_str();
}
+ if(strcmp(prop,"COMPILE_FEATURES") == 0)
+ {
+ static std::string output;
+ output = "";
+ std::string sep;
+ typedef cmTargetInternals::TargetPropertyEntry
+ TargetPropertyEntry;
+ for (std::vector<TargetPropertyEntry*>::const_iterator
+ it = this->Internal->CompileFeaturesEntries.begin(),
+ end = this->Internal->CompileFeaturesEntries.end();
+ it != end; ++it)
+ {
+ output += sep;
+ output += (*it)->ge->GetInput();
+ sep = ";";
+ }
+ return output.c_str();
+ }
if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
{
static std::string output;
@@ -5834,6 +5873,7 @@ cmTargetInternalPointer::~cmTargetInternalPointer()
{
deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
deleteAndClear(this->Pointer->CompileOptionsEntries);
+ deleteAndClear(this->Pointer->CompileFeaturesEntries);
deleteAndClear(this->Pointer->CompileDefinitionsEntries);
delete this->Pointer;
}
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=31fdddb09f496f3b3a1013ef102e42f60222d00b
commit 31fdddb09f496f3b3a1013ef102e42f60222d00b
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Oct 13 14:25:08 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:59:47 2013 +0100
Add target_compile_features command.
This can be used to set the compiler features required by particular
targets. An error is issued at CMake time if the compiler does not
support the required feature. If a language dialect flag is required
by the features used, that will be added automatically.
diff --git a/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst
new file mode 100644
index 0000000..aa438b2
--- /dev/null
+++ b/Help/command/target_compile_features.rst
@@ -0,0 +1,17 @@
+target_compile_features
+-----------------------
+
+Add expected compiler features to a target.
+
+::
+
+ target_compile_features(<target> PRIVATE <feature> [...])
+
+Specify compiler features required when compiling a given target. If the
+feature is not listed in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable,
+then an error will be reported by CMake. If the use of the feature requires
+an additional compiler flag, such as --std=c++11, the flag will be added
+automatically.
+
+The named <target> must have been created by a command such as
+add_executable or add_library and must not be an IMPORTED target.
diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst
index fb0d2b5..1294873 100644
--- a/Help/manual/cmake-commands.7.rst
+++ b/Help/manual/cmake-commands.7.rst
@@ -91,6 +91,7 @@ These commands may be used freely in CMake projects.
/command/source_group
/command/string
/command/target_compile_definitions
+ /command/target_compile_features
/command/target_compile_options
/command/target_include_directories
/command/target_link_libraries
diff --git a/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst b/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
index 6be0124..386f5c0 100644
--- a/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
+++ b/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
@@ -6,3 +6,6 @@ List of features known to the C++ compiler
These features are known to be available for use with the C++ compiler. This
list is a subset of the features listed in the :variable:`CMAKE_CXX_KNOWN_FEATURES`
variable.
+
+The features listed here may be used with the :command:`target_compile_features`
+command.
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 1e2a85c..8f89fd9 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -32,6 +32,7 @@
#include "cmSubdirDependsCommand.cxx"
#include "cmTargetCompileDefinitionsCommand.cxx"
#include "cmTargetCompileOptionsCommand.cxx"
+#include "cmTargetCompileFeaturesCommand.cxx"
#include "cmTargetIncludeDirectoriesCommand.cxx"
#include "cmTargetPropCommandBase.cxx"
#include "cmUseMangledMesaCommand.cxx"
@@ -77,6 +78,7 @@ void GetPredefinedCommands(std::list<cmCommand*>&
commands.push_back(new cmTargetIncludeDirectoriesCommand);
commands.push_back(new cmTargetCompileDefinitionsCommand);
commands.push_back(new cmTargetCompileOptionsCommand);
+ commands.push_back(new cmTargetCompileFeaturesCommand);
commands.push_back(new cmUseMangledMesaCommand);
commands.push_back(new cmUtilitySourceCommand);
commands.push_back(new cmVariableRequiresCommand);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index a34614b..b66b664 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4439,3 +4439,139 @@ void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
pm[pid] = this->GetPolicyStatus(pid);
}
}
+
+#define FEATURE_STRING(F) , #F
+
+static const char * const CXX_FEATURES[] = {
+ 0
+ FOR_EACH_CXX_FEATURE(FEATURE_STRING)
+};
+
+static const char * const CXX_STANDARDS[] = {
+ "98"
+ , "11"
+};
+
+bool cmMakefile::
+AddRequiredTargetFeature(cmTarget *target, const char *feature) const
+{
+ bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
+ cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
+ != cmArrayEnd(CXX_FEATURES);
+ if (!isCxxFeature)
+ {
+ return false;
+ }
+
+ const char* cxxFeaturesKnown =
+ this->GetDefinition("CMAKE_CXX_COMPILE_FEATURES");
+
+ if (!cxxFeaturesKnown)
+ {
+ // We know of no features for the compiler at all.
+ return true;
+ }
+
+ std::vector<std::string> availableFeatures;
+ cmSystemTools::ExpandListArgument(cxxFeaturesKnown, availableFeatures);
+ if (std::find(availableFeatures.begin(),
+ availableFeatures.end(),
+ feature) == availableFeatures.end())
+ {
+ cmOStringStream e;
+ e << "The compiler feature \"" << feature
+ << "\" is not known to compiler \""
+ << this->GetDefinition("CMAKE_CXX_COMPILER_ID") << "\" version "
+ << this->GetDefinition("CMAKE_CXX_COMPILER_VERSION") << ".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ return false;
+ }
+
+ bool needCxx98 = true;
+ bool needCxx11 = false;
+ bool needCxxExt = false;
+
+ if (const char *propCxx98 =
+ this->GetDefinition("CMAKE_CXX98_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx98, props);
+ needCxx98 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+ if (const char *propCxx11 =
+ this->GetDefinition("CMAKE_CXX11_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx11, props);
+ needCxx11 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+
+ if (const char *propCxx98ext =
+ this->GetDefinition("CMAKE_CXX98_COMPILER_EXTENSIONS"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx98ext, props);
+ needCxxExt = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+ if (const char *propCxx11ext =
+ this->GetDefinition("CMAKE_CXX11_COMPILER_EXTENSIONS"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx11ext, props);
+ bool needCxx11Ext = std::find(props.begin(), props.end(), feature)
+ != props.end();
+ needCxx11 = needCxx11Ext;
+ needCxxExt = needCxxExt || needCxx11Ext;
+ }
+
+ const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
+ if (existingCxxStandard)
+ {
+ if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
+ {
+ cmOStringStream e;
+ e << "The CXX_STANDARD property on target \"" << target->GetName()
+ << "\" contained an invalid value: \"" << existingCxxStandard << "\".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ return false;
+ }
+ }
+ const char * const *existingCxxIt = existingCxxStandard
+ ? std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard))
+ : cmArrayEnd(CXX_STANDARDS);
+
+ bool setCxx11 = needCxx11 && !existingCxxStandard;
+ bool setCxx98 = needCxx98 && !existingCxxStandard;
+ if (existingCxxStandard && existingCxxIt <
+ std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("11")))
+ {
+ setCxx11 = true;
+ }
+ else if(existingCxxStandard && existingCxxIt <
+ std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("98")))
+ {
+ setCxx98 = true;
+ }
+
+ if (setCxx11)
+ {
+ target->SetProperty("CXX_STANDARD", "11");
+ }
+ else if (setCxx98)
+ {
+ target->SetProperty("CXX_STANDARD", "98");
+ }
+ bool existingCxxExt = target->GetPropertyAsBool("CXX_EXTENSIONS");
+ if (needCxxExt && !existingCxxExt)
+ {
+ target->SetProperty("CXX_EXTENSIONS", "1");
+ }
+ return true;
+}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 76958ca..4aeffdf 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -883,6 +883,8 @@ public:
std::set<cmStdString> const & GetSystemIncludeDirectories() const
{ return this->SystemIncludeDirectories; }
+ bool AddRequiredTargetFeature(cmTarget *target, const char *feature) const;
+
protected:
// add link libraries and directories to the target
void AddGlobalLinkInformation(const char* name, cmTarget& target);
diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx
new file mode 100644
index 0000000..f89e075
--- /dev/null
+++ b/Source/cmTargetCompileFeaturesCommand.cxx
@@ -0,0 +1,56 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire at 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 "cmTargetCompileFeaturesCommand.h"
+
+bool cmTargetCompileFeaturesCommand::InitialPass(
+ std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ if (args.size() < 3)
+ {
+ this->SetError("called with wrong number of arguments.");
+ return false;
+ }
+ cmTarget *target = this->Makefile->FindTargetToUse(args[0].c_str());
+
+ if(!target)
+ {
+ this->SetError("specified invalid target.");
+ return false;
+ }
+
+ if(target->IsImported())
+ {
+ this->SetError("may not be used with an IMPORTED target.");
+ return false;
+ }
+
+ if(args[1] != "PRIVATE")
+ {
+ this->SetError("called with invalid arguments.");
+ return false;
+ }
+
+ for (size_t i = 2; i < args.size(); ++i)
+ {
+ std::string feature = args[i];
+
+ if (!this->Makefile->AddRequiredTargetFeature(target, feature.c_str()))
+ {
+ cmOStringStream e;
+ e << "specified unknown feature \"" << feature << "\".";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h
new file mode 100644
index 0000000..63beeca
--- /dev/null
+++ b/Source/cmTargetCompileFeaturesCommand.h
@@ -0,0 +1,32 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire at 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 cmTargetCompileFeaturesCommand_h
+#define cmTargetCompileFeaturesCommand_h
+
+#include "cmCommand.h"
+
+class cmTargetCompileFeaturesCommand : public cmCommand
+{
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetCompileFeaturesCommand;
+ }
+
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ virtual const char* GetName() const { return "target_compile_features";}
+
+ cmTypeMacro(cmTargetCompileFeaturesCommand, cmCommand);
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
new file mode 100644
index 0000000..c26ddbd
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.8.12)
+cmake_policy(SET CMP0025 NEW)
+project(target_compile_features)
+
+if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang")
+ add_executable(gnuxx_typeof_test gnuxx_typeof_test.cpp)
+endif()
+if (("${CMAKE_CXX_COMPILER}" MATCHES "MSVC"
+ AND NOT MSVC_VERSION VERSION_LESS 1400)
+ OR ("${CMAKE_CXX_COMPILER}" STREQUAL "Clang"
+ AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"))
+ add_executable(msvcxx_sealed_test msvcxx_sealed_test.cpp)
+endif()
+
+if (NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
+ add_executable(target_compile_features dummy.cpp)
+ return()
+endif()
+
+add_executable(target_compile_features main.cpp)
+target_compile_features(target_compile_features
+ PRIVATE cxx_delegating_constructors
+)
diff --git a/Tests/CMakeCommands/target_compile_features/dummy.cpp b/Tests/CMakeCommands/target_compile_features/dummy.cpp
new file mode 100644
index 0000000..341aaaf
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/dummy.cpp
@@ -0,0 +1,5 @@
+
+int main(int, char **)
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/gnuxx_typeof_test.cpp b/Tests/CMakeCommands/target_compile_features/gnuxx_typeof_test.cpp
new file mode 100644
index 0000000..3b8532e
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/gnuxx_typeof_test.cpp
@@ -0,0 +1,6 @@
+
+int main(int argc, char **argv)
+{
+ typeof(argc) ret = 0;
+ return ret;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/main.cpp b/Tests/CMakeCommands/target_compile_features/main.cpp
new file mode 100644
index 0000000..77671b0
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/main.cpp
@@ -0,0 +1,25 @@
+
+#include <cstring>
+
+class Foo
+{
+ Foo(int i)
+ :m_i(i)
+ {
+
+ }
+
+ Foo(const char *a)
+ : Foo(strlen(a))
+ {
+
+ }
+
+private:
+ int m_i;
+};
+
+int main(int, char **)
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/msvcxx_sealed_test.cpp b/Tests/CMakeCommands/target_compile_features/msvcxx_sealed_test.cpp
new file mode 100644
index 0000000..0127937
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/msvcxx_sealed_test.cpp
@@ -0,0 +1,8 @@
+
+class A sealed {};
+
+int main(int argc, char **argv)
+{
+ A a;
+ return 0;
+}
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index d817141..4cb912d 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -2093,6 +2093,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
ADD_TEST_MACRO(CMakeCommands.target_include_directories target_include_directories)
ADD_TEST_MACRO(CMakeCommands.target_compile_definitions target_compile_definitions)
ADD_TEST_MACRO(CMakeCommands.target_compile_options target_compile_options)
+ ADD_TEST_MACRO(CMakeCommands.target_compile_features target_compile_features)
ADD_TEST_MACRO(compile_features compile_features)
configure_file(
diff --git a/Tests/CxxDialect/CMakeLists.txt b/Tests/CxxDialect/CMakeLists.txt
index c55f838..f0b2d10 100644
--- a/Tests/CxxDialect/CMakeLists.txt
+++ b/Tests/CxxDialect/CMakeLists.txt
@@ -1,3 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12)
+cmake_policy(SET CMP0025 NEW)
project(CxxDialect)
add_executable(use_typeof use_typeof.cxx)
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 99a0fb3..afe4b58 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -129,4 +129,5 @@ endif()
add_RunCMake_test(File_Generate)
add_RunCMake_test(ExportWithoutLanguage)
add_RunCMake_test(target_link_libraries)
+add_RunCMake_test(target_compile_features)
add_RunCMake_test(CheckModules)
diff --git a/Tests/RunCMake/target_compile_features/CMakeLists.txt b/Tests/RunCMake/target_compile_features/CMakeLists.txt
new file mode 100644
index 0000000..aa7278d
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12)
+cmake_policy(SET CMP0025 NEW)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
new file mode 100644
index 0000000..28341c9
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
@@ -0,0 +1,4 @@
+include(RunCMake)
+
+run_cmake(not_a_cxx_feature)
+run_cmake(no_matching_cxx_feature)
diff --git a/Tests/RunCMake/target_compile_features/empty.cpp b/Tests/RunCMake/target_compile_features/empty.cpp
new file mode 100644
index 0000000..bfbbdde
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt
new file mode 100644
index 0000000..4df6ee4
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at no_matching_cxx_feature.cmake:[0-9][0-9]? \((target_compile_features|message)\):
+ The compiler feature "[^"]+" is not known to compiler "[^"]*"[ \n]*version[ \n]*.+\.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake
new file mode 100644
index 0000000..e74a8d7
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake
@@ -0,0 +1,26 @@
+
+if (NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";gnuxx_typeof;"
+ AND NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";msvcxx_sealed;" )
+ # Simulate passing the test.
+ message(SEND_ERROR
+ "The compiler feature \"gnuxx_dummy\" is not known to compiler \"GNU\" version 4.8.1."
+ )
+ return()
+endif()
+
+if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";gnuxx_typeof;")
+ set(feature msvcxx_sealed)
+ if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";msvcxx_sealed;")
+ # If a compiler supports both extensions, remove one of them.
+ list(REMOVE_ITEM CMAKE_CXX_COMPILE_FEATURES msvcxx_sealed)
+ endif()
+else()
+ set(feature gnuxx_typeof)
+endif()
+
+add_executable(main empty.cpp)
+
+target_compile_features(main
+ PRIVATE
+ ${feature}
+)
diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt
new file mode 100644
index 0000000..1b82258
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at not_a_cxx_feature.cmake:3 \(target_compile_features\):
+ target_compile_features specified unknown feature "cxx_not_a_feature".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake b/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake
new file mode 100644
index 0000000..0207b72
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake
@@ -0,0 +1,6 @@
+
+add_executable(main empty.cpp)
+target_compile_features(main
+ PRIVATE
+ cxx_not_a_feature
+)
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=30c1703d8a562e66e4befccbff07d68ae6af3b56
commit 30c1703d8a562e66e4befccbff07d68ae6af3b56
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Nov 9 09:18:53 2013 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:56:09 2013 +0100
Record compilers capable of msvcxx_sealed feature.
diff --git a/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst b/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
index 366e9cc..3aa5017 100644
--- a/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
+++ b/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
@@ -16,3 +16,6 @@ cxx_delegating_constructors
gnuxx_typeof
The GNU typeof extension.
+
+msvcxx_sealed
+ The MSVC sealed extension.
diff --git a/Modules/Compiler/Clang-CXX-FeatureTests.cmake b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
index 3580afc..cb56243 100644
--- a/Modules/Compiler/Clang-CXX-FeatureTests.cmake
+++ b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
@@ -14,3 +14,4 @@ endforeach()
unset(testable_features)
set(_cmake_feature_test_gnuxx_typeof "!defined(__STRICT_ANSI__)")
+set(_cmake_feature_test_msvcxx_sealed "_MSC_VER")
diff --git a/Modules/Compiler/MSVC-CXX-FeatureTests.cmake b/Modules/Compiler/MSVC-CXX-FeatureTests.cmake
new file mode 100644
index 0000000..7a56acd
--- /dev/null
+++ b/Modules/Compiler/MSVC-CXX-FeatureTests.cmake
@@ -0,0 +1,2 @@
+
+set(_cmake_feature_test_msvcxx_sealed "_MSC_VER >= 1400")
diff --git a/Modules/Platform/Windows-MSVC-CXX.cmake b/Modules/Platform/Windows-MSVC-CXX.cmake
index 0e85005..ebe3468 100644
--- a/Modules/Platform/Windows-MSVC-CXX.cmake
+++ b/Modules/Platform/Windows-MSVC-CXX.cmake
@@ -4,3 +4,7 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
set(_FS_CXX " /FS")
endif()
__windows_compiler_msvc(CXX)
+
+include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
+
+record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES)
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index e29aaf4..53b439a 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -246,6 +246,7 @@ macro(__windows_compiler_msvc lang)
"<CMAKE_${lang}_COMPILER> > <PREPROCESSED_SOURCE> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> -E <SOURCE>${CMAKE_END_TEMP_FILE}")
set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE
"<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> /FoNUL /FAs /Fa<ASSEMBLY_SOURCE> /c <SOURCE>${CMAKE_END_TEMP_FILE}")
+ set(_CMAKE_${lang}_CREATE_OBJECT_FILE "${CMAKE_CL_NOLOGO};/TP;<FLAGS>;-c;<SOURCE>")
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_${lang}_LINK_EXECUTABLE
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 0bb7913..a34614b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -43,7 +43,8 @@
#define FOR_EACH_CXX_FEATURE(F) \
F(cxx_delegating_constructors) \
- F(gnuxx_typeof)
+ F(gnuxx_typeof) \
+ F(msvcxx_sealed)
class cmMakefile::Internals
{
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4a2106f2b18add8c9dfd3623988cfd20c48b888f
commit 4a2106f2b18add8c9dfd3623988cfd20c48b888f
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Nov 9 09:18:32 2013 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:56:09 2013 +0100
Record compilers capable of the gnuxx_typeof feature.
diff --git a/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst b/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
index effaf6f..366e9cc 100644
--- a/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
+++ b/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
@@ -13,3 +13,6 @@ cxx_delegating_constructors
Delegating constructors, as defined in N1986_.
.. _N1986: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf
+
+gnuxx_typeof
+ The GNU typeof extension.
diff --git a/Modules/Compiler/Clang-CXX-FeatureTests.cmake b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
index 940a182..3580afc 100644
--- a/Modules/Compiler/Clang-CXX-FeatureTests.cmake
+++ b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
@@ -1,4 +1,9 @@
+if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
+ # This file is only loaded if Clang >= 2.1
+ message(FATAL_ERROR "This file should not be included for Clang < 2.1.")
+endif()
+
set(testable_features
cxx_delegating_constructors
)
@@ -7,3 +12,5 @@ foreach(feature ${testable_features})
endforeach()
unset(testable_features)
+
+set(_cmake_feature_test_gnuxx_typeof "!defined(__STRICT_ANSI__)")
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
index 0d3a538..31a3358 100644
--- a/Modules/Compiler/Clang-CXX.cmake
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -10,7 +10,9 @@ if(NOT appleClangPolicy STREQUAL NEW)
return()
endif()
+set(CMAKE_CXX98_COMPILE_EXTENSIONS)
set(CMAKE_CXX11_COMPILE_FEATURES)
+set(CMAKE_CXX11_COMPILE_EXTENSIONS)
include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
@@ -21,18 +23,26 @@ endmacro()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+ _get_clang_features(gnu++98 CMAKE_CXX98_COMPILE_EXTENSIONS)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+ _get_clang_features(gnu++11 CMAKE_CXX11_COMPILE_EXTENSIONS)
_get_clang_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+ _get_clang_features(gnu++0x CMAKE_CXX11_COMPILE_EXTENSIONS)
_get_clang_features(c++0x CMAKE_CXX11_COMPILE_FEATURES)
endif()
+string(REPLACE "${CMAKE_CXX11_COMPILE_FEATURES}" "" CMAKE_CXX11_COMPILE_EXTENSIONS "${CMAKE_CXX11_COMPILE_EXTENSIONS}")
+string(REPLACE "${CMAKE_CXX98_COMPILE_EXTENSIONS}" "" CMAKE_CXX11_COMPILE_EXTENSIONS "${CMAKE_CXX11_COMPILE_EXTENSIONS}")
+
set(CMAKE_CXX_COMPILE_FEATURES
+ ${CMAKE_CXX98_COMPILE_EXTENSIONS}
${CMAKE_CXX11_COMPILE_FEATURES}
+ ${CMAKE_CXX11_COMPILE_EXTENSIONS}
)
diff --git a/Modules/Compiler/GNU-CXX-FeatureTests.cmake b/Modules/Compiler/GNU-CXX-FeatureTests.cmake
index 7da0563..13c6128 100644
--- a/Modules/Compiler/GNU-CXX-FeatureTests.cmake
+++ b/Modules/Compiler/GNU-CXX-FeatureTests.cmake
@@ -1,2 +1,17 @@
-set(_cmake_feature_test_cxx_delegating_constructors "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407")
+set(_cmake_feature_test_gnuxx_typeof "!defined(__STRICT_ANSI__)")
+
+if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
+ # This file is only loaded if GCC >= 4.3
+ message(FATAL_ERROR "This file should not be included for GCC < 4.3.")
+endif()
+
+# For GCC 4.7, we can test the standard __cplusplus macro, ...
+# set(isCxx98Mode "__cplusplus >= 199711L")
+# set(isCxx11Mode "__cplusplus >= 201103L")
+# ... but before GCC 4.7, __cplusplus is always defined to 1, so check
+# the old macro.
+# set(isCxx98Mode "!defined(__GXX_EXPERIMENTAL_CXX0X__)")
+# set(isCxx11Mode "defined(__GXX_EXPERIMENTAL_CXX0X__)")
+
+set(_cmake_feature_test_cxx_delegating_constructors "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && __cplusplus >= 201103L")
diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake
index 6753d6a..68ae667 100644
--- a/Modules/Compiler/GNU-CXX.cmake
+++ b/Modules/Compiler/GNU-CXX.cmake
@@ -11,7 +11,9 @@ else()
endif()
endif()
+set(CMAKE_CXX98_COMPILE_EXTENSIONS)
set(CMAKE_CXX11_COMPILE_FEATURES)
+set(CMAKE_CXX11_COMPILE_EXTENSIONS)
include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
@@ -22,20 +24,28 @@ endmacro()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+ _get_gcc_features(gnu++98 CMAKE_CXX98_COMPILE_EXTENSIONS)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
-
_get_gcc_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
+ _get_gcc_features(gnu++11 CMAKE_CXX11_COMPILE_EXTENSIONS)
+
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
-
_get_gcc_features(c++0x CMAKE_CXX11_COMPILE_FEATURES)
+ _get_gcc_features(gnu++0x CMAKE_CXX11_COMPILE_EXTENSIONS)
+
endif()
+string(REPLACE "${CMAKE_CXX98_COMPILE_EXTENSIONS}" "" CMAKE_CXX11_COMPILE_EXTENSIONS "${CMAKE_CXX11_COMPILE_EXTENSIONS}")
+string(REPLACE "${CMAKE_CXX11_COMPILE_FEATURES}" "" CMAKE_CXX11_COMPILE_EXTENSIONS "${CMAKE_CXX11_COMPILE_EXTENSIONS}")
+
set(CMAKE_CXX_COMPILE_FEATURES
+ ${CMAKE_CXX98_COMPILE_EXTENSIONS}
${CMAKE_CXX11_COMPILE_FEATURES}
+ ${CMAKE_CXX11_COMPILE_EXTENSIONS}
)
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 103d44d..0bb7913 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -42,7 +42,8 @@
#include <assert.h>
#define FOR_EACH_CXX_FEATURE(F) \
- F(cxx_delegating_constructors)
+ F(cxx_delegating_constructors) \
+ F(gnuxx_typeof)
class cmMakefile::Internals
{
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5b706c62e9eb5b20bac4e0644f8c1e5c4d2ca152
commit 5b706c62e9eb5b20bac4e0644f8c1e5c4d2ca152
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Thu Oct 17 11:47:29 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:55:51 2013 +0100
Record the compilers capable of the cxx_delegating_constructors feature.
Add a feature test using the compiler macros and the preprocessor to
determine available features. Add a unit test which outputs the
feature test file compiled. Record the list of features in
the SystemInformation unit test.
Add a CMAKE_CXX_COMPILE_FEATURES variable which contains all features
known to the loaded compiler, and a CMAKE_CXX_KNOWN_FEATURES variable
containing all features known to CMake. Add language standard specific
variables for internal use to determine the standard-specific compile
flags to use. Add internal variables matching CMAKE_PP_NAME_<feature>
for each feature. Those variables are used as preprocessor defines.
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 9d23002..b06989b 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -222,6 +222,8 @@ Variables for Languages
:maxdepth: 1
/variable/CMAKE_COMPILER_IS_GNULANG
+ /variable/CMAKE_CXX_COMPILE_FEATURES
+ /variable/CMAKE_CXX_KNOWN_FEATURES
/variable/CMAKE_CXX_STANDARD
/variable/CMAKE_Fortran_MODDIR_DEFAULT
/variable/CMAKE_Fortran_MODDIR_FLAG
diff --git a/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst b/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
new file mode 100644
index 0000000..6be0124
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
@@ -0,0 +1,8 @@
+CMAKE_CXX_COMPILE_FEATURES
+--------------------------
+
+List of features known to the C++ compiler
+
+These features are known to be available for use with the C++ compiler. This
+list is a subset of the features listed in the :variable:`CMAKE_CXX_KNOWN_FEATURES`
+variable.
diff --git a/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst b/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
new file mode 100644
index 0000000..effaf6f
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_KNOWN_FEATURES.rst
@@ -0,0 +1,15 @@
+CMAKE_CXX_KNOWN_FEATURES
+------------------------
+
+List of C++ features known to this version of CMake.
+
+The features listed in this variable may be known to be available to the C++
+compiler. If the feature is available with the C++ compiler, it will be
+listed in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
+
+The features known to this version of CMake are:
+
+cxx_delegating_constructors
+ Delegating constructors, as defined in N1986_.
+
+.. _N1986: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf
diff --git a/Modules/Compiler/Clang-CXX-FeatureTests.cmake b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
new file mode 100644
index 0000000..940a182
--- /dev/null
+++ b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
@@ -0,0 +1,9 @@
+
+set(testable_features
+ cxx_delegating_constructors
+)
+foreach(feature ${testable_features})
+ set(_cmake_feature_test_${feature} "__has_extension(${feature})")
+endforeach()
+
+unset(testable_features)
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
index a1b3a10..0d3a538 100644
--- a/Modules/Compiler/Clang-CXX.cmake
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -10,6 +10,14 @@ if(NOT appleClangPolicy STREQUAL NEW)
return()
endif()
+set(CMAKE_CXX11_COMPILE_FEATURES)
+
+include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
+
+macro(_get_clang_features std_version list)
+ record_compiler_features(CXX "-std=${std_version}" ${list})
+endmacro()
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
@@ -18,7 +26,13 @@ endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+ _get_clang_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+ _get_clang_features(c++0x CMAKE_CXX11_COMPILE_FEATURES)
endif()
+
+set(CMAKE_CXX_COMPILE_FEATURES
+ ${CMAKE_CXX11_COMPILE_FEATURES}
+)
diff --git a/Modules/Compiler/GNU-CXX-FeatureTests.cmake b/Modules/Compiler/GNU-CXX-FeatureTests.cmake
new file mode 100644
index 0000000..7da0563
--- /dev/null
+++ b/Modules/Compiler/GNU-CXX-FeatureTests.cmake
@@ -0,0 +1,2 @@
+
+set(_cmake_feature_test_cxx_delegating_constructors "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407")
diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake
index 3ee8639..6753d6a 100644
--- a/Modules/Compiler/GNU-CXX.cmake
+++ b/Modules/Compiler/GNU-CXX.cmake
@@ -11,6 +11,14 @@ else()
endif()
endif()
+set(CMAKE_CXX11_COMPILE_FEATURES)
+
+include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
+
+macro(_get_gcc_features std_version list)
+ record_compiler_features(CXX "-std=${std_version}" ${list})
+endmacro()
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
@@ -19,7 +27,15 @@ endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+
+ _get_gcc_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+
+ _get_gcc_features(c++0x CMAKE_CXX11_COMPILE_FEATURES)
endif()
+
+set(CMAKE_CXX_COMPILE_FEATURES
+ ${CMAKE_CXX11_COMPILE_FEATURES}
+)
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index 504704d..37c9e6d 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -51,6 +51,7 @@ macro(__compiler_gnu lang)
set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+ set(_CMAKE_${lang}_CREATE_OBJECT_FILE "<FLAGS>;-c;<SOURCE>")
if(NOT APPLE)
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
endif()
diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake
new file mode 100644
index 0000000..3d59b7d
--- /dev/null
+++ b/Modules/Internal/FeatureTesting.cmake
@@ -0,0 +1,47 @@
+
+macro(record_compiler_features lang compile_flags feature_list)
+ include("${CMAKE_ROOT}/Modules/Compiler/${CMAKE_${lang}_COMPILER_ID}-${lang}-FeatureTests.cmake" OPTIONAL)
+
+ string(TOLOWER ${lang} lang_lc)
+ file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests${CMAKE_${lang}_OUTPUT_EXTENSION}")
+ file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "
+ extern const char features[] = {\"\"\n")
+ foreach(feature ${CMAKE_${lang}_KNOWN_FEATURES})
+ if (_cmake_feature_test_${feature})
+ if (${_cmake_feature_test_${feature}} STREQUAL 1)
+ set(_feature_condition "\"1\" ")
+ else()
+ set(_feature_condition "#if ${_cmake_feature_test_${feature}}\n\"1\"\n#else\n\"0\"\n#endif\n")
+ endif()
+ file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "\"${lang}_FEATURE:\"\n${_feature_condition}\"${feature}\\n\"\n")
+ endif()
+ endforeach()
+ file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "\n};\n")
+
+ string(REPLACE "<FLAGS>" "${compile_flags}" _compile_object_command "${_CMAKE_${lang}_CREATE_OBJECT_FILE}" )
+ string(REPLACE "<SOURCE>" "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" _compile_object_command "${_compile_object_command}" )
+ execute_process(COMMAND "${CMAKE_${lang}_COMPILER}"
+ ${_compile_object_command}
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/CMakeFiles"
+ ERROR_VARIABLE _error
+ OUTPUT_VARIABLE _output
+ RESULT_VARIABLE _result
+ )
+ # We need to capture these when running the process so that the output does
+ # not leak and confuse unit tests. Clear the variables so they do not leak
+ # to user CMake code either.
+ unset(_error)
+ unset(_output)
+ if (_result EQUAL 0 AND EXISTS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests${CMAKE_${lang}_OUTPUT_EXTENSION}")
+ file(STRINGS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests${CMAKE_${lang}_OUTPUT_EXTENSION}"
+ features REGEX "${lang}_FEATURE:.*")
+ foreach(info ${features})
+ string(REPLACE "${lang}_FEATURE:" "" info ${info})
+ string(SUBSTRING ${info} 0 1 has_feature)
+ if(has_feature)
+ string(REGEX REPLACE "^1" "" feature ${info})
+ list(APPEND ${feature_list} ${feature})
+ endif()
+ endforeach()
+ endif()
+endmacro()
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index c18a7eb..103d44d 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -41,6 +41,9 @@
#include <ctype.h> // for isspace
#include <assert.h>
+#define FOR_EACH_CXX_FEATURE(F) \
+ F(cxx_delegating_constructors)
+
class cmMakefile::Internals
{
public:
@@ -2409,6 +2412,19 @@ const char* cmMakefile::GetDefinition(const char* name) const
{
this->Internal->VarUsageStack.top().insert(name);
}
+ if (strcmp(name, "CMAKE_CXX_KNOWN_FEATURES") == 0)
+ {
+#define STRING_LIST_ELEMENT(F) ";" #F
+ return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
+#undef STRING_LIST_ELEMENT
+ }
+#define PP_FEATURE_NAME(F) \
+ if (strcmp(name, "CMAKE_PP_NAME_" #F) == 0) \
+ { \
+ return ("COMPILER_" + cmSystemTools::UpperCase(#F)).c_str(); \
+ }
+ FOR_EACH_CXX_FEATURE(PP_FEATURE_NAME)
+#undef PP_FEATURE_NAME
const char* def = this->Internal->VarStack.top().Get(name);
if(!def)
{
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 1b37472..d817141 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -2093,6 +2093,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
ADD_TEST_MACRO(CMakeCommands.target_include_directories target_include_directories)
ADD_TEST_MACRO(CMakeCommands.target_compile_definitions target_compile_definitions)
ADD_TEST_MACRO(CMakeCommands.target_compile_options target_compile_options)
+ ADD_TEST_MACRO(compile_features compile_features)
configure_file(
"${CMake_SOURCE_DIR}/Tests/CTestTestCrash/test.cmake.in"
diff --git a/Tests/SystemInformation/SystemInformation.in b/Tests/SystemInformation/SystemInformation.in
index df3bf49..69af703 100644
--- a/Tests/SystemInformation/SystemInformation.in
+++ b/Tests/SystemInformation/SystemInformation.in
@@ -21,6 +21,7 @@ CMAKE_C_COMPILER_ID == "${CMAKE_C_COMPILER_ID}"
CMAKE_C_COMPILER_VERSION == "${CMAKE_C_COMPILER_VERSION}"
CMAKE_CXX_COMPILER_ID == "${CMAKE_CXX_COMPILER_ID}"
CMAKE_CXX_COMPILER_VERSION == "${CMAKE_CXX_COMPILER_VERSION}"
+CMAKE_CXX_COMPILE_FEATURES == "${CMAKE_CXX_COMPILE_FEATURES}"
// C shared library flag
CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
diff --git a/Tests/compile_features/CMakeLists.txt b/Tests/compile_features/CMakeLists.txt
new file mode 100644
index 0000000..c234357
--- /dev/null
+++ b/Tests/compile_features/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8.12)
+cmake_policy(SET CMP0025 NEW)
+project(compile_features)
+
+if (EXISTS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.cxx")
+ file(READ "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.cxx" featureTest)
+ message("_CMAKE_CXX_CREATE_OBJECT_FILE: ${_CMAKE_CXX_CREATE_OBJECT_FILE}")
+ message("_compile_object_command: ${_compile_object_command}")
+ message("CTEST_FULL_OUTPUT\n${featureTest}")
+else()
+ message("No known features!")
+endif()
+
+add_executable(compile_features main.cpp)
diff --git a/Tests/compile_features/main.cpp b/Tests/compile_features/main.cpp
new file mode 100644
index 0000000..341aaaf
--- /dev/null
+++ b/Tests/compile_features/main.cpp
@@ -0,0 +1,5 @@
+
+int main(int, char **)
+{
+ return 0;
+}
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=718551001344234775ee8155ee3478ea8877ce73
commit 718551001344234775ee8155ee3478ea8877ce73
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Oct 13 02:00:24 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:40:42 2013 +0100
cmTarget: Add CXX_STANDARD and CXX_EXTENSION target properties.
These are used to determine whether to add -std=c++11, -std=gnu++11
etc flags on the compile line.
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index d6d42ad..55a1de2 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -98,6 +98,8 @@ Properties on Targets
/prop_tgt/COMPILE_OPTIONS
/prop_tgt/CONFIG_OUTPUT_NAME
/prop_tgt/CONFIG_POSTFIX
+ /prop_tgt/CXX_STANDARD
+ /prop_tgt/CXX_EXTENSIONS
/prop_tgt/DEBUG_POSTFIX
/prop_tgt/DEFINE_SYMBOL
/prop_tgt/EchoString
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 59e8064..9d23002 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -222,6 +222,7 @@ Variables for Languages
:maxdepth: 1
/variable/CMAKE_COMPILER_IS_GNULANG
+ /variable/CMAKE_CXX_STANDARD
/variable/CMAKE_Fortran_MODDIR_DEFAULT
/variable/CMAKE_Fortran_MODDIR_FLAG
/variable/CMAKE_Fortran_MODOUT_FLAG
diff --git a/Help/prop_tgt/CXX_EXTENSIONS.rst b/Help/prop_tgt/CXX_EXTENSIONS.rst
new file mode 100644
index 0000000..329e2c9
--- /dev/null
+++ b/Help/prop_tgt/CXX_EXTENSIONS.rst
@@ -0,0 +1,8 @@
+CXX_EXTENSIONS
+--------------
+
+Boolean specifying whether compiler specific extensions are requested.
+
+This property specifies whether compiler specific extensions should be
+used. For some compilers, this results in adding a flag such as -std=gnu++11
+instead of -std=c++11 to the compile line.
diff --git a/Help/prop_tgt/CXX_STANDARD.rst b/Help/prop_tgt/CXX_STANDARD.rst
new file mode 100644
index 0000000..c3cd486
--- /dev/null
+++ b/Help/prop_tgt/CXX_STANDARD.rst
@@ -0,0 +1,13 @@
+CXX_STANDARD
+------------
+
+The C++ standard whose features are required to build this target.
+
+This property specifies the C++ standard whose features are required
+to build this target. For some compilers, this results in adding a
+flag such as -std=c++11 to the compile line.
+
+Supported values are 98 and 11.
+
+This property is initialized by the value of the :variable:`CMAKE_CXX_STANDARD`
+variable if it is set when a target is created.
diff --git a/Help/variable/CMAKE_CXX_STANDARD.rst b/Help/variable/CMAKE_CXX_STANDARD.rst
new file mode 100644
index 0000000..87c00c8
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_STANDARD.rst
@@ -0,0 +1,8 @@
+CMAKE_CXX_STANDARD
+------------------
+
+Default value for CXX_STANDARD property of targets.
+
+This variable is used to initialize the :prop_tgt:`CXX_STANDARD`
+property on all targets. See that target property for additional
+information.
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 63ec576..08b9e86 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1386,6 +1386,7 @@ void cmLocalGenerator::AddCompileOptions(
this->AppendFlagEscape(flags, i->c_str());
}
}
+ this->AddCompilerRequirementFlag(flags, target, lang);
}
//----------------------------------------------------------------------------
@@ -2065,6 +2066,36 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags,
}
}
+//----------------------------------------------------------------------------
+void cmLocalGenerator::
+AddCompilerRequirementFlag(std::string &flags, cmTarget* target,
+ const char *lang)
+{
+ if (!lang)
+ {
+ return;
+ }
+ std::string l(lang);
+ std::string stdProp = l + "_STANDARD";
+ const char *standard = target->GetProperty(stdProp.c_str());
+ if (!standard)
+ {
+ return;
+ }
+ std::string extProp = l + "_EXTENSIONS";
+ bool ext = target->GetPropertyAsBool(extProp.c_str());
+ std::string type = ext ? "EXTENSION" : "STANDARD";
+
+ std::string compile_option =
+ "CMAKE_" + l + std::string(standard)
+ + "_" + type + "_COMPILE_OPTION";
+ if (const char *opt =
+ target->GetMakefile()->GetDefinition(compile_option.c_str()))
+ {
+ this->AppendFlags(flags, opt);
+ }
+}
+
static void AddVisibilityCompileOption(std::string &flags, cmTarget* target,
cmLocalGenerator *lg, const char *lang)
{
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 21700e9..4a307f7 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -147,6 +147,8 @@ public:
const char *lang);
void AddConfigVariableFlags(std::string& flags, const char* var,
const char* config);
+ void AddCompilerRequirementFlag(std::string &flags, cmTarget* target,
+ const char *lang);
///! Append flags to a string.
virtual void AppendFlags(std::string& flags, const char* newFlags);
virtual void AppendFlagEscape(std::string& flags, const char* rawFlag);
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index dc65297..4142b2a 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -280,6 +280,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("MACOSX_BUNDLE", 0);
this->SetPropertyDefault("MACOSX_RPATH", 0);
this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
+ this->SetPropertyDefault("CXX_STANDARD", 0);
// Collect the set of configuration types.
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index d4a55fc..1b37472 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -247,6 +247,12 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(CompatibleInterface CompatibleInterface)
ADD_TEST_MACRO(AliasTarget AliasTarget)
ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
+ if((CMAKE_CXX_COMPILER_ID STREQUAL GNU
+ AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL Clang
+ AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.9))
+ ADD_TEST_MACRO(CxxDialect CxxDialect)
+ endif()
set_tests_properties(EmptyLibrary PROPERTIES
PASS_REGULAR_EXPRESSION "CMake Error: CMake can not determine linker language for target: test")
ADD_TEST_MACRO(CrossCompile CrossCompile)
diff --git a/Tests/CxxDialect/CMakeLists.txt b/Tests/CxxDialect/CMakeLists.txt
new file mode 100644
index 0000000..c55f838
--- /dev/null
+++ b/Tests/CxxDialect/CMakeLists.txt
@@ -0,0 +1,12 @@
+project(CxxDialect)
+
+add_executable(use_typeof use_typeof.cxx)
+set_property(TARGET use_typeof PROPERTY CXX_STANDARD 98)
+set_property(TARGET use_typeof PROPERTY CXX_EXTENSIONS TRUE)
+
+add_executable(use_constexpr use_constexpr.cxx)
+set_property(TARGET use_constexpr PROPERTY CXX_STANDARD 11)
+
+add_executable(CxxDialect use_constexpr_and_typeof.cxx)
+set_property(TARGET CxxDialect PROPERTY CXX_STANDARD 11)
+set_property(TARGET CxxDialect PROPERTY CXX_EXTENSIONS TRUE)
diff --git a/Tests/CxxDialect/use_constexpr.cxx b/Tests/CxxDialect/use_constexpr.cxx
new file mode 100644
index 0000000..30ccc4c
--- /dev/null
+++ b/Tests/CxxDialect/use_constexpr.cxx
@@ -0,0 +1,10 @@
+
+constexpr int foo()
+{
+ return 0;
+}
+
+int main(int argc, char**)
+{
+ return foo();
+}
diff --git a/Tests/CxxDialect/use_constexpr_and_typeof.cxx b/Tests/CxxDialect/use_constexpr_and_typeof.cxx
new file mode 100644
index 0000000..af217b6
--- /dev/null
+++ b/Tests/CxxDialect/use_constexpr_and_typeof.cxx
@@ -0,0 +1,11 @@
+
+constexpr int foo()
+{
+ return 0;
+}
+
+int main(int argc, char**)
+{
+ typeof(argc) ret = foo();
+ return ret;
+}
diff --git a/Tests/CxxDialect/use_typeof.cxx b/Tests/CxxDialect/use_typeof.cxx
new file mode 100644
index 0000000..dabb61f
--- /dev/null
+++ b/Tests/CxxDialect/use_typeof.cxx
@@ -0,0 +1,6 @@
+
+int main(int argc, char**)
+{
+ typeof(argc) ret = 0;
+ return ret;
+}
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4144d4b9cdb0abbef99e6d8def703a1ec04940b8
commit 4144d4b9cdb0abbef99e6d8def703a1ec04940b8
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Oct 13 01:26:16 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:40:42 2013 +0100
Add some COMPILE_OPTIONS for specifying C++ dialect.
These are compiler-specific, compiler version specific, extension specific
and standard version specific.
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
index ab1b766..a1b3a10 100644
--- a/Modules/Compiler/Clang-CXX.cmake
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -9,3 +9,16 @@ cmake_policy(GET CMP0025 appleClangPolicy)
if(NOT appleClangPolicy STREQUAL NEW)
return()
endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+endif()
diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake
index 33d6093..3ee8639 100644
--- a/Modules/Compiler/GNU-CXX.cmake
+++ b/Modules/Compiler/GNU-CXX.cmake
@@ -10,3 +10,16 @@ else()
set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
endif()
endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+endif()
+
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+endif()
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=231cca7df67bdc9eaf76f11c3873dcc6a892137f
commit 231cca7df67bdc9eaf76f11c3873dcc6a892137f
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Nov 11 20:35:52 2013 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Nov 11 20:40:30 2013 +0100
Don't load Clang-CXX from AppleClang-CXX.
The Clang-CXX module is going to get version-specific checks, and
the version system for AppleClang is not the same as Clang.
diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake
index 680f720..0372e18 100644
--- a/Modules/Compiler/AppleClang-CXX.cmake
+++ b/Modules/Compiler/AppleClang-CXX.cmake
@@ -1 +1,6 @@
-include(Compiler/Clang-CXX)
+include(Compiler/Clang)
+__compiler_clang(CXX)
+
+if(NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
+ set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
+endif()
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
index 0372e18..ab1b766 100644
--- a/Modules/Compiler/Clang-CXX.cmake
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -4,3 +4,8 @@ __compiler_clang(CXX)
if(NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
endif()
+
+cmake_policy(GET CMP0025 appleClangPolicy)
+if(NOT appleClangPolicy STREQUAL NEW)
+ return()
+endif()
-----------------------------------------------------------------------
Summary of changes:
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list