mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-14 01:47:55 +08:00
Merge pull request #399 from bjornblissing/feature/cmake_prefix
Add PUGIXML as prefix to CMake options
This commit is contained in:
commit
7da44ddc5b
@ -7,32 +7,38 @@ include(GNUInstallDirs)
|
|||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
|
|
||||||
cmake_dependent_option(USE_VERSIONED_LIBDIR
|
cmake_dependent_option(PUGIXML_USE_VERSIONED_LIBDIR
|
||||||
"Use a private subdirectory to install the headers and libraries" OFF
|
"Use a private subdirectory to install the headers and libraries" OFF
|
||||||
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
||||||
|
|
||||||
cmake_dependent_option(USE_POSTFIX
|
cmake_dependent_option(PUGIXML_USE_POSTFIX
|
||||||
"Use separate postfix for each configuration to make sure you can install multiple build outputs" OFF
|
"Use separate postfix for each configuration to make sure you can install multiple build outputs" OFF
|
||||||
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
||||||
|
|
||||||
cmake_dependent_option(STATIC_CRT
|
cmake_dependent_option(PUGIXML_STATIC_CRT
|
||||||
"Use static MSVC RT libraries" OFF
|
"Use static MSVC RT libraries" OFF
|
||||||
"MSVC" OFF)
|
"MSVC" OFF)
|
||||||
|
|
||||||
cmake_dependent_option(BUILD_TESTS
|
cmake_dependent_option(PUGIXML_BUILD_TESTS
|
||||||
"Build pugixml tests" OFF
|
"Build pugixml tests" OFF
|
||||||
"BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
"BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
|
||||||
|
|
||||||
option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" OFF)
|
# Custom build defines
|
||||||
# Technically not needed for this file. This is builtin.
|
set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options")
|
||||||
|
separate_arguments(PUGIXML_BUILD_DEFINES)
|
||||||
|
|
||||||
|
# Technically not needed for this file. This is builtin CMAKE global variable.
|
||||||
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
|
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
|
||||||
|
|
||||||
set(BUILD_DEFINES CACHE STRING "Build defines")
|
# 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)
|
||||||
|
|
||||||
# This is used to backport a CMake 3.15 feature, but is also forwards compatible
|
# This is used to backport a CMake 3.15 feature, but is also forwards compatible
|
||||||
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
|
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
|
||||||
set(CMAKE_MSVC_RUNTIME_LIBRARY
|
set(CMAKE_MSVC_RUNTIME_LIBRARY
|
||||||
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${STATIC_CRT}>>:DLL>)
|
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
|
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
|
||||||
@ -43,7 +49,7 @@ if (NOT DEFINED CMAKE_CXX_STANDARD)
|
|||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (USE_POSTFIX)
|
if (PUGIXML_USE_POSTFIX)
|
||||||
set(CMAKE_RELWITHDEBINFO_POSTFIX _r)
|
set(CMAKE_RELWITHDEBINFO_POSTFIX _r)
|
||||||
set(CMAKE_MINSIZEREL_POSTFIX _m)
|
set(CMAKE_MINSIZEREL_POSTFIX _m)
|
||||||
set(CMAKE_DEBUG_POSTFIX _d)
|
set(CMAKE_DEBUG_POSTFIX _d)
|
||||||
@ -64,11 +70,11 @@ if (CMAKE_VERSION VERSION_LESS 3.15)
|
|||||||
set(msvc-rt-mt-static $<${msvc-rt-mt-static}:-MT>)
|
set(msvc-rt-mt-static $<${msvc-rt-mt-static}:-MT>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(versioned-dir $<$<BOOL:${USE_VERSIONED_LIBDIR}>:/pugixml-${PROJECT_VERSION}>)
|
set(versioned-dir $<$<BOOL:${PUGIXML_USE_VERSIONED_LIBDIR}>:/pugixml-${PROJECT_VERSION}>)
|
||||||
|
|
||||||
set(libs)
|
set(libs)
|
||||||
|
|
||||||
if (BUILD_SHARED_LIBS OR BUILD_SHARED_AND_STATIC_LIBS)
|
if (BUILD_SHARED_LIBS)
|
||||||
add_library(pugixml-shared SHARED
|
add_library(pugixml-shared SHARED
|
||||||
${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc
|
${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc
|
||||||
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
|
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
|
||||||
@ -80,6 +86,8 @@ if (BUILD_SHARED_LIBS OR BUILD_SHARED_AND_STATIC_LIBS)
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
||||||
target_compile_definitions(pugixml-shared
|
target_compile_definitions(pugixml-shared
|
||||||
|
PUBLIC
|
||||||
|
${PUGIXML_BUILD_DEFINES}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:PUGIXML_API=__declspec\(dllexport\)>)
|
$<$<CXX_COMPILER_ID:MSVC>:PUGIXML_API=__declspec\(dllexport\)>)
|
||||||
target_compile_options(pugixml-shared
|
target_compile_options(pugixml-shared
|
||||||
@ -90,7 +98,7 @@ if (BUILD_SHARED_LIBS OR BUILD_SHARED_AND_STATIC_LIBS)
|
|||||||
${msvc-rt-mt-static})
|
${msvc-rt-mt-static})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT BUILD_SHARED_LIBS OR BUILD_SHARED_AND_STATIC_LIBS)
|
if (NOT BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS)
|
||||||
add_library(pugixml-static STATIC
|
add_library(pugixml-static STATIC
|
||||||
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
|
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
|
||||||
add_library(pugixml::static ALIAS pugixml-static)
|
add_library(pugixml::static ALIAS pugixml-static)
|
||||||
@ -100,6 +108,9 @@ if (NOT BUILD_SHARED_LIBS OR BUILD_SHARED_AND_STATIC_LIBS)
|
|||||||
target_include_directories(pugixml-static
|
target_include_directories(pugixml-static
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
||||||
|
target_compile_definitions(pugixml-static
|
||||||
|
PUBLIC
|
||||||
|
${PUGIXML_BUILD_DEFINES})
|
||||||
target_compile_options(pugixml-static
|
target_compile_options(pugixml-static
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${msvc-rt-mtd-shared}
|
${msvc-rt-mtd-shared}
|
||||||
@ -142,7 +153,7 @@ write_basic_package_version_file(
|
|||||||
"${PROJECT_BINARY_DIR}/pugixml-config-version.cmake"
|
"${PROJECT_BINARY_DIR}/pugixml-config-version.cmake"
|
||||||
COMPATIBILITY SameMajorVersion)
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
if (USE_POSTFIX)
|
if (PUGIXML_USE_POSTFIX)
|
||||||
if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
||||||
set(LIB_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX})
|
set(LIB_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX})
|
||||||
elseif(CMAKE_BUILD_TYPE MATCHES MinSizeRel)
|
elseif(CMAKE_BUILD_TYPE MATCHES MinSizeRel)
|
||||||
@ -199,7 +210,7 @@ install(
|
|||||||
DESTINATION
|
DESTINATION
|
||||||
${CMAKE_INSTALL_INCLUDEDIR}${versioned-dir} COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
${CMAKE_INSTALL_INCLUDEDIR}${versioned-dir} COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT})
|
||||||
|
|
||||||
if (BUILD_TESTS)
|
if (PUGIXML_BUILD_TESTS)
|
||||||
set(fuzz-pattern "tests/fuzz_*.cpp")
|
set(fuzz-pattern "tests/fuzz_*.cpp")
|
||||||
set(test-pattern "tests/*.cpp")
|
set(test-pattern "tests/*.cpp")
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.11)
|
if (CMAKE_VERSION VERSION_GREATER 3.11)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user