CMake: let CMake set the needed flags for C and C++ standards

Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
This commit is contained in:
Rolf Eike Beer 2019-03-10 10:59:23 +01:00 committed by Dirk Hohndel
parent 8e43d2b8d2
commit d0acee4083
2 changed files with 16 additions and 16 deletions

View file

@ -4,7 +4,7 @@
# set(CMAKE_VERBOSE_MAKEFILE ON) # set(CMAKE_VERBOSE_MAKEFILE ON)
project(Subsurface) project(Subsurface)
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 3.1)
# don't process generated files - this is new in 3.10 # don't process generated files - this is new in 3.10
if (POLICY CMP0071) if (POLICY CMP0071)
@ -65,27 +65,25 @@ endif()
set(SUBSURFACE_SOURCE ${CMAKE_SOURCE_DIR}) set(SUBSURFACE_SOURCE ${CMAKE_SOURCE_DIR})
add_definitions(-DSUBSURFACE_SOURCE="${SUBSURFACE_SOURCE}") add_definitions(-DSUBSURFACE_SOURCE="${SUBSURFACE_SOURCE}")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# #
# TODO: This Compilation part should go on the Target specific CMake. # TODO: This Compilation part should go on the Target specific CMake.
# #
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
if ((CMAKE_SYSTEM_NAME MATCHES "Darwin") AND if ((CMAKE_SYSTEM_NAME MATCHES "Darwin") AND
((CMAKE_SYSTEM_VERSION MATCHES "11.4.") OR ((CMAKE_SYSTEM_VERSION MATCHES "11.4.") OR
(CMAKE_OSX_DEPLOYMENT_TARGET MATCHES "10.7") OR (CMAKE_OSX_DEPLOYMENT_TARGET MATCHES "10.7") OR
(CMAKE_OSX_DEPLOYMENT_TARGET MATCHES "10.8"))) (CMAKE_OSX_DEPLOYMENT_TARGET MATCHES "10.8")))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif() endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-inconsistent-missing-override")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Warn about possible float conversion errors # Warn about possible float conversion errors
# Use NOT VERSION_LESS since VERSION_GREATER_EQUAL is not available # Use NOT VERSION_LESS since VERSION_GREATER_EQUAL is not available
# in currently used cmake version. # in currently used cmake version.
@ -95,9 +93,7 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif() endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# works only for CMake 3.1 and later # using Intel C++
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# using Visual Studio C++ # using Visual Studio C++
endif() endif()

View file

@ -1,7 +1,7 @@
# Modified from Subsurface's CMakeLists.txt # Modified from Subsurface's CMakeLists.txt
project(smtk2ssrf) project(smtk2ssrf)
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 3.1)
option(COMMANDLINE "Build command line version" OFF) option(COMMANDLINE "Build command line version" OFF)
@ -9,6 +9,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE)
set(SSRF_PATH ../) set(SSRF_PATH ../)
set(CMAKE_MODULE_PATH ${SSRF_PATH}cmake/Modules) set(CMAKE_MODULE_PATH ${SSRF_PATH}cmake/Modules)
include(${CMAKE_MODULE_PATH}/MacroOutOfSourceBuild.cmake) include(${CMAKE_MODULE_PATH}/MacroOutOfSourceBuild.cmake)
@ -82,8 +83,11 @@ else()
endif() endif()
# Set compiler flags and definitions # Set compiler flags and definitions
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC") set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(SMTK_LINK_LIBRARIES ${SMTK_LINK_LIBRARIES} -lssh2 -lz -lpthread) set(SMTK_LINK_LIBRARIES ${SMTK_LINK_LIBRARIES} -lssh2 -lz -lpthread)