Install cmake config of header-only module in /usr/lib/cmake
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Fri, 22 Nov 2024 14:28:16 +0000 (15:28 +0100)
committerMarkus Blatt <markus@dr-blatt.de>
Fri, 22 Nov 2024 14:28:16 +0000 (15:28 +0100)
Needed to make it work in multiarch settings.
Author: Markus Blatt
Gbp-Pq: Name install-cmake-config-to-lib-headerless

cmake/modules/DuneAddLibrary.cmake
cmake/modules/DuneProject.cmake

index 9342c62cf84e582ffe29e73e247306f27f466607..744066bab66d24079478c6fe1ef5f3e79aea3283 100644 (file)
@@ -135,7 +135,6 @@ Add a library to a Dune module.
 #]=======================================================================]
 include_guard(GLOBAL)
 
-
 # Public interface for creating a module library
 function(dune_add_library _name)
   cmake_parse_arguments(ARG "OBJECT;INTERFACE" "" "" ${ARGN})
@@ -210,6 +209,8 @@ function(dune_add_library_normal _name)
       set(ARG_NAMESPACE Dune::)
     endif()
 
+    set_property(GLOBAL PROPERTY ${PROJECT_NAME}_HAS_LIB ON)
+
     set(alias ${ARG_NAMESPACE}${ARG_EXPORT_NAME})
     if(NOT TARGET ${alias})
       add_library(${alias} ALIAS ${_name})
index 635dc4c47a8f04d4efb4dc0c692864d40a0f3602..63d870a45c94790ed2b325a0a1f521d82ba3a72d 100644 (file)
@@ -343,7 +343,15 @@ endif()")
   if(DEFINED DUNE_INSTALL_LIBDIR)
     message(DEPRECATION "DUNE_INSTALL_LIBDIR is deprecated, use CMAKE_INSTALL_LIBDIR instead")
   else()
-    set(DUNE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
+    # Determine whether this module is header-only
+    # In the case the property is not defined
+    get_property(_has_lib GLOBAL PROPERTY ${PROJECT_NAME}_HAS_LIB SET)
+
+    if(_has_lib)
+      set(DUNE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
+    else()
+      set(DUNE_INSTALL_LIBDIR ${DUNE_INSTALL_NONOBJECTLIBDIR})
+    endif()
   endif()
 
   # Set the location of the doc file source. Needed by custom package configuration
@@ -446,7 +454,7 @@ get_filename_component(_dir \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)
 
     # install library export set
     install(EXPORT ${_export_set}
-      DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ProjectName}
+      DESTINATION ${DUNE_INSTALL_LIBDIR}/cmake/${ProjectName}
       NAMESPACE ${_namespace}
       FILE ${_target_file})