Commit bc0630f9 authored by GILLES Sebastien's avatar GILLES Sebastien

#1217 CMake: minor improvements; in peculiar the trick found on the Web...

#1217 CMake: minor improvements; in peculiar the trick found on the Web concerning default CMAKE_BUILD_TYPE didn't work correctly; replaced it by another one which seems to fare better.
parent bf4473af
# A minimum version for cmake command is required.
cmake_minimum_required(VERSION 3.8)
# TODO Add check whether the provided value is valid.
# ===================================================================================================================
# Include a file with default setting. Some of them might be overriden by command line, such as the C or C++ compiler.
# ===================================================================================================================
if(NOT SETTINGS_FILE)
message(FATAL_ERROR "-DSETTINGS_FILE must be present in the command line and point to a file that specify the paths and settings to use in the build. A default one is defined in cmake/Paths.cmake; feel free to copy and adapt it to your needs.")
message(FATAL_ERROR "-DSETTINGS_FILE must be present in the command line and point to a file that specify the paths and settings to use in the build. Examples are given in cmake/Settings folder; feel free to copy and adapt them to your needs.")
endif()
include(${SETTINGS_FILE})
......@@ -35,20 +34,18 @@ endif()
# WARNING: all those calls must occur BEFORE the call to project, so that overriding remains possible.
# ===================================================================================================================
# From https://cmake.org/pipermail/cmake/2008-September/023808.html
# Ensure if the user doesn't specify arenything in command line debug is chosen (CMake default is no optimization and no debug symbol, which is rather useless).
if(DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of
build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug
Release RelWithDebInfo MinSizeRel.")
else()
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build,
options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
RelWithDebInfo MinSizeRel.")
# From http://cmake.3232098.n2.nabble.com/Default-value-for-CMAKE-BUILD-TYPE-td7550756.html#a7550797
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
set(MOREFEM_INSTALL_DIR ${MOREFEM_INSTALL_DIR}/${CMAKE_BUILD_TYPE})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake)
# Set C and CXX compilers from the values read in the setting file. Might be overridden in command line.
if (NOT DEFINED CMAKE_C_COMPILER)
......@@ -69,9 +66,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF) # I want c++17, not gnu++17.
include(cmake/CustomCommands.cmake)
include(CustomCommands)
# All --all_load in target_link_libraries of executables if STATIC library are chose.
......@@ -83,7 +80,7 @@ endif()
MESSAGE("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
include(cmake/Compiler.cmake)
include(Compiler)
# Add LTO support in non debug mode.
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
......
......@@ -15,6 +15,8 @@ if(${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang" OR ${CMAKE_C_COMPILER_ID} STREQU
add_cxx_compiler_flag("-stdlib=libc++")
message("BUILD TYPE" ${CMAKE_BUILD_TYPE})
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_definitions(-D_LIBCPP_DEBUG2=0) # Additional checks such as index out of bounds in vectors in libc++; might
# be removed at any point from libc++.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment