From 83208c9127aa48e98014434f303cb6ca08a88b58 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 26 Mar 2015 16:42:03 +0100 Subject: [PATCH] CMake: Add "DEBUG|RELEASE" parameter to DEAL_II_SETUP_TARGET It is now possible to force compilation and linkage against a specific flavor of deal.II by using "DEBUG" or "RELEASE" as keywords, e.g., DEAL_II_SETUP_TARGET(target DEBUG) --- cmake/macros/macro_deal_ii_add_test.cmake | 26 ++++---- cmake/macros/macro_deal_ii_setup_target.cmake | 66 +++++++++---------- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/cmake/macros/macro_deal_ii_add_test.cmake b/cmake/macros/macro_deal_ii_add_test.cmake index 8862908f46..c2df104830 100644 --- a/cmake/macros/macro_deal_ii_add_test.cmake +++ b/cmake/macros/macro_deal_ii_add_test.cmake @@ -27,7 +27,7 @@ # # # Usage: -# DEAL_II_ADD_TEST(category test_name comparison_file [ARGN]) +# DEAL_II_ADD_TEST(category test_name comparison_file) # # This macro assumes that a source file "./tests/category/.cc" # as well as the comparison file "" is available in the @@ -102,6 +102,10 @@ MACRO(DEAL_II_ADD_TEST _category _test_name _comparison_file) STRING(TOUPPER ${_expect} _expect) ENDIF() + # + # Determine for which build types a test should be defined: + # + FOREACH(_build ${DEAL_II_BUILD_TYPES}) @@ -152,25 +156,19 @@ MACRO(DEAL_II_ADD_TEST _category _test_name _comparison_file) COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc ) - ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL ${_test_name}.cc + ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL + ${_test_name}.cc ${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc ) + DEAL_II_SETUP_TARGET(${_target} ${_build}) + TARGET_LINK_LIBRARIES(${_target} + ${TARGET_LIBRARIES} ${TARGET_LIBRARIES_${_build}} + ) SET_TARGET_PROPERTIES(${_target} PROPERTIES - LINK_FLAGS "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}" - COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS};${DEAL_II_USER_DEFINITIONS_${_build}}" - COMPILE_FLAGS "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" - LINKER_LANGUAGE "CXX" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ) - SET_PROPERTY(TARGET ${_target} APPEND PROPERTY - INCLUDE_DIRECTORIES "${DEAL_II_INCLUDE_DIRS}" - ) - SET_PROPERTY(TARGET ${_target} APPEND PROPERTY - COMPILE_DEFINITIONS - SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" - ) - TARGET_LINK_LIBRARIES(${_target} ${DEAL_II_TARGET_${_build}}) + ENDIF() # diff --git a/cmake/macros/macro_deal_ii_setup_target.cmake b/cmake/macros/macro_deal_ii_setup_target.cmake index 7dc10d8bf5..65b8dab69d 100644 --- a/cmake/macros/macro_deal_ii_setup_target.cmake +++ b/cmake/macros/macro_deal_ii_setup_target.cmake @@ -1,6 +1,6 @@ ## --------------------------------------------------------------------- ## -## Copyright (C) 2012 - 2014 by the deal.II authors +## Copyright (C) 2012 - 2015 by the deal.II authors ## ## This file is part of the deal.II library. ## @@ -19,12 +19,19 @@ # # Usage: # DEAL_II_SETUP_TARGET(target) +# DEAL_II_SETUP_TARGET(target DEBUG|RELEASE) # # This appends necessary include directories, linker flags, compile # definitions and the deal.II library link interface to the given target. # -# The current CMAKE_BUILD_TYPE is respected by setting the appropriate -# debug or release variants (if available). +# If no "DEBUG" or "RELEASE" keyword is specified after the target, the +# current CMAKE_BUILD_TYPE determines which compiler and linker flags as +# well as compile definitions to use and against which deal.II library it +# should be linked against. +# +# If the requested build type is not availabe (e.g. DEBUG request but +# deal.II was compiled with release mode only), the other available will be +# used instead. # MACRO(DEAL_II_SETUP_TARGET _target) @@ -62,46 +69,29 @@ MACRO(DEAL_II_SETUP_TARGET _target) # # Append build type dependent flags and definitions. # - - # - # For this we obey the behaviour of the "optimized" and "debug" - # keywords and this is a bit tricky: + # Every build type that (case insensitively) matches "debug" is + # considered a debug build: # - # If the global property DEBUG_CONFIGURATIONS is set all build types that - # (case insensitively) match one of the listed build types is considered - # a "debug" build. The rest is "optimized". + SET(_on_debug_build FALSE) + STRING(TOLOWER "${CMAKE_BUILD_TYPE}" _cmake_build_type) + IF("${_cmake_build_type}" MATCHES "debug") + SET(_on_debug_build TRUE) + ENDIF() + # - # Otherwise every build type that (case insensitively) matches "debug" is - # considered a debug build. + # Override _on_debug_build if ${ARGN} is set: # - GET_PROPERTY(_debug_configurations_set - GLOBAL PROPERTY DEBUG_CONFIGURATIONS SET - ) - IF(_debug_configurations_set) - STRING(TOLOWER "${CMAKE_BUILD_TYPE}" _cmake_build_type) - GET_PROPERTY(_debug_configurations - GLOBAL PROPERTY DEBUG_CONFIGURATIONS - ) - FOREACH(_debug_type ${_debug_configurations}) - STRING(TOLOWER "${_debug_type}" _debug_type) - IF("${_cmake_build_type}" STREQUAL "${_debug_type}") - SET(_on_debug_build TRUE) - BREAK() - ENDIF() - ENDFOREACH() - ELSE() - STRING(TOLOWER "${CMAKE_BUILD_TYPE}" _cmake_build_type) - IF("${_cmake_build_type}" STREQUAL "debug") - SET(_on_debug_build TRUE) - ENDIF() + IF("${ARGN}" MATCHES "^DEBUG$") + SET(_on_debug_build TRUE) + ELSEIF ("${ARGN}" MATCHES "^RELEASE$") + SET(_on_debug_build FALSE) ENDIF() # # We can only append DEBUG link flags and compile definitions if deal.II - # was build with Debug or DebugRelease build type. So test for this: + # was built with the Debug or DebugRelease build type. So test for this: # - IF( _on_debug_build - AND DEAL_II_BUILD_TYPE MATCHES "Debug" ) + IF(_on_debug_build AND DEAL_II_BUILD_TYPE MATCHES "Debug") SET_PROPERTY(TARGET ${_target} APPEND_STRING PROPERTY LINK_FLAGS " ${DEAL_II_LINKER_FLAGS_DEBUG}" ) @@ -122,7 +112,11 @@ MACRO(DEAL_II_SETUP_TARGET _target) # GET_PROPERTY(_type TARGET ${_target} PROPERTY TYPE) IF(NOT "${_type}" STREQUAL "OBJECT_LIBRARY") - TARGET_LINK_LIBRARIES(${_target} ${DEAL_II_TARGET}) + IF(_on_debug_build AND DEAL_II_BUILD_TYPE MATCHES "Debug") + TARGET_LINK_LIBRARIES(${_target} ${DEAL_II_TARGET_DEBUG}) + ELSE() + TARGET_LINK_LIBRARIES(${_target} ${DEAL_II_TARGET_RELEASE}) + ENDIF() ENDIF() # -- 2.39.5