-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCMakeLists.txt
205 lines (155 loc) · 6.19 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
cmake_minimum_required (VERSION 3.16)
project (airdcpp-webclient)
if (APPLE)
set (PROJECT_NAME_GLOBAL AirDC++ Web Client)
else (APPLE)
set (PROJECT_NAME_GLOBAL airdcpp-webclient)
endif (APPLE)
set (PROJECT_NAME "AirDC++ Web Client")
set (TAG_APPLICATION "AirDC++w")
set (APPLICATION_ID "airdcpp-web")
set (VERSION "2.13.2") # NOTE: the minor version must match the lastest UI version
set (SOVERSION "2.13.2" )
set (GNUCXX_MINIMUM_VERSION "12.0")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "RelWithDebInfo")
endif (NOT CMAKE_BUILD_TYPE)
include (GNUInstallDirs)
include (CheckIncludeFile)
include (CheckIncludeFiles)
include (CheckFunctionExists)
include (FindPkgConfig)
include (CheckCXXSourceCompiles)
include (cmake/CheckAtomic.cmake)
# PRE-CHECKS
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
if (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GNUCXX_MINIMUM_VERSION)
message (FATAL_ERROR "GCC version must be at least ${GNUCXX_MINIMUM_VERSION}!")
endif()
endif()
# OPTIONS
#OPTION(ENABLE_NATPMP "Enable support for the NAT-PMP protocol via libnatpmp"
# ON)
#OPTION(ENABLE_TBB "Enable support of the TBB library to improve performance"
# ON)
# 1.x had a different default value
unset(INSTALL_RUNTIME_PATH CACHE)
option (INSTALL_RUNTIME_PATH "Install rpath" ON)
option (STRIP "Strip debugging symbols to a separate file" OFF)
option (INSTALL_WEB_UI "Download and install the Web UI package" ON)
option (WITH_ASAN "Enable address sanitizer" OFF) # With clang: http://clang.llvm.org/docs/AddressSanitizer.html
# STATIC/SHARED
if (NOT DEFINED BUILD_SHARED_LIBS AND NOT WIN32)
set(BUILD_SHARED_LIBS ON)
elseif (NOT BUILD_SHARED_LIBS)
# http://cmake.3232098.n2.nabble.com/Howto-compile-static-executable-td5580269.html
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set_property(GLOBAL PROPERTY LINK_SEARCH_START_STATIC ON)
set_property(GLOBAL PROPERTY LINK_SEARCH_END_STATIC ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static")
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
# Boost UUID uses getrandom() kernel call, which is not supported on older platforms (which can't be detected by Boost with static builds)
# https://github.com/boostorg/uuid/issues/91
add_definitions ( -DBOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX )
endif()
## DEPENDENCIES
find_package (PkgConfig)
# PATHS
if (NOT LIBDIR)
set (LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
endif (NOT LIBDIR)
message (STATUS "Library directory: ${LIBDIR}")
if (INSTALL_RUNTIME_PATH AND BUILD_SHARED_LIBS)
set (CMAKE_INSTALL_RPATH "${LIBDIR}")
endif ()
if (NOT RESOURCE_DIRECTORY)
set (RESOURCE_DIRECTORY "${CMAKE_INSTALL_FULL_DATAROOTDIR}/airdcpp/")
endif (NOT RESOURCE_DIRECTORY)
message (STATUS "Resource directory: ${RESOURCE_DIRECTORY}")
if (NOT GLOBAL_CONFIG_DIRECTORY)
set (GLOBAL_CONFIG_DIRECTORY "${CMAKE_INSTALL_FULL_SYSCONFDIR}/airdcpp/")
endif (NOT GLOBAL_CONFIG_DIRECTORY)
message (STATUS "Startup config directory: ${GLOBAL_CONFIG_DIRECTORY}")
if (WIN32 OR HAIKU)
set (BINDIR .)
elseif (UNIX)
set (BINDIR bin)
if (APPLE)
set (BUNDLEDIR .)
endif (APPLE)
endif (WIN32 OR HAIKU)
# COMPILING DEFINITIONS
if (APPLE)
add_definitions(-DAPPLE)
endif (APPLE)
# Support files > 2 GB
add_definitions (-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64)
# Flags
if (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
#if (USE_GOLD)
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-linker-plugin")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-linker-plugin")
#endif()
if (NOT APPLE)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
endif ()
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexperimental-library")
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
# Disable ABI change notification spam
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
endif ()
if (WITH_ASAN)
# llvm-symbolizer must be on the path.
# Ubuntu: ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-3.8/bin/llvm-symbolizer ASAN_OPTIONS=suppressions=MyASan.supp
# MyASan.supp: interceptor_via_lib:libminiupnpc.so
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-optimize-sibling-calls -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
message(STATUS "Address sanitizer is enabled")
endif()
# FILES TO COMPILE
# Remove possible old generated files
execute_process(COMMAND rm airdcpp-core/airdcpp/StringDefs.cpp OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND rm airdcpp-core/airdcpp/version.inc OUTPUT_QUIET ERROR_QUIET)
add_subdirectory (airdcpp-core)
add_subdirectory (airdcpp-webapi)
add_subdirectory (airdcppd)
# WEB UI
if (INSTALL_WEB_UI)
find_program(NPM_EXECUTABLE npm PATHS /sw/bin)
if(NOT NPM_EXECUTABLE)
message(FATAL_ERROR "Could not find 'npm' executable. Please install npm")
endif()
message(STATUS "Installing Web UI")
execute_process (COMMAND sh scripts/install_webui.sh ${SOVERSION} scripts/parse_webui_version.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE SCRIPT_RESULT)
if(NOT "${SCRIPT_RESULT}" STREQUAL "0")
message(FATAL_ERROR "Failed to install Web UI")
endif()
else (INSTALL_WEB_UI)
message(STATUS "Skipping Web UI installation")
endif (INSTALL_WEB_UI)
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake")
if(INSTALL_WEB_UI)
install (DIRECTORY node_modules/airdcpp-webui/dist/ DESTINATION ${RESOURCE_DIRECTORY}web-resources)
endif (INSTALL_WEB_UI)