Features: Add cxx_auto_type.

Record the availability of this feature for GNU 4.8 on (UNIX AND
NOT APPLE) only.  In the future, availability can be recorded for
earlier GNU, for other platforms and for other compilers. Initially
the affected configurations are as restricted as possible to allow
for easy testing while extending the features vector in only one
dimension.

The error message when using the set_property API directly is not
very good, but follow up commits will provide origin debugging of
the property and a target_compile_features command which will
provide a configure-time backtrace when possible.
This commit is contained in:
Stephen Kelly 2014-04-02 15:34:16 +02:00
parent 03355d6b5b
commit f97bf4370c
16 changed files with 105 additions and 2 deletions

View File

@ -6,3 +6,10 @@ 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_auto_type``
Automatic type deduction, as defined in N1984_.
.. _N1984: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf

View File

@ -0,0 +1,8 @@
# Reference: http://gcc.gnu.org/projects/cxx0x.html
set(_oldestSupported "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408")
# TODO: Should be supported by GNU 4.4
set(GNU44_CXX11 "${_oldestSupported} && __cplusplus >= 201103L")
set(_cmake_feature_test_cxx_auto_type "${GNU44_CXX11}")
set(_oldestSupported)

View File

@ -23,3 +23,15 @@ 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()
macro(cmake_record_cxx_compile_features)
macro(_get_gcc_features std_version list)
record_compiler_features(CXX "-std=${std_version}" ${list})
endmacro()
if (UNIX AND NOT APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
_get_gcc_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
else()
set(_result 0)
endif()
endmacro()

View File

@ -41,7 +41,8 @@
#include <ctype.h> // for isspace
#include <assert.h>
#define FOR_EACH_CXX_FEATURE(F)
#define FOR_EACH_CXX_FEATURE(F) \
F(cxx_auto_type)
class cmMakefile::Internals
{
@ -2453,6 +2454,12 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
{
this->Internal->VarUsageStack.top().insert(name);
}
if (name == "CMAKE_CXX_KNOWN_FEATURES")
{
#define STRING_LIST_ELEMENT(F) ";" #F
return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
#undef STRING_LIST_ELEMENT
}
const char* def = this->Internal->VarStack.top().Get(name);
if(!def)
{
@ -4520,7 +4527,15 @@ AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
if (!isCxxFeature)
{
cmOStringStream e;
e << "specified unknown feature \"" << feature << "\" specified for "
if (error)
{
e << "specified";
}
else
{
e << "Specified";
}
e << " unknown feature \"" << feature << "\" for "
"target \"" << target->GetName() << "\".";
if (error)
{

View File

@ -197,6 +197,10 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(TarTest TarTest)
ADD_TEST_MACRO(SystemInformation SystemInformation)
ADD_TEST_MACRO(MathTest MathTest)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
ADD_TEST_MACRO(CompileFeatures CompileFeatures)
endif()
# assume no resources building to test
set(TEST_RESOURCES FALSE)
# for windows and cygwin assume we have resources

View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.0)
project(CompileFeatures)
macro(run_test feature)
if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ${feature})
add_library(test_${feature} OBJECT ${feature}.cpp)
set_property(TARGET test_${feature}
PROPERTY COMPILE_FEATURES "${feature}"
)
else()
message("Not supported: ${feature}")
endif()
endmacro()
foreach(feature ${CMAKE_CXX_KNOWN_FEATURES})
run_test(${feature})
endforeach()
add_executable(CompileFeatures main.cpp)
set_property(TARGET CompileFeatures
PROPERTY COMPILE_FEATURES "cxx_auto_type"
)

View File

@ -0,0 +1,5 @@
void someFunc()
{
auto x = 3.14;
}

View File

@ -0,0 +1,6 @@
int main(int,char**)
{
auto value = 0;
return value;
}

View File

@ -53,6 +53,7 @@ add_RunCMake_test(ObjectLibrary)
add_RunCMake_test(TargetObjects)
add_RunCMake_test(TargetSources)
add_RunCMake_test(find_dependency)
add_RunCMake_test(CompileFeatures)
if(NOT WIN32)
add_RunCMake_test(PositionIndependentCode)
set(SKIP_VISIBILITY 0)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(${RunCMake_TEST} CXX)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
CMake Error in CMakeLists.txt:
Specified unknown feature "not_a_feature" for target "somelib".

View File

@ -0,0 +1,3 @@
add_library(somelib STATIC empty.cpp)
set_property(TARGET somelib PROPERTY COMPILE_FEATURES "not_a_feature")

View File

@ -0,0 +1,3 @@
include(RunCMake)
run_cmake(NotAFeature)

View File

@ -0,0 +1,7 @@
#ifdef _WIN32
__declspec(dllexport)
#endif
int empty()
{
return 0;
}

View File

@ -25,6 +25,8 @@ CMAKE_CXX98_STANDARD_COMPILE_OPTION == "${CMAKE_CXX98_STANDARD_COMPILE_OPTION}"
CMAKE_CXX11_STANDARD_COMPILE_OPTION == "${CMAKE_CXX11_STANDARD_COMPILE_OPTION}"
CMAKE_CXX98_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX98_EXTENSION_COMPILE_OPTION}"
CMAKE_CXX11_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX11_EXTENSION_COMPILE_OPTION}"
CMAKE_CXX_COMPILE_FEATURES == "${CMAKE_CXX_COMPILE_FEATURES}"
CMAKE_CXX11_COMPILE_FEATURES == "${CMAKE_CXX11_COMPILE_FEATURES}"
// C shared library flag
CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}"