From 7f1221647e24812cb4cd551c2085d33eab2a2a6f Mon Sep 17 00:00:00 2001
From: Matthias Maier Table of contents
ELSE()
, ENDIF()
,
+ ENDFOREACH()
, etc. statements shall not repeat the
+ corresponding condition in IF()
,
+ FOREACH()
, etc.
+ + + FOREACH(_build ${DEAL_II_BUILD_TYPES}) + # + # Set an appropriate keyword depending on target and build type: + # + IF(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease") + SET(_keyword "general") + ELSE() + IF(_build MATCHES DEBUG) + SET(_keyword "debug") + ELSE() + SET(_keyword "optimized") + ENDIF() + ENDIF() + ENDFOREACH() ++
+ + LIST(APPEND CONFIG_LIBRARIES + ${_keyword} + ${CONFIG_LIBRARIES_${_build}} + ) + + SET_TARGET_PROPERTIES(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + PROPERTIES + VERSION ${VERSION} + SOVERSION ${VERSION} + LINK_FLAGS "${DEAL_II_SHARED_LINKER_FLAGS_${build}}" + COMPILE_DEFINITIONS "${DEAL_II_DEFINITIONS};${DEAL_II_DEFINITIONS_${build}}" + COMPILE_FLAGS "${DEAL_II_CXX_FLAGS_${build}}" + ) ++ CMake operates almost always with variables in global state. To guard + against accidential overwrite of variables the following naming + conventions must be followed at all times: +
DEAL_II_
.
+ (Global variables defined by CMake are usually prefixed by
+ CMAKE_
.)
+ ./CMakeLists.txt
and ./cmake/setup_*.cmake
+ The very first configuration steps after some initial setup in
+ ./CMakeLists.txt
takes place in some
+ ./cmake/setup_*.cmake
files:
+
setup_cached_variables.cmake
:
+ This sets up all cached variables prior to the call to
+ PROJECT(deal.II)
. For details see the comment at the
+ top. Furthermore, some bookkeeping for compiler and linker flags
+ takes place, see the section
+ about compile flags.
+ setup_deal_ii.cmake
:
+ This file is included immediately after the call to
+ PROJECT(deal.II)
and will set up all magic
+ numbers such as names, definitions, relative and absolute
+ paths used in the build system. Most of the definitions are
+ guarded with the help of the SET_IF_EMPTY
macro so
+ that it is possible to override the values from the command line.
+ setup_compiler_flags.cmake
+ sets up a suitable set of default compile flag for a known
+ compiler by including the appropriate
+ setup_compiler_flags_*.cmake
file. When adding new
+ flags or compiler support, please respect the following note
+ + + # + # (./cmake/setup_compiler_flags.cmake) + # + # #################### + # # FAT NOTE: # + # #################### + # + # All configuration in setup_compiler_flags.cmake and + # setup_compiler_flags_+.cmake shall ONLY modify: + # + # CMAKE_CXX_FLAGS + # DEAL_II_CXX_FLAGS_DEBUG + # DEAL_II_CXX_FLAGS_RELEASE + # CMAKE_SHARED_LINKER_FLAGS + # DEAL_II_SHARED_LINKER_FLAGS_DEBUG + # DEAL_II_SHARED_LINKER_FLAGS_RELEASE + # + # All modifications shall be guarded with the ENABLE_IF_SUPPORTED + # or ENABLE_IF_LINKS macro, e.g. + # + # ENABLE_IF_SUPPORTED(CMAKE_CXX_FLAGS "-fpic") + # ENABLE_IF_LINKS(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") + # + # Compiler flags for platform dependent optimization (such as + # -march=native) must always be guarded with + # DEAL_II_ALLOW_PLATFORM_INTROSPECTION: + # + # IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) + # ENABLE_IF_SUPPORTED(CMAKE_CXX_FLAGS "-march=native") + # ENDIF() + # + # Checks for compiler features (such as C++11 support) and compiler + # specific bugs that + # - usually set up further configuration (such as preprocessor + # definitions) + # - disable a specific flag for a specific compiler version. + # + # belong the corresponding file: + # + # ./cmake/checks/check_01_compiler_features.cmake + # ./cmake/checks/check_01_cpu_features.cmake + # ./cmake/checks/check_01_cxx_features.cmake + # ./cmake/checks/check_01_system_features.cmake + # ./cmake/checks/check_02_compiler_bugs.cmake + # +
./cmake/checks/check_*.cmake
+ The next step in the configuration process is to include all
+ checks residing under ./cmake/checks
. Currently
+ there are:
+
+ + ./cmake/checks/check_01_compiler_features.cmake + - Search for support for compiler dependent features such as stack + trace support, demangler support, etc. + + ./cmake/checks/check_01_cpu_features.cmake + - Platform introspection for CPU features goes here and must be + guarded with DEAL_II_ALLOW_PLATFORM_INTROSPECTION + + ./cmake/checks/check_01_cxx_features.cmake + - Check for supported C++ language features such as sufficient C++11 + support + + ./cmake/checks/check_01_system_features.cmake + - Checks for specific platform (Linux/Darwin/CYGWIN/Windows..) + features and support + + ./cmake/checks/check_02_compiler_bugs.cmake + - Check for compiler bugs ++
HAVE_<..>
, resp.
+ DEAL_II_(HAVE|USE)_<..>
. It is forbidden to
+ use a variable name starting with
+ DEAL_II_WITH_<..>
because this prefix is
+ exclusively reserved for the feature mechanism described
+ below. For some tests it might be necessary to manipulate global variables.
+ + + CHECK_CXX_SOURCE_COMPILES(source variable) + - Checks whether it is possible to compile _and_ link the code snipet + <source>. If succesful, variable is set to 1. + + CHECK_CXX_SOURCE_RUNS(source variable) + - variable is set to 1 if <source> coulde be succesfully compiled and + linked and the resulting program ran and exited without error. + Avoid this macro outside of a DEAL_II_ALLOW_PLATFORM_INTROSPECTION + guard. A sensible fallback should be provided if the check cannot + be run (e.g. when cross compiling). + + CHECK_CXX_COMPILER_BUG(source variable) + - Inverts the logic of CHECK_CXX_SOURCE_COMPILES(), i.e. variable is + set to 1 if it was not possible to compile and link <source>. + + CHECK_INCLUDE_FILE_CXX(header variable) + - Check whether it is possible to compile and link a dummy program + including <header>. + + CHECK_FUNCTION_EXISTS(function variable) + - Check for the existence of a function prototype with name + <function>. (Don't forget to specify the link libraries, see + below.) Use CHECK_CXX_SYMBOL_EXISTS to search for C++ function + definitions instead, if possible. + + CHECK_CXX_SYMBOL_EXISTS(symbol header_file variable) + - Check for the existence of a symbol definition in the header_file + as well as for the presence in the current link interface + (Don't forget to specify the link libraries, see below.) + + CHECK_CXX_COMPILER_FLAG(flag variable) + - Sets the variable to 1 if the compiler understands the flag. ++ +
CMAKE_REQUIRED_FLAGS
. There are two small macros
+ that do this job nicely:
+ + + PUSH_TEST_FLAG("-Werror") + CHECK_CXX_SOURCE_COMPILES(...) + POP_TEST_FLAG() ++ +
CMAKE_REQUIRED_LIBRARIES
. It is best two hard set
+ this variable to a specific value and later on cleaning it,
+ instead of appending/removing:
+ + + SET(CMAKE_REQUIRED_LIBRARIES <a list of libraries> + CHECK_CXX_SOURCE_COMPILES(...) + SET(CMAKE_REQUIRED_LIBRARIES) ++
./include/deal.II/base/config.h.in<
include/deal.II/base/config.h.in
should have a
+ prominent comment explaining it and should be grouped by file
+ exporting the definition
+
- To keep things clean, only the following variables should be
- appended in the platform checks and feature configuration (beside
- setting a lot of DEAL_II_*
definitions...):
+ The following list describes all global variables controlling the
+ build process and the visibility associated with it (internal use for
+ compiling deal.Ii, externally used variables will get exported in
+ deal.IIConfig.cmake). Lists should be manipulated with
+ LIST(APPEND ...)
, flags with ADD_FLAGS(...)
+ (or if it is necessary to guard them with
+ ENABLE_IF_SUPPORTED(...)
.)
- Platform checks reside under cmake/checks
. We currently have
-
- - cmake/check/check_for_compiler_bugs.cmake - cmake/check/check_for_compiler_features.cmake - cmake/check/check_for_cxx_features.cmake -- -
- Some Notes: -
- - CHECK_CXX_SOURCE_COMPILES(source variable) - - Checks whether it is possible to compile _and_ link the code snipet - <source>. If succesful, variable is set to 1. - - CHECK_CXX_SOURCE_RUNS(source variable) - - variable is set to 1 if <source> coulde be succesfully compiled and - linked and the resulting program ran and exited without error. - - CHECK_CXX_COMPILER_BUG(source variable) - - Inverts the logic of CHECK_CXX_SOURCE_COMPILES(), i.e. variable is - set to 1 if it was not possible to compile and link <source>. - - CHECK_INCLUDE_FILE_CXX(header variable) - - Check whether it is possible to compile and link a dummy program - including <header>. - - CHECK_FUNCTION_EXISTS(function variable) - - Check for the existence of a function prototype with name - <function>. (Don't forget to specify the link libraries, see - below.) - - CHECK_CXX_COMPILER_FLAG(flag variable) - - Sets the variable to 1 if the compiler understands the flag. -- -
CMAKE_REQUIRED_FLAGS
. There are two small macros
- that do this job nicely:
- - - PUSH_TEST_FLAG("-Werror") - CHECK_CXX_SOURCE_COMPILES(...) - POP_TEST_FLAG() -- -
CMAKE_REQUIRED_LIBRARIES
. It is best two hard set
- this variable to a specific value and later on cleaning it,
- instead of appending/removing:
- - - SET(CMAKE_REQUIRED_LIBRARIES <a list of libraries> - CHECK_CXX_SOURCE_COMPILES(...) - SET(CMAKE_REQUIRED_LIBRARIES) --
- General notes: -
include/deal.II/base/config.h.in
should have a
- prominent comment explaining it and should be grouped by file
- exporting the definition
- - - $ cmake -C Config.sample <...> -- can be found here. - This sample configuration covers all options mentioned in this - documentation as well as some advanced aspects in feature - configuration. -
-U
together with a globbing
expression. E.g. to remove the current feature configuration and
- rerun the autodetection on can invoke
+ rerun the autodetection one can invoke
cmake -U"DEAL_II_WITH_*" . -- 2.39.5