diff options
author | Even Rouault <even.rouault@spatialys.com> | 2023-06-19 14:49:59 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-06-22 14:18:07 (GMT) |
commit | 302501ad363628176d15bf91687d9adc4df6e5ce (patch) | |
tree | 4aeeb9c7829d44de060520b4aa0714d8f063d610 | |
parent | af9489a4f2858db0bf666c29f99dd332426f5ca1 (diff) | |
download | CMake-302501ad363628176d15bf91687d9adc4df6e5ce.zip CMake-302501ad363628176d15bf91687d9adc4df6e5ce.tar.gz CMake-302501ad363628176d15bf91687d9adc4df6e5ce.tar.bz2 |
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
-rw-r--r-- | Help/release/dev/FindEXPAT-static.rst | 5 | ||||
-rw-r--r-- | Modules/FindEXPAT.cmake | 23 |
2 files changed, 26 insertions, 2 deletions
diff --git a/Help/release/dev/FindEXPAT-static.rst b/Help/release/dev/FindEXPAT-static.rst new file mode 100644 index 0000000..8808ebd --- /dev/null +++ b/Help/release/dev/FindEXPAT-static.rst @@ -0,0 +1,5 @@ +FindEXPAT-static +---------------- + +* The :module:`FindEXPAT` module gained a ``EXPAT_USE_STATIC_LIBS`` hint + to select static libraries. diff --git a/Modules/FindEXPAT.cmake b/Modules/FindEXPAT.cmake index 3bedc73..762931e 100644 --- a/Modules/FindEXPAT.cmake +++ b/Modules/FindEXPAT.cmake @@ -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) |