Skip to content

Commit

Permalink
enable changing install prefix for PKG config
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKoch committed Jan 18, 2024
1 parent 67c2c1b commit 556a62e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
12 changes: 0 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,6 @@ if(GINKGO_BUILD_DOC)
endif()


# add escape character '\' for space
string(REPLACE " " "\ " PKG_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# add escape character '\' for space in regex mode
list(TRANSFORM GINKGO_INTERFACE_LINK_FLAGS REPLACE " " "\\\\ ")
list(TRANSFORM GINKGO_INTERFACE_CXX_FLAGS REPLACE " " "\\\\ ")
# convert the list to string
string(REPLACE ";" " " GINKGO_INTERFACE_CXX_FLAGS "${GINKGO_INTERFACE_CXX_FLAGS}")
string(REPLACE ";" " " GINKGO_INTERFACE_LINK_FLAGS "${GINKGO_INTERFACE_LINK_FLAGS}")
configure_file(${Ginkgo_SOURCE_DIR}/cmake/ginkgo.pc.in
${Ginkgo_BINARY_DIR}/ginkgo.pc.in @ONLY)
file(GENERATE OUTPUT ${Ginkgo_BINARY_DIR}/ginkgo_$<CONFIG>.pc
INPUT ${Ginkgo_BINARY_DIR}/ginkgo.pc.in)

# WINDOWS NVCC has " inside the string, add escape character
# to avoid config problem.
Expand Down
28 changes: 28 additions & 0 deletions cmake/generate_pkg.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is run as a standalone script. Thus no cmake variables related to Ginkgo are
# available through the ${...} syntax. Instead, the file containing the actual values
# of the necessary variables is generated through `configure_file`. But this leaves
# generator expressions unresolved, so another pass through `file(GENERATE ...)` is
# necessary. That call can't be put into this file, since the script is used as part
# of `install(SCRIPT ...)` which doesn't support generator expressions in the script
# content

# add escape character '\' for space
string(REPLACE " " "\ " GINKGO_PKG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# add escape character '\' for space in regex mode
string(REPLACE ";" "\ " GINKGO_INTERFACE_LINK_FLAGS "@GINKGO_INTERFACE_LINK_FLAGS@")
string(REPLACE ";" "\ " GINKGO_INTERFACE_CXX_FLAGS "@GINKGO_INTERFACE_CXX_FLAGS@")

set(GINKGO_INSTALL_FULL_LIBDIR "${GINKGO_PKG_INSTALL_PREFIX}/@CMAKE_INSTALL_LIBDIR@")
set(GINKGO_INSTALL_FULL_INCLUDEDIR "${GINKGO_PKG_INSTALL_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@")
set(GINKGO_PROJECT_NAME "@CMAKE_PROJECT_NAME@")
set(GINKGO_DESCRIPTION "@Ginkgo_DESCRIPTION@")
set(GINKGO_VERSION "@Ginkgo_VERSION@")

set(GINKGO_INSTALL_PKGCONFIG_DIR "${GINKGO_INSTALL_FULL_LIBDIR}/pkgconfig")

set(GINKGO_SOURCE_DIR "@Ginkgo_SOURCE_DIR@")
set(GINKGO_BINARY_DIR "@Ginkgo_BINARY_DIR@")

configure_file(${GINKGO_SOURCE_DIR}/cmake/ginkgo.pc.in
${GINKGO_INSTALL_PKGCONFIG_DIR}/ginkgo_$<CONFIG>.pc
@ONLY)
12 changes: 6 additions & 6 deletions cmake/ginkgo.pc.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
prefix=@PKG_CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
prefix=@GINKGO_PKG_INSTALL_PREFIX@
libdir=@GINKGO_INSTALL_FULL_LIBDIR@
includedir=@GINKGO_INSTALL_FULL_INCLUDEDIR@

Name: @CMAKE_PROJECT_NAME@
Description: @Ginkgo_DESCRIPTION@
Version: @Ginkgo_VERSION@
Name: @GINKGO_PROJECT_NAME@
Description: @GINKGO_DESCRIPTION@
Version: @GINKGO_VERSION@
URL: https://ginkgo-project.github.io/

Requires:
Expand Down
17 changes: 12 additions & 5 deletions cmake/install_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ include(CMakePackageConfigHelpers)
include(GNUInstallDirs)


set(GINKGO_INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(GINKGO_INSTALL_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Ginkgo")
set(GINKGO_INSTALL_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Ginkgo/Modules")

Expand Down Expand Up @@ -60,10 +59,18 @@ function(ginkgo_install_library name)
endfunction()

function(ginkgo_install)
# pkg-config file
install(FILES ${Ginkgo_BINARY_DIR}/ginkgo_$<CONFIG>.pc
DESTINATION "${GINKGO_INSTALL_PKGCONFIG_DIR}"
RENAME ginkgo.pc
# generate pkg-config file, a three-step process is necessary to include the correct install prefix
# Step 1: substitute project variables in the generation script
configure_file("${Ginkgo_SOURCE_DIR}/cmake/generate_pkg.cmake.in"
"${Ginkgo_BINARY_DIR}/cmake/generate_pkg.cmake"
@ONLY)
# Step 2: substitute generator expressions
file(GENERATE OUTPUT ${Ginkgo_BINARY_DIR}/cmake/generate_pkg_$<CONFIG>.cmake
INPUT ${Ginkgo_BINARY_DIR}/cmake/generate_pkg.cmake)
# Step 3: at install time, call the generation script which has all variables
# except the install prefix already replaced. Use the install prefix
# that is specified at install time
install(SCRIPT "${Ginkgo_BINARY_DIR}/cmake/generate_pkg_$<CONFIG>.cmake"
COMPONENT Ginkgo_Development)

# install the public header files
Expand Down

0 comments on commit 556a62e

Please sign in to comment.