]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Include target definitions if the compiler is set up
authorMatthias Maier <tamiko@43-1.org>
Fri, 2 Dec 2022 20:50:56 +0000 (14:50 -0600)
committerMatthias Maier <tamiko@43-1.org>
Fri, 17 Mar 2023 12:44:53 +0000 (07:44 -0500)
cmake/config/Config.cmake.in

index d5f1dac5641dc5514d532ab0b1fd61f7d73c0bc3..6686b02b65c534ff5847932dfec2b2367a658b65 100644 (file)
@@ -140,9 +140,40 @@ set(DEAL_II_MPIEXEC_POSTFLAGS "@MPIEXEC_POSTFLAGS@")
 # Information about library targets and feature configuration
 #
 
-# The library targets file:
 set(DEAL_II_TARGET_CONFIG "${DEAL_II_PATH}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake")
 
+#
+# We support a rather nonstandard situation where the find_package(deal.II)
+# call happens before proper setup of a toolchain via project(). The
+# reasoning behind this was to properly initialize the compiler in user
+# projects via the deal_ii_initialize_cached_variables():
+#
+#   find_package(deal.II)
+#   deal_ii_initialize_cached_variables()
+#   project(...)
+#   ...
+#   deal_ii_setup_target(...)
+#
+# This requires that the deal_ii_setup_target() loads the target
+# configuration because this has to happen after the call to project().
+#
+# Unfortunately _not_ automatically including all target definitions is
+# non-standard behavior and rather surprising. Therefore, in order to
+# support the modern way of searching for a dependency and using it:
+#
+#   project(...)
+#   find_package(deal.II)
+#   ...
+#   target_link_libraries(... dealii::dealii_[debug|release])
+#
+# we check whether project(... [CXX]) has been called prior to
+# find_package(deal.II) and if yes simply include our target configuration:
+#
+if(DEFINED CMAKE_CXX_COMPILER_ABI)
+  include(${DEAL_II_TARGET_CONFIG})
+  set(DEAL_II_TARGET_CONFIG_INCLUDED TRUE)
+endif()
+
 # The Debug target:
 set(DEAL_II_TARGET_DEBUG "@CONFIG_TARGET_DEBUG@")
 

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.