mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-03 21:00:01 -05:00
Merge topic 'target_compile_features'
9eaf3755Export: Populate INTERFACE_COMPILE_FEATURES property.8ed59fc2Add target_compile_features command.4e6ca504cmTargetPropCommandBase: Change the interface to return bool.5412dedecmTarget: Transitively evaluate compiler features.baff4434cmTarget: Allow populating COMPILE_FEATURES using generator expressions.f97bf437Features: Add cxx_auto_type.03355d6bcmTarget: Add COMPILE_FEATURES target property.faeddf64project: Add infrastructure for recording CXX compiler features913394afcmTarget: Add CXX_STANDARD and CXX_EXTENSION target properties.8238a6cdAdd some COMPILE_OPTIONS for specifying C++ dialect.892243fcTests: Require CMake 3.0 for the SystemInformation test.59b5fdd3Don't load Clang-CXX from AppleClang-CXX.
This commit is contained in:
@@ -2,6 +2,9 @@ set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
|
||||
set(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@")
|
||||
set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
|
||||
set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
|
||||
set(CMAKE_CXX_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@")
|
||||
set(CMAKE_CXX11_COMPILE_FEATURES "@CMAKE_CXX11_COMPILE_FEATURES@")
|
||||
|
||||
set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@")
|
||||
set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@")
|
||||
set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@")
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2013 Stephen Kelly <steveire@gmail.com>
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
function(cmake_determine_compile_features lang)
|
||||
|
||||
if(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
|
||||
message(STATUS "Detecting ${lang} compile features")
|
||||
|
||||
set(CMAKE_CXX11_COMPILE_FEATURES)
|
||||
|
||||
include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
|
||||
|
||||
cmake_record_cxx_compile_features()
|
||||
|
||||
if(NOT _result EQUAL 0)
|
||||
message(STATUS "Detecting ${lang} compile features - failed")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CXX_COMPILE_FEATURES)
|
||||
set(CMAKE_CXX_COMPILE_FEATURES
|
||||
${CMAKE_CXX11_COMPILE_FEATURES}
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES} PARENT_SCOPE)
|
||||
set(CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES} PARENT_SCOPE)
|
||||
|
||||
message(STATUS "Detecting ${lang} compile features - done")
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
@@ -66,6 +66,9 @@ else()
|
||||
# Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
|
||||
|
||||
# Re-configure to save learned information.
|
||||
configure_file(
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -4,3 +4,21 @@ __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()
|
||||
|
||||
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()
|
||||
|
||||
@@ -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)
|
||||
@@ -10,3 +10,28 @@ 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()
|
||||
|
||||
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()
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
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.bin")
|
||||
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\nint main(int, char **) { return 0; }\n")
|
||||
|
||||
try_compile(CMAKE_${lang}_FEATURE_TEST
|
||||
${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}"
|
||||
COMPILE_DEFINITIONS "${compile_flags}"
|
||||
OUTPUT_VARIABLE _output
|
||||
COPY_FILE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin"
|
||||
COPY_FILE_ERROR _copy_error
|
||||
)
|
||||
if(CMAKE_${lang}_FEATURE_TEST AND NOT _copy_error)
|
||||
set(_result 0)
|
||||
else()
|
||||
set(_result 255)
|
||||
endif()
|
||||
unset(CMAKE_${lang}_FEATURE_TEST CACHE)
|
||||
|
||||
if (_result EQUAL 0)
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"\n\nDetecting ${lang} [${compile_flags}] compiler features compiled with the following output:\n${_output}\n\n")
|
||||
if(EXISTS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin")
|
||||
file(STRINGS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin"
|
||||
features REGEX "${lang}_FEATURE:.*")
|
||||
foreach(info ${features})
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
" Feature record: ${info}\n")
|
||||
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()
|
||||
else()
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Detecting ${lang} [${compile_flags}] compiler features failed to compile with the following output:\n${_output}\n${_copy_error}\n\n")
|
||||
endif()
|
||||
endmacro()
|
||||
Reference in New Issue
Block a user