Merge pull request #7945

4afd9a7 cmake: set required C/C++ standard to 11 (selsta)
This commit is contained in:
luigi1111 2021-09-23 22:22:42 -05:00
commit 6b824c9ed0
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
4 changed files with 27 additions and 13 deletions

View File

@ -92,6 +92,14 @@ endif()
enable_language(C ASM) enable_language(C ASM)
# Require C11/C++11 and disable extensions for all targets
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
function (die msg) function (die msg)
if (NOT WIN32) if (NOT WIN32)
string(ASCII 27 Esc) string(ASCII 27 Esc)
@ -560,7 +568,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
endif () endif ()
if (APPLE AND NOT IOS) if (APPLE AND NOT IOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
if (NOT OPENSSL_ROOT_DIR) if (NOT OPENSSL_ROOT_DIR)
EXECUTE_PROCESS(COMMAND brew --prefix openssl EXECUTE_PROCESS(COMMAND brew --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR OUTPUT_VARIABLE OPENSSL_ROOT_DIR
@ -608,8 +616,6 @@ if (NOT (MSVC OR ARCH))
set_default_arch() set_default_arch()
endif() endif()
CHECK_C_COMPILER_FLAG(-std=c11 HAVE_C11)
option(COVERAGE "Enable profiling for test coverage report" OFF) option(COVERAGE "Enable profiling for test coverage report" OFF)
if(COVERAGE) if(COVERAGE)
message(STATUS "Building with profiling for test coverage report") message(STATUS "Building with profiling for test coverage report")
@ -782,14 +788,14 @@ else()
endif() endif()
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes") set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes")
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers") set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test-static-assert.c" COMPILE_DEFINITIONS "-std=c11") try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test-static-assert.c" CMAKE_FLAGS -DCMAKE_CXX_STANDARD=11)
if(STATIC_ASSERT_RES) if(STATIC_ASSERT_RES)
set(STATIC_ASSERT_FLAG "") set(STATIC_ASSERT_FLAG "")
else() else()
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert") set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
endif() endif()
try_compile(STATIC_ASSERT_CPP_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test-static-assert.cpp" COMPILE_DEFINITIONS "-std=c++11") try_compile(STATIC_ASSERT_CPP_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test-static-assert.cpp" CMAKE_FLAGS -DCMAKE_CXX_STANDARD=11)
if(STATIC_ASSERT_CPP_RES) if(STATIC_ASSERT_CPP_RES)
set(STATIC_ASSERT_CPP_FLAG "") set(STATIC_ASSERT_CPP_FLAG "")
else() else()
@ -885,8 +891,8 @@ else()
message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}") message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}")
message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}") message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${PIC_FLAG} ${C_SECURITY_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${PIC_FLAG} ${C_SECURITY_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${PIC_FLAG} ${CXX_SECURITY_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${PIC_FLAG} ${CXX_SECURITY_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS} ${LD_BACKCOMPAT_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS} ${LD_BACKCOMPAT_FLAGS}")
# With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that # With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that

View File

@ -47,9 +47,7 @@ if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW)))
monero_add_library(epee_readline readline_buffer.cpp) monero_add_library(epee_readline readline_buffer.cpp)
endif() endif()
if(HAVE_C11) set_property(SOURCE memwipe.c PROPERTY C_STANDARD 11)
SET_PROPERTY(SOURCE memwipe.c PROPERTY COMPILE_FLAGS -std=c11)
endif()
# Build and install libepee if we're building for GUI # Build and install libepee if we're building for GUI
if (BUILD_GUI_DEPS) if (BUILD_GUI_DEPS)

View File

@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(Boost_USE_MULTITHREADED ON) set(Boost_USE_MULTITHREADED ON)
include_directories(.) include_directories(.)
@ -14,8 +21,8 @@ IF (MSVC)
include_directories(SYSTEM platform/msvc) include_directories(SYSTEM platform/msvc)
ELSE() ELSE()
# set stuff for other systems # set stuff for other systems
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-reorder") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-reorder")
ENDIF() ENDIF()

View File

@ -30,7 +30,10 @@ cmake_minimum_required(VERSION 3.5)
project(easylogging CXX) project(easylogging CXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
monero_enable_coverage() monero_enable_coverage()
find_package(Threads) find_package(Threads)