Skip to content

Commit

Permalink
CMake: Fix pkg-config generation when using absolute paths
Browse files Browse the repository at this point in the history
Assuming that CMAKE_INSTALL_{INCLUDE,LIB}DIR is always a path relative
to the prefix can lead to broken paths added to pkg-config if the path
is relative.
Solution: Check if the paths are absolute and only add the prefix if they
are not.

Fixes #23
  • Loading branch information
selmf committed May 19, 2022
1 parent 02129fe commit eb4f17c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,8 +3,11 @@
## 1.1.0 (unreleased)

### Changed

* Build 7z support by default

### Fixed
* Fix pkg-config when using absolute paths

## 1.1.0.beta1 - 2022-05-01

### Added
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Expand Up @@ -205,6 +205,18 @@ if(MSVC)
target_compile_definitions(unarr PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

# Generate paths for pkg-config file
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(PROJECT_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
else()
set(PROJECT_INSTALL_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(PROJECT_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_LIBDIR})

This comment has been minimized.

Copy link
@alexshpilkin

alexshpilkin May 19, 2022

Thank you for the quick response, but shouldn’t this have been INCLUDEDIR?

This comment has been minimized.

Copy link
@selmf

selmf via email May 20, 2022

Author Owner
else()
set(PROJECT_INSTALL_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

# Write pkg-config file
configure_file("pkg-config.pc.cmake" "lib${PROJECT_NAME}.pc" @ONLY)

Expand Down
4 changes: 2 additions & 2 deletions pkg-config.pc.cmake
@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@PROJECT_INSTALL_INCLUDEDIR@
libdir=@PROJECT_INSTALL_LIBDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Expand Down

0 comments on commit eb4f17c

Please sign in to comment.