--- CMakeLists.txt.orig +++ CMakeLists.txt @@ -141,12 +141,16 @@ MESSAGE(status "Skipping compiler version check.") ENDIF() -# Configure C++ standard if not externally specified (will actually be -# set after CppUnit check below). Use the variable CMAKE_CXX_STANDARD -# since it will actually be used for this purposes starting in CMake 3.1. +######################################################################## +# Configure C++ standard if not externally specified. Use the variable +# CMAKE_CXX_STANDARD since it will actually be used for this purposes +# starting in CMake 3.1. +######################################################################## -SET(CMAKE_C_EXTENSIONS OFF) -SET(CMAKE_CXX_EXTENSIONS OFF) +# save current setting, if provided +IF(CMAKE_CXX_STANDARD) + SET(CMAKE_CXX_STANDARD_EXT ${CMAKE_CXX_STANDARD}) +ENDIF() IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") SET(CMAKE_CXX_STANDARD 11) @@ -155,9 +159,60 @@ ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") SET(CMAKE_CXX_STANDARD 11) ELSE() - message(WARNING "C++ standard could not be set because compiler is not GNU, Clang or MSVC.") + MESSAGE(WARNING "C++ standard could not be set because compiler is not GNU, Clang or MSVC.") +ENDIF() + +# if the CXX standard was provided externally, make sure it meets GR's minimum +IF(CMAKE_CXX_STANDARD_EXT) + # verify that the provided C++ standard is one CMake + # accepts. options are 90, 99, and 11 as of CMake 3.11.4 (with 20 + # coming in 3.12). + IF(NOT ${CMAKE_CXX_STANDARD_EXT} VERSION_EQUAL "98" AND + NOT ${CMAKE_CXX_STANDARD_EXT} VERSION_EQUAL "11" AND + NOT ${CMAKE_CXX_STANDARD_EXT} VERSION_EQUAL "14" AND + NOT ${CMAKE_CXX_STANDARD_EXT} VERSION_EQUAL "17") + MESSAGE(WARNING "Requested C++ standard (${CMAKE_CXX_STANDARD_EXT}) isn't recognized by CMake; expecting one of 98, 11, 14, or 17. Ignoring and using the GNU Radio default C++ standard (${CMAKE_CXX_STANDARD}).") + SET(CMAKE_CXX_STANDARD_EXT ${CMAKE_CXX_STANDARD}) + ENDIF() + # fix settings to be comparables. It will be -many- years until we + # have to worry about this value getting large enough to wrap + # around (to 90), so just add 100 to any value not in the 90's, + # for comparison sake. + IF(${CMAKE_CXX_STANDARD} VERSION_EQUAL "98") + # just copy the value + SET(CMAKE_CXX_STANDARD_CMP ${CMAKE_CXX_STANDARD}) + ELSE() + # add 100 to the value + MATH(EXPR CMAKE_CXX_STANDARD_CMP "${CMAKE_CXX_STANDARD} + 100") + ENDIF() + IF(${CMAKE_CXX_STANDARD_EXT} VERSION_EQUAL "98") + # just copy the value + SET(CMAKE_CXX_STANDARD_EXT_CMP ${CMAKE_CXX_STANDARD_EXT}) + ELSE() + # add 100 to the value + MATH(EXPR CMAKE_CXX_STANDARD_EXT_CMP "${CMAKE_CXX_STANDARD_EXT} + 100") + ENDIF() + # compare values + IF(${CMAKE_CXX_STANDARD_EXT_CMP} VERSION_LESS ${CMAKE_CXX_STANDARD_CMP}) + MESSAGE(WARNING "Requested C++ standard (${CMAKE_CXX_STANDARD_EXT}) isn't modern enough to build GNU Radio; using minimum required C++ standard (${CMAKE_CXX_STANDARD}) instead and hoping for the best!") + ELSEIF(${CMAKE_CXX_STANDARD_EXT_CMP} VERSION_GREATER ${CMAKE_CXX_STANDARD_CMP}) + MESSAGE(WARNING "Requested C++ standard (${CMAKE_CXX_STANDARD_EXT}) is more recent than the minimum required C++ standard (${CMAKE_CXX_STANDARD}). GNU Radio might have issues building using this C++ standard; going with it and hoping for the best!") + SET(CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD_EXT}) + ENDIF() +ENDIF() + +######################################################################## +# Configure C standard if not externally specified. Use the variable +# CMAKE_C_STANDARD since it will actually be used for this purposes +# starting in CMake 3.1. +######################################################################## + +# save current setting, if provided +IF(CMAKE_C_STANDARD) + SET(CMAKE_C_STANDARD_EXT ${CMAKE_C_STANDARD}) ENDIF() +# set GR preferred setting IF(CMAKE_C_COMPILER_ID STREQUAL "GNU") SET(CMAKE_C_STANDARD 11) ELSEIF(CMAKE_C_COMPILER_ID MATCHES "Clang") @@ -165,7 +220,58 @@ ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "MSVC") SET(CMAKE_C_STANDARD 11) ELSE() - message(WARNING "C standard could not be set because compiler is not GNU, Clang or MSVC.") + MESSAGE(WARNING "C standard could not be set because compiler is not GNU, Clang or MSVC.") +ENDIF() + +# if the C standard was provided externally, make sure it meets GR's minimum +IF(CMAKE_C_STANDARD_EXT) + # verify that the provided C standard is one CMake + # accepts. options are 90, 99, and 11 as of CMake 3.11.4. + IF(NOT ${CMAKE_C_STANDARD_EXT} VERSION_EQUAL "90" AND + NOT ${CMAKE_C_STANDARD_EXT} VERSION_EQUAL "99" AND + NOT ${CMAKE_C_STANDARD_EXT} VERSION_EQUAL "11") + MESSAGE(WARNING "Requested C standard (${CMAKE_C_STANDARD_EXT}) isn't recognized by CMake; expecting one of 90, 99, or 11. Ignoring and using the GNU Radio default C standard (${CMAKE_C_STANDARD}).") + SET(CMAKE_C_STANDARD_EXT ${CMAKE_C_STANDARD}) + ENDIF() + # fix settings to be comparable. It will be -many- years until we + # have to worry about this value getting large enough to wrap + # around (to 90), so just add 100 to any value not in the 90's, + # for comparison sake. + IF(${CMAKE_C_STANDARD} VERSION_EQUAL "90" OR + ${CMAKE_C_STANDARD} VERSION_EQUAL "99") + # just copy the value + SET(CMAKE_C_STANDARD_CMP ${CMAKE_C_STANDARD}) + ELSE() + # add 100 to the value + MATH(EXPR CMAKE_C_STANDARD_CMP "${CMAKE_C_STANDARD} + 100") + ENDIF() + IF(${CMAKE_C_STANDARD_EXT} VERSION_EQUAL "90" OR + ${CMAKE_C_STANDARD_EXT} VERSION_EQUAL "99") + # just copy the value + SET(CMAKE_C_STANDARD_EXT_CMP ${CMAKE_C_STANDARD_EXT}) + ELSE() + # add 100 to the value + MATH(EXPR CMAKE_C_STANDARD_EXT_CMP "${CMAKE_C_STANDARD_EXT} + 100") + ENDIF() + # compare values + IF(${CMAKE_C_STANDARD_EXT_CMP} VERSION_LESS ${CMAKE_C_STANDARD_CMP}) + MESSAGE(WARNING "Requested C standard (${CMAKE_C_STANDARD_EXT}) isn't modern enough to build GNU Radio; using minimum required C standard (${CMAKE_C_STANDARD}) instead and hoping for the best!") + ELSEIF(${CMAKE_C_STANDARD_EXT_CMP} VERSION_GREATER ${CMAKE_C_STANDARD_CMP}) + MESSAGE(WARNING "Requested C standard (${CMAKE_C_STANDARD_EXT}) is more recent than the minimum required C standard (${CMAKE_C_STANDARD}). GNU Radio might have issues building using this C standard; going with it and hoping for the best!") + SET(CMAKE_C_STANDARD ${CMAKE_C_STANDARD_EXT}) + ENDIF() +ENDIF() + +######################################################################## +# If C/CXX EXTENSIONS are defined, don't change them. GNU Radio itself +# does not require them. If not defined, then disable them as a safe default. +######################################################################## + +IF(NOT CMAKE_C_EXTENSIONS) + SET(CMAKE_C_EXTENSIONS OFF) +ENDIF() +IF(NOT CMAKE_CXX_EXTENSIONS) + SET(CMAKE_CXX_EXTENSIONS OFF) ENDIF() ########################################################################