]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Add "DEBUG|RELEASE" parameter to DEAL_II_SETUP_TARGET
authorMatthias Maier <tamiko@43-1.org>
Thu, 26 Mar 2015 15:42:03 +0000 (16:42 +0100)
committerMatthias Maier <tamiko@43-1.org>
Thu, 26 Mar 2015 17:22:37 +0000 (18:22 +0100)
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
cmake/macros/macro_deal_ii_setup_target.cmake

index 8862908f464610cb5de487b1ed7717754c15d99f..c2df1048303ec7859892f3ac588dc554b2c3e5a2 100644 (file)
@@ -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/<test_name>.cc"
 # as well as the comparison file "<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()
 
       #
index 7dc10d8bf549d6e95ce7dfa0d5020523d50acb66..65b8dab69d59a6c5c722340c813745dfcf855a3e 100644 (file)
@@ -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.
 ##
 #
 # 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()
 
   #

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.