forked from leethomason/tinyxml2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
129 lines (102 loc) · 3.29 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.15)
project(tinyxml2 VERSION 9.0.0)
include(CTest)
option(tinyxml2_BUILD_TESTING "Build tests for tinyxml2" "${BUILD_TESTING}")
##
## Honor tinyxml2_SHARED_LIBS to match install interface
##
if (DEFINED tinyxml2_SHARED_LIBS)
set(BUILD_SHARED_LIBS "${tinyxml2_SHARED_LIBS}")
endif ()
##
## Main library build
##
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
add_library(tinyxml2::tinyxml2 ALIAS tinyxml2)
# Uncomment the following line to require C++11 (or greater) to use tinyxml2
# target_compile_features(tinyxml2 PUBLIC cxx_std_11)
target_include_directories(tinyxml2 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
target_compile_definitions(
tinyxml2
PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>
INTERFACE $<$<BOOL:${BUILD_SHARED_LIBS}>:TINYXML2_IMPORT>
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
)
set_target_properties(
tinyxml2
PROPERTIES
DEFINE_SYMBOL "TINYXML2_EXPORT"
VERSION "${tinyxml2_VERSION}"
SOVERSION "${tinyxml2_VERSION_MAJOR}"
)
if (tinyxml2_BUILD_TESTING)
add_executable(xmltest xmltest.cpp)
target_link_libraries(xmltest PRIVATE tinyxml2::tinyxml2)
add_test(
NAME xmltest
COMMAND xmltest
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
set_tests_properties(xmltest PROPERTIES PASS_REGULAR_EXPRESSION ", Fail 0")
endif ()
##
## Installation
##
## Standard modules
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
## Custom locations
set(tinyxml2_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE PATH "Directory for pkgconfig files")
set(tinyxml2_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/tinyxml2"
CACHE STRING "Path to tinyxml2 CMake files")
## CMake targets and export scripts
install(
TARGETS tinyxml2 EXPORT tinyxml2-targets
RUNTIME COMPONENT tinyxml2_runtime
LIBRARY COMPONENT tinyxml2_runtime
NAMELINK_COMPONENT tinyxml2_development
ARCHIVE COMPONENT tinyxml2_development
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Type-specific targets
if (BUILD_SHARED_LIBS)
set(type shared)
else ()
set(type static)
endif ()
install(
EXPORT tinyxml2-targets
DESTINATION "${tinyxml2_INSTALL_CMAKEDIR}"
NAMESPACE tinyxml2::
FILE tinyxml2-${type}-targets.cmake
COMPONENT tinyxml2_development
)
# Auto-generated version compatibility file
write_basic_package_version_file(
tinyxml2-config-version.cmake
COMPATIBILITY SameMajorVersion
)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/tinyxml2-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/tinyxml2-config-version.cmake"
DESTINATION "${tinyxml2_INSTALL_CMAKEDIR}"
COMPONENT tinyxml2_development
)
## Headers
install(
FILES tinyxml2.h
TYPE INCLUDE
COMPONENT tinyxml2_development
)
## pkg-config
configure_file(cmake/tinyxml2.pc.in tinyxml2.pc.gen @ONLY)
file(GENERATE OUTPUT tinyxml2.pc INPUT "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc.gen")
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc"
DESTINATION "${tinyxml2_INSTALL_PKGCONFIGDIR}"
COMPONENT tinyxml2_development
)