-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCMakeLists.txt
274 lines (226 loc) · 8.64 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
cmake_minimum_required(VERSION 3.15)
# Version string
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0077 NEW)
if (UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
project(torrenttools
DESCRIPTION "A commandline tool for creating, inspecting and modifying BitTorrent metafiles."
LANGUAGES CXX
VERSION 0.6.2
HOMEPAGE_URL https://www.github.com/fbdtemme/torrenttools)
# Make Find modules in cmake dir available
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
if (APPLE)
set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib")
endif()
if (TORRENTTOOLS_PACKAGES_ONLY)
include(packages/packages.cmake)
return()
endif()
include(CTest)
include(GNUInstallDirs)
# Path including images, config files etc
set(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
include(CMakeDependentOption)
option(TORRENTTOOLS_BUILD_TESTS
"Build tests" OFF)
cmake_dependent_option(TORRENTTOOLS_BUILD_TESTS_COVERAGE
"Build tests with coverage." OFF "TORRENTTOOLS_BUILD_TESTS" OFF)
option(TORRENTTOOLS_BUILD_DOCS
"Generate documentation" OFF)
option(TORRENTTOOLS_INSTALL
"Generate an install target" ON)
option(TORRENTTOOLS_TBB "Accelerate using Intel TBB library." ON)
#add_subdirectory(../cliprogress cliprogress)
#add_subdirectory(../dottorrent dottorrent)
#add_subdirectory(../termcontrol termcontrol)
#add_subdirectory(../bencode bencode)
include(external/external.cmake)
if (TORRENTTOOLS_TBB)
find_package(TBB REQUIRED)
endif()
add_executable(torrenttools
src/app_data.cpp
src/argument_parsers.cpp
src/common.cpp
src/config_parser.cpp
src/create.cpp
src/main_app.cpp
src/edit.cpp
src/escape_binary_fields.cpp
src/formatters.cpp
src/indicator.cpp
src/info.cpp
src/magnet.cpp
src/main.cpp
src/pad.cpp
src/progress.cpp
src/show.cpp
src/tracker_database.cpp
src/tree_view.cpp
src/verify.cpp
src/profile.cpp
src/ls_colors.cpp
)
target_include_directories(torrenttools PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_features(torrenttools PUBLIC cxx_std_20)
target_link_libraries(torrenttools PRIVATE
dottorrent::dottorrent
termcontrol::termcontrol
cliprogress::cliprogress
fmt::fmt
date::date
gsl::gsl-lite-v1
CLI11::CLI11
re2::re2
yaml-cpp
nlohmann_json::nlohmann_json
)
if (TORRENTTOOLS_TBB)
message(STATUS "Using Intel TBB library.")
target_link_libraries(torrenttools PRIVATE TBB::tbb)
target_compile_definitions(torrenttools PRIVATE TORRENTTOOLS_USE_TBB)
endif()
# Set the linker to lld to get decent link times on MinGW
if (MINGW)
find_program(HAS_LLD_LINKER "lld")
if (HAS_LLD_LINKER)
message(STATUS "Using lld linker for MinGW generator.")
target_link_options(torrenttools PRIVATE -fuse-ld=lld)
endif()
endif()
if (TORRENTTOOLS_BUILD_TESTS)
add_subdirectory(tests)
endif()
if(TORRENTTOOLS_BUILD_DOCS)
add_subdirectory(docs)
endif()
# Set the install prefix to /usr/local/bin/torrenttools
message(DEBUG ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
if (MINGW OR WIN32)
# Set the install prefix to Program Files instead of Program Files (x86)
message(DEBUG ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(DEBUG "Changing default install prefix")
SET(CMAKE_INSTALL_PREFIX "C:/Program Files/${PROJECT_NAME}" CACHE PATH
"Install path prefix, prepended onto install directories." FORCE)
endif()
elseif (APPLE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(DEBUG "Changing default install prefix")
set(CMAKE_INSTALL_PREFIX "/Library/${PROJECT_NAME}" CACHE PATH
"Install path prefix, prepended onto install directories." FORCE)
endif()
endif()
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
## Load the sysconf install dir as set by the RPM and DEB
if(NOT DEFINED SYSCONF_INSTALL_DIR)
set(SYSCONF_INSTALL_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR})
message(DEBUG "Setting SYSCONF_INSTALL_DIR: ${SYSCONF_INSTALL_DIR}")
else()
message(DEBUG "Setting SYSCONF_INSTALL_DIR: ${SYSCONF_INSTALL_DIR}")
endif()
# torrenttools_sysconf_dir: Full path used to lookup system scope configuration files.
if (LINUX)
set(torrenttools_sysconf_dir "${SYSCONF_INSTALL_DIR}/torrenttools")
elseif (WIN32)
# Dump everything in the install prefix on windows
set(torrenttools_sysconf_dir "${CMAKE_INSTALL_PREFIX}")
elseif (APPLE)
set(torrenttools_sysconf_dir "${CMAKE_INSTALL_PREFIX}/etc")
endif ()
message(STATUS "Install sysconf dir: ${torrenttools_sysconf_dir}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp)
if (TORRENTTOOLS_INSTALL)
if (LINUX)
# install trackers to system config dir since it is global data.
install(FILES resources/trackers.json
resources/config.yml
COMPONENT torrenttools
DESTINATION ${torrenttools_sysconf_dir})
# install executable
install(TARGETS torrenttools
COMPONENT torrenttools
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if (MINGW OR WIN32)
# install resources in the install prefix
install(FILES resources/trackers.json
resources/config.yml
COMPONENT torrenttools
DESTINATION ".")
# install executable
install(TARGETS torrenttools
COMPONENT torrenttools
RUNTIME DESTINATION ".")
# Install mingw shared libraries to the project dir
# Filter out core windows libraries with regex
install(CODE [[
set(LIBRARY_PATH $ENV{PATH})
string(REPLACE "\\" "/" LIBRARY_PATH "${LIBRARY_PATH}")
message(STATUS "Searching for libraries in: ${LIBRARY_PATH}")
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES $<TARGET_FILE:torrenttools>
DIRECTORIES ${LIBRARY_PATH}
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
PRE_EXCLUDE_REGEXES ".*-ms-win-.*" ".*ext-ms-.*"
POST_INCLUDE_REGEXES ".*libcrypto.*"
POST_EXCLUDE_REGEXES ".*system32.*"
)
foreach(_file ${_r_deps})
file(INSTALL ${_file}
DESTINATION "${CMAKE_INSTALL_PREFIX}"
FOLLOW_SYMLINK_CHAIN)
endforeach()
list(LENGTH _u_deps _u_length)
if("${_u_length}" GREATER 0)
message(STATUS "${_u_deps}")
message(WARNING "Unresolved dependencies detected!")
foreach(_u_dep ${_u_deps})
message(WARNING "Dependency unresolved: ${_u_dep}")
endforeach()
endif()
]]
COMPONENT torrenttools)
endif()
if (APPLE)
# install executable
install(TARGETS torrenttools
COMPONENT torrenttools
DESTINATION "bin")
# install configuration
install(FILES resources/trackers.json
resources/config.yml
COMPONENT torrenttools
DESTINATION "etc")
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES $<TARGET_FILE:torrenttools>
DIRECTORIES "/usr/bin/local/Cellar" "/usr/bin/local"
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
PRE_EXCLUDE_REGEXES ".*libSystem.B.*"
)
foreach(_file ${_r_deps})
file(INSTALL ${_file}
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
FOLLOW_SYMLINK_CHAIN)
get_filename_component(_file_name "${_file}" NAME)
execute_process(COMMAND install_name_tool -change "${_file}" "@executable_path/../lib/${_file_name}" "${CMAKE_INSTALL_PREFIX}/bin/torrenttools" )
endforeach()
list(LENGTH _u_deps _u_length)
if("${_u_length}" GREATER 0)
message(STATUS "${_u_deps}")
message(WARNING "Unresolved dependencies detected!")
foreach(_u_dep ${_u_deps})
message(WARNING "Dependency unresolved: ${_u_dep}")
endforeach()
endif()
]]
COMPONENT torrenttools)
endif()
endif()
include(packages/packages.cmake)