finally got compilinig flags for C++11 using gnu extensions

* related to https://codeberg.org/minenux/minetest-engine/issues/18
* use c++11 but with gnu xtensions
* related to https://codeberg.org/minenux/minetest-engine/issues/14
* complete fix for 4ef3bc602f and set C++11/C++0X depends on compiler
* final set continuation of commit 83a552ed1ac26e9f9d98a98661a6cdb79e7329d2
* fix cmake if-else misctakes error sintax
This commit is contained in:
Герхард PICCORO Lenz McKAY 2021-11-30 14:23:39 -04:00
parent 9cd74b3419
commit 6a757711fb
3 changed files with 36 additions and 34 deletions

View File

@ -5,34 +5,40 @@ if(${CMAKE_VERSION} STREQUAL "2.8.2")
message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!")
endif()
# determine compiler compatible and set flags, assume if C++ is installed also CC is installed
# This can be read from ${PROJECT_NAME} after project() is called
project(minetest)
set(PROJECT_NAME_CAPITALIZED "Minetest4")
# check compatible compileer must be after project definition 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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c1x")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu1x")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c11")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
endif()
message(STATUS "using gnu compiler")
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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
endif()
message(STATUS "using clang compiler")
else()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.1")
if (CMAKE_VERSION VERSION_GREATER 3.0)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
else
else()
if(APPLE)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
@ -40,13 +46,9 @@ else()
endif ()
endif ()
endif()
message(STATUS "using default installed compiler")
endif()
# This can be read from ${PROJECT_NAME} after project() is called
project(minetest)
set(PROJECT_NAME_CAPITALIZED "Minetest4")
# Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
set(VERSION_MAJOR 4)
set(VERSION_MINOR 0)

View File

@ -66,12 +66,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_CFLAGS}")
# 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")
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu99")
elseif(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu1x")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c11")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu11")
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")
@ -81,7 +81,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
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")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
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")
@ -89,9 +89,9 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} ${CMAKE_C_FLAGS} -g")
else()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.1")
if(CMAKE_VERSION VERSION_GREATER 3.0)
set(CMAKE_C_STANDARD 11)
else
else()
if(APPLE)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)

View File

@ -745,31 +745,31 @@ else()
# 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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu99")
elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c1x")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu1x")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c11")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu11")
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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
endif()
else()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.1")
if (CMAKE_VERSION VERSION_GREATER 3.0)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
else
else()
if(APPLE)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)