From ef4a620835b9e63b67f59b895960863b40489eeb Mon Sep 17 00:00:00 2001 From: maier Date: Sun, 10 Mar 2013 09:11:29 +0000 Subject: [PATCH] CMake: Bugfixes in macro_deal_ii_setup_target.cmake git-svn-id: https://svn.dealii.org/trunk@28844 0785d39b-7218-0410-832d-ea1e28bc413d --- .../macros/macro_deal_ii_setup_target.cmake | 94 ++++++++++++++----- 1 file changed, 69 insertions(+), 25 deletions(-) diff --git a/deal.II/cmake/macros/macro_deal_ii_setup_target.cmake b/deal.II/cmake/macros/macro_deal_ii_setup_target.cmake index 21ba75c998..beb31a8bcc 100644 --- a/deal.II/cmake/macros/macro_deal_ii_setup_target.cmake +++ b/deal.II/cmake/macros/macro_deal_ii_setup_target.cmake @@ -1,6 +1,6 @@ ##### ## -## Copyright (C) 2012 by the deal.II authors +## Copyright (C) 2012, 2013 by the deal.II authors ## ## This file is part of the deal.II library. ## @@ -19,9 +19,11 @@ # Usage: # DEAL_II_SETUP_TARGET(target) # -# This sets the necessary include directories, linker flags, compile -# definitions and the deal.II library the target will be linked against. +# 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). # MACRO(DEAL_II_SETUP_TARGET _target) @@ -39,37 +41,79 @@ MACRO(DEAL_II_SETUP_TARGET _target) SET(DEAL_II_TARGET_CONFIG_INCLUDED TRUE) ENDIF() - # Necessary for setting INCLUDE_DIRECTORIES via SET_TARGET_PROPERTIES + # Necessary for setting INCLUDE_DIRECTORIES via SET_PROPERTY CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8) - GET_DIRECTORY_PROPERTY(_inc_dirs_so_far INCLUDE_DIRECTORIES) - SET_TARGET_PROPERTIES(${_target} PROPERTIES - INCLUDE_DIRECTORIES - "${_inc_dirs_so_far};${DEAL_II_INCLUDE_DIRS}" - LINK_FLAGS - "${DEAL_II_LINKER_FLAGS}" - COMPILE_DEFINITIONS - "${DEAL_II_USER_DEFINITIONS}" + # + # Append include directories, and build-type independent linker flags and + # compile definitions + # + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + INCLUDE_DIRECTORIES "${DEAL_II_INCLUDE_DIRS}" + ) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + LINK_FLAGS "${DEAL_II_LINKER_FLAGS}" + ) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS}" ) # - # Set build type dependend flags and definitions: + # Append build type dependend flags and definitions. # - FOREACH(_build ${DEAL_II_BUILD_TYPES}) - SET_TARGET_PROPERTIES(${_target} PROPERTIES - LINK_FLAGS_${_build} - "${DEAL_II_LINKER_FLAGS_${_build}}" - COMPILE_DEFINITIONS_${_build} - "${DEAL_II_USER_DEFINITIONS_${_build}}" - ) - ENDFOREACH() # - # Link against the deal.II targets: + # For this we obey the behaviour of the "optimized" and "debug" + # keywords and this is a bit tricky: # - TARGET_LINK_LIBRARIES(${_target} - ${DEAL_II_TARGET} + # If the global property DEBUG_CONFIGURATIONS is set all build + # types that (case insensitive) match one of the listed build types is + # considered a "debug" build. Ther rest is "optimized". + # + # Otherwise every build type that (case insensitively) matches "debug" is + # considered a debug build. + # + 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() + ENDIF() -ENDMACRO() + IF(_on_debug_build) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + LINK_FLAGS "${DEAL_II_LINKER_FLAGS_DEBUG}" + ) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS_DEBUG}" + ) + ELSE() + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + LINK_FLAGS "${DEAL_II_LINKER_FLAGS_RELEASE}" + ) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS_RELEASE}" + ) + ENDIF() + # + # Set up the link interface: + # + TARGET_LINK_LIBRARIES(${_target} ${DEAL_II_TARGET}) + +ENDMACRO() -- 2.39.5