From dcf3e1a55147defb8cf60bac172b16181ae8f6d5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 7 Mar 2024 20:47:28 -0800 Subject: [PATCH] Fix a number of packaging issues (#423) * cmake: set PROJECT_DESCRIPTION and PROJECT_HOMEPAGE_URL after project() Otherwise they are set to an empty string. * cmake: set the pkg-config URL field Since the information is already there to set it. * cmake: use CMAKE_INSTALL_DATAROOTDIR if CMAKE_LIBRARY_ARCHITECTURE is unset This causes files on NixOS to be put in the proper architecture independent place, which otherwise was selecting the architecture dependent location. * cmake: Properly set pkg-config requires when configured with ICU In this case the pkg-config file needs to set icu-cu in the `Required` field, and needs to add the flag `-DCXXOPTS_USE_UNICODE` to the `Cflags` field. * cmake: cxxopts is not arch independent when built with ICU support Since it links to an architecture dependent ICU --- CMakeLists.txt | 5 +++-- cmake/cxxopts.cmake | 22 ++++++++++++++-------- packaging/pkgconfig.pc.in | 4 +++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c1a686..a6e4e86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,6 @@ cmake_minimum_required(VERSION 3.1...3.19) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") include(cxxopts) -set("PROJECT_DESCRIPTION" "A header-only lightweight C++ command line option parser") -set("PROJECT_HOMEPAGE_URL" "https://github.com/jarro2783/cxxopts") # Get the version of the library cxxopts_getversion(VERSION) @@ -32,6 +30,9 @@ project(cxxopts LANGUAGES CXX ) +set("PROJECT_DESCRIPTION" "A header-only lightweight C++ command line option parser") +set("PROJECT_HOMEPAGE_URL" "https://github.com/jarro2783/cxxopts") + # Must include after the project call due to GNUInstallDirs requiring a language be enabled (IE. CXX) include(GNUInstallDirs) diff --git a/cmake/cxxopts.cmake b/cmake/cxxopts.cmake index 0ead543..b26c18a 100644 --- a/cmake/cxxopts.cmake +++ b/cmake/cxxopts.cmake @@ -87,10 +87,17 @@ endfunction() # Helper function to ecapsulate install logic function(cxxopts_install_logic) - if(CMAKE_LIBRARY_ARCHITECTURE) - string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}") + if(NOT CXXOPTS_USE_UNICODE_HELP) + if(CMAKE_LIBRARY_ARCHITECTURE) + string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}") + else() + # On some systems (e.g. NixOS), `CMAKE_LIBRARY_ARCHITECTURE` can be empty + set(CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_DATAROOTDIR}") + endif() + if(${CMAKE_VERSION} VERSION_GREATER "3.14") + set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") + endif() else() - # On some systems (e.g. NixOS), `CMAKE_LIBRARY_ARCHITECTURE` can be empty set(CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}") endif() set(CXXOPTS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/cxxopts" CACHE STRING "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.") @@ -99,11 +106,6 @@ function(cxxopts_install_logic) set(targets_export_name cxxopts-targets) set(PackagingTemplatesDir "${PROJECT_SOURCE_DIR}/packaging") - - if(${CMAKE_VERSION} VERSION_GREATER "3.14") - set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") - endif() - # Generate the version, config and target files into the build directory. write_basic_package_version_file( ${version_config} @@ -154,6 +156,10 @@ function(cxxopts_install_logic) set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc") + if(CXXOPTS_USE_UNICODE_HELP) + set(PKG_CONFIG_REQUIRES "icu-cu") + set(PKG_CONFIG_EXTRA_CFLAGS "-DCXXOPTS_USE_UNICODE") + endif() configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY) install(FILES "${PKG_CONFIG_FILE_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/pkgconfig" diff --git a/packaging/pkgconfig.pc.in b/packaging/pkgconfig.pc.in index 9b6a44c..256eda2 100644 --- a/packaging/pkgconfig.pc.in +++ b/packaging/pkgconfig.pc.in @@ -3,5 +3,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: @PROJECT_NAME@ Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ -Cflags: -I${includedir} +Requires: @PKG_CONFIG_REQUIRES@ +Cflags: -I${includedir} @PKG_CONFIG_EXTRA_CFLAGS@