Mercurial > minori
comparison dep/pugixml/CMakeLists.txt @ 55:d10b6c6b432e
add xml lib, we will need to use it eventually
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 26 Sep 2023 12:37:08 -0400 |
parents | |
children | a45edd073f9e |
comparison
equal
deleted
inserted
replaced
54:466ac9870df9 | 55:d10b6c6b432e |
---|---|
1 cmake_minimum_required(VERSION 3.4) | |
2 project(pugixml VERSION 1.13 LANGUAGES CXX) | |
3 | |
4 include(CMakePackageConfigHelpers) | |
5 include(CMakeDependentOption) | |
6 include(GNUInstallDirs) | |
7 include(CTest) | |
8 | |
9 cmake_dependent_option(PUGIXML_USE_VERSIONED_LIBDIR | |
10 "Use a private subdirectory to install the headers and libraries" OFF | |
11 "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) | |
12 | |
13 cmake_dependent_option(PUGIXML_USE_POSTFIX | |
14 "Use separate postfix for each configuration to make sure you can install multiple build outputs" OFF | |
15 "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) | |
16 | |
17 cmake_dependent_option(PUGIXML_STATIC_CRT | |
18 "Use static MSVC RT libraries" OFF | |
19 "MSVC" OFF) | |
20 | |
21 cmake_dependent_option(PUGIXML_BUILD_TESTS | |
22 "Build pugixml tests" OFF | |
23 "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) | |
24 | |
25 # Custom build defines | |
26 set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options") | |
27 separate_arguments(PUGIXML_BUILD_DEFINES) | |
28 | |
29 # Technically not needed for this file. This is builtin CMAKE global variable. | |
30 option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF) | |
31 | |
32 # Expose option to build PUGIXML as static as well when the global BUILD_SHARED_LIBS variable is set | |
33 cmake_dependent_option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS | |
34 "Build both shared and static libraries" OFF | |
35 "BUILD_SHARED_LIBS" OFF) | |
36 | |
37 # Expose options from the pugiconfig.hpp | |
38 option(PUGIXML_WCHAR_MODE "Enable wchar_t mode" OFF) | |
39 option(PUGIXML_COMPACT "Enable compact mode" OFF) | |
40 | |
41 # Advanced options from pugiconfig.hpp | |
42 option(PUGIXML_NO_XPATH "Disable XPath" OFF) | |
43 option(PUGIXML_NO_STL "Disable STL" OFF) | |
44 option(PUGIXML_NO_EXCEPTIONS "Disable Exceptions" OFF) | |
45 mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS) | |
46 | |
47 # Policy configuration | |
48 if(POLICY CMP0091) | |
49 cmake_policy(SET CMP0091 NEW) # Enables use of MSVC_RUNTIME_LIBRARY | |
50 endif() | |
51 | |
52 set(PUGIXML_PUBLIC_DEFINITIONS | |
53 $<$<BOOL:${PUGIXML_WCHAR_MODE}>:PUGIXML_WCHAR_MODE> | |
54 $<$<BOOL:${PUGIXML_COMPACT}>:PUGIXML_COMPACT> | |
55 $<$<BOOL:${PUGIXML_NO_XPATH}>:PUGIXML_NO_XPATH> | |
56 $<$<BOOL:${PUGIXML_NO_STL}>:PUGIXML_NO_STL> | |
57 $<$<BOOL:${PUGIXML_NO_EXCEPTIONS}>:PUGIXML_NO_EXCEPTIONS>) | |
58 | |
59 # This is used to backport a CMake 3.15 feature, but is also forwards compatible | |
60 if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) | |
61 set(CMAKE_MSVC_RUNTIME_LIBRARY | |
62 MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>) | |
63 endif() | |
64 | |
65 if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED) | |
66 set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
67 endif() | |
68 | |
69 if (NOT DEFINED CMAKE_CXX_STANDARD) | |
70 set(CMAKE_CXX_STANDARD 11) | |
71 endif() | |
72 | |
73 if (PUGIXML_USE_POSTFIX) | |
74 set(CMAKE_RELWITHDEBINFO_POSTFIX _r) | |
75 set(CMAKE_MINSIZEREL_POSTFIX _m) | |
76 set(CMAKE_DEBUG_POSTFIX _d) | |
77 endif() | |
78 | |
79 if (CMAKE_VERSION VERSION_LESS 3.15) | |
80 set(msvc-rt $<TARGET_PROPERTY:MSVC_RUNTIME_LIBRARY>) | |
81 | |
82 set(msvc-rt-mtd-shared $<STREQUAL:${msvc-rt},MultiThreadedDebugDLL>) | |
83 set(msvc-rt-mtd-static $<STREQUAL:${msvc-rt},MultiThreadedDebug>) | |
84 set(msvc-rt-mt-shared $<STREQUAL:${msvc-rt},MultiThreadedDLL>) | |
85 set(msvc-rt-mt-static $<STREQUAL:${msvc-rt},MultiThreaded>) | |
86 unset(msvc-rt) | |
87 | |
88 set(msvc-rt-mtd-shared $<${msvc-rt-mtd-shared}:-MDd>) | |
89 set(msvc-rt-mtd-static $<${msvc-rt-mtd-static}:-MTd>) | |
90 set(msvc-rt-mt-shared $<${msvc-rt-mt-shared}:-MD>) | |
91 set(msvc-rt-mt-static $<${msvc-rt-mt-static}:-MT>) | |
92 endif() | |
93 | |
94 set(versioned-dir $<$<BOOL:${PUGIXML_USE_VERSIONED_LIBDIR}>:/pugixml-${PROJECT_VERSION}>) | |
95 | |
96 set(libs) | |
97 | |
98 if (BUILD_SHARED_LIBS) | |
99 add_library(pugixml-shared SHARED | |
100 ${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc | |
101 ${PROJECT_SOURCE_DIR}/src/pugixml.cpp) | |
102 add_library(pugixml::shared ALIAS pugixml-shared) | |
103 list(APPEND libs pugixml-shared) | |
104 string(CONCAT pugixml.msvc $<OR: | |
105 $<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>, | |
106 $<CXX_COMPILER_ID:MSVC> | |
107 >) | |
108 | |
109 set_property(TARGET pugixml-shared PROPERTY EXPORT_NAME shared) | |
110 target_include_directories(pugixml-shared | |
111 PUBLIC | |
112 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) | |
113 target_compile_definitions(pugixml-shared | |
114 PUBLIC | |
115 ${PUGIXML_BUILD_DEFINES} | |
116 ${PUGIXML_PUBLIC_DEFINITIONS} | |
117 PRIVATE | |
118 PUGIXML_API=$<IF:${pugixml.msvc},__declspec\(dllexport\),__attribute__\(\(visibility\("default"\)\)\)> | |
119 ) | |
120 target_compile_options(pugixml-shared | |
121 PRIVATE | |
122 ${msvc-rt-mtd-shared} | |
123 ${msvc-rt-mtd-static} | |
124 ${msvc-rt-mt-shared} | |
125 ${msvc-rt-mt-static}) | |
126 endif() | |
127 | |
128 if (NOT BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) | |
129 add_library(pugixml-static STATIC | |
130 ${PROJECT_SOURCE_DIR}/src/pugixml.cpp) | |
131 add_library(pugixml::static ALIAS pugixml-static) | |
132 list(APPEND libs pugixml-static) | |
133 | |
134 set_property(TARGET pugixml-static PROPERTY EXPORT_NAME static) | |
135 target_include_directories(pugixml-static | |
136 PUBLIC | |
137 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) | |
138 target_compile_definitions(pugixml-static | |
139 PUBLIC | |
140 ${PUGIXML_BUILD_DEFINES} | |
141 ${PUGIXML_PUBLIC_DEFINITIONS}) | |
142 target_compile_options(pugixml-static | |
143 PRIVATE | |
144 ${msvc-rt-mtd-shared} | |
145 ${msvc-rt-mtd-static} | |
146 ${msvc-rt-mt-shared} | |
147 ${msvc-rt-mt-static}) | |
148 endif() | |
149 | |
150 if (BUILD_SHARED_LIBS) | |
151 set(pugixml-alias pugixml-shared) | |
152 else() | |
153 set(pugixml-alias pugixml-static) | |
154 endif() | |
155 add_library(pugixml INTERFACE) | |
156 target_link_libraries(pugixml INTERFACE ${pugixml-alias}) | |
157 add_library(pugixml::pugixml ALIAS pugixml) | |
158 | |
159 set_target_properties(${libs} | |
160 PROPERTIES | |
161 MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY} | |
162 EXCLUDE_FROM_ALL ON | |
163 POSITION_INDEPENDENT_CODE ON | |
164 SOVERSION ${PROJECT_VERSION_MAJOR} | |
165 VERSION ${PROJECT_VERSION} | |
166 OUTPUT_NAME pugixml) | |
167 | |
168 set_target_properties(${libs} | |
169 PROPERTIES | |
170 EXCLUDE_FROM_ALL OFF) | |
171 set(install-targets pugixml ${libs}) | |
172 | |
173 configure_package_config_file( | |
174 "${PROJECT_SOURCE_DIR}/scripts/pugixml-config.cmake.in" | |
175 "${PROJECT_BINARY_DIR}/pugixml-config.cmake" | |
176 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
177 NO_CHECK_REQUIRED_COMPONENTS_MACRO | |
178 NO_SET_AND_CHECK_MACRO) | |
179 | |
180 write_basic_package_version_file( | |
181 "${PROJECT_BINARY_DIR}/pugixml-config-version.cmake" | |
182 COMPATIBILITY SameMajorVersion) | |
183 | |
184 if (PUGIXML_USE_POSTFIX) | |
185 if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) | |
186 set(LIB_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX}) | |
187 elseif(CMAKE_BUILD_TYPE MATCHES MinSizeRel) | |
188 set(LIB_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX}) | |
189 elseif(CMAKE_BUILD_TYPE MATCHES Debug) | |
190 set(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX}) | |
191 endif() | |
192 endif() | |
193 | |
194 configure_file(scripts/pugixml.pc.in pugixml.pc @ONLY) | |
195 | |
196 if (NOT DEFINED PUGIXML_RUNTIME_COMPONENT) | |
197 set(PUGIXML_RUNTIME_COMPONENT Runtime) | |
198 endif() | |
199 | |
200 if (NOT DEFINED PUGIXML_LIBRARY_COMPONENT) | |
201 set(PUGIXML_LIBRARY_COMPONENT Library) | |
202 endif() | |
203 | |
204 if (NOT DEFINED PUGIXML_DEVELOPMENT_COMPONENT) | |
205 set(PUGIXML_DEVELOPMENT_COMPONENT Development) | |
206 endif() | |
207 | |
208 set(namelink-component) | |
209 if (NOT CMAKE_VERSION VERSION_LESS 3.12) | |
210 set(namelink-component NAMELINK_COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT}) | |
211 endif() | |
212 install(TARGETS ${install-targets} | |
213 EXPORT pugixml-targets | |
214 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PUGIXML_RUNTIME_COMPONENT} | |
215 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${PUGIXML_LIBRARY_COMPONENT} ${namelink-component} | |
216 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT} | |
217 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}${versioned-dir}) | |
218 | |
219 install(EXPORT pugixml-targets | |
220 NAMESPACE pugixml:: | |
221 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pugixml COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT}) | |
222 | |
223 export(EXPORT pugixml-targets | |
224 NAMESPACE pugixml::) | |
225 | |
226 install(FILES | |
227 "${PROJECT_BINARY_DIR}/pugixml-config-version.cmake" | |
228 "${PROJECT_BINARY_DIR}/pugixml-config.cmake" | |
229 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pugixml COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT}) | |
230 | |
231 install(FILES ${PROJECT_BINARY_DIR}/pugixml.pc | |
232 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT}) | |
233 | |
234 install( | |
235 FILES | |
236 "${PROJECT_SOURCE_DIR}/src/pugiconfig.hpp" | |
237 "${PROJECT_SOURCE_DIR}/src/pugixml.hpp" | |
238 DESTINATION | |
239 ${CMAKE_INSTALL_INCLUDEDIR}${versioned-dir} COMPONENT ${PUGIXML_DEVELOPMENT_COMPONENT}) | |
240 | |
241 if (PUGIXML_BUILD_TESTS) | |
242 set(fuzz-pattern "tests/fuzz_*.cpp") | |
243 set(test-pattern "tests/*.cpp") | |
244 if (CMAKE_VERSION VERSION_GREATER 3.11) | |
245 list(INSERT fuzz-pattern 0 CONFIGURE_DEPENDS) | |
246 list(INSERT test-pattern 0 CONFIGURE_DEPENDS) | |
247 endif() | |
248 file(GLOB test-sources ${test-pattern}) | |
249 file(GLOB fuzz-sources ${fuzz-pattern}) | |
250 list(REMOVE_ITEM test-sources ${fuzz-sources}) | |
251 | |
252 add_custom_target(check | |
253 COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) | |
254 | |
255 add_executable(pugixml-check ${test-sources}) | |
256 add_test(NAME pugixml::test | |
257 COMMAND pugixml-check | |
258 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) | |
259 add_dependencies(check pugixml-check) | |
260 target_link_libraries(pugixml-check | |
261 PRIVATE | |
262 pugixml::pugixml) | |
263 endif() |