1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find the XSL Transformations, Extensible Stylesheet Language
9 Transformations (XSLT) library (LibXslt)
14 .. versionadded:: 3.18
16 The following :prop_tgt:`IMPORTED` targets may be defined:
19 If the libxslt library has been found
21 If the libexslt library has been found
23 If the xsltproc command-line executable has been found
28 This module will set the following variables in your project:
30 LIBXSLT_FOUND - system has LibXslt
31 LIBXSLT_INCLUDE_DIR - the LibXslt include directory
32 LIBXSLT_LIBRARIES - Link these to LibXslt
33 LIBXSLT_DEFINITIONS - Compiler switches required for using LibXslt
34 LIBXSLT_VERSION_STRING - version of LibXslt found (since CMake 2.8.8)
36 Additionally, the following two variables are set (but not required
39 ``LIBXSLT_EXSLT_INCLUDE_DIR``
40 .. versionadded:: 3.18
41 The include directory for exslt.
42 ``LIBXSLT_EXSLT_LIBRARIES``
43 Link to these if you need to link against the exslt library.
44 ``LIBXSLT_XSLTPROC_EXECUTABLE``
45 Contains the full path to the xsltproc executable if found.
46 #]=======================================================================]
49 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
51 # use pkg-config to get the directories and then use these values
52 # in the find_path() and find_library() calls
53 find_package(PkgConfig QUIET)
54 PKG_CHECK_MODULES(PC_LIBXSLT QUIET libxslt)
55 set(LIBXSLT_DEFINITIONS ${PC_LIBXSLT_CFLAGS_OTHER})
57 find_path(LIBXSLT_INCLUDE_DIR NAMES libxslt/xslt.h
59 ${PC_LIBXSLT_INCLUDEDIR}
60 ${PC_LIBXSLT_INCLUDE_DIRS}
63 # CMake 3.17 and below used 'LIBXSLT_LIBRARIES' as the name of
64 # the cache entry storing the find_library result. Use the
65 # value if it was set by the project or user.
66 if(DEFINED LIBXSLT_LIBRARIES AND NOT DEFINED LIBXSLT_LIBRARY)
67 set(LIBXSLT_LIBRARY ${LIBXSLT_LIBRARIES})
70 find_library(LIBXSLT_LIBRARY NAMES xslt libxslt
73 ${PC_LIBXSLT_LIBRARY_DIRS}
76 set(LIBXSLT_LIBRARIES ${LIBXSLT_LIBRARY})
78 PKG_CHECK_MODULES(PC_LIBXSLT_EXSLT QUIET libexslt)
79 set(LIBXSLT_EXSLT_DEFINITIONS ${PC_LIBXSLT_EXSLT_CFLAGS_OTHER})
81 find_path(LIBXSLT_EXSLT_INCLUDE_DIR NAMES libexslt/exslt.h
83 ${PC_LIBXSLT_EXSLT_INCLUDEDIR}
84 ${PC_LIBXSLT_EXSLT_INCLUDE_DIRS}
87 find_library(LIBXSLT_EXSLT_LIBRARY NAMES exslt libexslt
90 ${PC_LIBXSLT_LIBRARY_DIRS}
91 ${PC_LIBXSLT_EXSLT_LIBDIR}
92 ${PC_LIBXSLT_EXSLT_LIBRARY_DIRS}
95 set(LIBXSLT_EXSLT_LIBRARIES ${LIBXSLT_EXSLT_LIBRARY} )
97 find_program(LIBXSLT_XSLTPROC_EXECUTABLE xsltproc)
99 if(PC_LIBXSLT_VERSION)
100 set(LIBXSLT_VERSION_STRING ${PC_LIBXSLT_VERSION})
101 elseif(LIBXSLT_INCLUDE_DIR AND EXISTS "${LIBXSLT_INCLUDE_DIR}/libxslt/xsltconfig.h")
102 file(STRINGS "${LIBXSLT_INCLUDE_DIR}/libxslt/xsltconfig.h" libxslt_version_str
103 REGEX "^#define[\t ]+LIBXSLT_DOTTED_VERSION[\t ]+\".*\"")
105 string(REGEX REPLACE "^#define[\t ]+LIBXSLT_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
106 LIBXSLT_VERSION_STRING "${libxslt_version_str}")
107 unset(libxslt_version_str)
110 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
111 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXslt
112 REQUIRED_VARS LIBXSLT_LIBRARIES LIBXSLT_INCLUDE_DIR
113 VERSION_VAR LIBXSLT_VERSION_STRING)
115 mark_as_advanced(LIBXSLT_INCLUDE_DIR
117 LIBXSLT_EXSLT_INCLUDE_DIR
118 LIBXSLT_EXSLT_LIBRARY
119 LIBXSLT_XSLTPROC_EXECUTABLE)
121 if(LIBXSLT_FOUND AND NOT TARGET LibXslt::LibXslt)
122 add_library(LibXslt::LibXslt UNKNOWN IMPORTED)
123 set_target_properties(LibXslt::LibXslt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXSLT_INCLUDE_DIR}")
124 set_target_properties(LibXslt::LibXslt PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXSLT_DEFINITIONS}")
125 set_property(TARGET LibXslt::LibXslt APPEND PROPERTY IMPORTED_LOCATION "${LIBXSLT_LIBRARY}")
128 if(LIBXSLT_FOUND AND NOT TARGET LibXslt::LibExslt)
129 add_library(LibXslt::LibExslt UNKNOWN IMPORTED)
130 set_target_properties(LibXslt::LibExslt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXSLT_EXSLT_INCLUDE_DIR}")
131 set_target_properties(LibXslt::LibExslt PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXSLT_EXSLT_DEFINITIONS}")
132 set_property(TARGET LibXslt::LibExslt APPEND PROPERTY IMPORTED_LOCATION "${LIBXSLT_EXSLT_LIBRARY}")
135 if(LIBXSLT_XSLTPROC_EXECUTABLE AND NOT TARGET LibXslt::xsltproc)
136 add_executable(LibXslt::xsltproc IMPORTED)
137 set_target_properties(LibXslt::xsltproc PROPERTIES IMPORTED_LOCATION "${LIBXSLT_XSLTPROC_EXECUTABLE}")