-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
297 lines (258 loc) · 11.2 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
include (${CMAKE_CURRENT_SOURCE_DIR}/scripts/VersionConfig.cmake)
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/modules/Common/scripts;${CMAKE_CURRENT_SOURCE_DIR}/../Common/scripts;${CMAKE_CURRENT_SOURCE_DIR}/scripts")
include (Configuration)
include (Macros)
include (OS)
include (compiler_init)
cmake_minimum_required (VERSION 2.8...3.12)
cmake_policy (SET CMP0069 NEW) # IPO is enforced when enabled
include (CheckIPOSupported)
check_ipo_supported (RESULT IPO_SUPPORTED
OUTPUT IPO_REASON)
# global options
if (IPO_SUPPORTED)
set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif (IPO_SUPPORTED)
#set (CMAKE_VERBOSE_MAKEFILE ON)
set_property (GLOBAL PROPERTY USE_FOLDERS ON)
if (UNIX)
find_program (CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
# set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif (CCACHE_PROGRAM)
set (ENV{CCACHE_DISABLE} "true")
endif (UNIX)
# build type
#variable_watch (CMAKE_BUILD_TYPE)
# *NOTE*: iff the user specifies -DCMAKE_BUILD_TYPE on the command line, take
# their definition and dump it in the cache along with proper
# documentation, otherwise set CMAKE_BUILD_TYPE to Debug prior to
# calling PROJECT()
set (BUILD_TYPE_CACHE_STRING "choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
if (DEFINED CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING ${BUILD_TYPE_CACHE_STRING})
elseif (NOT CMAKE_CONFIGURATION_TYPES)
set (CMAKE_BUILD_TYPE Debug CACHE STRING ${BUILD_TYPE_CACHE_STRING})
endif ()
include (PrePreToolChain)
# *NOTE*: sets CMAKE_TOOLCHAIN_FILE, so include BEFORE project()
include (vcpkg)
# project
cmake_policy (SET CMP0048 NEW) # allow project VERSION
#cmake_policy (SET CMP0056 OLD) # honor per-config flags in try_compile()
#cmake_policy (SET CMP0066 OLD) # honor per-config flags in try_compile()
cmake_policy (SET CMP0091 NEW) # MSVC runtime library flags are selected by an abstraction
project (${PROJECT_NAME}
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
LANGUAGES CXX C)
include (PreToolChain)
include (SetToolChain)
include (ToolChain)
# *NOTE*: or use the cmake.exe '-T' option instead
include (SetTargetPlatform)
include (TargetPlatform)
# directories
# override the installation directories ?
#set (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF)
if (UNIX)
include (GNUInstallDirs)
# set (INSTALL_SHARE_DIR "share" CACHE PATH "Installation directory for shared files")
endif (UNIX)
set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set (INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
if (WIN32 AND NOT CYGWIN)
set (DEF_INSTALL_CMAKE_DIR CMake)
else ()
set (DEF_INSTALL_CMAKE_DIR lib/CMake/${PROJECT_NAME})
endif ()
set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
# make relative paths absolute (needed later on)
foreach (path BIN CMAKE SHARE INCLUDE LIB)
set (var INSTALL_${path}_DIR)
# if (NOT IS_ABSOLUTE "${${var}}")
string (TOLOWER "${path}" RELATIVE_INSTALL_PATH)
if (UNIX)
set (${var} "${CMAKE_INSTALL_PREFIX}/${RELATIVE_INSTALL_PATH}")
elseif (WIN32)
set (${var} ${RELATIVE_INSTALL_PATH})
endif ()
# message (STATUS "set \"${var}\" to \"${${var}}\"")
endforeach ()
# project options
if (CMAKE_BUILD_TYPE STREQUAL Debug)
if (CMAKE_COMPILER_IS_GNUCXX)
add_compile_options (-g)
add_compile_options (-O0)
add_compile_options (-fno-inline)
endif ()
add_definitions (-D_DEBUG)
if (WIN32)
# add_definitions (-D_ITERATOR_DEBUG_LEVEL=2)
endif (WIN32)
# set_property (SOURCE PROPERTY COMPILE_DEFINITIONS _DEBUG)
elseif (CMAKE_BUILD_TYPE STREQUAL Release)
if (CMAKE_COMPILER_IS_GNUCXX)
add_compile_options (-O3)
endif ()
add_definitions (-DACE_NDEBUG)
# set_property (SOURCE PROPERTY COMPILE_DEFINITIONS ACE_NDEBUG)
if (WIN32)
# add_definitions (-D_ITERATOR_DEBUG_LEVEL=0)
endif ()
endif ()
if (MSVC)
remove_definitions (/DWINVER)
remove_definitions (/D_WIN32_WINNT)
endif (MSVC)
option (TRACING "enable tracing" OFF)
if (TRACING)
add_definitions (-DACESTREAM_NTRACE=0)
# set_property (SOURCE PROPERTY COMPILE_DEFINITIONS ACESTREAM_NTRACE=0)
else ()
add_definitions (-DACESTREAM_NTRACE=1)
# set_property (SOURCE PROPERTY COMPILE_DEFINITIONS ACESTREAM_NTRACE=1)
endif ()
include (valgrind)
option (BUILD_MODULES "build (git) sub-modules" OFF)
if (CMAKE_COMPILER_IS_GNUCXX)
# add_compile_options (-ansi)
# add_compile_options (-std=c++11)
add_compile_options (-Wall)
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g")
add_definitions (-D_GNU_SOURCE)
# set_property (SOURCE PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE)
elseif (MSVC)
add_compile_options (/MP)
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
add_definitions (-D_WINSOCK_DEPRECATED_NO_WARNINGS)
set (MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:NO")
foreach (FLAG_TYPE EXE MODULE SHARED STATIC)
string (REGEX REPLACE "/INCREMENTAL* " "/INCREMENTAL:NO " CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG "${CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG}")
# message (STATUS "flag: ${FLAG_TYPE}: ${CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG}")
string (REPLACE "/EDITANDCONTINUE" "" CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG "${CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG}")
set (CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG "${CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG}"
CACHE STRING "Overriding default debug ${FLAG_TYPE} linker flags." FORCE)
mark_as_advanced (CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG)
endforeach ()
endif ()
set (LLVM_COMPILER_ID_STRING "Clang")
string (TOLOWER "${LLVM_COMPILER_ID_STRING}" LLVM_COMPILER_ID_STRING_LOWER)
string (TOLOWER "${CMAKE_CXX_COMPILER_ID}" CXX_COMPILER_ID_STRING_LOWER)
if (CXX_COMPILER_ID_STRING_LOWER STREQUAL LLVM_COMPILER_ID_STRING_LOWER)
add_compile_options (-fPIC)
# add_definitions (-D_GLIBCXX_USE_CXX11_ABI=0)
endif ()
################################################################################
# policies
cmake_policy (SET CMP0007 NEW)
cmake_policy (SET CMP0011 NEW)
cmake_policy (SET CMP0074 NEW)
################################################################################
# configuration files
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export (PACKAGE ${PROJECT_NAME})
# Create the ACEStreamConfig.cmake and ACEStreamConfigVersion.cmake files
# *NOTE*: see: https://cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file
#file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
# ... for the build tree
set (CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
if (UNIX)
set (NEWLINE_STYLE UNIX)
elseif (WIN32)
set (NEWLINE_STYLE WIN32)
else ()
set (NEWLINE_STYLE UNIX)
endif ()
configure_file (${PROJECT_NAME}Config.cmake.in
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
@ONLY
NEWLINE_STYLE ${NEWLINE_STYLE})
# ... for the install tree
set (CONF_INCLUDE_DIRS "\${ACEStream_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file (${PROJECT_NAME}Config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
@ONLY
NEWLINE_STYLE ${NEWLINE_STYLE})
# ... for both
configure_file (${PROJECT_NAME}ConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
@ONLY
NEWLINE_STYLE ${NEWLINE_STYLE})
set (PACKAGE ${PROJECT_NAME})
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_config.h
@ONLY
NEWLINE_STYLE ${NEWLINE_STYLE})
#add_custom_target (${PROJECT_NAME}_config)
#set_target_properties (${PROJECT_NAME}_config PROPERTIES
# PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_config.h")
add_definitions (-DHAVE_CONFIG_H)
#set_property (SOURCE PROPERTY COMPILE_DEFINITIONS HAVE_CONFIG_H)
include (libraries_init)
################################################################################
add_subdirectory (src)
################################################################################
# Install the ACEStreamConfig.cmake and ACEStreamConfigVersion.cmake
install (FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
# "${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
# "${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# Install the export set for use with the install-tree
install (EXPORT ${PROJECT_NAME}Targets
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_config.h"
DESTINATION "${INSTALL_INCLUDE_DIR}/${PROJECT_NAME}"
COMPONENT dev)
################################################################################
if (DEFINED ENV{LIB_ROOT})
file (TO_CMAKE_PATH "$ENV{LIB_ROOT}/cmake-modules" CMAKE_MODULES_PATH)
else ()
set (CMAKE_MODULES_PATH "modules/cmake-modules")
endif (DEFINED ENV{LIB_ROOT})
list (APPEND CMAKE_MODULE_PATH "${CMAKE_MODULES_PATH}")
#include (UseBackportedModules)
cmake_policy (SET CMP0026 OLD)
cmake_policy (SET CMP0053 OLD)
include (CreateLaunchers)
# enable (unit/integration) tests
#include (CTest)
#enable_testing ()
################################################################################
add_subdirectory (test_u)
add_subdirectory (test_i)
################################################################################
if (UNIX)
include (GNUInstallDirs)
elseif (WIN32)
if (MSVC)
# set (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "10.0.16299.0") # set Windows SDK version
# message (STATUS "CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
# add_definitions (-CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
endif (MSVC)
endif ()
#set (NSIS_PROJECT_FILE "${PROJECT_NAME}.nsi")
#add_custom_command (TARGET ${PROJECT_NAME}
# POST_BUILD
# COMMAND make_installer.bat ${NSIS_PROJECT_FILE}
# WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/scripts"
# COMMENT "making installer..."
# VERBATIM)
# build a CPack driven installer package
# *NOTE*: "... If CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS is NOT set, then
# this file warns about required files that do not exist. You can set
# this variable to ON before including this file to avoid the warning.
# For example, the Visual Studio Express editions do not include the
# redistributable files, so if you include this file on a machine with
# only VS Express installed, you’ll get the warning. ..."
include (InstallRequiredSystemLibraries)
#set (CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
#set (CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
#set (CPACK_PACKAGE_VERSION_PATCH ${VERSION_MICRO})
#set (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
#set (CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README)
# build a CPack driven installer package
include (CPack)