Skip to content

Commit 934c0d4

Browse files
committed
Remove the use of pkg-config in cmake config
Add logic to generate the needed paths manually for autotools Import prefix handling is based on CMakePackageConfigHelpers
1 parent 19ab47e commit 934c0d4

2 files changed

Lines changed: 57 additions & 19 deletions

File tree

builds/liblcf-config.cmake.in

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#.rst:
2-
# FindLCF
2+
# liblcf-config
33
# -------
44
#
5-
# Find the native liblcf headers and library.
5+
# Exports the native liblcf headers and library.
66
#
77
# Imported Targets
88
# ^^^^^^^^^^^^^^^^
@@ -26,26 +26,47 @@
2626
# ``LIBLCF_VERSION_STRING``
2727
# version of liblcf
2828

29-
find_package(PkgConfig QUIET)
30-
31-
pkg_check_modules(PC_LIBLCF QUIET lcf)
29+
# Compute the installation prefix relative to this file.
30+
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
31+
# Use original install prefix when loaded through a
32+
# cross-prefix symbolic link such as /lib -> /usr/lib.
33+
get_filename_component(_realCurr "${_IMPORT_PREFIX}" REALPATH)
34+
get_filename_component(_realOrig "@CMAKE_INSTALL_FULL_LIBDIR@/cmake/liblcf" REALPATH)
35+
if(_realCurr STREQUAL _realOrig)
36+
set(_IMPORT_PREFIX "${_realOrig}")
37+
endif()
38+
unset(_realOrig)
39+
unset(_realCurr)
40+
# peel layers until above library directory
41+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
42+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
43+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
44+
# debian multiarch has one layer more
45+
if(_IMPORT_PREFIX MATCHES ".+/lib$")
46+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
47+
endif()
48+
if(_IMPORT_PREFIX STREQUAL "/")
49+
set(_IMPORT_PREFIX "")
50+
endif()
3251

33-
# Look for the header file.
34-
find_path(LIBLCF_INCLUDE_DIR
35-
NAMES "lcf/reader_lcf.h"
36-
PATH_SUFFIXES liblcf lcf
37-
HINTS ${PC_LIBLCF_INCLUDE_DIRS})
52+
# Set the header file directory.
53+
set(LIBLCF_INCLUDE_DIR "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@"
54+
CACHE PATH "LCF include directory")
3855

3956
# Look for the library.
4057
# Allow LIBLCF_LIBRARY to be set manually, as the location of the liblcf library
4158
if(NOT LIBLCF_LIBRARY)
4259
find_library(LIBLCF_LIBRARY_RELEASE
43-
NAMES lcf liblcf
44-
HINTS ${PC_LIBLCF_LIBRARY_DIRS})
60+
NAMES lcf
61+
PATHS ${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@
62+
DOC "LCF library (release)"
63+
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
4564

4665
find_library(LIBLCF_LIBRARY_DEBUG
47-
NAMES lcf@CMAKE_DEBUG_POSTFIX@ liblcf@CMAKE_DEBUG_POSTFIX@
48-
HINTS ${PC_LIBLCF_LIBRARY_DIRS})
66+
NAMES lcf@CMAKE_DEBUG_POSTFIX@
67+
PATHS ${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@
68+
DOC "LCF library (debug)"
69+
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
4970

5071
include(SelectLibraryConfigurations)
5172
select_library_configurations(LIBLCF)
@@ -107,10 +128,8 @@ if(LIBLCF_FOUND)
107128
IMPORTED_LOCATION "${LIBLCF_LIBRARY}")
108129
endif()
109130

110-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.8")
111-
set_property(TARGET liblcf::liblcf APPEND PROPERTY
112-
COMPILE_FEATURES cxx_std_14)
113-
endif()
131+
set_property(TARGET liblcf::liblcf APPEND PROPERTY
132+
COMPILE_FEATURES cxx_std_14)
114133

115134
mark_as_advanced(LIBLCF_LINK_LIBRARIES)
116135
endif()

configure.ac

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,26 @@ AC_SUBST([AM_CPPFLAGS])
7070
AC_SUBST([AM_CXXFLAGS])
7171
AC_SUBST([AM_LDFLAGS])
7272

73-
# liblcf-config.cmake (use empty postfix)
73+
# liblcf-config.cmake
74+
AC_PROG_SED
75+
AC_PROG_GREP
76+
# remove the (exec_)prefix from includedir and libdir
77+
prefix_remover_sed="$SED -e s%^\${\(exec_\)\{0,1\}prefix}%% \
78+
-e s%^${prefix}%% -e s%^${exec_prefix}%% -e s%^/%%"
79+
sub_incdir=`AS_ECHO(${includedir}) | ${prefix_remover_sed}`
80+
sub_libdir=`AS_ECHO(${libdir}) | ${prefix_remover_sed}`
81+
# concatenate, if not absolute path
82+
full_libdir=${libdir}
83+
AS_IF([AS_ECHO(${libdir}) | $GREP -v "^/" >/dev/null], [
84+
AS_IF([test "x${exec_prefix}" != "xNONE"],
85+
[full_libdir="${exec_prefix}/${sub_libdir}"],
86+
[test "x${prefix}" != "xNONE"],
87+
[full_libdir="${prefix}/${sub_libdir}"],
88+
[full_libdir="${ac_default_prefix}/${sub_libdir}"])
89+
])
90+
AC_SUBST([CMAKE_INSTALL_INCLUDEDIR], [$sub_incdir])
91+
AC_SUBST([CMAKE_INSTALL_LIBDIR], [$sub_libdir])
92+
AC_SUBST([CMAKE_INSTALL_FULL_LIBDIR], [$full_libdir])
7493
AC_SUBST([CMAKE_DEBUG_POSTFIX])
7594

7695
# Files to generate

0 commit comments

Comments
 (0)