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# ^^^^^^^^^^^^^^^^
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
4158if (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 ()
121136endif ()
122137
0 commit comments