From 91f65f127b74ba7957c80e5f2d31f48f910dfdbc Mon Sep 17 00:00:00 2001 From: maier Date: Thu, 13 Sep 2012 09:59:30 +0000 Subject: [PATCH] Add a comment git-svn-id: https://svn.dealii.org/branches/branch_cmake@26343 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/CMakeLists.txt | 40 ++++++----- .../cmake/configure/configure_build.cmake | 69 +++++++++++++++++-- 2 files changed, 88 insertions(+), 21 deletions(-) diff --git a/deal.II/CMakeLists.txt b/deal.II/CMakeLists.txt index 805dc8f346..3271176ba6 100644 --- a/deal.II/CMakeLists.txt +++ b/deal.II/CMakeLists.txt @@ -44,8 +44,21 @@ SET(VERSION "8.0.pre") # We support the "Debug" and "Release" build types. Default is the # "Release" target. # -# TODO: Explanation +# Debug will enable a lot of debug code paths and Assertions, as well as +# compiling the library with a suitable set of debug compiler flags. # +# Release will chose a suitable set of optimizing flags. +# +# The default CXXFLAGS (and CFLAGS) are stored in the following cached +# variables (as is common practise for cmake): +# +# CMAKE_CXX_FLAGS - used during all builds +# CMAKE_CXX_FLAGS_DEBUG - additional flags used during debug builds +# CMAKE_CXX_FLAGS_RELEASE - additional flags used during release builds +# +# (same for CMAKE_C_...) +# + # # General configuration options: @@ -135,19 +148,18 @@ SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/contrib/cmake/modules/" ) -# We have to initialize this cached variable before PROJECT is called: -IF(CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING - "Choose the type of build, options are: Debug Release.") -ELSE() - SET(CMAKE_BUILD_TYPE Release CACHE STRING - "Choose the type of build, options are: Debug Release.") -ENDIF() +# +# We have to initialize some cached variable before PROJECT is called, so +# configure the cached, user editable CMAKE_BUILD_TYPES, CMAKE_CXX_FLAGS, +# etc. variables at this point: +# +INCLUDE(configure_build) +# +# Now, set the project: +# PROJECT(deal.II) - - # # Set up deal.II specific variables # @@ -176,12 +188,6 @@ ADD_CUSTOM_TARGET(deal_ii_target_dependencies) SET(deal_ii_external_libraries "") SET(deal_ii_required_linker_flags "") -# -# Configuration for CMAKE_BUILD_TYPES (CFLAGS, CXXFLAGS, ..) -# - -INCLUDE(configure_build) - # # Platform checks: # diff --git a/deal.II/contrib/cmake/configure/configure_build.cmake b/deal.II/contrib/cmake/configure/configure_build.cmake index 3d0847795d..67f1047b6a 100644 --- a/deal.II/contrib/cmake/configure/configure_build.cmake +++ b/deal.II/contrib/cmake/configure/configure_build.cmake @@ -1,11 +1,72 @@ # -# Setup the build type and compiler flags +# FAT NOTE: # +# We set up the default compiler configuration, i.e. CMAKE_BUILD_TYPE, +# CMAKE_C_FLAGS, CMAKE_CXX_FLAGS as CACHED variables, so that the user can +# actually see and change them. +# +# Beware of the fact that compiler flags set later in the configuration via +# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} <...>" are UNCACHED variables. +# +# cmake later concatenates cached and uncached variables together. So for a +# release build we will end up with (more or less) something like the +# following: +# +# $ \ +# \ +# <...> <...>.c -o <...>.o +# + + +# +# Setup CMAKE_BUILD_TYPE: +# + +SET(CMAKE_BUILD_TYPE + "Release" + CACHE STRING + "Choose the type of build, options are: Debug Release.") + +IF( NOT CMAKE_BUILD_TYPE MATCHES "Release" AND + NOT CMAKE_BUILD_TYPE MATCHES "Debug" ) + + MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE does neither match Release, nor Debug.") + +ENDIF() + + +# +# Setup default compiler flags: +# + +# TODO: Copy the CFLAGS and CXXFLAGS logic from the former build system + +SET(CMAKE_C_FLAGS + "-Wfatal-errors -D_REENTRANT -fPIC -O2 -march=native" + CACHE STRING + "Flags used by the compiler during all build types.") +SET(CMAKE_CXX_FLAGS + "-Wfatal-errors -D_REENTRANT -fPIC -O2 -march=native" + CACHE STRING + "Flags used by the compiler during all build types.") -#TODO: +SET(CMAKE_C_FLAGS_RELEASE + "-O2" + CACHE STRING + "Flags used by the compiler during all release builds.") +SET(CMAKE_CXX_FLAGS_RELEASE + "-O2" + CACHE STRING + "Flags used by the compiler during all release builds.") -SET(CMAKE_CXX_FLAGS "-Wfatal-errors -D_REENTRANT -fPIC -O2 -march=native") -SET(CMAKE_C_FLAGS "-Wfatal-errors -D_REENTRANT -fPIC -O2 -march=native") +SET(CMAKE_C_FLAGS_DEBUG + "-O0 -ggdb -DDEBUG" + CACHE STRING + "Flags used by the compiler during all debug builds.") +SET(CMAKE_CXX_FLAGS_DEBUG + "-O0 -ggdb -DDEBUG" + CACHE STRING + "Flags used by the compiler during all debug builds.") -- 2.39.5