Browse Source

Check compiler options.

ObjPtr
Michael Uleysky 9 years ago
parent
commit
186017f05c
  1. 39
      CMakeLists.txt

39
CMakeLists.txt

@ -16,13 +16,48 @@ endif()
project(gmt_makemap CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/" CACHE INTERNAL "Location of our custom CMake modules." FORCE)
include_directories(include)
set(default_options -std=gnu++11 -flto -fvisibility=hidden -Wl,--export-dynamic -Wall)
# Checking compiler options
set(default_options -Wall)
include(CheckCXXCompilerFlag)
# C++11 is required
CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG(-std=c++0x COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(default_options ${default_options} -std=c++11)
elseif(COMPILER_SUPPORTS_CXX0X)
set(default_options ${default_options} -std=c++0x)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# Link time optimization check
CHECK_CXX_COMPILER_FLAG(-flto COMPILER_SUPPORTS_FLTO)
if(COMPILER_SUPPORTS_FLTO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(default_options ${default_options} -flto)
endif()
# -ipo flag check (Intel compiler link time optimization)
CHECK_CXX_COMPILER_FLAG(-ipo COMPILER_SUPPORTS_IPO)
if(COMPILER_SUPPORTS_IPO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(default_options ${default_options} -ipo)
endif()
# Default hidden visibility check
CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden COMPILER_SUPPORTS_HIDDEN)
if(COMPILER_SUPPORTS_HIDDEN)
set(default_options ${default_options} -fvisibility=hidden)
endif()
# Export dynamic. Required as modules mast call functions from main programm
CHECK_CXX_COMPILER_FLAG(-Wl,--export-dynamic COMPILER_SUPPORTS_EXPORTDYNAMIC)
if(COMPILER_SUPPORTS_EXPORTDYNAMIC)
set(default_options ${default_options} -Wl,--export-dynamic)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no support of --export-dynamic. Please use a different C++ compiler.")
endif()
add_compile_options(${default_options})
file(GLOB modules modules/*)

Loading…
Cancel
Save