2023-07-19 09:20:14 -04:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
2023-04-21 13:24:59 -07:00
|
|
|
|
|
|
|
# Policy configuration; this *MUST* be specified before project is defined
|
|
|
|
if(POLICY CMP0091)
|
|
|
|
cmake_policy(SET CMP0091 NEW) # Enables use of MSVC_RUNTIME_LIBRARY
|
|
|
|
endif()
|
|
|
|
|
2023-09-07 11:55:13 -07:00
|
|
|
project(pugixml VERSION 1.14 LANGUAGES CXX)
|
2015-12-03 12:33:44 +02:00
|
|
|
|
2019-09-28 10:47:15 -07:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
include(CMakeDependentOption)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
cmake_dependent_option(PUGIXML_USE_VERSIONED_LIBDIR
|
2019-09-28 10:47:15 -07:00
|
|
|
"Use a private subdirectory to install the headers and libraries" OFF
|
|
|
|
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
cmake_dependent_option(PUGIXML_USE_POSTFIX
|
2019-09-28 10:47:15 -07:00
|
|
|
"Use separate postfix for each configuration to make sure you can install multiple build outputs" OFF
|
|
|
|
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
cmake_dependent_option(PUGIXML_STATIC_CRT
|
2019-09-28 10:47:15 -07:00
|
|
|
"Use static MSVC RT libraries" OFF
|
|
|
|
"MSVC" OFF)
|
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
cmake_dependent_option(PUGIXML_BUILD_TESTS
|
2019-09-28 13:02:55 -07:00
|
|
|
"Build pugixml tests" OFF
|
2023-10-06 10:02:15 +02:00
|
|
|
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2021-06-15 09:00:31 +02:00
|
|
|
# Custom build defines
|
2021-06-19 11:22:31 +02:00
|
|
|
set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options")
|
|
|
|
separate_arguments(PUGIXML_BUILD_DEFINES)
|
2021-06-15 09:00:31 +02:00
|
|
|
|
2021-06-19 12:51:27 +02:00
|
|
|
# Technically not needed for this file. This is builtin CMAKE global variable.
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
|
|
|
|
|
|
|
|
# Expose option to build PUGIXML as static as well when the global BUILD_SHARED_LIBS variable is set
|
|
|
|
cmake_dependent_option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS
|
|
|
|
"Build both shared and static libraries" OFF
|
|
|
|
"BUILD_SHARED_LIBS" OFF)
|
2022-02-08 19:56:41 -08:00
|
|
|
|
2021-06-26 23:16:24 +02:00
|
|
|
# Expose options from the pugiconfig.hpp
|
2021-06-23 11:05:34 +02:00
|
|
|
option(PUGIXML_WCHAR_MODE "Enable wchar_t mode" OFF)
|
|
|
|
option(PUGIXML_COMPACT "Enable compact mode" OFF)
|
2023-10-12 02:05:35 +04:00
|
|
|
option(PUGIXML_INSTALL "Enable installation rules" ON)
|
2021-06-23 11:05:34 +02:00
|
|
|
|
2021-06-26 23:16:24 +02:00
|
|
|
# Advanced options from pugiconfig.hpp
|
2021-06-23 11:05:34 +02:00
|
|
|
option(PUGIXML_NO_XPATH "Disable XPath" OFF)
|
|
|
|
option(PUGIXML_NO_STL "Disable STL" OFF)
|
|
|
|
option(PUGIXML_NO_EXCEPTIONS "Disable Exceptions" OFF)
|
2021-06-26 23:16:24 +02:00
|
|
|
mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS)
|
2021-06-23 11:05:34 +02:00
|
|
|
|
2021-06-28 19:51:20 +02:00
|
|
|
set(PUGIXML_PUBLIC_DEFINITIONS
|
|
|
|
$<$<BOOL:${PUGIXML_WCHAR_MODE}>:PUGIXML_WCHAR_MODE>
|
|
|
|
$<$<BOOL:${PUGIXML_COMPACT}>:PUGIXML_COMPACT>
|
|
|
|
$<$<BOOL:${PUGIXML_NO_XPATH}>:PUGIXML_NO_XPATH>
|
|
|
|
$<$<BOOL:${PUGIXML_NO_STL}>:PUGIXML_NO_STL>
|
|
|
|
$<$<BOOL:${PUGIXML_NO_EXCEPTIONS}>:PUGIXML_NO_EXCEPTIONS>)
|
|
|
|
|
2019-10-01 10:20:30 -07:00
|
|
|
# This is used to backport a CMake 3.15 feature, but is also forwards compatible
|
2019-09-28 10:47:15 -07:00
|
|
|
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY
|
2021-01-11 16:13:52 +01:00
|
|
|
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>)
|
2019-09-28 10:47:15 -07:00
|
|
|
endif()
|
|
|
|
|
2019-09-28 13:02:55 -07:00
|
|
|
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2019-09-28 10:47:15 -07:00
|
|
|
endif()
|
2018-01-18 10:43:05 -05:00
|
|
|
|
2019-09-28 13:02:55 -07:00
|
|
|
if (NOT DEFINED CMAKE_CXX_STANDARD)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
2019-09-19 16:27:40 +02:00
|
|
|
endif()
|
2010-07-19 09:57:32 +00:00
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
if (PUGIXML_USE_POSTFIX)
|
2019-09-28 13:02:55 -07:00
|
|
|
set(CMAKE_RELWITHDEBINFO_POSTFIX _r)
|
|
|
|
set(CMAKE_MINSIZEREL_POSTFIX _m)
|
|
|
|
set(CMAKE_DEBUG_POSTFIX _d)
|
2014-07-28 16:08:43 +00:00
|
|
|
endif()
|
|
|
|
|
2019-10-01 10:20:30 -07:00
|
|
|
if (CMAKE_VERSION VERSION_LESS 3.15)
|
|
|
|
set(msvc-rt $<TARGET_PROPERTY:MSVC_RUNTIME_LIBRARY>)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2019-10-01 10:20:30 -07:00
|
|
|
set(msvc-rt-mtd-shared $<STREQUAL:${msvc-rt},MultiThreadedDebugDLL>)
|
|
|
|
set(msvc-rt-mtd-static $<STREQUAL:${msvc-rt},MultiThreadedDebug>)
|
|
|
|
set(msvc-rt-mt-shared $<STREQUAL:${msvc-rt},MultiThreadedDLL>)
|
|
|
|
set(msvc-rt-mt-static $<STREQUAL:${msvc-rt},MultiThreaded>)
|
|
|
|
unset(msvc-rt)
|
|
|
|
|
|
|
|
set(msvc-rt-mtd-shared $<${msvc-rt-mtd-shared}:-MDd>)
|
|
|
|
set(msvc-rt-mtd-static $<${msvc-rt-mtd-static}:-MTd>)
|
|
|
|
set(msvc-rt-mt-shared $<${msvc-rt-mt-shared}:-MD>)
|
|
|
|
set(msvc-rt-mt-static $<${msvc-rt-mt-static}:-MT>)
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
set(versioned-dir $<$<BOOL:${PUGIXML_USE_VERSIONED_LIBDIR}>:/pugixml-${PROJECT_VERSION}>)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2020-04-27 13:26:37 -04:00
|
|
|
set(libs)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2021-06-19 12:51:27 +02:00
|
|
|
if (BUILD_SHARED_LIBS)
|
2020-04-27 13:26:37 -04:00
|
|
|
add_library(pugixml-shared SHARED
|
|
|
|
${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc
|
|
|
|
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
|
|
|
|
add_library(pugixml::shared ALIAS pugixml-shared)
|
|
|
|
list(APPEND libs pugixml-shared)
|
2022-10-20 13:35:04 -07:00
|
|
|
string(CONCAT pugixml.msvc $<OR:
|
|
|
|
$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>,
|
|
|
|
$<CXX_COMPILER_ID:MSVC>
|
|
|
|
>)
|
2020-04-27 13:26:37 -04:00
|
|
|
|
|
|
|
set_property(TARGET pugixml-shared PROPERTY EXPORT_NAME shared)
|
|
|
|
target_include_directories(pugixml-shared
|
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
|
|
|
target_compile_definitions(pugixml-shared
|
2021-06-28 13:36:55 +02:00
|
|
|
PUBLIC
|
2021-06-28 12:41:11 +02:00
|
|
|
${PUGIXML_BUILD_DEFINES}
|
2021-06-28 19:51:20 +02:00
|
|
|
${PUGIXML_PUBLIC_DEFINITIONS}
|
2021-06-28 13:36:55 +02:00
|
|
|
PRIVATE
|
2022-10-20 13:35:04 -07:00
|
|
|
PUGIXML_API=$<IF:${pugixml.msvc},__declspec\(dllexport\),__attribute__\(\(visibility\("default"\)\)\)>
|
2022-04-20 13:00:41 +02:00
|
|
|
)
|
2020-04-27 13:26:37 -04:00
|
|
|
target_compile_options(pugixml-shared
|
|
|
|
PRIVATE
|
|
|
|
${msvc-rt-mtd-shared}
|
|
|
|
${msvc-rt-mtd-static}
|
|
|
|
${msvc-rt-mt-shared}
|
|
|
|
${msvc-rt-mt-static})
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2021-06-19 12:51:27 +02:00
|
|
|
if (NOT BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS)
|
2020-04-27 13:26:37 -04:00
|
|
|
add_library(pugixml-static STATIC
|
|
|
|
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
|
|
|
|
add_library(pugixml::static ALIAS pugixml-static)
|
|
|
|
list(APPEND libs pugixml-static)
|
|
|
|
|
|
|
|
set_property(TARGET pugixml-static PROPERTY EXPORT_NAME static)
|
|
|
|
target_include_directories(pugixml-static
|
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
2021-06-28 12:41:11 +02:00
|
|
|
target_compile_definitions(pugixml-static
|
2021-06-28 13:36:55 +02:00
|
|
|
PUBLIC
|
2021-06-28 12:41:11 +02:00
|
|
|
${PUGIXML_BUILD_DEFINES}
|
2021-08-07 09:51:54 -07:00
|
|
|
${PUGIXML_PUBLIC_DEFINITIONS})
|
2020-04-27 13:26:37 -04:00
|
|
|
target_compile_options(pugixml-static
|
|
|
|
PRIVATE
|
|
|
|
${msvc-rt-mtd-shared}
|
|
|
|
${msvc-rt-mtd-static}
|
|
|
|
${msvc-rt-mt-shared}
|
|
|
|
${msvc-rt-mt-static})
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2021-06-19 12:51:27 +02:00
|
|
|
if (BUILD_SHARED_LIBS)
|
2020-04-27 13:26:37 -04:00
|
|
|
set(pugixml-alias pugixml-shared)
|
|
|
|
else()
|
|
|
|
set(pugixml-alias pugixml-static)
|
|
|
|
endif()
|
|
|
|
add_library(pugixml INTERFACE)
|
|
|
|
target_link_libraries(pugixml INTERFACE ${pugixml-alias})
|
|
|
|
add_library(pugixml::pugixml ALIAS pugixml)
|
|
|
|
|
|
|
|
set_target_properties(${libs}
|
2019-09-28 13:02:55 -07:00
|
|
|
PROPERTIES
|
|
|
|
MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY}
|
|
|
|
EXCLUDE_FROM_ALL ON
|
2019-12-06 17:25:37 +01:00
|
|
|
POSITION_INDEPENDENT_CODE ON
|
2019-09-28 13:02:55 -07:00
|
|
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
2020-02-07 14:55:25 +01:00
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
OUTPUT_NAME pugixml)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2020-04-27 13:26:37 -04:00
|
|
|
set_target_properties(${libs}
|
|
|
|
PROPERTIES
|
|
|
|
EXCLUDE_FROM_ALL OFF)
|
|
|
|
set(install-targets pugixml ${libs})
|
2019-09-28 13:02:55 -07:00
|
|
|
|
|
|
|
configure_package_config_file(
|
2019-09-30 22:00:04 -07:00
|
|
|
"${PROJECT_SOURCE_DIR}/scripts/pugixml-config.cmake.in"
|
2019-09-28 13:02:55 -07:00
|
|
|
"${PROJECT_BINARY_DIR}/pugixml-config.cmake"
|
2019-10-17 21:44:48 -07:00
|
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2019-09-28 13:02:55 -07:00
|
|
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
|
|
|
NO_SET_AND_CHECK_MACRO)
|
|
|
|
|
|
|
|
write_basic_package_version_file(
|
|
|
|
"${PROJECT_BINARY_DIR}/pugixml-config-version.cmake"
|
|
|
|
COMPATIBILITY SameMajorVersion)
|
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
if (PUGIXML_USE_POSTFIX)
|
2020-07-15 21:59:05 +02:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
|
|
|
set(LIB_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX})
|
|
|
|
elseif(CMAKE_BUILD_TYPE MATCHES MinSizeRel)
|
|
|
|
set(LIB_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX})
|
|
|
|
elseif(CMAKE_BUILD_TYPE MATCHES Debug)
|
|
|
|
set(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-03-22 14:05:43 +01:00
|
|
|
# Handle both relative and absolute paths (e.g. NixOS) for a relocatable package
|
|
|
|
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
set(PUGIXML_PC_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
else()
|
|
|
|
set(PUGIXML_PC_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
endif()
|
|
|
|
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
set(PUGIXML_PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
else()
|
|
|
|
set(PUGIXML_PC_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
configure_file(scripts/pugixml.pc.in pugixml.pc @ONLY)
|
|
|
|
|
2023-10-12 02:05:35 +04:00
|
|
|
export(TARGETS ${install-targets}
|
2019-09-28 13:02:55 -07:00
|
|
|
NAMESPACE pugixml::
|
2023-10-12 02:05:35 +04:00
|
|
|
FILE pugixml-targets.cmake)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2023-10-12 02:05:35 +04:00
|
|
|
if(PUGIXML_INSTALL)
|
|
|
|
if (NOT DEFINED PUGIXML_RUNTIME_COMPONENT)
|
|
|
|
set(PUGIXML_RUNTIME_COMPONENT Runtime)
|
|
|
|
endif()
|
2020-04-27 16:02:56 -04:00
|
|
|
|
2023-10-12 02:05:35 +04:00
|
|
|
if (NOT DEFINED PUGIXML_LIBRARY_COMPONENT)
|
|
|
|
set(PUGIXML_LIBRARY_COMPONENT Library)
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2023-10-12 02:05:35 +04:00
|
|
|
if (NOT DEFINED PUGIXML_DEVELOPMENT_COMPONENT)
|
|
|
|
set(PUGIXML_DEVELOPMENT_COMPONENT Development)
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2023-10-12 02:05:35 +04:00
|
|
|
set(namelink-component)
|
|
|
|
if (NOT CMAKE_VERSION VERSION_LESS 3.12)
|
|
|
|
set(namelink-component NAMELINK_COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
|
|
|
endif()
|
|
|
|
install(TARGETS ${install-targets}
|
|
|
|
EXPORT pugixml-targets
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PUGIXML_RUNTIME_COMPONENT}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${PUGIXML_LIBRARY_COMPONENT} ${namelink-component}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}${versioned-dir})
|
|
|
|
|
|
|
|
install(EXPORT pugixml-targets
|
|
|
|
NAMESPACE pugixml::
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pugixml COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
|
|
|
|
|
|
|
install(FILES
|
|
|
|
"${PROJECT_BINARY_DIR}/pugixml-config-version.cmake"
|
|
|
|
"${PROJECT_BINARY_DIR}/pugixml-config.cmake"
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pugixml COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
|
|
|
|
|
|
|
install(FILES ${PROJECT_BINARY_DIR}/pugixml.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
|
|
|
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"${PROJECT_SOURCE_DIR}/src/pugiconfig.hpp"
|
|
|
|
"${PROJECT_SOURCE_DIR}/src/pugixml.hpp"
|
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_INCLUDEDIR}${versioned-dir} COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
|
2021-01-11 16:13:52 +01:00
|
|
|
if (PUGIXML_BUILD_TESTS)
|
2023-10-06 09:51:29 +02:00
|
|
|
include(CTest)
|
2019-09-28 13:02:55 -07:00
|
|
|
set(fuzz-pattern "tests/fuzz_*.cpp")
|
|
|
|
set(test-pattern "tests/*.cpp")
|
|
|
|
if (CMAKE_VERSION VERSION_GREATER 3.11)
|
|
|
|
list(INSERT fuzz-pattern 0 CONFIGURE_DEPENDS)
|
|
|
|
list(INSERT test-pattern 0 CONFIGURE_DEPENDS)
|
2019-02-06 16:39:23 +01:00
|
|
|
endif()
|
2019-09-28 13:02:55 -07:00
|
|
|
file(GLOB test-sources ${test-pattern})
|
|
|
|
file(GLOB fuzz-sources ${fuzz-pattern})
|
|
|
|
list(REMOVE_ITEM test-sources ${fuzz-sources})
|
|
|
|
|
2019-09-30 22:00:04 -07:00
|
|
|
add_custom_target(check
|
|
|
|
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
|
2019-09-28 13:02:55 -07:00
|
|
|
|
|
|
|
add_executable(pugixml-check ${test-sources})
|
|
|
|
add_test(NAME pugixml::test
|
|
|
|
COMMAND pugixml-check
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
|
|
|
add_dependencies(check pugixml-check)
|
|
|
|
target_link_libraries(pugixml-check
|
|
|
|
PRIVATE
|
2020-04-27 13:26:37 -04:00
|
|
|
pugixml::pugixml)
|
2011-07-20 04:21:49 +00:00
|
|
|
endif()
|