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

* use normal right extension on clang, only gnu for gcc
* related to minenux/minetest-engine-minetest#18
* use c++11 but with gnu xtensions
* related to minenux/minetest-engine-minetest#14
* complete fix for 4ef3bc602f and set C++11/C++0X depends on compiler
* final set continuation of commit 83a552ed1a
* fix cmake if-else misctakes error sintax
* backported from 6a757711fbaa1b6c845dc6bf50ed7260d999cec9
This commit is contained in:
mckaygerhard 2023-01-05 13:47:42 -04:00
parent 2ba4f559aa
commit e3d46356c0
3 changed files with 15 additions and 14 deletions

View File

@ -12,16 +12,16 @@ set(PROJECT_NAME_CAPITALIZED "Minetest")
# 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)
@ -33,10 +33,10 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
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)
@ -44,6 +44,7 @@ else()
endif ()
endif ()
endif()
message(STATUS "using default flags installed compiler without any c++ flags specified")
endif()
# Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing

View File

@ -66,11 +66,11 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_CFLAGS}")
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")
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()
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")
@ -88,7 +88,7 @@ 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
if(APPLE)

View File

@ -744,11 +744,11 @@ else()
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")
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()
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")