Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@ 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)

# 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)

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 )


Expand Down Expand Up @@ -189,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()
Expand All @@ -198,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()
9 changes: 9 additions & 0 deletions build/cmake/XmlwrappConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/cmake/add_subdirectory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion examples/cmake/find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 7 additions & 5 deletions include/xmlwrapp/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#ifndef _xmlwrapp_version_h_
#define _xmlwrapp_version_h_

#include "xmlwrapp/export.h"

/**
Compile-time major version of the library.

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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

Expand Down
49 changes: 47 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
# 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 version)
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 SOVERSION to the major VERSION component.
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
VISIBILITY_INLINES_HIDDEN ON
VERSION ${version}
SOVERSION ${soversion}
)
endif()
endfunction()

add_library(xmlwrapp ${XMLWRAPP_LIB_TYPE})
target_sources(xmlwrapp
PRIVATE
Expand Down Expand Up @@ -41,9 +82,11 @@ target_link_libraries(xmlwrapp
PUBLIC
${LIBXML2_LIBRARIES}
)
set_target_properties(xmlwrapp PROPERTIES VERSION 6.0.0 SOVERSION 6)
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
Expand Down Expand Up @@ -71,6 +114,8 @@ if( XMLWRAPP_WITH_LIBXSLT )
${LIBXSLT_LIBRARIES}
${LIBEXSLT_LIBRARIES}
)
set_target_properties(xsltwrapp PROPERTIES VERSION 4.0.0 SOVERSION 4)
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 )