port of cmake c++ standard detection from RC_1_1

This commit is contained in:
Alden Torres 2018-11-18 13:52:12 -05:00 committed by Arvid Norberg
parent 8841c58435
commit 8258a114b9
1 changed files with 18 additions and 3 deletions

View File

@ -54,20 +54,35 @@ macro(find_public_dependency _name)
endif()
endmacro()
function(_cxx_standard_to_year _yearVar _std)
if (${_std} GREATER 97)
math(EXPR _year "1900 + ${_std}")
else()
math(EXPR _year "2000 + ${_std}")
endif()
set(${_yearVar} ${_year} PARENT_SCOPE)
endfunction()
function(select_cxx_standard _target _minimal_supported_version)
message(STATUS "Compiler default is C++${CMAKE_CXX_STANDARD_DEFAULT}")
# make the CXX_STANDARD property public to ensure it makes it into the pkg-config file
get_target_property(_std ${_target} CXX_STANDARD)
# ${CMAKE_CXX_STANDARD_DEFAULT} could be 98, which is lower version than C++11. Thus we convert std
# version to year value and compare years
_cxx_standard_to_year(minimal_supported_version_year ${_minimal_supported_version})
# if it is unset, select the default if it is sufficient or the ${_minimal_supported_version}
if (NOT ${_std})
if (${CMAKE_CXX_STANDARD_DEFAULT} GREATER_EQUAL ${_minimal_supported_version})
_cxx_standard_to_year(std_default_year ${CMAKE_CXX_STANDARD_DEFAULT})
if (${std_default_year} GREATER_EQUAL ${minimal_supported_version_year})
set(_std ${CMAKE_CXX_STANDARD_DEFAULT})
else()
set(_std ${_minimal_supported_version})
endif()
else()
if (${_std} LESS ${_minimal_supported_version})
message(FATAL_ERROR "Sorry, C++${_std} is not supported by libtorrent")
_cxx_standard_to_year(std_year ${_std})
if (${std_year} LESS ${minimal_supported_version_year})
message(SEND_ERROR "Sorry, C++${_std} is not supported by libtorrent with the given Boost version")
message(FATAL_ERROR "The minimal supported C++ standard version is C++${_minimal_supported_version}")
endif()
endif()