Skip to content

Commit

Permalink
Merge pull request #431 from carstene1ns/bugfix/cmake-no-pkgconfig
Browse files Browse the repository at this point in the history
Remove the need for pkgconfig in cmake config
  • Loading branch information
Ghabry authored Aug 31, 2021
2 parents 89d46f6 + 934c0d4 commit c6b2e20
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

tests/doctest.h -diff linguist-vendored
builds/autoconf/m4/ax_*.m4 -diff linguist-vendored
src/lcf/third_party/*.h -diff linguist-vendored

src/generated/** -diff
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
.dirstamp
Makefile.in
aclocal.m4
config.h
config.h.in
config.log
config.status
configure
liblcf-*.tar.*
libtool
stamp-h1
*.la
*.lo

# cmake build method
bin/
builds/liblcf-config.cmake
CMakeCache.txt
CMakeFiles/
*.cmake
Expand Down Expand Up @@ -65,6 +61,11 @@ Makefile
*.a
*.o
*.pc
config.h
builds/liblcf-config.cmake

# tests
test_runner*

# distribution archives
liblcf-*.tar.*
19 changes: 5 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ endif()

project(liblcf VERSION 0.6.2 LANGUAGES CXX)

# Deprecation handling. Remove these lines one release later.
SET(new_params "WITH_ICU;WITH_XML;UPDATE_MIMEDB;ENABLE_TOOLS;ENABLE_BENCHMARKS")
SET(old_params "DISABLE_ICU;DISABLE_XML;DISABLE_UPDATE_MIMEDB;DISABLE_TOOLS;DISABLE_BENCHMARKS")
foreach(x IN LISTS old_params)
if(DEFINED ${x})
list(FIND old_params ${x} index)
list(GET new_params ${index} new_value)
message(FATAL_ERROR "${x} was renamed to LIBLCF_${new_value} and the logic inverted.")
endif()
endforeach()

# Compilation options
option(BUILD_SHARED_LIBS "Build shared library, disable for building the static library (default: ON)" ON)
option(LIBLCF_WITH_ICU "ICU encoding detection (when OFF fallback to iconv, not recommended, default: ON)" ON)
Expand Down Expand Up @@ -336,17 +325,19 @@ set_property(TARGET lcf PROPERTY DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
set_property(TARGET lcf PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)

# icu or fallback to iconv
set(LCF_SUPPORT_ICU 0)
if(LIBLCF_WITH_ICU)
find_package(ICU COMPONENTS i18n uc data REQUIRED)
target_link_libraries(lcf ICU::i18n ICU::uc ICU::data)
list(APPEND LIBLCF_DEPS "icu-i18n")
set(LCF_SUPPORT_ICU "1")
set(LCF_SUPPORT_ICU 1)
else()
find_package(Iconv REQUIRED)
target_link_libraries(lcf Iconv::Iconv)
endif()

# expat
set(LCF_SUPPORT_XML 0)
if(LIBLCF_WITH_XML)
find_package(expat CONFIG)
if(expat_FOUND)
Expand All @@ -357,15 +348,15 @@ if(LIBLCF_WITH_XML)
target_link_libraries(lcf EXPAT::EXPAT)
endif()
list(APPEND LIBLCF_DEPS "expat")
set(LCF_SUPPORT_XML "1")
set(LCF_SUPPORT_XML 1)
endif()

# mime types
if(LIBLCF_UPDATE_MIMEDB AND NOT CMAKE_CROSSCOMPILING)
find_program(UPDATE_MIME_DATABASE update-mime-database)
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake.config.h.in" "src/lcf/config.h" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/builds/config.h.in" "src/lcf/config.h" @ONLY)
target_sources(lcf PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src/lcf/config.h)

# .so version
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lcfthirdpartyincludedir = $(includedir)/lcf/third_party
lib_LTLIBRARIES = liblcf.la
liblcf_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(builddir)/autogen \
-I$(builddir)/src \
-I$(srcdir)/src \
-I$(srcdir)/src/generated
liblcf_la_CXXFLAGS = \
Expand Down Expand Up @@ -307,7 +307,7 @@ lcfthirdpartyinclude_HEADERS = \
src/lcf/third_party/span.h \
src/lcf/third_party/string_view.h

nodist_lcfinclude_HEADERS = autogen/lcf/config.h
nodist_lcfinclude_HEADERS = src/lcf/config.h

check_PROGRAMS = test_runner
test_runner_SOURCES = \
Expand Down
8 changes: 0 additions & 8 deletions builds/cmake.config.h.in

This file was deleted.

1 change: 1 addition & 0 deletions builds/autoconf.config.h.in → builds/config.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* Generated by the buildsystem DO NOT EDIT */

/* Enable encoding detection (ICU) */
#define LCF_SUPPORT_ICU @LCF_SUPPORT_ICU@
Expand Down
91 changes: 53 additions & 38 deletions builds/liblcf-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#.rst:
# FindLCF
# liblcf-config
# -------
#
# Find the native liblcf headers and library.
# Exports the native liblcf headers and library.
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
Expand All @@ -26,26 +26,47 @@
# ``LIBLCF_VERSION_STRING``
# version of liblcf

find_package(PkgConfig QUIET)

pkg_check_modules(PC_LIBLCF QUIET lcf)
# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
# Use original install prefix when loaded through a
# cross-prefix symbolic link such as /lib -> /usr/lib.
get_filename_component(_realCurr "${_IMPORT_PREFIX}" REALPATH)
get_filename_component(_realOrig "@CMAKE_INSTALL_FULL_LIBDIR@/cmake/liblcf" REALPATH)
if(_realCurr STREQUAL _realOrig)
set(_IMPORT_PREFIX "${_realOrig}")
endif()
unset(_realOrig)
unset(_realCurr)
# peel layers until above library directory
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
# debian multiarch has one layer more
if(_IMPORT_PREFIX MATCHES ".+/lib$")
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
endif()
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()

# Look for the header file.
find_path(LIBLCF_INCLUDE_DIR
NAMES "lcf/reader_lcf.h"
PATH_SUFFIXES liblcf lcf
HINTS ${PC_LIBLCF_INCLUDE_DIRS})
# Set the header file directory.
set(LIBLCF_INCLUDE_DIR "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@"
CACHE PATH "LCF include directory")

# Look for the library.
# Allow LIBLCF_LIBRARY to be set manually, as the location of the liblcf library
if(NOT LIBLCF_LIBRARY)
find_library(LIBLCF_LIBRARY_RELEASE
NAMES lcf liblcf
HINTS ${PC_LIBLCF_LIBRARY_DIRS})
NAMES lcf
PATHS ${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@
DOC "LCF library (release)"
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)

find_library(LIBLCF_LIBRARY_DEBUG
NAMES lcf@CMAKE_DEBUG_POSTFIX@ liblcf@CMAKE_DEBUG_POSTFIX@
HINTS ${PC_LIBLCF_LIBRARY_DIRS})
NAMES lcf@CMAKE_DEBUG_POSTFIX@
PATHS ${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@
DOC "LCF library (debug)"
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)

include(SelectLibraryConfigurations)
select_library_configurations(LIBLCF)
Expand All @@ -66,26 +87,22 @@ if(LIBLCF_FOUND)
if(NOT TARGET liblcf::liblcf)
add_library(liblcf::liblcf UNKNOWN IMPORTED)

set(LIBLCF_LIBRARY_DEPS "@AX_PACKAGE_REQUIRES_PRIVATE@")
string(REPLACE " " ";" LIBLCF_LIBRARY_DEPS "${LIBLCF_LIBRARY_DEPS}")

foreach(dep ${LIBLCF_LIBRARY_DEPS})
if(dep STREQUAL "icu-i18n")
find_package(ICU COMPONENTS i18n uc data REQUIRED QUIET)
list(APPEND LIBLCF_LIBRARIES ${ICU_LIBRARIES})
list(APPEND LIBLCF_LINK_LIBRARIES ICU::i18n ICU::uc ICU::data)
elseif(dep STREQUAL "expat")
find_package(expat CONFIG QUIET)
if(expat_FOUND)
list(APPEND LIBLCF_LINK_LIBRARIES expat::expat)
else()
# Fallback to old expat detection
find_package(EXPAT REQUIRED QUIET)
list(APPEND LIBLCF_LINK_LIBRARIES EXPAT::EXPAT)
endif()
list(APPEND LIBLCF_LIBRARIES ${EXPAT_LIBRARIES})
if(@LCF_SUPPORT_ICU@)
find_package(ICU COMPONENTS i18n uc data REQUIRED QUIET)
list(APPEND LIBLCF_LIBRARIES ${ICU_LIBRARIES})
list(APPEND LIBLCF_LINK_LIBRARIES ICU::i18n ICU::uc ICU::data)
endif()
if(@LCF_SUPPORT_XML@)
find_package(expat CONFIG QUIET)
if(expat_FOUND)
list(APPEND LIBLCF_LINK_LIBRARIES expat::expat)
else()
# Fallback to old expat detection
find_package(EXPAT REQUIRED QUIET)
list(APPEND LIBLCF_LINK_LIBRARIES EXPAT::EXPAT)
endif()
endforeach()
list(APPEND LIBLCF_LIBRARIES ${EXPAT_LIBRARIES})
endif()

set_target_properties(liblcf::liblcf PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
Expand All @@ -111,12 +128,10 @@ if(LIBLCF_FOUND)
IMPORTED_LOCATION "${LIBLCF_LIBRARY}")
endif()

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.8")
set_property(TARGET liblcf::liblcf APPEND PROPERTY
COMPILE_FEATURES cxx_std_14)
endif()
set_property(TARGET liblcf::liblcf APPEND PROPERTY
COMPILE_FEATURES cxx_std_14)

mark_as_advanced(LIBLCF_LIBRARY_DEPS LIBLCF_LINK_LIBRARIES)
mark_as_advanced(LIBLCF_LINK_LIBRARIES)
endif()
endif()

Expand Down
27 changes: 23 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ AM_CONDITIONAL(CROSS_COMPILING,[test "x$cross_compiling" = "xyes"])
AC_SUBST([LCF_SUPPORT_ICU],[0])
AC_ARG_ENABLE([icu],[AS_HELP_STRING([--disable-icu],[Disable ICU encoding detection (fallback to iconv) [default=no]])])
AS_IF([test "x$enable_icu" != "xno"],[
AX_PKG_CHECK_MODULES([ICU],[],[icu-i18n],[AC_SUBST([LCF_SUPPORT_ICU],[1])])
AX_PKG_CHECK_MODULES([ICU],[],[icu-i18n],[LCF_SUPPORT_ICU=1])
])

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

Expand Down Expand Up @@ -70,13 +70,32 @@ AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

# liblcf-config.cmake (use empty postfix)
# liblcf-config.cmake
AC_PROG_SED
AC_PROG_GREP
# remove the (exec_)prefix from includedir and libdir
prefix_remover_sed="$SED -e s%^\${\(exec_\)\{0,1\}prefix}%% \
-e s%^${prefix}%% -e s%^${exec_prefix}%% -e s%^/%%"
sub_incdir=`AS_ECHO(${includedir}) | ${prefix_remover_sed}`
sub_libdir=`AS_ECHO(${libdir}) | ${prefix_remover_sed}`
# concatenate, if not absolute path
full_libdir=${libdir}
AS_IF([AS_ECHO(${libdir}) | $GREP -v "^/" >/dev/null], [
AS_IF([test "x${exec_prefix}" != "xNONE"],
[full_libdir="${exec_prefix}/${sub_libdir}"],
[test "x${prefix}" != "xNONE"],
[full_libdir="${prefix}/${sub_libdir}"],
[full_libdir="${ac_default_prefix}/${sub_libdir}"])
])
AC_SUBST([CMAKE_INSTALL_INCLUDEDIR], [$sub_incdir])
AC_SUBST([CMAKE_INSTALL_LIBDIR], [$sub_libdir])
AC_SUBST([CMAKE_INSTALL_FULL_LIBDIR], [$full_libdir])
AC_SUBST([CMAKE_DEBUG_POSTFIX])

# Files to generate
AC_CONFIG_FILES([Makefile
builds/liblcf.pc
builds/liblcf-config.cmake
autogen/lcf/config.h:builds/autoconf.config.h.in])
src/lcf/config.h:builds/config.h.in])

AC_OUTPUT

0 comments on commit c6b2e20

Please sign in to comment.