2014-04-02 17:34:16 +04:00
|
|
|
|
2015-01-06 21:31:30 +03:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2014-04-02 17:34:16 +04:00
|
|
|
|
|
|
|
project(CompileFeatures)
|
|
|
|
|
2013-11-04 04:15:43 +04:00
|
|
|
if (NOT CMAKE_C_COMPILE_FEATURES AND NOT CMAKE_CXX_COMPILE_FEATURES)
|
2014-04-16 19:22:01 +04:00
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp"
|
|
|
|
"int main(int,char**) { return 0; }\n"
|
|
|
|
)
|
|
|
|
add_executable(CompileFeatures "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2014-04-06 15:00:17 +04:00
|
|
|
macro(run_test feature lang)
|
|
|
|
if (";${CMAKE_${lang}_COMPILE_FEATURES};" MATCHES ${feature})
|
|
|
|
add_library(test_${feature} OBJECT ${feature})
|
2014-04-02 17:34:16 +04:00
|
|
|
set_property(TARGET test_${feature}
|
|
|
|
PROPERTY COMPILE_FEATURES "${feature}"
|
|
|
|
)
|
|
|
|
else()
|
2014-04-06 15:00:17 +04:00
|
|
|
list(APPEND ${lang}_non_features ${feature})
|
2014-04-02 17:34:16 +04:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2013-11-04 04:15:43 +04:00
|
|
|
get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES)
|
|
|
|
foreach(feature ${c_features})
|
|
|
|
run_test(${feature} C)
|
|
|
|
endforeach()
|
2014-04-06 15:00:17 +04:00
|
|
|
get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
|
|
|
|
foreach(feature ${cxx_features})
|
|
|
|
run_test(${feature} CXX)
|
2014-04-02 17:34:16 +04:00
|
|
|
endforeach()
|
|
|
|
|
2015-01-09 22:18:26 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
|
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
|
|
|
|
# AppleClang prior to 5.1 does not set any preprocessor define to distinguish
|
|
|
|
# c++1y from c++11, so CMake does not support c++1y features before AppleClang 5.1.
|
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
cxx_attribute_deprecated
|
|
|
|
cxx_binary_literals
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
|
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.2)
|
|
|
|
# AppleClang prior to 4.1 reports false for __has_feature(cxx_local_type_template_args)
|
|
|
|
# and __has_feature(cxx_unrestricted_unions) but it happens to pass these tests.
|
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
cxx_local_type_template_args
|
|
|
|
cxx_unrestricted_unions
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2015-01-16 21:26:37 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro)
|
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
cxx_attribute_deprecated
|
|
|
|
cxx_contextual_conversions
|
|
|
|
cxx_extended_friend_declarations
|
|
|
|
cxx_long_long_type
|
|
|
|
cxx_sizeof_member
|
|
|
|
cxx_variadic_macros
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2015-01-22 17:39:35 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5)
|
|
|
|
# The cxx_raw_string_literals feature happens to work in some distributions
|
|
|
|
# of GNU 4.4, but it is first documented as available with GNU 4.5.
|
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
cxx_raw_string_literals
|
|
|
|
)
|
|
|
|
endif()
|
2015-01-18 16:44:13 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
|
|
|
|
# The cxx_constexpr feature happens to work (for *this* testcase) with
|
|
|
|
# GNU 4.5, but it is first documented as available with GNU 4.6.
|
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
cxx_constexpr
|
|
|
|
)
|
|
|
|
endif()
|
2015-01-06 21:31:30 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
2013-10-21 18:59:40 +04:00
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
|
2015-01-03 17:18:39 +03:00
|
|
|
# The cxx_alignof feature happens to work (for *this* testcase) with
|
|
|
|
# GNU 4.7, but it is first documented as available with GNU 4.8.
|
2013-10-21 18:59:40 +04:00
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
cxx_alignof
|
|
|
|
)
|
|
|
|
endif()
|
2015-01-06 21:31:30 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
2014-05-06 02:21:14 +04:00
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
|
|
|
|
# GNU prior to 4.9 does not set any preprocessor define to distinguish
|
|
|
|
# c++1y from c++11, so CMake does not support c++1y features before GNU 4.9.
|
|
|
|
list(REMOVE_ITEM CXX_non_features
|
|
|
|
# GNU 4.8 knows cxx_attributes, but doesn't know [[deprecated]]
|
|
|
|
# and warns that it is unknown and ignored.
|
|
|
|
cxx_attribute_deprecated
|
|
|
|
cxx_binary_literals
|
|
|
|
cxx_lambda_init_captures
|
|
|
|
cxx_return_type_deduction
|
|
|
|
)
|
|
|
|
endif()
|
2013-10-21 18:59:40 +04:00
|
|
|
|
2013-11-04 04:15:43 +04:00
|
|
|
set(C_ext c)
|
|
|
|
set(C_standard_flag 11)
|
2014-05-09 19:27:55 +04:00
|
|
|
set(CXX_ext cpp)
|
2014-05-06 02:21:14 +04:00
|
|
|
set(CXX_standard_flag 14)
|
2013-11-04 04:15:43 +04:00
|
|
|
foreach(lang CXX C)
|
2014-05-09 19:27:55 +04:00
|
|
|
if (CMAKE_${lang}_COMPILE_FEATURES)
|
|
|
|
foreach(feature ${${lang}_non_features})
|
|
|
|
message("Testing feature : ${feature}")
|
|
|
|
try_compile(${feature}_works
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${feature}_test"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/feature_test.${${lang}_ext}"
|
2015-01-21 23:42:08 +03:00
|
|
|
COMPILE_DEFINITIONS "-DTEST=${feature}.${${lang}_ext}"
|
2014-05-09 19:27:55 +04:00
|
|
|
CMAKE_FLAGS "-DCMAKE_${lang}_STANDARD=${${lang}_standard_flag}"
|
2015-01-21 23:42:08 +03:00
|
|
|
"-DINCLUDE_DIRECTORIES=${CMAKE_CURRENT_SOURCE_DIR}"
|
2014-05-09 19:27:55 +04:00
|
|
|
OUTPUT_VARIABLE OUTPUT
|
|
|
|
)
|
|
|
|
if (${feature}_works)
|
|
|
|
message(SEND_ERROR
|
|
|
|
"Feature ${feature} expected not to work for ${lang} ${CMAKE_${lang}_COMPILER_ID}-${CMAKE_${lang}_COMPILER_VERSION}.
|
|
|
|
Update the supported features or blacklist it.\n${OUTPUT}")
|
|
|
|
else()
|
|
|
|
message("Testing feature : ${feature} -- Fails, as expected.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2014-04-06 15:00:17 +04:00
|
|
|
|
2014-11-18 01:24:31 +03:00
|
|
|
if (CMAKE_C_COMPILE_FEATURES)
|
|
|
|
string(FIND "${CMAKE_C_FLAGS}" "-std=" std_flag_idx)
|
|
|
|
if (std_flag_idx EQUAL -1)
|
|
|
|
add_executable(default_dialect_C default_dialect.c)
|
|
|
|
target_compile_definitions(default_dialect_C PRIVATE
|
|
|
|
DEFAULT_C11=$<EQUAL:${CMAKE_C_STANDARD_DEFAULT},11>
|
|
|
|
DEFAULT_C99=$<EQUAL:${CMAKE_C_STANDARD_DEFAULT},99>
|
|
|
|
DEFAULT_C90=$<EQUAL:${CMAKE_C_STANDARD_DEFAULT},90>
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2014-11-18 23:33:08 +03:00
|
|
|
if (CMAKE_CXX_COMPILE_FEATURES)
|
2014-11-18 01:24:31 +03:00
|
|
|
string(FIND "${CMAKE_CXX_FLAGS}" "-std=" std_flag_idx)
|
|
|
|
if (std_flag_idx EQUAL -1)
|
|
|
|
add_executable(default_dialect default_dialect.cpp)
|
|
|
|
target_compile_definitions(default_dialect PRIVATE
|
|
|
|
DEFAULT_CXX14=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},14>
|
|
|
|
DEFAULT_CXX11=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},11>
|
|
|
|
DEFAULT_CXX98=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},98>
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2014-11-18 23:33:08 +03:00
|
|
|
add_executable(CompileFeatures main.cpp)
|
|
|
|
set_property(TARGET CompileFeatures
|
|
|
|
PROPERTY COMPILE_FEATURES "cxx_auto_type"
|
|
|
|
)
|
|
|
|
set_property(TARGET CompileFeatures
|
|
|
|
PROPERTY CXX_STANDARD_REQUIRED TRUE
|
|
|
|
)
|
2013-10-22 17:05:49 +04:00
|
|
|
|
2014-11-18 23:33:08 +03:00
|
|
|
add_executable(GenexCompileFeatures main.cpp)
|
|
|
|
set_property(TARGET GenexCompileFeatures
|
|
|
|
PROPERTY COMPILE_FEATURES "$<1:cxx_auto_type>;$<0:not_a_feature>"
|
|
|
|
)
|
2013-10-22 03:40:47 +04:00
|
|
|
|
2014-11-18 23:33:08 +03:00
|
|
|
add_library(iface INTERFACE)
|
|
|
|
set_property(TARGET iface
|
|
|
|
PROPERTY INTERFACE_COMPILE_FEATURES "cxx_auto_type"
|
|
|
|
)
|
|
|
|
add_executable(IfaceCompileFeatures main.cpp)
|
|
|
|
target_link_libraries(IfaceCompileFeatures iface)
|
2014-05-15 13:32:30 +04:00
|
|
|
|
2015-01-12 22:02:17 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
|
|
|
|
add_definitions(
|
2015-01-10 22:05:54 +03:00
|
|
|
-DEXPECT_OVERRIDE_CONTROL=1
|
2015-01-12 22:02:17 +03:00
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=1
|
|
|
|
-DEXPECT_FINAL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
|
|
|
|
)
|
|
|
|
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
|
|
|
|
add_definitions(
|
2015-01-10 22:05:54 +03:00
|
|
|
-DEXPECT_OVERRIDE_CONTROL=1
|
2015-01-12 22:02:17 +03:00
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=0
|
|
|
|
-DEXPECT_FINAL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_definitions(
|
2015-01-10 22:05:54 +03:00
|
|
|
-DEXPECT_OVERRIDE_CONTROL=0
|
2015-01-12 22:02:17 +03:00
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=0
|
|
|
|
-DEXPECT_FINAL=0
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
add_definitions(
|
2015-01-10 22:05:54 +03:00
|
|
|
-DEXPECT_OVERRIDE_CONTROL=1
|
2015-01-12 22:02:17 +03:00
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=1
|
|
|
|
-DEXPECT_FINAL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
|
|
|
|
)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
|
|
|
add_definitions(
|
2015-01-10 22:05:54 +03:00
|
|
|
-DEXPECT_OVERRIDE_CONTROL=1
|
2015-01-12 22:02:17 +03:00
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=1
|
|
|
|
-DEXPECT_FINAL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_definitions(
|
2015-01-10 22:05:54 +03:00
|
|
|
-DEXPECT_OVERRIDE_CONTROL=1
|
2015-01-12 22:02:17 +03:00
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=0
|
|
|
|
-DEXPECT_FINAL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
|
|
|
|
)
|
|
|
|
endif()
|
2015-01-16 21:26:37 +03:00
|
|
|
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
|
|
|
|
add_definitions(
|
|
|
|
-DEXPECT_OVERRIDE_CONTROL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS=1
|
|
|
|
-DEXPECT_FINAL=1
|
|
|
|
-DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
|
|
|
|
)
|
2015-01-12 22:02:17 +03:00
|
|
|
endif()
|
|
|
|
|
2014-11-18 23:33:08 +03:00
|
|
|
add_executable(CompileFeaturesGenex genex_test.cpp)
|
|
|
|
set_property(TARGET CompileFeaturesGenex PROPERTY CXX_STANDARD 11)
|
2015-01-03 17:09:53 +03:00
|
|
|
target_compile_definitions(CompileFeaturesGenex PRIVATE
|
|
|
|
HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>
|
2015-01-17 17:58:45 +03:00
|
|
|
HAVE_AUTO_TYPE=$<COMPILE_FEATURES:cxx_auto_type>
|
2015-01-12 22:02:17 +03:00
|
|
|
HAVE_INHERITING_CONSTRUCTORS=$<COMPILE_FEATURES:cxx_inheriting_constructors>
|
|
|
|
HAVE_FINAL=$<COMPILE_FEATURES:cxx_final>
|
|
|
|
HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final>
|
2015-01-03 17:09:53 +03:00
|
|
|
)
|
2014-05-15 13:32:30 +04:00
|
|
|
|
2014-11-18 23:33:08 +03:00
|
|
|
add_executable(CompileFeaturesGenex2 genex_test.cpp)
|
2015-01-03 17:04:39 +03:00
|
|
|
target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_static_assert)
|
2015-01-03 17:09:53 +03:00
|
|
|
target_compile_definitions(CompileFeaturesGenex2 PRIVATE
|
|
|
|
HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>
|
2015-01-17 17:58:45 +03:00
|
|
|
HAVE_AUTO_TYPE=$<COMPILE_FEATURES:cxx_auto_type>
|
2015-01-12 22:02:17 +03:00
|
|
|
HAVE_INHERITING_CONSTRUCTORS=$<COMPILE_FEATURES:cxx_inheriting_constructors>
|
|
|
|
HAVE_FINAL=$<COMPILE_FEATURES:cxx_final>
|
|
|
|
HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final>
|
2015-01-03 17:09:53 +03:00
|
|
|
)
|
2014-05-15 13:32:30 +04:00
|
|
|
|
2015-01-03 17:04:39 +03:00
|
|
|
add_library(static_assert_iface INTERFACE)
|
|
|
|
target_compile_features(static_assert_iface INTERFACE cxx_static_assert)
|
2014-11-18 23:33:08 +03:00
|
|
|
add_executable(CompileFeaturesGenex3 genex_test.cpp)
|
2015-01-03 17:04:39 +03:00
|
|
|
target_link_libraries(CompileFeaturesGenex3 PRIVATE static_assert_iface)
|
2015-01-03 17:09:53 +03:00
|
|
|
target_compile_definitions(CompileFeaturesGenex3 PRIVATE
|
|
|
|
HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>
|
2015-01-17 17:58:45 +03:00
|
|
|
HAVE_AUTO_TYPE=$<COMPILE_FEATURES:cxx_auto_type>
|
2015-01-12 22:02:17 +03:00
|
|
|
HAVE_INHERITING_CONSTRUCTORS=$<COMPILE_FEATURES:cxx_inheriting_constructors>
|
|
|
|
HAVE_FINAL=$<COMPILE_FEATURES:cxx_final>
|
|
|
|
HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final>
|
2015-01-03 17:09:53 +03:00
|
|
|
)
|
2014-11-18 23:33:08 +03:00
|
|
|
endif()
|