fix flags: complete fix for 4ef3bc602f and set C++11/C++0X depends on compiler

* property fix backported commit 582ee14446d4b56f18587994c08bc0638494d87e
* added missing flac for standar 11 in CC not only in C++
* property set flags due C++11 now is need in all the code
* also its need due commit a4cd5f8e48 and 8507e651eb optimizations
* almost the last changes need c++11 standard, this is c++0x in olders
* build in jsoncpp need it to compile
This commit is contained in:
Герхард PICCORO Lenz McKAY 2021-11-30 12:21:34 -04:00
parent 1783ccf348
commit 83a552ed1a
3 changed files with 107 additions and 30 deletions

View File

@ -5,15 +5,42 @@ if(${CMAKE_VERSION} STREQUAL "2.8.2")
message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!")
endif()
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "--std=gnu++0x ${CMAKE_C_FLAGS}")
endif ()
else ()
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
endif ()
# determine compiler compatible and set flags, assume if C++ is installed also CC is installed
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99")
elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c1x")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c11")
endif()
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
endif()
else()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.1")
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
else
if(APPLE)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
endif ()
endif()
endif()
# This can be read from ${PROJECT_NAME} after project() is called
project(minetest)

View File

@ -63,15 +63,43 @@ endif(LUA_ANSI)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_CFLAGS}")
# Standard flags to use for each build type.
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic -std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -O1 -g")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2 -g")
endif(CMAKE_COMPILER_IS_GNUCC)
# determine compiler compatible and set flags, assume if C++ is installed also CC is installed
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic")
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99")
elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c1x")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c11")
endif()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS} ")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS} -g")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} ${CMAKE_C_FLAGS} -O1 -g")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} ${CMAKE_C_FLAGS} -g")
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
endif()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS} ")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS} -g")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} ${CMAKE_C_FLAGS} -O1 -g")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} ${CMAKE_C_FLAGS} -g")
else()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.1")
set(CMAKE_C_STANDARD 11)
else
if(APPLE)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
endif ()
endif()
endif()
add_subdirectory(src build)

View File

@ -741,22 +741,44 @@ if(MSVC)
# /MT = Link statically with standard library stuff
set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT")
else()
# Probably GCC
if (CMAKE_VERSION VERSION_LESS "2.8.10")
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
# determine compiler compatible and set flags, assume if C++ is installed also CC is installed
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
set (CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
else ()
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99")
elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c1x")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c11")
endif()
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
endif()
else()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.1")
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else
if(APPLE)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
endif ()
endif()
endif ()
endif()
if(WARN_ALL)
set(RELEASE_WARNING_FLAGS "-Wall")
else()
@ -799,12 +821,12 @@ else()
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops")
if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS} -Os")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ffast-math -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS} -O3 -ffast-math -fomit-frame-pointer")
endif(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)")
set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}")
set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS} ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS} ${CMAKE_CXX_FLAGS}")
if(USE_GPROF)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")