Skip to content

Commit c6b2e20

Browse files
authored
Merge pull request #431 from carstene1ns/bugfix/cmake-no-pkgconfig
Remove the need for pkgconfig in cmake config
2 parents 89d46f6 + 934c0d4 commit c6b2e20

8 files changed

Lines changed: 92 additions & 70 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
tests/doctest.h -diff linguist-vendored
1515
builds/autoconf/m4/ax_*.m4 -diff linguist-vendored
16+
src/lcf/third_party/*.h -diff linguist-vendored
17+
18+
src/generated/** -diff

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
.dirstamp
1010
Makefile.in
1111
aclocal.m4
12-
config.h
13-
config.h.in
1412
config.log
1513
config.status
1614
configure
17-
liblcf-*.tar.*
1815
libtool
1916
stamp-h1
2017
*.la
2118
*.lo
2219

2320
# cmake build method
2421
bin/
25-
builds/liblcf-config.cmake
2622
CMakeCache.txt
2723
CMakeFiles/
2824
*.cmake
@@ -65,6 +61,11 @@ Makefile
6561
*.a
6662
*.o
6763
*.pc
64+
config.h
65+
builds/liblcf-config.cmake
6866

6967
# tests
7068
test_runner*
69+
70+
# distribution archives
71+
liblcf-*.tar.*

CMakeLists.txt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ endif()
66

77
project(liblcf VERSION 0.6.2 LANGUAGES CXX)
88

9-
# Deprecation handling. Remove these lines one release later.
10-
SET(new_params "WITH_ICU;WITH_XML;UPDATE_MIMEDB;ENABLE_TOOLS;ENABLE_BENCHMARKS")
11-
SET(old_params "DISABLE_ICU;DISABLE_XML;DISABLE_UPDATE_MIMEDB;DISABLE_TOOLS;DISABLE_BENCHMARKS")
12-
foreach(x IN LISTS old_params)
13-
if(DEFINED ${x})
14-
list(FIND old_params ${x} index)
15-
list(GET new_params ${index} new_value)
16-
message(FATAL_ERROR "${x} was renamed to LIBLCF_${new_value} and the logic inverted.")
17-
endif()
18-
endforeach()
19-
209
# Compilation options
2110
option(BUILD_SHARED_LIBS "Build shared library, disable for building the static library (default: ON)" ON)
2211
option(LIBLCF_WITH_ICU "ICU encoding detection (when OFF fallback to iconv, not recommended, default: ON)" ON)
@@ -336,17 +325,19 @@ set_property(TARGET lcf PROPERTY DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
336325
set_property(TARGET lcf PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
337326

338327
# icu or fallback to iconv
328+
set(LCF_SUPPORT_ICU 0)
339329
if(LIBLCF_WITH_ICU)
340330
find_package(ICU COMPONENTS i18n uc data REQUIRED)
341331
target_link_libraries(lcf ICU::i18n ICU::uc ICU::data)
342332
list(APPEND LIBLCF_DEPS "icu-i18n")
343-
set(LCF_SUPPORT_ICU "1")
333+
set(LCF_SUPPORT_ICU 1)
344334
else()
345335
find_package(Iconv REQUIRED)
346336
target_link_libraries(lcf Iconv::Iconv)
347337
endif()
348338

349339
# expat
340+
set(LCF_SUPPORT_XML 0)
350341
if(LIBLCF_WITH_XML)
351342
find_package(expat CONFIG)
352343
if(expat_FOUND)
@@ -357,15 +348,15 @@ if(LIBLCF_WITH_XML)
357348
target_link_libraries(lcf EXPAT::EXPAT)
358349
endif()
359350
list(APPEND LIBLCF_DEPS "expat")
360-
set(LCF_SUPPORT_XML "1")
351+
set(LCF_SUPPORT_XML 1)
361352
endif()
362353

363354
# mime types
364355
if(LIBLCF_UPDATE_MIMEDB AND NOT CMAKE_CROSSCOMPILING)
365356
find_program(UPDATE_MIME_DATABASE update-mime-database)
366357
endif()
367358

368-
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake.config.h.in" "src/lcf/config.h" @ONLY)
359+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/builds/config.h.in" "src/lcf/config.h" @ONLY)
369360
target_sources(lcf PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src/lcf/config.h)
370361

371362
# .so version

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ lcfthirdpartyincludedir = $(includedir)/lcf/third_party
2323
lib_LTLIBRARIES = liblcf.la
2424
liblcf_la_CPPFLAGS = \
2525
$(AM_CPPFLAGS) \
26-
-I$(builddir)/autogen \
26+
-I$(builddir)/src \
2727
-I$(srcdir)/src \
2828
-I$(srcdir)/src/generated
2929
liblcf_la_CXXFLAGS = \
@@ -307,7 +307,7 @@ lcfthirdpartyinclude_HEADERS = \
307307
src/lcf/third_party/span.h \
308308
src/lcf/third_party/string_view.h
309309

310-
nodist_lcfinclude_HEADERS = autogen/lcf/config.h
310+
nodist_lcfinclude_HEADERS = src/lcf/config.h
311311

312312
check_PROGRAMS = test_runner
313313
test_runner_SOURCES = \

builds/cmake.config.h.in

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Generated by the buildsystem DO NOT EDIT */
12

23
/* Enable encoding detection (ICU) */
34
#define LCF_SUPPORT_ICU @LCF_SUPPORT_ICU@

builds/liblcf-config.cmake.in

Lines changed: 53 additions & 38 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)
@@ -66,26 +87,22 @@ if(LIBLCF_FOUND)
6687
if(NOT TARGET liblcf::liblcf)
6788
add_library(liblcf::liblcf UNKNOWN IMPORTED)
6889

69-
set(LIBLCF_LIBRARY_DEPS "@AX_PACKAGE_REQUIRES_PRIVATE@")
70-
string(REPLACE " " ";" LIBLCF_LIBRARY_DEPS "${LIBLCF_LIBRARY_DEPS}")
71-
72-
foreach(dep ${LIBLCF_LIBRARY_DEPS})
73-
if(dep STREQUAL "icu-i18n")
74-
find_package(ICU COMPONENTS i18n uc data REQUIRED QUIET)
75-
list(APPEND LIBLCF_LIBRARIES ${ICU_LIBRARIES})
76-
list(APPEND LIBLCF_LINK_LIBRARIES ICU::i18n ICU::uc ICU::data)
77-
elseif(dep STREQUAL "expat")
78-
find_package(expat CONFIG QUIET)
79-
if(expat_FOUND)
80-
list(APPEND LIBLCF_LINK_LIBRARIES expat::expat)
81-
else()
82-
# Fallback to old expat detection
83-
find_package(EXPAT REQUIRED QUIET)
84-
list(APPEND LIBLCF_LINK_LIBRARIES EXPAT::EXPAT)
85-
endif()
86-
list(APPEND LIBLCF_LIBRARIES ${EXPAT_LIBRARIES})
90+
if(@LCF_SUPPORT_ICU@)
91+
find_package(ICU COMPONENTS i18n uc data REQUIRED QUIET)
92+
list(APPEND LIBLCF_LIBRARIES ${ICU_LIBRARIES})
93+
list(APPEND LIBLCF_LINK_LIBRARIES ICU::i18n ICU::uc ICU::data)
94+
endif()
95+
if(@LCF_SUPPORT_XML@)
96+
find_package(expat CONFIG QUIET)
97+
if(expat_FOUND)
98+
list(APPEND LIBLCF_LINK_LIBRARIES expat::expat)
99+
else()
100+
# Fallback to old expat detection
101+
find_package(EXPAT REQUIRED QUIET)
102+
list(APPEND LIBLCF_LINK_LIBRARIES EXPAT::EXPAT)
87103
endif()
88-
endforeach()
104+
list(APPEND LIBLCF_LIBRARIES ${EXPAT_LIBRARIES})
105+
endif()
89106

90107
set_target_properties(liblcf::liblcf PROPERTIES
91108
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
@@ -111,12 +128,10 @@ if(LIBLCF_FOUND)
111128
IMPORTED_LOCATION "${LIBLCF_LIBRARY}")
112129
endif()
113130

114-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.8")
115-
set_property(TARGET liblcf::liblcf APPEND PROPERTY
116-
COMPILE_FEATURES cxx_std_14)
117-
endif()
131+
set_property(TARGET liblcf::liblcf APPEND PROPERTY
132+
COMPILE_FEATURES cxx_std_14)
118133

119-
mark_as_advanced(LIBLCF_LIBRARY_DEPS LIBLCF_LINK_LIBRARIES)
134+
mark_as_advanced(LIBLCF_LINK_LIBRARIES)
120135
endif()
121136
endif()
122137

configure.ac

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ AM_CONDITIONAL(CROSS_COMPILING,[test "x$cross_compiling" = "xyes"])
2424
AC_SUBST([LCF_SUPPORT_ICU],[0])
2525
AC_ARG_ENABLE([icu],[AS_HELP_STRING([--disable-icu],[Disable ICU encoding detection (fallback to iconv) [default=no]])])
2626
AS_IF([test "x$enable_icu" != "xno"],[
27-
AX_PKG_CHECK_MODULES([ICU],[],[icu-i18n],[AC_SUBST([LCF_SUPPORT_ICU],[1])])
27+
AX_PKG_CHECK_MODULES([ICU],[],[icu-i18n],[LCF_SUPPORT_ICU=1])
2828
])
2929

3030
AC_SUBST([LCF_SUPPORT_XML],[0])
3131
AC_ARG_ENABLE([xml],[AS_HELP_STRING([--disable-xml],[Disable XML reading support (expat) [default=no]])])
3232
AS_IF([test "x$enable_xml" != "xno"],[
33-
AX_PKG_CHECK_MODULES([EXPAT],[],[expat >= 2.1],[AC_SUBST([LCF_SUPPORT_XML],[1])])
33+
AX_PKG_CHECK_MODULES([EXPAT],[],[expat >= 2.1],[LCF_SUPPORT_XML=1])
3434
])
3535
AM_CONDITIONAL(SUPPORT_XML,[test $LCF_SUPPORT_XML == 1])
3636

@@ -70,13 +70,32 @@ 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
7796
AC_CONFIG_FILES([Makefile
7897
builds/liblcf.pc
7998
builds/liblcf-config.cmake
80-
autogen/lcf/config.h:builds/autoconf.config.h.in])
99+
src/lcf/config.h:builds/config.h.in])
81100

82101
AC_OUTPUT

0 commit comments

Comments
 (0)