CMake 3.5: Work around some issues with C_STANDARD and CXX_STANDARD not working properly for C11/C++11.

Needed for Ubuntu 16.04.

This *might* be related to commit af0e29f7eb.
(CMakeLists.txt: Use C++20 if it's available.)
This commit is contained in:
David Korth 2025-03-23 15:25:36 -04:00
parent 526009a434
commit a547396dca
2 changed files with 18 additions and 2 deletions

View File

@ -99,8 +99,18 @@ ELSEIF(CMAKE_VERSION VERSION_GREATER 3.7) # >= 3.8
SET(CMAKE_C_STANDARD 11)
SET(CMAKE_CXX_STANDARD 17)
ELSE()
SET(CMAKE_C_STANDARD 11)
SET(CMAKE_CXX_STANDARD 14)
# FIXME: CMake 3.5 on Ubuntu 16.04 doesn't seem to detect the
# compiler standards properly, even though this was added in
# CMake 3.1...
#SET(CMAKE_C_STANDARD 11)
#SET(CMAKE_CXX_STANDARD 14)
IF(CMAKE_COMPILER_IS_GNUCC)
# NOTE: unice68 has C_STANDARD 99, which *does* work, and overrides this.
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF()
IF(MSVC AND CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.18362.0)
# Windows SDK prior to 10.0.18362.0 has issues when compiling as either C11 or C17.

View File

@ -333,11 +333,14 @@ if (FMT_PEDANTIC)
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
endif ()
# rom-properties FIXME: CMake 3.5 doesn't handle this properly.
IF(CMAKE_VERSION VERSION_GREATER 3.5.99)
if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(fmt PUBLIC cxx_std_11)
else ()
message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler")
endif ()
ENDIF(CMAKE_VERSION VERSION_GREATER 3.5.99)
target_include_directories(fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
@ -403,7 +406,10 @@ else ()
endif ()
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
# rom-properties FIXME: CMake 3.5 doesn't handle this properly.
IF(CMAKE_VERSION VERSION_GREATER 3.5.99)
target_compile_features(fmt-header-only INTERFACE cxx_std_11)
ENDIF(CMAKE_VERSION VERSION_GREATER 3.5.99)
target_include_directories(fmt-header-only
${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE INTERFACE