Skip to content

Commit dcf3e1a

Browse files
authored
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
1 parent 3d9a4c0 commit dcf3e1a

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ cmake_minimum_required(VERSION 3.1...3.19)
2121

2222
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
2323
include(cxxopts)
24-
set("PROJECT_DESCRIPTION" "A header-only lightweight C++ command line option parser")
25-
set("PROJECT_HOMEPAGE_URL" "https://github.com/jarro2783/cxxopts")
2624

2725
# Get the version of the library
2826
cxxopts_getversion(VERSION)
@@ -32,6 +30,9 @@ project(cxxopts
3230
LANGUAGES CXX
3331
)
3432

33+
set("PROJECT_DESCRIPTION" "A header-only lightweight C++ command line option parser")
34+
set("PROJECT_HOMEPAGE_URL" "https://github.com/jarro2783/cxxopts")
35+
3536
# Must include after the project call due to GNUInstallDirs requiring a language be enabled (IE. CXX)
3637
include(GNUInstallDirs)
3738

cmake/cxxopts.cmake

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,17 @@ endfunction()
8787

8888
# Helper function to ecapsulate install logic
8989
function(cxxopts_install_logic)
90-
if(CMAKE_LIBRARY_ARCHITECTURE)
91-
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
90+
if(NOT CXXOPTS_USE_UNICODE_HELP)
91+
if(CMAKE_LIBRARY_ARCHITECTURE)
92+
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
93+
else()
94+
# On some systems (e.g. NixOS), `CMAKE_LIBRARY_ARCHITECTURE` can be empty
95+
set(CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_DATAROOTDIR}")
96+
endif()
97+
if(${CMAKE_VERSION} VERSION_GREATER "3.14")
98+
set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
99+
endif()
92100
else()
93-
# On some systems (e.g. NixOS), `CMAKE_LIBRARY_ARCHITECTURE` can be empty
94101
set(CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
95102
endif()
96103
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)
99106
set(targets_export_name cxxopts-targets)
100107
set(PackagingTemplatesDir "${PROJECT_SOURCE_DIR}/packaging")
101108

102-
103-
if(${CMAKE_VERSION} VERSION_GREATER "3.14")
104-
set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
105-
endif()
106-
107109
# Generate the version, config and target files into the build directory.
108110
write_basic_package_version_file(
109111
${version_config}
@@ -154,6 +156,10 @@ function(cxxopts_install_logic)
154156
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
155157

156158
set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc")
159+
if(CXXOPTS_USE_UNICODE_HELP)
160+
set(PKG_CONFIG_REQUIRES "icu-cu")
161+
set(PKG_CONFIG_EXTRA_CFLAGS "-DCXXOPTS_USE_UNICODE")
162+
endif()
157163
configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
158164
install(FILES "${PKG_CONFIG_FILE_NAME}"
159165
DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/pkgconfig"

packaging/pkgconfig.pc.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
33

44
Name: @PROJECT_NAME@
55
Description: @PROJECT_DESCRIPTION@
6+
URL: @PROJECT_HOMEPAGE_URL@
67
Version: @PROJECT_VERSION@
7-
Cflags: -I${includedir}
8+
Requires: @PKG_CONFIG_REQUIRES@
9+
Cflags: -I${includedir} @PKG_CONFIG_EXTRA_CFLAGS@

0 commit comments

Comments
 (0)