Skip to content

Commit

Permalink
Support relative prefix in pkg-config (AcademySoftwareFoundation#291)
Browse files Browse the repository at this point in the history
* Support relative prefix in pkg-config

CMake now exports CMAKE_INSTALL_LIBDIR/CMAKE_INSTALL_INCLUDEDIR
instead of the *_FULL_* variables, and Imath.pc.in prepends the prefix
explicitly, which makes it possible to support relative installation
paths

Signed-off-by: Cary Phillips <cary@ilm.com>

* Add CMake logic to handle relative vs absolute libdir/includedir

Signed-off-by: Cary Phillips <cary@ilm.com>

---------

Signed-off-by: Cary Phillips <cary@ilm.com>
  • Loading branch information
cary-ilm committed Feb 27, 2023
1 parent 802bc24 commit e92ca03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 15 additions & 4 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ install(TARGETS ImathConfig EXPORT ${PROJECT_NAME})
add_library(Imath::Config ALIAS ImathConfig)

if(IMATH_INSTALL_PKG_CONFIG)

# Prepend prefix for includedir only if CMAKE_INSTALL_INCLUDEDIR is relative
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(PKG_CONFIG_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(PKG_CONFIG_INSTALL_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

# Prepend exec_prefix for libdir only if CMAKE_INSTALL_LIBDIR is relative
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(PKG_CONFIG_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
set(PKG_CONFIG_INSTALL_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()

# use a helper function to avoid variable pollution, but pretty simple
function(imath_pkg_config_help pcinfile)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
set(LIB_SUFFIX_DASH ${IMATH_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX})
string(REPLACE ".in" "" pcout ${pcinfile})
Expand Down
8 changes: 4 additions & 4 deletions config/Imath.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
## Copyright Contributors to the OpenEXR Project.
##

prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@PKG_CONFIG_INSTALL_LIBDIR@
includedir=@PKG_CONFIG_INSTALL_INCLUDEDIR@
libsuffix=@LIB_SUFFIX_DASH@
Name: Imath
Description: Imath library: vector/matrix and math operations, plus the half type.
Expand Down

0 comments on commit e92ca03

Please sign in to comment.