FindEXPAT: add a EXPAT_USE_STATIC_LIBS hint

The effect of that hint is to restrict the candidate library names, but
more essentially to set the `XML_STATIC` compile definitions which is
required to get proper linking.

Vcpkg-Issue: https://github.com/microsoft/vcpkg/issues/1100
GDAL-Issue: https://github.com/OSGeo/gdal/issues/7955
This commit is contained in:
Even Rouault
2023-06-19 16:49:59 +02:00
committed by Brad King
parent af9489a4f2
commit 302501ad36
2 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
FindEXPAT-static
----------------
* The :module:`FindEXPAT` module gained a ``EXPAT_USE_STATIC_LIBS`` hint
to select static libraries.

View File

@@ -30,6 +30,15 @@ This module will set the following variables in your project:
``EXPAT_FOUND``
true if the Expat headers and libraries were found.
Hints
^^^^^
``EXPAT_USE_STATIC_LIBS``
.. versionadded:: 3.28
Set to ``TRUE`` to use static libraries.
#]=======================================================================]
find_package(PkgConfig QUIET)
@@ -43,8 +52,13 @@ set(EXPAT_NAMES expat expatw)
set(EXPAT_NAMES_DEBUG expatd expatwd)
if(WIN32)
list(APPEND EXPAT_NAMES expatMT expatMD expatwMT expatwMD)
list(APPEND EXPAT_NAMES_DEBUG expatdMT expatdMD expatwdMT expatwdMD)
if(EXPAT_USE_STATIC_LIBS)
list(APPEND EXPAT_NAMES expatMT expatwMT)
list(APPEND EXPAT_NAMES_DEBUG expatdMT expatwdMT)
else()
list(APPEND EXPAT_NAMES expatMT expatMD expatwMT expatwMD)
list(APPEND EXPAT_NAMES_DEBUG expatdMT expatdMD expatwdMT expatwdMD)
endif()
endif()
# Allow EXPAT_LIBRARY to be set manually, as the location of the expat library
@@ -115,6 +129,11 @@ if(EXPAT_FOUND)
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
if(EXPAT_USE_STATIC_LIBS)
set_property(TARGET EXPAT::EXPAT APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS "XML_STATIC")
endif()
if(EXPAT_LIBRARY_RELEASE)
set_property(TARGET EXPAT::EXPAT APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)