mirror of
https://github.com/reactos/CMake.git
synced 2024-11-29 06:20:23 +00:00
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:
parent
03355d6b5b
commit
f97bf4370c
@ -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
|
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
|
C++ compiler. If the feature is available with the C++ compiler, it will
|
||||||
be listed in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
|
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
|
||||||
|
8
Modules/Compiler/GNU-CXX-FeatureTests.cmake
Normal file
8
Modules/Compiler/GNU-CXX-FeatureTests.cmake
Normal 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)
|
@ -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_STANDARD_COMPILE_OPTION "-std=c++0x")
|
||||||
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
|
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
|
||||||
endif()
|
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()
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
#include <ctype.h> // for isspace
|
#include <ctype.h> // for isspace
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define FOR_EACH_CXX_FEATURE(F)
|
#define FOR_EACH_CXX_FEATURE(F) \
|
||||||
|
F(cxx_auto_type)
|
||||||
|
|
||||||
class cmMakefile::Internals
|
class cmMakefile::Internals
|
||||||
{
|
{
|
||||||
@ -2453,6 +2454,12 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
|
|||||||
{
|
{
|
||||||
this->Internal->VarUsageStack.top().insert(name);
|
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);
|
const char* def = this->Internal->VarStack.top().Get(name);
|
||||||
if(!def)
|
if(!def)
|
||||||
{
|
{
|
||||||
@ -4520,7 +4527,15 @@ AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
|
|||||||
if (!isCxxFeature)
|
if (!isCxxFeature)
|
||||||
{
|
{
|
||||||
cmOStringStream e;
|
cmOStringStream e;
|
||||||
e << "specified unknown feature \"" << feature << "\" specified for "
|
if (error)
|
||||||
|
{
|
||||||
|
e << "specified";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e << "Specified";
|
||||||
|
}
|
||||||
|
e << " unknown feature \"" << feature << "\" for "
|
||||||
"target \"" << target->GetName() << "\".";
|
"target \"" << target->GetName() << "\".";
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
@ -197,6 +197,10 @@ if(BUILD_TESTING)
|
|||||||
ADD_TEST_MACRO(TarTest TarTest)
|
ADD_TEST_MACRO(TarTest TarTest)
|
||||||
ADD_TEST_MACRO(SystemInformation SystemInformation)
|
ADD_TEST_MACRO(SystemInformation SystemInformation)
|
||||||
ADD_TEST_MACRO(MathTest MathTest)
|
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
|
# assume no resources building to test
|
||||||
set(TEST_RESOURCES FALSE)
|
set(TEST_RESOURCES FALSE)
|
||||||
# for windows and cygwin assume we have resources
|
# for windows and cygwin assume we have resources
|
||||||
|
24
Tests/CompileFeatures/CMakeLists.txt
Normal file
24
Tests/CompileFeatures/CMakeLists.txt
Normal 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"
|
||||||
|
)
|
5
Tests/CompileFeatures/cxx_auto_type.cpp
Normal file
5
Tests/CompileFeatures/cxx_auto_type.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
void someFunc()
|
||||||
|
{
|
||||||
|
auto x = 3.14;
|
||||||
|
}
|
6
Tests/CompileFeatures/main.cpp
Normal file
6
Tests/CompileFeatures/main.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
int main(int,char**)
|
||||||
|
{
|
||||||
|
auto value = 0;
|
||||||
|
return value;
|
||||||
|
}
|
@ -53,6 +53,7 @@ add_RunCMake_test(ObjectLibrary)
|
|||||||
add_RunCMake_test(TargetObjects)
|
add_RunCMake_test(TargetObjects)
|
||||||
add_RunCMake_test(TargetSources)
|
add_RunCMake_test(TargetSources)
|
||||||
add_RunCMake_test(find_dependency)
|
add_RunCMake_test(find_dependency)
|
||||||
|
add_RunCMake_test(CompileFeatures)
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
add_RunCMake_test(PositionIndependentCode)
|
add_RunCMake_test(PositionIndependentCode)
|
||||||
set(SKIP_VISIBILITY 0)
|
set(SKIP_VISIBILITY 0)
|
||||||
|
3
Tests/RunCMake/CompileFeatures/CMakeLists.txt
Normal file
3
Tests/RunCMake/CompileFeatures/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
project(${RunCMake_TEST} CXX)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
1
Tests/RunCMake/CompileFeatures/NotAFeature-result.txt
Normal file
1
Tests/RunCMake/CompileFeatures/NotAFeature-result.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
2
Tests/RunCMake/CompileFeatures/NotAFeature-stderr.txt
Normal file
2
Tests/RunCMake/CompileFeatures/NotAFeature-stderr.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
CMake Error in CMakeLists.txt:
|
||||||
|
Specified unknown feature "not_a_feature" for target "somelib".
|
3
Tests/RunCMake/CompileFeatures/NotAFeature.cmake
Normal file
3
Tests/RunCMake/CompileFeatures/NotAFeature.cmake
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
add_library(somelib STATIC empty.cpp)
|
||||||
|
set_property(TARGET somelib PROPERTY COMPILE_FEATURES "not_a_feature")
|
3
Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
Normal file
3
Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(NotAFeature)
|
7
Tests/RunCMake/CompileFeatures/empty.cpp
Normal file
7
Tests/RunCMake/CompileFeatures/empty.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifdef _WIN32
|
||||||
|
__declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
int empty()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
@ -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_CXX11_STANDARD_COMPILE_OPTION == "${CMAKE_CXX11_STANDARD_COMPILE_OPTION}"
|
||||||
CMAKE_CXX98_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX98_EXTENSION_COMPILE_OPTION}"
|
CMAKE_CXX98_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX98_EXTENSION_COMPILE_OPTION}"
|
||||||
CMAKE_CXX11_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX11_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
|
// C shared library flag
|
||||||
CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
|
CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
|
||||||
|
Loading…
Reference in New Issue
Block a user