From 848904404c5349a0c9418259ec8a6d5b37de7cc0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 Jul 2025 23:21:53 +0200 Subject: [PATCH 1/9] Fix search for pkg-confg modules Fix syntax of the version check: previously, we searched for any version of libxml-2.0 and then, if not found, for ">=" and "2.4.28" modules (!). Remove spaces to do what we really need to do. Also use pkg_check_modules() rather than pkg_search_module() because the latter is meant for searching for multiple modules, but here we know which module we need, so use the simpler command instead. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d99d860..8b39a9b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,11 +58,11 @@ set(CMAKE_CXX_COMPILER_VISIBILITY_PRESET hidden) find_package(PkgConfig) -pkg_search_module(LIBXML2 REQUIRED libxml-2.0 >= 2.4.28) +pkg_check_modules(LIBXML2 REQUIRED libxml-2.0>=2.4.28) if( XMLWRAPP_WITH_LIBXSLT ) - pkg_search_module(LIBXSLT REQUIRED libxslt >= 1.1.6) - pkg_search_module(LIBEXSLT REQUIRED libexslt) + pkg_check_modules(LIBXSLT REQUIRED libxslt>=1.1.6) + pkg_check_modules(LIBEXSLT REQUIRED libexslt) endif( XMLWRAPP_WITH_LIBXSLT ) From 9f529b80270bff0551401b73bd3c0e8ec95eb040 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 Jul 2025 23:25:09 +0200 Subject: [PATCH 2/9] Correct comment for XMLWRAPP_WITH_LIBXSLT There was a typo changing the meaning of the comment there. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b39a9b3..920032b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,8 +47,8 @@ option(XMLWRAPP_DOC "Build and install the documentation (requires Doxygen)" ${P option(XMLWRAPP_EXAMPLES "Build examples" ${PROJECT_IS_TOP_LEVEL}) option(XMLWRAPP_TESTS "Build tests" ${PROJECT_IS_TOP_LEVEL}) -# This is always disabled but can be disabled by the super-project if it is -# not needed before calling add_subdirectory(). +# This is always enabled but can be disabled by the super-project if it is not +# needed before calling add_subdirectory(). option(XMLWRAPP_WITH_LIBXSLT "Build libxsltwrapp library" ON) include(GNUInstallDirs) From b2acf8bfcc52f66bb6d7be4ef614bf84718f043a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 Jul 2025 23:57:59 +0200 Subject: [PATCH 3/9] Fix using hidden ELF visibility for the shared libraries Setting CMAKE_CXX_COMPILER_VISIBILITY_PRESET didn't work (any more?), so do it properly, by setting per-target options. Also define the necessary symbols, i.e. DLL_EXPORT when building the libraries and XMLWRAPP_USE_DLL or XSLTWRAPP_USE_DLL when using them. --- CMakeLists.txt | 2 -- src/CMakeLists.txt | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 920032b5..c3f6fc79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,8 +54,6 @@ option(XMLWRAPP_WITH_LIBXSLT "Build libxsltwrapp library" ON) include(GNUInstallDirs) set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/xmlwrapp) -set(CMAKE_CXX_COMPILER_VISIBILITY_PRESET hidden) - find_package(PkgConfig) pkg_check_modules(LIBXML2 REQUIRED libxml-2.0>=2.4.28) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5cc0e9a5..dc8b535e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,24 @@ +# Configure the given library to use hidden visibility. +# +# Note that this does nothing when shared libraries are not used. +function(use_hidden_visibility target) + if (XMLWRAPP_SHARED) + # Construct XMLWRAPP_USE_DLL or XSLTWRAPP_USE_DLL symbol name. + string(TOUPPER "${target}_USE_DLL" use_dll_symbol) + target_compile_definitions(${target} + PRIVATE + HAVE_VISIBILITY + INTERFACE + ${use_dll_symbol} + ) + set_target_properties(${target} PROPERTIES + DEFINE_SYMBOL "DLL_EXPORT" + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON + ) + endif() +endfunction() + add_library(xmlwrapp ${XMLWRAPP_LIB_TYPE}) target_sources(xmlwrapp PRIVATE @@ -42,6 +63,7 @@ target_link_libraries(xmlwrapp ${LIBXML2_LIBRARIES} ) set_target_properties(xmlwrapp PROPERTIES VERSION 6.0.0 SOVERSION 6) +use_hidden_visibility(xmlwrapp) install (TARGETS xmlwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) if( XMLWRAPP_WITH_LIBXSLT ) @@ -72,5 +94,6 @@ if( XMLWRAPP_WITH_LIBXSLT ) ${LIBEXSLT_LIBRARIES} ) set_target_properties(xsltwrapp PROPERTIES VERSION 4.0.0 SOVERSION 4) + use_hidden_visibility(xsltwrapp) install (TARGETS xsltwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif( XMLWRAPP_WITH_LIBXSLT ) From 25938ed42e0b0789aa4fe9f389136d6ebd4dc065 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Jul 2025 00:04:03 +0200 Subject: [PATCH 4/9] Use $ORIGIN in the runpath of libxsltwrapp.so This makes the binary relocatable. Rename use_hidden_visibility() function to setup_shared_library() as it now does more than just sets up the hidden visibility. --- src/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc8b535e..c61eeac7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,10 @@ -# Configure the given library to use hidden visibility. +# Configure shared library with the given name. +# +# Set properties for using hidden ELF visibility, defining proper DLL-related +# symbols and use $ORIGIN in the runpath. # # Note that this does nothing when shared libraries are not used. -function(use_hidden_visibility target) +function(setup_shared_library target) if (XMLWRAPP_SHARED) # Construct XMLWRAPP_USE_DLL or XSLTWRAPP_USE_DLL symbol name. string(TOUPPER "${target}_USE_DLL" use_dll_symbol) @@ -12,6 +15,7 @@ function(use_hidden_visibility target) ${use_dll_symbol} ) set_target_properties(${target} PROPERTIES + BUILD_RPATH_USE_ORIGIN ON DEFINE_SYMBOL "DLL_EXPORT" CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON @@ -63,7 +67,7 @@ target_link_libraries(xmlwrapp ${LIBXML2_LIBRARIES} ) set_target_properties(xmlwrapp PROPERTIES VERSION 6.0.0 SOVERSION 6) -use_hidden_visibility(xmlwrapp) +setup_shared_library(xmlwrapp) install (TARGETS xmlwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) if( XMLWRAPP_WITH_LIBXSLT ) @@ -94,6 +98,6 @@ if( XMLWRAPP_WITH_LIBXSLT ) ${LIBEXSLT_LIBRARIES} ) set_target_properties(xsltwrapp PROPERTIES VERSION 4.0.0 SOVERSION 4) - use_hidden_visibility(xsltwrapp) + setup_shared_library(xsltwrapp) install (TARGETS xsltwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif( XMLWRAPP_WITH_LIBXSLT ) From 52585023b0142dcb4afe5341b2ea0b1ac4e52b38 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Jul 2025 00:11:30 +0200 Subject: [PATCH 5/9] Move setting VERSION and SOVERSION into helper function too As this is something that only needs to be done for shared libraries (and always needs to be done for them), do it in the same function that is already used for setting visibility and runpath options. --- src/CMakeLists.txt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c61eeac7..985ae90d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,10 @@ -# Configure shared library with the given name. +# Configure shared library with the given name and (full) ELF version. # # Set properties for using hidden ELF visibility, defining proper DLL-related # symbols and use $ORIGIN in the runpath. # # Note that this does nothing when shared libraries are not used. -function(setup_shared_library target) +function(setup_shared_library target version) if (XMLWRAPP_SHARED) # Construct XMLWRAPP_USE_DLL or XSLTWRAPP_USE_DLL symbol name. string(TOUPPER "${target}_USE_DLL" use_dll_symbol) @@ -14,11 +14,18 @@ function(setup_shared_library target) INTERFACE ${use_dll_symbol} ) + + # Set SOVERSION to the major VERSION component. + string(REPLACE "." ";" version_as_list ${version}) + list(GET version_as_list 0 soversion) + set_target_properties(${target} PROPERTIES BUILD_RPATH_USE_ORIGIN ON DEFINE_SYMBOL "DLL_EXPORT" CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON + VERSION ${version} + SOVERSION ${soversion} ) endif() endfunction() @@ -66,8 +73,7 @@ target_link_libraries(xmlwrapp PUBLIC ${LIBXML2_LIBRARIES} ) -set_target_properties(xmlwrapp PROPERTIES VERSION 6.0.0 SOVERSION 6) -setup_shared_library(xmlwrapp) +setup_shared_library(xmlwrapp 6.0.0) install (TARGETS xmlwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) if( XMLWRAPP_WITH_LIBXSLT ) @@ -97,7 +103,6 @@ if( XMLWRAPP_WITH_LIBXSLT ) ${LIBXSLT_LIBRARIES} ${LIBEXSLT_LIBRARIES} ) - set_target_properties(xsltwrapp PROPERTIES VERSION 4.0.0 SOVERSION 4) - setup_shared_library(xsltwrapp) + setup_shared_library(xsltwrapp 4.0.0) install (TARGETS xsltwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif( XMLWRAPP_WITH_LIBXSLT ) From 705e02e69299e02d7059e425b6dc0fe0b4ccb774 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Jul 2025 00:18:50 +0200 Subject: [PATCH 6/9] Add XMLWRAPP_NAME_{PREFIX,SUFFIX} CMake build options Allow customizing the shared libraries names. This is useful to avoid conflicts with the other libraries that may be present on the system. --- CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3f6fc79..4558ce98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,11 @@ option(XMLWRAPP_TESTS "Build tests" ${PROJECT_IS_TOP_LEVEL}) # needed before calling add_subdirectory(). option(XMLWRAPP_WITH_LIBXSLT "Build libxsltwrapp library" ON) +# These options are not set by default but can be used to customize the naming +# of the produced libraries. +set(XMLWRAPP_NAME_PREFIX "" CACHE STRING "Use the given prefix for the libraries") +set(XMLWRAPP_NAME_SUFFIX "" CACHE STRING "Use the given suffix for the libraries") + include(GNUInstallDirs) set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/xmlwrapp) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 985ae90d..c6c243bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,16 @@ function(setup_shared_library target version) string(REPLACE "." ";" version_as_list ${version}) list(GET version_as_list 0 soversion) + set(output_name "${target}") + if( XMLWRAPP_NAME_PREFIX ) + set(output_name "${XMLWRAPP_NAME_PREFIX}${output_name}") + endif() + if( XMLWRAPP_NAME_SUFFIX ) + set(output_name "${output_name}${XMLWRAPP_NAME_SUFFIX}") + endif() + set_target_properties(${target} PROPERTIES + OUTPUT_NAME ${output_name} BUILD_RPATH_USE_ORIGIN ON DEFINE_SYMBOL "DLL_EXPORT" CXX_VISIBILITY_PRESET hidden From 8458396ff1c5f4826e93f8774c584b0c6f2fb87e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Jul 2025 00:24:00 +0200 Subject: [PATCH 7/9] Export recently added version-related functions from the DLL Add missing XMLWRAPP_API to the functions declarations. --- include/xmlwrapp/version.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/xmlwrapp/version.h b/include/xmlwrapp/version.h index 1bac73ed..a304d50b 100644 --- a/include/xmlwrapp/version.h +++ b/include/xmlwrapp/version.h @@ -39,6 +39,8 @@ #ifndef _xmlwrapp_version_h_ #define _xmlwrapp_version_h_ +#include "xmlwrapp/export.h" + /** Compile-time major version of the library. @@ -118,7 +120,7 @@ namespace xml @since 0.10.0 */ -int get_major_version(); +XMLWRAPP_API int get_major_version(); /** Return minor runtime version of xmlwrapp library. @@ -127,7 +129,7 @@ int get_major_version(); @since 0.10.0 */ -int get_minor_version(); +XMLWRAPP_API int get_minor_version(); /** Return micro runtime version of xmlwrapp library. @@ -136,7 +138,7 @@ int get_minor_version(); @since 0.10.0 */ -int get_micro_version(); +XMLWRAPP_API int get_micro_version(); /** Return the full runtime version of xmlwrapp library. @@ -147,7 +149,7 @@ int get_micro_version(); @since 0.10.0 */ -const char* get_version_string(); +XMLWRAPP_API const char* get_version_string(); /** Check that the library version is at least the given one. @@ -159,7 +161,7 @@ const char* get_version_string(); @since 0.10.0 */ -bool check_version(int major, int minor, int micro); +XMLWRAPP_API bool check_version(int major, int minor, int micro); } // namespace xml From 186904abb19715e771de1b11db1284962b67a612 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Jul 2025 23:39:32 +0200 Subject: [PATCH 8/9] Skip build summary during reconfiguration if nothing changed Don't give the same message every time CMake is rerun, this is more annoying than useful. --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4558ce98..2f32b284 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,7 +192,14 @@ add_custom_target(distcheck VERBATIM ) -# Give build summary at the end. +# Give build summary at the end but only if it's the first time we're running, +# as indicated by XMLWRAPP_SUMMARY not being cached yet, or if it has changed. +set(XMLWRAPP_SUMMARY_NOW + "${XMLWRAPP_VERSION}-${XMLWRAPP_LIB_TYPE}-${CMAKE_BUILD_TYPE}-${XMLWRAPP_WITH_LIBXSLT}-${XMLWRAPP_DOC}-${XMLWRAPP_EXAMPLES}-${XMLWRAPP_TESTS}" +) +if(NOT "${XMLWRAPP_SUMMARY_NOW}" STREQUAL "$CACHE{XMLWRAPP_SUMMARY}") +set(XMLWRAPP_SUMMARY ${XMLWRAPP_SUMMARY_NOW} CACHE INTERNAL "xmlwrapp internal build summary") + if (CMAKE_BUILD_TYPE) set(XMLWRAPP_CONFIG_DESCRIPTION " in ${CMAKE_BUILD_TYPE} configuration") endif() @@ -201,3 +208,5 @@ message(STATUS " Build xsltwrapp: ${XMLWRAPP_WITH_LIBXSLT}") message(STATUS " Documentation: ${XMLWRAPP_DOC}") message(STATUS " Examples: ${XMLWRAPP_EXAMPLES}") message(STATUS " Tests: ${XMLWRAPP_TESTS}") + +endif() From ad9843445d55e4209c497e9fe72e07e8e2a5c2d6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Jul 2025 23:26:44 +0200 Subject: [PATCH 9/9] Add xmlwrapp:: alias CMake targets The library is expected to define these targets too by convention, so do it. --- build/cmake/XmlwrappConfig.cmake.in | 9 +++++++++ examples/cmake/add_subdirectory/CMakeLists.txt | 2 +- examples/cmake/find_package/CMakeLists.txt | 2 +- src/CMakeLists.txt | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build/cmake/XmlwrappConfig.cmake.in b/build/cmake/XmlwrappConfig.cmake.in index eddbbd9e..099082f1 100644 --- a/build/cmake/XmlwrappConfig.cmake.in +++ b/build/cmake/XmlwrappConfig.cmake.in @@ -31,6 +31,15 @@ endif(XMLWRAPP_XSLT_FOUND) # Our library dependencies (contains definitions form IMPORTED targets) include("${CMAKE_CURRENT_LIST_DIR}/XmlwrappTargets.cmake") +# Create alias targets if they don't exist yet (normally they should not, but +# if find_package() is somehow used twice, this might happen). +if(NOT TARGET xmlwrapp::xmlwrapp) + add_library(xmlwrapp::xmlwrapp ALIAS xmlwrapp) +endif() +if(XMLWRAPP_XSLT_FOUND AND NOT TARGET xmlwrapp::xsltwrapp) + add_library(xmlwrapp::xsltwrapp ALIAS xsltwrapp) +endif() + # These are imported targets created by XmlwrappTargets.cmake set(XMLWRAPP_XML_LIBRARIES xmlwrapp) if(XMLWRAPP_XSLT_FOUND) diff --git a/examples/cmake/add_subdirectory/CMakeLists.txt b/examples/cmake/add_subdirectory/CMakeLists.txt index f825e2c7..3aeebf8c 100644 --- a/examples/cmake/add_subdirectory/CMakeLists.txt +++ b/examples/cmake/add_subdirectory/CMakeLists.txt @@ -43,4 +43,4 @@ set(XMLWRAPP_WITH_LIBXSLT OFF) add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/xmlwrapp) add_executable(example example.cpp) -target_link_libraries(example PRIVATE xmlwrapp) +target_link_libraries(example PRIVATE xmlwrapp::xmlwrapp) diff --git a/examples/cmake/find_package/CMakeLists.txt b/examples/cmake/find_package/CMakeLists.txt index 647548ca..dbb299d3 100644 --- a/examples/cmake/find_package/CMakeLists.txt +++ b/examples/cmake/find_package/CMakeLists.txt @@ -38,4 +38,4 @@ project(XmlwrappFindPackageExample find_package(Xmlwrapp 0.10 REQUIRED) add_executable(example example.cpp) -target_link_libraries(example PRIVATE xmlwrapp) +target_link_libraries(example PRIVATE xmlwrapp::xmlwrapp) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c6c243bb..059ac99e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,6 +85,8 @@ target_link_libraries(xmlwrapp setup_shared_library(xmlwrapp 6.0.0) install (TARGETS xmlwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) +add_library(xmlwrapp::xmlwrapp ALIAS xmlwrapp) + if( XMLWRAPP_WITH_LIBXSLT ) add_library(xsltwrapp ${XMLWRAPP_LIB_TYPE}) target_sources(xsltwrapp @@ -114,4 +116,6 @@ if( XMLWRAPP_WITH_LIBXSLT ) ) setup_shared_library(xsltwrapp 4.0.0) install (TARGETS xsltwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + add_library(xmlwrapp::xsltwrapp ALIAS xsltwrapp) endif( XMLWRAPP_WITH_LIBXSLT )