-
Notifications
You must be signed in to change notification settings - Fork 370
/
CMakeLists.txt
642 lines (561 loc) · 24.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# Copyright (c) 2019, QuantStack and Mamba Contributors
#
# Distributed under the terms of the BSD 3-Clause License.
#
# The full license is in the file LICENSE, distributed with this software.
cmake_minimum_required (VERSION 3.16)
cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0
cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13
project(libmamba)
set(LIBMAMBA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(LIBMAMBA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(LIBMAMBA_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
# Versioning
# ===========
file(STRINGS "${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp" libmamba_version_defines
REGEX "#define LIBMAMBA_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${libmamba_version_defines})
if(ver MATCHES "#define LIBMAMBA_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(LIBMAMBA_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${LIBMAMBA_VERSION_MAJOR}.${LIBMAMBA_VERSION_MINOR}.${LIBMAMBA_VERSION_PATCH})
message(STATUS "Building libmamba v${${PROJECT_NAME}_VERSION}")
# Binary version
# See the following URL for explanations about the binary versionning
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
file(STRINGS "${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp" libmamba_version_defines
REGEX "#define LIBMAMBA_BINARY_(CURRENT|REVISION|AGE)")
foreach(ver ${libmamba_version_defines})
if(ver MATCHES "#define LIBMAMBA_BINARY_(CURRENT|REVISION|AGE) +([^ ]+)$")
set(LIBMAMBA_BINARY_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(LIBMAMBA_BINARY_VERSION
${LIBMAMBA_BINARY_CURRENT}.${LIBMAMBA_BINARY_REVISION}.${LIBMAMBA_BINARY_AGE})
message(STATUS "libmamba binary version: v${LIBMAMBA_BINARY_VERSION}")
# Build options
# =============
option(BUILD_TESTS "Build libmamba C++ tests" OFF)
option(BUILD_SHARED "Build shared libmamba library" OFF)
option(BUILD_STATIC "Build static libmamba library with static linkage to its dependencies" OFF)
set(BUILD_LOG_LEVEL "TRACE" CACHE STRING "Logger active level at compile time")
if (NOT ${BUILD_LOG_LEVEL} MATCHES "^(TRACE|DEBUG|INFO|WARN|ERROR|CRITICAL|OFF)$")
message(FATAL_ERROR "Invalid log level: ${BUILD_LOG_LEVEL}, should be one of { TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF }")
endif ()
if (BUILD_STATIC)
add_definitions("-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${BUILD_LOG_LEVEL}")
add_definitions(-DLIBMAMBA_STATIC_DEPS)
endif ()
if (WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()
option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF)
if(ENABLE_ASAN)
message(WARNING "Address-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=address)
add_link_options(-fno-omit-frame-pointer -fsanitize=address)
endif()
if(ENABLE_TSAN)
message(WARNING "Thread-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=thread)
add_link_options(-fno-omit-frame-pointer -fsanitize=thread)
endif()
if(ENABLE_USAN)
message(WARNING "Undefined-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined)
add_link_options(-fno-omit-frame-pointer -fsanitize=undefined)
endif()
# Source files
# ============
find_package (Python3 COMPONENTS Interpreter)
set(SHELL_SCRIPTS
micromamba.sh
micromamba.csh
micromamba.bat
activate.bat
_mamba_activate.bat
mamba_hook.bat
mamba_hook.ps1
Mamba.psm1
mamba.xsh
mamba.fish
compile_pyc.py
mamba_completion.posix)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shell_scripts)
foreach(script ${SHELL_SCRIPTS})
string(REPLACE "." "_" script_var ${script})
add_custom_command(OUTPUT shell_scripts/${script}.cpp
DEPENDS data/${script}
COMMAND ${Python3_EXECUTABLE} ${LIBMAMBA_DATA_DIR}/bin2header.py
--extern
-v data_${script_var}
-i ${CMAKE_CURRENT_SOURCE_DIR}/data/${script}
-o ${CMAKE_CURRENT_BINARY_DIR}/shell_scripts/${script}.cpp)
endforeach()
set(LIBMAMBA_SOURCES
longpath.manifest
${LIBMAMBA_SOURCE_DIR}/version.cpp
# C++ wrapping of libsolv
${LIBMAMBA_SOURCE_DIR}/solv-cpp/queue.cpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/pool.cpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/repo.cpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/solvable.cpp
# C++ wrapping of libcurl
${LIBMAMBA_SOURCE_DIR}/core/curl.cpp
# C++ wrapping of compression libs (zstd and bzlib)
${LIBMAMBA_SOURCE_DIR}/core/compression.cpp
# Implementation of version and matching specs
${LIBMAMBA_SOURCE_DIR}/specs/version.cpp
${LIBMAMBA_SOURCE_DIR}/specs/repo_data.cpp
# Core API (low-level)
${LIBMAMBA_SOURCE_DIR}/core/singletons.cpp
${LIBMAMBA_SOURCE_DIR}/core/activation.cpp
${LIBMAMBA_SOURCE_DIR}/core/channel.cpp
${LIBMAMBA_SOURCE_DIR}/core/context.cpp
${LIBMAMBA_SOURCE_DIR}/core/environment.cpp
${LIBMAMBA_SOURCE_DIR}/core/environments_manager.cpp
${LIBMAMBA_SOURCE_DIR}/core/error_handling.cpp
${LIBMAMBA_SOURCE_DIR}/core/fetch.cpp
${LIBMAMBA_SOURCE_DIR}/core/transaction_context.cpp
${LIBMAMBA_SOURCE_DIR}/core/link.cpp
${LIBMAMBA_SOURCE_DIR}/core/history.cpp
${LIBMAMBA_SOURCE_DIR}/core/mamba_fs.cpp
${LIBMAMBA_SOURCE_DIR}/core/match_spec.cpp
${LIBMAMBA_SOURCE_DIR}/core/menuinst.cpp
${LIBMAMBA_SOURCE_DIR}/core/url.cpp
${LIBMAMBA_SOURCE_DIR}/core/output.cpp
${LIBMAMBA_SOURCE_DIR}/core/package_handling.cpp
${LIBMAMBA_SOURCE_DIR}/core/package_cache.cpp
${LIBMAMBA_SOURCE_DIR}/core/pool.cpp
${LIBMAMBA_SOURCE_DIR}/core/prefix_data.cpp
${LIBMAMBA_SOURCE_DIR}/core/satisfiability_error.cpp
${LIBMAMBA_SOURCE_DIR}/core/progress_bar.cpp
${LIBMAMBA_SOURCE_DIR}/core/progress_bar_impl.cpp
${LIBMAMBA_SOURCE_DIR}/core/pinning.cpp
${LIBMAMBA_SOURCE_DIR}/core/package_info.cpp
${LIBMAMBA_SOURCE_DIR}/core/package_paths.cpp
${LIBMAMBA_SOURCE_DIR}/core/query.cpp
${LIBMAMBA_SOURCE_DIR}/core/repo.cpp
${LIBMAMBA_SOURCE_DIR}/core/run.cpp
${LIBMAMBA_SOURCE_DIR}/core/shell_init.cpp
${LIBMAMBA_SOURCE_DIR}/core/solver.cpp
${LIBMAMBA_SOURCE_DIR}/core/subdirdata.cpp
${LIBMAMBA_SOURCE_DIR}/core/thread_utils.cpp
${LIBMAMBA_SOURCE_DIR}/core/transaction.cpp
${LIBMAMBA_SOURCE_DIR}/core/util.cpp
${LIBMAMBA_SOURCE_DIR}/core/fsutil.cpp
${LIBMAMBA_SOURCE_DIR}/core/util_string.cpp
${LIBMAMBA_SOURCE_DIR}/core/util_os.cpp
${LIBMAMBA_SOURCE_DIR}/core/validate.cpp
${LIBMAMBA_SOURCE_DIR}/core/virtual_packages.cpp
${LIBMAMBA_SOURCE_DIR}/core/env_lockfile.cpp
${LIBMAMBA_SOURCE_DIR}/core/execution.cpp
${LIBMAMBA_SOURCE_DIR}/core/timeref.cpp
# API (high-level)
${LIBMAMBA_SOURCE_DIR}/api/c_api.cpp
${LIBMAMBA_SOURCE_DIR}/api/channel_loader.cpp
${LIBMAMBA_SOURCE_DIR}/api/clean.cpp
${LIBMAMBA_SOURCE_DIR}/api/config.cpp
${LIBMAMBA_SOURCE_DIR}/api/configuration.cpp
${LIBMAMBA_SOURCE_DIR}/api/create.cpp
${LIBMAMBA_SOURCE_DIR}/api/info.cpp
${LIBMAMBA_SOURCE_DIR}/api/install.cpp
${LIBMAMBA_SOURCE_DIR}/api/list.cpp
${LIBMAMBA_SOURCE_DIR}/api/remove.cpp
${LIBMAMBA_SOURCE_DIR}/api/repoquery.cpp
${LIBMAMBA_SOURCE_DIR}/api/shell.cpp
${LIBMAMBA_SOURCE_DIR}/api/update.cpp
)
foreach(script ${SHELL_SCRIPTS})
list(APPEND LIBMAMBA_SOURCES shell_scripts/${script}.cpp)
endforeach()
set(LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp
# Utility library
${LIBMAMBA_INCLUDE_DIR}/mamba/util/flat_set.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/graph.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/compare.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/cast.hpp
# Implementation of version and matching specs
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/version.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/repo_data.hpp
# Core API (low-level)
${LIBMAMBA_INCLUDE_DIR}/mamba/core/activation.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/channel.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/channel_builder.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/palette.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/context.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/environment.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/environments_manager.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/error_handling.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/fetch.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/satisfiability_error.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/history.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/link.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/mamba_fs.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/match_spec.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/menuinst.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/output.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/package_cache.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/package_handling.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/package_info.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/package_paths.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/pool.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/prefix_data.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/progress_bar.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/pinning.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/query.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/repo.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/run.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/shell_init.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/solver.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/subdirdata.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/thread_utils.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/transaction.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/transaction_context.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/url.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/fsutil.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_os.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_random.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_scope.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_string.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/validate.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/virtual_packages.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/env_lockfile.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/tasksync.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/invoke.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/timeref.hpp
# API (high-level)
${LIBMAMBA_INCLUDE_DIR}/mamba/api/c_api.h
${LIBMAMBA_INCLUDE_DIR}/mamba/api/channel_loader.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/clean.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/config.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/configuration.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/configuration_impl.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/constants.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/create.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/info.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/install.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/list.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/remove.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/repoquery.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/shell.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/api/update.hpp
)
set(LIBMAMBA_PRIVATE_HEADERS
# C++ wrapping of libsolv
${LIBMAMBA_SOURCE_DIR}/solv-cpp/queue.hpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/ids.hpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/pool.hpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/solvable.hpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/repo.hpp
# C++ wrapping of compression libs (zstd and bzlib)
${LIBMAMBA_SOURCE_DIR}/core/compression.hpp
# C++ wrapping of libcurl
${LIBMAMBA_SOURCE_DIR}/core/curl.hpp
)
# Targets and link
# ================
macro(libmamba_create_target target_name linkage output_name)
string(TOUPPER "${linkage}" linkage_upper)
if (NOT ${linkage_upper} MATCHES "^(SHARED|STATIC)$")
message(FATAL_ERROR "Invalid library linkage: ${linkage}")
endif ()
# Output
# ======
add_library(
${target_name} ${linkage_upper}
${LIBMAMBA_PUBLIC_HEADERS}
${LIBMAMBA_PRIVATE_HEADERS}
${LIBMAMBA_SOURCES}
)
mamba_target_add_compile_warnings(
${target_name}
WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR}
)
if (${linkage_upper} STREQUAL "STATIC")
message(" -> Statically linking against libmamba (static) dependencies")
if (UNIX)
set(REQUIRED_STATIC_DEPS
libcurl.a
libssh2.a
libgssapi_krb5.a
libkrb5.a
libk5crypto.a
libkrb5support.a
libcom_err.a
libssl.a
libcrypto.a
libarchive.a
libsolv.a
libsolvext.a
libiconv.a
libbz2.a
liblz4.a
libzstd.a
libz.a
liblzma.a
libnghttp2.a
libyaml-cpp.a
libreproc++.a
libreproc.a
)
if (APPLE)
set(REQUIRED_STATIC_DEPS ${REQUIRED_STATIC_DEPS} libc++.a)
endif()
if (UNIX AND NOT APPLE)
list(REMOVE_ITEM REQUIRED_STATIC_DEPS libiconv.a)
endif()
set(STATIC_DEPS "")
foreach(LIB ${REQUIRED_STATIC_DEPS})
set(TMP_LIB "${LIB}-NOTFOUND")
find_library(TMP_LIB
NAMES "${LIB}"
)
list(APPEND STATIC_DEPS "${TMP_LIB}")
endforeach(LIB)
if (APPLE)
find_library(SECURITY_LIBRARY Security)
find_library(SYSTEMCONFIGURATION_LIBRARY SystemConfiguration)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
message("Found library: ${SECURITY_LIBRARY}\n${COREFOUNDATION_LIBRARY}")
list(APPEND STATIC_DEPS ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY} ${SYSTEMCONFIGURATION_LIBRARY})
endif()
message(" -> Found static dependencies:")
foreach(LIB ${STATIC_DEPS})
message(" - ${LIB}")
endforeach(LIB)
if (APPLE)
set (MAMBA_FORCE_DYNAMIC_LIBS resolv c++abi)
target_link_options(${target_name} PRIVATE -static-libstdc++)
elseif (UNIX)
set(MAMBA_FORCE_DYNAMIC_LIBS rt dl resolv)
target_link_options(${target_name} PUBLIC -static-libstdc++ -static-libgcc)
endif()
find_package(fmt REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(tl-expected REQUIRED)
add_compile_definitions(SPDLOG_FMT_EXTERNAL)
target_link_libraries(
${target_name}
PUBLIC
${STATIC_DEPS}
${MAMBA_FORCE_DYNAMIC_LIBS}
spdlog::spdlog_header_only
fmt::fmt-header-only
)
elseif (WIN32)
set(CMAKE_PREFIX_PATH "$ENV{VCPKG_ROOT}/installed/x64-windows-static/")
set_target_properties(${target_name} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# For Windows we have a vcpkg based build system right now.
find_package(LibArchive REQUIRED)
find_package(CURL CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_library(LIBLZMA_LIBRARIES lzma REQUIRED)
find_library(LZ4_LIBRARY NAMES lz4)
find_library(LZO2_LIBRARY NAMES lzo2)
find_package(zstd CONFIG REQUIRED)
find_library(BZIP2_LIBRARIES NAMES bz2)
find_library(CRYPTO_LIBRARIES NAMES libcrypto)
find_library(LIBSOLV_BUILD_STATICRARIES NAMES solv_static)
find_library(LIBSOLVEXT_BUILD_STATICRARIES NAMES solvext_static)
find_package(reproc++ CONFIG REQUIRED)
find_package(tl-expected REQUIRED)
find_library(LIBXML2_LIBRARY NAMES libxml2)
find_library(ICONV_LIBRARY NAMES libiconv iconv)
find_library(CHARSET_LIBRARY NAMES libcharset charset)
message("Found: ${LIBXML2_LIBRARY} ${ICONV_LIBRARY} ${CHARSET_LIBRARY}")
target_link_libraries(${target_name} PUBLIC
${CRYPTO_LIBRARIES}
${LibArchive_LIBRARY}
${LIBXML2_LIBRARY}
${ICONV_LIBRARY}
${CHARSET_LIBRARY}
zstd::libzstd_static
${LZ4_LIBRARY}
${LZO2_LIBRARY}
${BZIP2_LIBRARIES}
${LIBLZMA_LIBRARIES}
CURL::libcurl
nlohmann_json::nlohmann_json
fmt::fmt-header-only
# Since conda-forge spdlog is built with a bundled version of fmt we use the
# header only version to avoid chasing after the correct fmt version mathching
# the one used in the bundle
spdlog::spdlog_header_only
yaml-cpp
${LIBSOLV_BUILD_STATICRARIES}
${LIBSOLVEXT_BUILD_STATICRARIES}
${sodium_LIBRARY_RELEASE}
reproc++
reproc
tl::expected
)
add_compile_definitions(
SPDLOG_FMT_EXTERNAL
LIBARCHIVE_STATIC
CURL_STATICLIB
SOLV_BUILD_STATIC
)
include_directories($ENV{CONDA_PREFIX}/Library/include/)
include_directories($ENV{VCPKG_ROOT}/installed/x64-windows-static/include/)
endif()
else ()
message(" -> Dynamically linking against libmamba (shared) dependencies")
find_library(LIBSOLV_LIBRARIES NAMES solv)
find_library(LIBSOLVEXT_LIBRARIES NAMES solvext)
find_package(CURL REQUIRED)
find_package(LibArchive REQUIRED)
find_package(zstd REQUIRED)
find_package(BZip2 REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(reproc++ CONFIG REQUIRED)
find_package(tl-expected REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog CONFIG REQUIRED)
set(LIBMAMBA_LIBRARIES_DEPS
${LIBSOLV_LIBRARIES}
${LIBSOLVEXT_LIBRARIES}
${LibArchive_LIBRARIES}
zstd::libzstd_shared
${CURL_LIBRARIES}
${OPENSSL_LIBRARIES}
zstd::libzstd_shared
BZip2::BZip2
yaml-cpp
reproc++
reproc
tl::expected
fmt::fmt
# Since conda-forge spdlog is built with a bundled version of fmt we use the
# header only version to avoid chasing after the correct fmt version mathching
# the one used in the bundle
spdlog::spdlog_header_only
)
add_compile_definitions(SPDLOG_FMT_EXTERNAL)
target_link_libraries(${target_name} PUBLIC
${LIBMAMBA_LIBRARIES_DEPS}
${MAMBA_FORCE_DYNAMIC_LIBS})
endif ()
target_compile_features(${target_name} PUBLIC cxx_std_17)
target_include_directories(
${target_name}
PUBLIC
$<BUILD_INTERFACE:${LIBMAMBA_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)
if (WIN32)
find_path(
WINREG_INCLUDE_DIR
NAMES WinReg.hpp
PATH_SUFFIXES winreg
)
endif()
target_include_directories(
${target_name}
PRIVATE
${LIBMAMBA_SOURCE_DIR}
${WINREG_INCLUDE_DIR}
)
if (UNIX)
math(EXPR LIBMAMBA_BINARY_COMPATIBLE "${LIBMAMBA_BINARY_CURRENT} - ${LIBMAMBA_BINARY_AGE}")
set_target_properties(
${target_name}
PROPERTIES
#PUBLIC_HEADER "${LIBMAMBA_PUBLIC_HEADERS}"
COMPILE_DEFINITIONS "LIBMAMBA_EXPORTS"
PREFIX ""
VERSION "${LIBMAMBA_BINARY_COMPATIBLE}.${LIBMAMBA_BINARY_REVISION}.${LIBMAMBA_BINARY_AGE}"
SOVERSION ${LIBMAMBA_BINARY_COMPATIBLE}
OUTPUT_NAME "${output_name}"
)
else()
set_target_properties(
${target_name}
PROPERTIES
#PUBLIC_HEADER "${LIBMAMBA_PUBLIC_HEADERS}"
COMPILE_DEFINITIONS "LIBMAMBA_EXPORTS"
PREFIX ""
VERSION ${LIBMAMBA_BINARY_VERSION}
SOVERSION ${LIBMAMBA_BINARY_CURRENT}
OUTPUT_NAME "${output_name}"
)
target_compile_definitions(${target_name} PUBLIC GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE)
endif()
if (${linkage_upper} STREQUAL "STATIC")
find_package(nlohmann_json CONFIG REQUIRED)
find_package(Threads REQUIRED)
target_link_libraries(${target_name} PUBLIC
nlohmann_json::nlohmann_json
Threads::Threads)
endif ()
list(APPEND libmamba_targets ${target_name})
endmacro()
set(libmamba_targets "")
if (BUILD_SHARED)
message(STATUS "Adding shared libmamba target")
libmamba_create_target(libmamba SHARED libmamba)
endif ()
if (BUILD_STATIC)
message(STATUS "Adding static libmamba target")
# On Windows, a static library should use a different output name
# to avoid the conflict with the import library of a shared one.
if (CMAKE_HOST_WIN32)
libmamba_create_target(libmamba-static STATIC libmamba_static)
else ()
libmamba_create_target(libmamba-static STATIC libmamba)
endif ()
endif ()
if (NOT (BUILD_SHARED OR BUILD_STATIC))
message(FATAL_ERROR "Select at least a build variant for libmamba")
endif ()
# Tests
if (BUILD_TESTS)
add_subdirectory(tests)
endif()
# Installation
# ============
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(LIBMAMBA_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for libmambaConfig.cmake")
install(TARGETS ${libmamba_targets}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY "${LIBMAMBA_INCLUDE_DIR}/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h")
# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
# Configure 'mambaConfig.cmake' for a build tree
set(MAMBA_CONFIG_CODE "####### Expanded from \@MAMBA_CONFIG_CODE\@ #######\n")
set(MAMBA_CONFIG_CODE "${MAMBA_CONFIG_CODE}set(CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake;\${CMAKE_MODULE_PATH}\")\n")
set(MAMBA_CONFIG_CODE "${MAMBA_CONFIG_CODE}##################################################")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${PROJECT_BINARY_DIR})
# Configure 'mambaConfig.cmake' for an install tree
set(MAMBA_CONFIG_CODE "")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${MAMBA_VERSION_MAJOR}.${MAMBA_VERSION_MINOR}.${MAMBA_VERSION_PATCH}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR})
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR})