Issues about Fedora packaging of libheinz library
@c.trageser @j.wuttke When I try make RPM packaging of libheinz for Fedora Linux, I applied a patch to CMake files, which it will use GNUInstallDirs
to facilitate the installation of the library. Can you see the patch? If it is ok, you can apply it to the source code of libheinz, since I cannot make a PR on the repository. Thanks.
The patch do the following things:
- use
GNUInstallDirs
to facilitate the installation of the library [1, 2] - use
ARCH_INDEPENDENT
for header-only library when CMake >= 3.14 [3] - create the INTERFACE library since the library is header-only [4]
Ref:
- [1] https://cmake.org/cmake/help/latest/command/install.html
- [2] https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
- [3] https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#generating-a-package-version-file
- [4] https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries
The similar work also did in other header-only library like Guidelines Support Library (GSL), cxxopts. [5, 6]
- [5] https://github.com/microsoft/GSL/blob/main/CMakeLists.txt
- [6] https://github.com/jarro2783/cxxopts/blob/master/CMakeLists.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0eca7a1..96f392d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,10 +30,14 @@ if(WERROR)
add_compile_options(-Werror)
endif()
+include(GNUInstallDirs)
+
## Subdirectories.
include(CTest)
+add_library(heinz INTERFACE)
+add_library(heinz::heinz ALIAS heinz)
add_subdirectory(inc)
add_subdirectory(test)
@@ -49,21 +53,36 @@ include(CMakePackageConfigHelpers)
export(PACKAGE LibHeinz)
## Config files.
+set(targets_export_name LibHeinzTargets)
+
+if(${CMAKE_VERSION} VERSION_GREATER "3.14")
+ set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
+endif()
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/LibHeinzConfig.cmake"
- INSTALL_DESTINATION "lib/cmake/example"
- NO_SET_AND_CHECK_MACRO
- NO_CHECK_REQUIRED_COMPONENTS_MACRO
+ INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/LibHeinz"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/LibHeinzConfigVersion.cmake"
VERSION "${LibHeinz_VERSION}"
COMPATIBILITY AnyNewerVersion
+ ${OPTIONAL_ARCH_INDEPENDENT}
)
install(FILES
"${PROJECT_BINARY_DIR}/LibHeinzConfig.cmake"
"${PROJECT_BINARY_DIR}/LibHeinzConfigVersion.cmake"
- DESTINATION cmake COMPONENT dev)
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/LibHeinz
+ COMPONENT dev)
+
+install(EXPORT ${targets_export_name}
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/LibHeinz
+ FILE ${targets_export_name}.cmake
+ NAMESPACE heinz::
+)
+
+install(TARGETS heinz
+ EXPORT ${targets_export_name}
+)
diff --git a/Config.cmake.in b/Config.cmake.in
index 5588d04..9ea9cbc 100644
--- a/Config.cmake.in
+++ b/Config.cmake.in
@@ -1,5 +1,9 @@
# Config file for the LibHeinz package
@PACKAGE_INIT@
+if(TARGET heinz::heinz)
+ include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake)
+endif()
set(LibHeinz_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include")
+check_required_components(LibHeinz)
diff --git a/inc/CMakeLists.txt b/inc/CMakeLists.txt
index ff3e1f0..7843258 100644
--- a/inc/CMakeLists.txt
+++ b/inc/CMakeLists.txt
@@ -2,5 +2,5 @@ set(api_files heinz/Complex.h heinz/Vectors3D.h heinz/Rotations3D.h)
install(
FILES ${api_files}
- DESTINATION include/heinz
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/heinz
COMPONENT Headers)
There is another issue when the reviewer see my package review of libheinz, he suggested that the libheinz upstream project here could give more detailed descriptions about the library, which can be used in description field of the .spec file during the Fedora packaging. [7]