-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
266 lines (239 loc) · 8.1 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#
# This file is part of the Util library.
# Copyright (C) 2009-2017 Benjamin Eikel <[email protected]>
# Copyright (C) 2014-2019 Sascha Brandt <[email protected]>
#
# This library is subject to the terms of the Mozilla Public License, v. 2.0.
# You should have received a copy of the MPL along with this library; see the
# file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
#
cmake_minimum_required(VERSION 3.1.0)
project(Util VERSION 0.4.0)
if(POLICY CMP0076)
cmake_policy(SET CMP0076 OLD)
endif()
# options
option(UTIL_BUILD_TESTS "Defines if CppUnit tests for the Util library are built." OFF)
# Set up install directories
include(GNUInstallDirs)
set(CMAKE_INSTALL_CMAKECONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Util)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
add_library(Util SHARED "")
target_sources(Util PRIVATE
Encoding.cpp
GenericAttribute.cpp
GenericAttributeSerialization.cpp
GenericConversion.cpp
Hashing.cpp
JSON_Parser.cpp
LibRegistry.cpp
LoadLibrary.cpp
Macros.cpp
MicroXML.cpp
ProgressIndicator.cpp
StringIdentifier.cpp
StringUtils.cpp
Timer.cpp
TypeConstant.cpp
Util.cpp
Utils.cpp
)
# Install the header files
install(FILES
AttributeProvider.h
BidirectionalMap.h
CountedObjectWrapper.h
Encoding.h
GenericAttribute.h
GenericAttributeSerialization.h
GenericConversion.h
Generic.h
Hashing.h
JSON_Parser.h
LibRegistry.h
LoadLibrary.h
Macros.h
MicroXML.h
Numeric.h
ObjectExtension.h
ProgressIndicator.h
ReferenceCounter.h
References.h
Registry.h
RegistryHelper.h
StringIdentifier.h
StringUtils.h
Timer.h
TriState.h
TypeConstant.h
TypeNameMacro.h
UpdatableHeap.h
Util.h
Utils.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Util
COMPONENT headers
)
add_subdirectory(Factory)
add_subdirectory(Graphics)
add_subdirectory(IO)
add_subdirectory(Network)
add_subdirectory(Profiling)
add_subdirectory(Resources)
add_subdirectory(Serialization)
add_subdirectory(UI)
add_subdirectory(examples)
add_subdirectory(extern)
if(UTIL_BUILD_TESTS)
if(UNIX AND NOT APPLE)
find_program(MEMORYCHECK_COMMAND NAMES valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--tool=memcheck --leak-check=summary --num-callers=1 --vgdb=no")
endif()
include(CTest)
add_subdirectory(tests)
endif()
if(WIN32)
if(MSVC)
target_link_libraries(Util PRIVATE "psapi.lib" "gdi32.lib")
else()
target_link_libraries(Util PRIVATE "-lpsapi -lgdi32")
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(Util PRIVATE rt)
endif()
#set c++ standard to c++17
target_compile_features(Util PUBLIC cxx_std_17)
if(MSVC)
target_compile_definitions(Util PRIVATE NOMINMAX)
target_compile_definitions(Util PRIVATE "UTILAPI=__declspec(dllexport)")
target_compile_definitions(Util INTERFACE "UTILAPI=__declspec(dllimport)")
else()
target_compile_definitions(Util PRIVATE "UTILAPI=")
target_compile_definitions(Util INTERFACE "UTILAPI=")
endif()
#target_compile_definitions(Util PUBLIC UtilExtern)
#target_include_directories(Util PRIVATE UtilExtern)
target_link_libraries(Util PRIVATE UtilExtern)
# Dependency to pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(TARGET Threads::Threads)
target_link_libraries(Util PRIVATE ${CMAKE_THREAD_LIBS_INIT})
endif()
include(CheckIncludeFileCXX)
include(CheckCXXSymbolExists)
# Test if the header execinfo.h exists
check_include_file_cxx(execinfo.h UTIL_HAVE_EXECINFO_H)
if(UTIL_HAVE_EXECINFO_H)
target_compile_definitions(Util PRIVATE UTIL_HAVE_EXECINFO_H)
endif()
# Test if the header malloc.h exists
check_include_file_cxx(malloc.h UTIL_HAVE_MALLOC_H)
if(UTIL_HAVE_MALLOC_H)
target_compile_definitions(Util PRIVATE UTIL_HAVE_MALLOC_H)
endif()
# Test if mallinfo exists
check_cxx_symbol_exists(mallinfo malloc.h UTIL_HAVE_MALLINFO)
if(UTIL_HAVE_MALLINFO)
target_compile_definitions(Util PRIVATE UTIL_HAVE_MALLINFO)
endif()
# Test if malloc_info exists
check_cxx_symbol_exists(malloc_info malloc.h UTIL_HAVE_MALLOC_INFO)
if(UTIL_HAVE_MALLOC_INFO)
target_compile_definitions(Util PRIVATE UTIL_HAVE_MALLOC_INFO)
endif()
# Test if open_memstream exists
check_cxx_symbol_exists(open_memstream stdio.h UTIL_HAVE_OPEN_MEMSTREAM)
if(UTIL_HAVE_OPEN_MEMSTREAM)
target_compile_definitions(Util PRIVATE UTIL_HAVE_OPEN_MEMSTREAM)
endif()
# Set version of library
set_target_properties(Util PROPERTIES VERSION ${Util_VERSION}
SOVERSION ${Util_VERSION_MAJOR}
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
include(FeatureSummary)
set_package_properties(CURL PROPERTIES
TYPE OPTIONAL
PURPOSE "Support for using the http:// and ftp:// virtual file system."
)
set_package_properties(Freetype PROPERTIES
TYPE OPTIONAL
PURPOSE "Creation of a bitmap containing a font's glyphs."
)
set_package_properties(LibArchive PROPERTIES
TYPE OPTIONAL
PURPOSE "Support for using the virtual file systems for archives (e.g. zip, tar)."
)
set_package_properties(libzip PROPERTIES
TYPE OPTIONAL
PURPOSE "Support for using the zip:// virtual file system."
)
set_package_properties(LibXml2 PROPERTIES
TYPE OPTIONAL
PURPOSE "Replace the provided XML parser by libxml2's parser."
)
set_package_properties(PNG PROPERTIES
TYPE OPTIONAL
PURPOSE "Read/write support for PNG (Portable Network Graphics) raster image files."
)
set_package_properties(SDL2 PROPERTIES
TYPE OPTIONAL
PURPOSE "Multi-platform creation of a window and a rendering context. Multi-platform concurrency support."
)
set_package_properties(SDL2_image PROPERTIES
TYPE OPTIONAL
PURPOSE "Read/write support for additional raster image file formats (e.g. JPEG, TIFF)."
)
set_package_properties(SDL2_net PROPERTIES
TYPE OPTIONAL
PURPOSE "Multi-platform support for network communication."
)
set_package_properties(SQLite3 PROPERTIES
TYPE OPTIONAL
PURPOSE "Support for using the dbfs:// virtual file system."
)
set_package_properties(ZLIB PROPERTIES
TYPE OPTIONAL
PURPOSE "Helper library required by other external libraries (e.g. libpng, libzip)."
)
feature_summary(DESCRIPTION "The following packages have been found:" WHAT PACKAGES_FOUND)
feature_summary(DESCRIPTION "The following packages have *not* been found:" WHAT PACKAGES_NOT_FOUND)
# Install the library
install(TARGETS Util EXPORT LibraryExport
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtimelibraries
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtimelibraries
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT developmentlibraries
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Set include directories for users of this library
target_include_directories(Util
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/.."
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
# Library export
# to use from the build tree
export(EXPORT LibraryExport FILE UtilTargets.cmake)
# to use from installation tree
install(EXPORT LibraryExport DESTINATION ${CMAKE_INSTALL_CMAKECONFIGDIR} FILE UtilTargets.cmake COMPONENT developmentlibraries)
# Create the configuration files
include(CMakePackageConfigHelpers)
configure_file(UtilConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/UtilConfig.cmake COPYONLY)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/UtilConfigVersion.cmake
VERSION ${Util_VERSION}
COMPATIBILITY SameMajorVersion)
# Install the configuration files
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/UtilConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/UtilConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_CMAKECONFIGDIR} COMPONENT developmentlibraries)
# Packaging
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_NAME "libutil${Util_VERSION_MAJOR}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Util library")
set(CPACK_PACKAGE_VENDOR "Benjamin Eikel; Claudius Jaehn; Ralf Petring; Sascha Brandt")
set(CPACK_PACKAGE_CONTACT "Benjamin Eikel <[email protected]>")
set(CPACK_PACKAGE_VERSION_MAJOR ${Util_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${Util_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${Util_VERSION_PATCH})
set(CPACK_PACKAGE_FILE_NAME "libUtil")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_STRIP_FILES ON)
include(CPack)