cmake/Modules/FindEXPAT.cmake

80 lines
2.5 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2014-08-03 19:52:23 +02:00
#.rst:
# FindEXPAT
# ---------
#
2018-01-26 17:06:56 +01:00
# Find the native Expat headers and library.
2014-08-03 19:52:23 +02:00
#
2018-01-26 17:06:56 +01:00
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
2018-01-26 17:06:56 +01:00
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``EXPAT::EXPAT``
# The Expat ``expat`` library, if found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``EXPAT_INCLUDE_DIRS``
# where to find expat.h, etc.
# ``EXPAT_LIBRARIES``
# the libraries to link against to use Expat.
# ``EXPAT_FOUND``
# true if the Expat headers and libraries were found.
2014-08-03 19:52:23 +02:00
#
2016-10-30 18:24:19 +01:00
find_package(PkgConfig QUIET)
pkg_check_modules(PC_EXPAT QUIET expat)
2009-10-04 10:30:41 +03:00
# Look for the header file.
2016-10-30 18:24:19 +01:00
find_path(EXPAT_INCLUDE_DIR NAMES expat.h HINTS ${PC_EXPAT_INCLUDE_DIRS})
# Look for the library.
2016-10-30 18:24:19 +01:00
find_library(EXPAT_LIBRARY NAMES expat libexpat HINTS ${PC_EXPAT_LIBRARY_DIRS})
2012-04-19 19:04:21 +03:00
if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h")
file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str
REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$")
unset(EXPAT_VERSION_STRING)
foreach(VPART MAJOR MINOR MICRO)
foreach(VLINE ${expat_version_str})
2015-04-27 22:25:09 +02:00
if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$")
set(EXPAT_VERSION_PART "${CMAKE_MATCH_1}")
2012-04-19 19:04:21 +03:00
if(EXPAT_VERSION_STRING)
2016-10-30 18:24:19 +01:00
string(APPEND EXPAT_VERSION_STRING ".${EXPAT_VERSION_PART}")
2013-03-16 19:13:01 +02:00
else()
2012-04-19 19:04:21 +03:00
set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}")
2013-03-16 19:13:01 +02:00
endif()
2012-04-19 19:04:21 +03:00
endif()
2013-03-16 19:13:01 +02:00
endforeach()
endforeach()
endif ()
2012-04-19 19:04:21 +03:00
2013-03-16 19:13:01 +02:00
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
2012-04-19 19:04:21 +03:00
FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
VERSION_VAR EXPAT_VERSION_STRING)
2018-01-26 17:06:56 +01:00
# Copy the results to the output variables and target.
2013-03-16 19:13:01 +02:00
if(EXPAT_FOUND)
set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
2018-01-26 17:06:56 +01:00
if(NOT TARGET EXPAT::EXPAT)
add_library(EXPAT::EXPAT UNKNOWN IMPORTED)
set_target_properties(EXPAT::EXPAT PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${EXPAT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
endif()
2013-03-16 19:13:01 +02:00
endif()
2013-03-16 19:13:01 +02:00
mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)