Add cmake-format (#2962)

* Add cmake-format

* Apply cmake-format
This commit is contained in:
Antoine Prouvost 2023-11-07 11:08:26 +01:00 committed by GitHub
parent 2b948ce1cc
commit d116ff8917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 410 additions and 321 deletions

32
.cmake-format.json Normal file
View File

@ -0,0 +1,32 @@
{
"encode": {
"emit_byteorder_mark": false,
"input_encoding": "utf-8",
"output_encoding": "utf-8"
},
"format": {
"always_wrap": [],
"autosort": false,
"command_case": "lower",
"dangle_align": "prefix",
"dangle_parens": true,
"enable_sort": true,
"keyword_case": "upper",
"layout_passes": {},
"line_ending": "unix",
"line_width": 100,
"max_lines_hwrap": 0,
"max_pargs_hwrap": 6,
"max_prefix_chars": 0,
"max_rows_cmdline": 1,
"max_subgroups_hwrap": 2,
"min_prefix_chars": 0,
"require_valid_layout": false,
"separate_ctrl_name_with_space": false,
"separate_fn_name_with_space": false,
"tab_size": 4
},
"misc": {
"per_command": {}
}
}

View File

@ -1,49 +1,53 @@
exclude: libmamba/tests/data/repodata_json_cache* exclude: libmamba/tests/data/repodata_json_cache*
repos: repos:
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 23.9.1 rev: 23.9.1
hooks: hooks:
- id: black - id: black
args: [--safe, --quiet] args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs - repo: https://github.com/asottile/blacken-docs
rev: 1.16.0 rev: 1.16.0
hooks: hooks:
- id: blacken-docs - id: blacken-docs
additional_dependencies: [black==22.3.0] additional_dependencies: [black==22.3.0]
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 rev: v4.4.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
- id: fix-encoding-pragma - id: fix-encoding-pragma
args: [--remove] args: [--remove]
- id: check-yaml - id: check-yaml
exclude: ^.+(/tests/|/recipe/).+$ exclude: ^.+(/tests/|/recipe/).+$
- id: check-toml - id: check-toml
- id: check-json - id: check-json
- id: check-merge-conflict - id: check-merge-conflict
- id: pretty-format-json - id: pretty-format-json
args: [--autofix] args: [--autofix]
- id: debug-statements - id: debug-statements
language_version: python3 language_version: python3
- repo: https://github.com/pre-commit/mirrors-isort - repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1 rev: v5.10.1
hooks: hooks:
- id: isort - id: isort
exclude: tests/data exclude: tests/data
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/flake8
rev: 6.1.0 rev: 6.1.0
hooks: hooks:
- id: flake8 - id: flake8
language_version: python3 language_version: python3
additional_dependencies: additional_dependencies:
- flake8-typing-imports==1.15.0 - flake8-typing-imports==1.15.0
- flake8-builtins==2.1.0 - flake8-builtins==2.1.0
- flake8-bugbear==23.9.16 - flake8-bugbear==23.9.16
- flake8-isort==6.1.0 - flake8-isort==6.1.0
- repo: https://github.com/pre-commit/mirrors-clang-format - repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6 rev: v16.0.6
hooks: hooks:
- id: clang-format - id: clang-format
args: [--style=file] args: [--style=file]
exclude: ".json" exclude: ".json"
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format

View File

@ -4,7 +4,7 @@
# #
# The full license is in the file LICENSE, distributed with this software. # The full license is in the file LICENSE, distributed with this software.
cmake_minimum_required (VERSION 3.16) cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0 cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0
cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13 cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13
@ -19,25 +19,39 @@ option(BUILD_LIBMAMBA_TESTS "Build libmamba C++ tests" OFF)
option(BUILD_MICROMAMBA "Build micromamba" OFF) option(BUILD_MICROMAMBA "Build micromamba" OFF)
option(BUILD_MAMBA_PACKAGE "Build mamba package utility" OFF) option(BUILD_MAMBA_PACKAGE "Build mamba package utility" OFF)
option(MAMBA_WARNING_AS_ERROR "Treat compiler warnings as errors" OFF) option(MAMBA_WARNING_AS_ERROR "Treat compiler warnings as errors" OFF)
set(MAMBA_LTO "Default" CACHE STRING "Apply Link Time Optimization to targets") set(
MAMBA_LTO
"Default"
CACHE STRING "Apply Link Time Optimization to targets"
)
include("cmake/CompilerWarnings.cmake") include("cmake/CompilerWarnings.cmake")
include("cmake/LinkTimeOptimization.cmake") include("cmake/LinkTimeOptimization.cmake")
include("cmake/Checks.cmake") include("cmake/Checks.cmake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
if (MSVC) if(MSVC)
# NOMINMAX : prevent tons of code to be included when having to `#include <windows.h>` # NOMINMAX : prevent tons of code to be included when having to `#include <windows.h>` /EHsc :
# /EHsc : enable C++ exceptions (otherwise exceptions do not work) # enable C++ exceptions (otherwise exceptions do not work) /Zc:__cplusplus : makes sure
# /Zc:__cplusplus : makes sure `__cplusplus` is set to the current C++ version language. Otherwise it is always set to an incorrect wrong value. # `__cplusplus` is set to the current C++ version language. Otherwise it is always set to an
# /MP : enable multi-process build with MSBuild (it should be on by default but CMake generates the project files without the right params). # incorrect wrong value. /MP : enable multi-process build with MSBuild (it should be on by
# /external:I $ENV{CONDA_PREFIX}: consider the conda env prefix libraries headers as "external" to this project. # default but CMake generates the project files without the right params). /external:I
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX /EHsc /Zc:__cplusplus /MP /experimental:external /external:I $ENV{CONDA_PREFIX}") # $ENV{CONDA_PREFIX}: consider the conda env prefix libraries headers as "external" to this
# project.
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX /EHsc /Zc:__cplusplus /MP /experimental:external /external:I $ENV{CONDA_PREFIX}"
)
# Force release mode to avoid debug libraries to be linked # Force release mode to avoid debug libraries to be linked
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The build type") set(
CMAKE_BUILD_TYPE
"Release"
CACHE STRING "The build type"
)
# add_definitions("-DUNICODE -D_UNICODE") # add_definitions("-DUNICODE -D_UNICODE")
set( set(
CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CMAKE_MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
CACHE STRING "MSVC runtime library" CACHE STRING "MSVC runtime library"
) )
endif() endif()
@ -46,21 +60,21 @@ endif()
# ======== # ========
# libmamba library and tests # libmamba library and tests
if (BUILD_LIBMAMBA) if(BUILD_LIBMAMBA)
add_subdirectory(libmamba) add_subdirectory(libmamba)
endif() endif()
# Python bindings of libmamba # Python bindings of libmamba
if (BUILD_LIBMAMBAPY) if(BUILD_LIBMAMBAPY)
add_subdirectory(libmambapy) add_subdirectory(libmambapy)
endif() endif()
# micromamba # micromamba
if (BUILD_MICROMAMBA) if(BUILD_MICROMAMBA)
add_subdirectory(micromamba) add_subdirectory(micromamba)
endif() endif()
# mamba package tarball utility # mamba package tarball utility
if (BUILD_MAMBA_PACKAGE) if(BUILD_MAMBA_PACKAGE)
add_subdirectory(mamba_package) add_subdirectory(mamba_package)
endif() endif()

View File

@ -2,8 +2,7 @@
# Check that the target has the proper type. # Check that the target has the proper type.
# #
# This is useful for targets that can be either static or dynamic but have the # This is useful for targets that can be either static or dynamic but have the same name.
# same name.
function(mamba_target_check_type target expected_type log_level) function(mamba_target_check_type target expected_type log_level)
get_target_property(actual_type ${target} TYPE) get_target_property(actual_type ${target} TYPE)
if(NOT actual_type STREQUAL expected_type) if(NOT actual_type STREQUAL expected_type)

View File

@ -15,16 +15,16 @@ function(mamba_target_add_compile_warnings target)
# Extra arguments not accounted for # Extra arguments not accounted for
if(ARG_UNPARSED_ARGUMENTS) if(ARG_UNPARSED_ARGUMENTS)
message( message(
AUTHOR_WARNING AUTHOR_WARNING "Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: "
"Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: " "${ARG_UNPARSED_ARGUMENTS}"
"${ARG_UNPARSED_ARGUMENTS}"
) )
endif() endif()
set( set(
msvc_warnings msvc_warnings
# External sever warnings # External sever warnings
/experimental:external /external:W1 /experimental:external
/external:W1
# Baseline reasonable warnings # Baseline reasonable warnings
/W4 /W4
# "identfier": conversion from "type1" to "type1", possible loss of data # "identfier": conversion from "type1" to "type1", possible loss of data

View File

@ -2,7 +2,6 @@
include(CheckIPOSupported) include(CheckIPOSupported)
# Detect is setting Link Time Optimization is recommended. # Detect is setting Link Time Optimization is recommended.
# #
# Currenlty checks if LTO is supported and if the build is a release. # Currenlty checks if LTO is supported and if the build is a release.
@ -17,9 +16,8 @@ function(mamba_should_lto)
# Extra arguments not accounted for # Extra arguments not accounted for
if(arg_UNPARSED_ARGUMENTS) if(arg_UNPARSED_ARGUMENTS)
message( message(
AUTHOR_WARNING AUTHOR_WARNING "Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: "
"Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: " "${ARG_UNPARSED_ARGUMENTS}"
"${ARG_UNPARSED_ARGUMENTS}"
) )
endif() endif()
@ -27,28 +25,46 @@ function(mamba_should_lto)
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower) string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
set(valid_release_names "release" "relwithdebinfo") set(valid_release_names "release" "relwithdebinfo")
if(NOT ${build_type_lower} IN_LIST valid_release_names) if(NOT ${build_type_lower} IN_LIST valid_release_names)
set(${arg_RESULT} FALSE PARENT_SCOPE) set(
set(${arg_OUTPUT} "the build type is not a release" PARENT_SCOPE) ${arg_RESULT}
FALSE
PARENT_SCOPE
)
set(
${arg_OUTPUT}
"the build type is not a release"
PARENT_SCOPE
)
return() return()
endif() endif()
# Check if LTO is supported by compiler # Check if LTO is supported by compiler
check_ipo_supported(RESULT lto_is_supported OUTPUT lto_not_supported_reason) check_ipo_supported(RESULT lto_is_supported OUTPUT lto_not_supported_reason)
if(NOT lto_is_supported) if(NOT lto_is_supported)
set(${arg_RESULT} FALSE PARENT_SCOPE) set(
set(${arg_OUTPUT} "${lto_not_supported_reason}" PARENT_SCOPE) ${arg_RESULT}
FALSE
PARENT_SCOPE
)
set(
${arg_OUTPUT}
"${lto_not_supported_reason}"
PARENT_SCOPE
)
endif() endif()
set(${arg_RESULT} TRUE PARENT_SCOPE) set(
${arg_RESULT}
TRUE
PARENT_SCOPE
)
endfunction() endfunction()
# Set Link Time Optimization on a given target. # Set Link Time Optimization on a given target.
# #
# MODE parameter takes the possible values # MODE parameter takes the possible values - A false constant: deactivate LTO - A true constant:
# - A false constant: deactivate LTO # activate LTO, fails if this is not supported by the compiler - "Default" or "Auto": set LTO if
# - A true constant: activate LTO, fails if this is not supported by the compiler # supported and the build type is a release.
# - "Default" or "Auto": set LTO if supported and the build type is a release.
function(mamba_target_set_lto target) function(mamba_target_set_lto target)
# Names of option parameters (without arguments) # Names of option parameters (without arguments)
set(options) set(options)
@ -60,9 +76,8 @@ function(mamba_target_set_lto target)
# Extra arguments not accounted for # Extra arguments not accounted for
if(arg_UNPARSED_ARGUMENTS) if(arg_UNPARSED_ARGUMENTS)
message( message(
AUTHOR_WARNING AUTHOR_WARNING "Unrecoginzed parameter passed to ${CMAKE_CURRENT_FUNCTION}: "
"Unrecoginzed parameter passed to ${CMAKE_CURRENT_FUNCTION}: " "'${arg_UNPARSED_ARGUMENTS}'"
"'${arg_UNPARSED_ARGUMENTS}'"
) )
return() return()
endif() endif()

View File

@ -1,30 +1,36 @@
find_package(PkgConfig) find_package(PkgConfig)
pkg_check_modules(PC_Libsolv QUIET libsolv) pkg_check_modules(PC_Libsolv QUIET libsolv)
find_path(Libsolv_INCLUDE_DIR find_path(
Libsolv_INCLUDE_DIR
NAMES solv/pool.h solvversion.h NAMES solv/pool.h solvversion.h
PATHS ${PC_Libsolv_INCLUDE_DIRS} PATHS ${PC_Libsolv_INCLUDE_DIRS}
) )
find_path(Libsolvext_INCLUDE_DIR find_path(
Libsolvext_INCLUDE_DIR
NAMES solv/repo_conda.h repo_conda.h NAMES solv/repo_conda.h repo_conda.h
PATHS ${PC_Libsolv_INCLUDE_DIRS} PATHS ${PC_Libsolv_INCLUDE_DIRS}
) )
find_library(Libsolv_LIBRARY find_library(
Libsolv_LIBRARY
NAMES libsolv.so libsolv.dylib solv.lib NAMES libsolv.so libsolv.dylib solv.lib
PATHS ${PC_Libsolv_LIBRARY_DIRS} PATHS ${PC_Libsolv_LIBRARY_DIRS}
) )
find_library(Libsolv_static_LIBRARY find_library(
Libsolv_static_LIBRARY
NAMES libsolv.a solv_static NAMES libsolv.a solv_static
PATHS ${PC_Libsolv_LIBRARY_DIRS} PATHS ${PC_Libsolv_LIBRARY_DIRS}
) )
find_library(Libsolvext_LIBRARY find_library(
Libsolvext_LIBRARY
NAMES libsolvext.so libsolvext.dylib solvext.lib NAMES libsolvext.so libsolvext.dylib solvext.lib
PATHS ${PC_Libsolv_LIBRARY_DIRS} PATHS ${PC_Libsolv_LIBRARY_DIRS}
) )
find_library(Libsolvext_static_LIBRARY find_library(
Libsolvext_static_LIBRARY
NAMES libsolvext.a solvext_static NAMES libsolvext.a solvext_static
PATHS ${PC_Libsolv_LIBRARY_DIRS} PATHS ${PC_Libsolv_LIBRARY_DIRS}
) )
@ -44,10 +50,11 @@ if(Libsolv_FOUND)
if(NOT TARGET solv::libsolv_static AND Libsolv_static_LIBRARY) if(NOT TARGET solv::libsolv_static AND Libsolv_static_LIBRARY)
add_library(solv::libsolv_static STATIC IMPORTED) add_library(solv::libsolv_static STATIC IMPORTED)
set_target_properties( set_target_properties(
solv::libsolv_static PROPERTIES solv::libsolv_static
IMPORTED_LOCATION "${Libsolv_static_LIBRARY}" PROPERTIES
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}" IMPORTED_LOCATION "${Libsolv_static_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}"
) )
endif() endif()
if(NOT TARGET solv::libsolv AND Libsolv_LIBRARY) if(NOT TARGET solv::libsolv AND Libsolv_LIBRARY)
@ -57,20 +64,22 @@ if(Libsolv_FOUND)
add_library(solv::libsolv UNKNOWN IMPORTED) add_library(solv::libsolv UNKNOWN IMPORTED)
endif() endif()
set_target_properties( set_target_properties(
solv::libsolv PROPERTIES solv::libsolv
IMPORTED_LOCATION "${Libsolv_LIBRARY}" PROPERTIES
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}" IMPORTED_LOCATION "${Libsolv_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}"
) )
endif() endif()
if(NOT TARGET solv::libsolvext_static AND Libsolvext_static_LIBRARY) if(NOT TARGET solv::libsolvext_static AND Libsolvext_static_LIBRARY)
add_library(solv::libsolvext_static STATIC IMPORTED) add_library(solv::libsolvext_static STATIC IMPORTED)
set_target_properties( set_target_properties(
solv::libsolvext_static PROPERTIES solv::libsolvext_static
IMPORTED_LOCATION "${Libsolvext_static_LIBRARY}" PROPERTIES
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}" IMPORTED_LOCATION "${Libsolvext_static_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}"
) )
endif() endif()
if(NOT TARGET solv::libsolvext AND Libsolvext_LIBRARY) if(NOT TARGET solv::libsolvext AND Libsolvext_LIBRARY)
@ -80,12 +89,11 @@ if(Libsolv_FOUND)
add_library(solv::libsolvext UNKNOWN IMPORTED) add_library(solv::libsolvext UNKNOWN IMPORTED)
endif() endif()
set_target_properties( set_target_properties(
solv::libsolvext PROPERTIES solv::libsolvext
IMPORTED_LOCATION "${Libsolvext_LIBRARY}" PROPERTIES
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}" IMPORTED_LOCATION "${Libsolvext_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}"
) )
endif() endif()
endif( endif()
)

View File

@ -8,6 +8,7 @@ dependencies:
- clang - clang
- clangxx - clangxx
- lld - lld
- cmake-format
# C++ Debugging # C++ Debugging
- gdb - gdb
- valgrind - valgrind

View File

@ -4,7 +4,7 @@
# #
# The full license is in the file LICENSE, distributed with this software. # The full license is in the file LICENSE, distributed with this software.
cmake_minimum_required (VERSION 3.16) cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0 cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0
cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13 cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13
project(libmamba) project(libmamba)
@ -15,81 +15,110 @@ set(LIBMAMBA_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
# Versioning # Versioning
# =========== # ===========
file(STRINGS "${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp" libmamba_version_defines file(
REGEX "#define LIBMAMBA_VERSION_(MAJOR|MINOR|PATCH)") STRINGS "${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp" libmamba_version_defines
REGEX "#define LIBMAMBA_VERSION_(MAJOR|MINOR|PATCH)"
)
foreach(ver ${libmamba_version_defines}) foreach(ver ${libmamba_version_defines})
if(ver MATCHES "#define LIBMAMBA_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") if(ver MATCHES "#define LIBMAMBA_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(LIBMAMBA_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") set(
LIBMAMBA_VERSION_${CMAKE_MATCH_1}
"${CMAKE_MATCH_2}"
CACHE INTERNAL ""
)
endif() endif()
endforeach() endforeach()
set(${PROJECT_NAME}_VERSION set(
${LIBMAMBA_VERSION_MAJOR}.${LIBMAMBA_VERSION_MINOR}.${LIBMAMBA_VERSION_PATCH}) ${PROJECT_NAME}_VERSION
${LIBMAMBA_VERSION_MAJOR}.${LIBMAMBA_VERSION_MINOR}.${LIBMAMBA_VERSION_PATCH}
)
message(STATUS "Building libmamba v${${PROJECT_NAME}_VERSION}") message(STATUS "Building libmamba v${${PROJECT_NAME}_VERSION}")
# Binary version See the following URL for explanations about the binary versionning
# 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 # 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 file(
REGEX "#define LIBMAMBA_BINARY_(CURRENT|REVISION|AGE)") STRINGS "${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp" libmamba_version_defines
REGEX "#define LIBMAMBA_BINARY_(CURRENT|REVISION|AGE)"
)
foreach(ver ${libmamba_version_defines}) foreach(ver ${libmamba_version_defines})
if(ver MATCHES "#define LIBMAMBA_BINARY_(CURRENT|REVISION|AGE) +([^ ]+)$") if(ver MATCHES "#define LIBMAMBA_BINARY_(CURRENT|REVISION|AGE) +([^ ]+)$")
set(LIBMAMBA_BINARY_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") set(
LIBMAMBA_BINARY_${CMAKE_MATCH_1}
"${CMAKE_MATCH_2}"
CACHE INTERNAL ""
)
endif() endif()
endforeach() endforeach()
set(LIBMAMBA_BINARY_VERSION set(
${LIBMAMBA_BINARY_CURRENT}.${LIBMAMBA_BINARY_REVISION}.${LIBMAMBA_BINARY_AGE}) LIBMAMBA_BINARY_VERSION
${LIBMAMBA_BINARY_CURRENT}.${LIBMAMBA_BINARY_REVISION}.${LIBMAMBA_BINARY_AGE}
)
message(STATUS "libmamba binary version: v${LIBMAMBA_BINARY_VERSION}") message(STATUS "libmamba binary version: v${LIBMAMBA_BINARY_VERSION}")
# Build options # Build options
# ============= # =============
option(BUILD_TESTS "Build libmamba C++ tests" OFF) option(BUILD_TESTS "Build libmamba C++ tests" OFF)
option(BUILD_SHARED "Build shared libmamba library" OFF) option(BUILD_SHARED "Build shared libmamba library" OFF)
option(BUILD_STATIC "Build static libmamba library with static linkage to its dependencies" 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") 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)$") 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 }") message(
endif () FATAL_ERROR
"Invalid log level: ${BUILD_LOG_LEVEL}, should be one of { TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF }"
)
endif()
if (BUILD_STATIC) if(BUILD_STATIC)
add_definitions("-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${BUILD_LOG_LEVEL}") add_definitions("-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${BUILD_LOG_LEVEL}")
add_definitions(-DLIBMAMBA_STATIC_DEPS) add_definitions(-DLIBMAMBA_STATIC_DEPS)
endif () endif()
if (WIN32) if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif () endif()
option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF) option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF)
if(ENABLE_ASAN) if(ENABLE_ASAN)
message(WARNING "Address-Sanitizer instrumentation will be injected into binaries - do not release these binaries") message(
add_compile_options(-fno-omit-frame-pointer -fsanitize=address) WARNING
add_link_options(-fno-omit-frame-pointer -fsanitize=address) "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() endif()
if(ENABLE_TSAN) if(ENABLE_TSAN)
message(WARNING "Thread-Sanitizer instrumentation will be injected into binaries - do not release these binaries") message(
add_compile_options(-fno-omit-frame-pointer -fsanitize=thread) WARNING
add_link_options(-fno-omit-frame-pointer -fsanitize=thread) "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() endif()
if(ENABLE_USAN) if(ENABLE_USAN)
message(WARNING "Undefined-Sanitizer instrumentation will be injected into binaries - do not release these binaries") message(
add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined) WARNING
add_link_options(-fno-omit-frame-pointer -fsanitize=undefined) "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() endif()
# Source files # Source files
# ============ # ============
find_package (Python3 COMPONENTS Interpreter) find_package(Python3 COMPONENTS Interpreter)
set(SHELL_SCRIPTS set(
SHELL_SCRIPTS
micromamba.sh micromamba.sh
micromamba.csh micromamba.csh
micromamba.bat micromamba.bat
@ -101,21 +130,24 @@ set(SHELL_SCRIPTS
mamba.xsh mamba.xsh
mamba.fish mamba.fish
compile_pyc.py compile_pyc.py
mamba_completion.posix) mamba_completion.posix
)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shell_scripts) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shell_scripts)
foreach(script ${SHELL_SCRIPTS}) foreach(script ${SHELL_SCRIPTS})
string(REPLACE "." "_" script_var ${script}) string(REPLACE "." "_" script_var ${script})
add_custom_command(OUTPUT shell_scripts/${script}.cpp add_custom_command(
DEPENDS data/${script} OUTPUT shell_scripts/${script}.cpp
COMMAND ${Python3_EXECUTABLE} ${LIBMAMBA_DATA_DIR}/bin2header.py DEPENDS data/${script}
--extern COMMAND
-v data_${script_var} ${Python3_EXECUTABLE} ${LIBMAMBA_DATA_DIR}/bin2header.py --extern -v data_${script_var}
-i ${CMAKE_CURRENT_SOURCE_DIR}/data/${script} -i ${CMAKE_CURRENT_SOURCE_DIR}/data/${script} -o
-o ${CMAKE_CURRENT_BINARY_DIR}/shell_scripts/${script}.cpp) ${CMAKE_CURRENT_BINARY_DIR}/shell_scripts/${script}.cpp
)
endforeach() endforeach()
set(LIBMAMBA_SOURCES set(
LIBMAMBA_SOURCES
longpath.manifest longpath.manifest
${LIBMAMBA_SOURCE_DIR}/version.cpp ${LIBMAMBA_SOURCE_DIR}/version.cpp
# Filesystem library # Filesystem library
@ -191,7 +223,6 @@ set(LIBMAMBA_SOURCES
${LIBMAMBA_SOURCE_DIR}/core/env_lockfile.cpp ${LIBMAMBA_SOURCE_DIR}/core/env_lockfile.cpp
${LIBMAMBA_SOURCE_DIR}/core/execution.cpp ${LIBMAMBA_SOURCE_DIR}/core/execution.cpp
${LIBMAMBA_SOURCE_DIR}/core/timeref.cpp ${LIBMAMBA_SOURCE_DIR}/core/timeref.cpp
# API (high-level) # API (high-level)
${LIBMAMBA_SOURCE_DIR}/api/c_api.cpp ${LIBMAMBA_SOURCE_DIR}/api/c_api.cpp
${LIBMAMBA_SOURCE_DIR}/api/channel_loader.cpp ${LIBMAMBA_SOURCE_DIR}/api/channel_loader.cpp
@ -212,7 +243,8 @@ foreach(script ${SHELL_SCRIPTS})
list(APPEND LIBMAMBA_SOURCES shell_scripts/${script}.cpp) list(APPEND LIBMAMBA_SOURCES shell_scripts/${script}.cpp)
endforeach() endforeach()
set(LIBMAMBA_PUBLIC_HEADERS set(
LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp
# Filesystem library # Filesystem library
${LIBMAMBA_INCLUDE_DIR}/mamba/fs/filesystem.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/fs/filesystem.hpp
@ -310,7 +342,8 @@ set(LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/api/update.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/api/update.hpp
) )
set(LIBMAMBA_PRIVATE_HEADERS set(
LIBMAMBA_PRIVATE_HEADERS
# C++ wrapping of libsolv # C++ wrapping of libsolv
${LIBMAMBA_SOURCE_DIR}/solv-cpp/queue.hpp ${LIBMAMBA_SOURCE_DIR}/solv-cpp/queue.hpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/ids.hpp ${LIBMAMBA_SOURCE_DIR}/solv-cpp/ids.hpp
@ -340,34 +373,24 @@ find_package(Libsolv REQUIRED)
macro(libmamba_create_target target_name linkage output_name) macro(libmamba_create_target target_name linkage output_name)
string(TOUPPER "${linkage}" linkage_upper) string(TOUPPER "${linkage}" linkage_upper)
if (NOT ${linkage_upper} MATCHES "^(SHARED|STATIC)$") if(NOT ${linkage_upper} MATCHES "^(SHARED|STATIC)$")
message(FATAL_ERROR "Invalid library linkage: ${linkage}") message(FATAL_ERROR "Invalid library linkage: ${linkage}")
endif () endif()
# Output # Output
# ====== # ======
add_library( add_library(
${target_name} ${linkage_upper} ${target_name}
${LIBMAMBA_PUBLIC_HEADERS} ${linkage_upper} ${LIBMAMBA_PUBLIC_HEADERS} ${LIBMAMBA_PRIVATE_HEADERS} ${LIBMAMBA_SOURCES}
${LIBMAMBA_PRIVATE_HEADERS}
${LIBMAMBA_SOURCES}
) )
# Header only libraries are always linked the same way # Header only libraries are always linked the same way
target_link_libraries( target_link_libraries(${target_name} PUBLIC tl::expected nlohmann_json::nlohmann_json)
${target_name}
PUBLIC
tl::expected
nlohmann_json::nlohmann_json
)
mamba_target_add_compile_warnings( mamba_target_add_compile_warnings(${target_name} WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR})
${target_name}
WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR}
)
mamba_target_set_lto(${target_name} MODE ${MAMBA_LTO}) mamba_target_set_lto(${target_name} MODE ${MAMBA_LTO})
if (${linkage_upper} STREQUAL "STATIC") if(${linkage_upper} STREQUAL "STATIC")
message(" -> Statically linking against libmamba (static) dependencies") message(" -> Statically linking against libmamba (static) dependencies")
target_compile_definitions(${target_name} PUBLIC SPDLOG_FMT_EXTERNAL) target_compile_definitions(${target_name} PUBLIC SPDLOG_FMT_EXTERNAL)
@ -386,65 +409,62 @@ macro(libmamba_create_target target_name linkage output_name)
yaml-cpp::yaml-cpp yaml-cpp::yaml-cpp
solv::libsolv_static solv::libsolv_static
solv::libsolvext_static solv::libsolvext_static
PRIVATE PRIVATE reproc reproc++ simdjson::simdjson_static
reproc
reproc++
simdjson::simdjson_static
) )
if (UNIX) if(UNIX)
set(REQUIRED_STATIC_DEPS set(
REQUIRED_STATIC_DEPS
libcurl.a libcurl.a
libssh2.a libssh2.a
libgssapi_krb5.a libgssapi_krb5.a
libkrb5.a libkrb5.a
libk5crypto.a libk5crypto.a
libkrb5support.a libkrb5support.a
libcom_err.a libcom_err.a
libssl.a libssl.a
libcrypto.a libcrypto.a
libarchive.a libarchive.a
libiconv.a libiconv.a
libbz2.a libbz2.a
liblz4.a liblz4.a
libzstd.a libzstd.a
libz.a libz.a
liblzma.a liblzma.a
libnghttp2.a libnghttp2.a
) )
if (APPLE) if(APPLE)
set(REQUIRED_STATIC_DEPS ${REQUIRED_STATIC_DEPS} libc++.a) set(REQUIRED_STATIC_DEPS ${REQUIRED_STATIC_DEPS} libc++.a)
endif() endif()
if (UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
list(REMOVE_ITEM REQUIRED_STATIC_DEPS libiconv.a) list(REMOVE_ITEM REQUIRED_STATIC_DEPS libiconv.a)
endif() endif()
set(STATIC_DEPS "") set(STATIC_DEPS "")
foreach(LIB ${REQUIRED_STATIC_DEPS}) foreach(LIB ${REQUIRED_STATIC_DEPS})
set(TMP_LIB "${LIB}-NOTFOUND") set(TMP_LIB "${LIB}-NOTFOUND")
find_library(TMP_LIB find_library(TMP_LIB NAMES "${LIB}")
NAMES "${LIB}" if(NOT ${TMP_LIB} STREQUAL "TMP_LIB-NOTFOUND")
)
if (NOT ${TMP_LIB} STREQUAL "TMP_LIB-NOTFOUND")
list(APPEND STATIC_DEPS "${TMP_LIB}") list(APPEND STATIC_DEPS "${TMP_LIB}")
else () else()
list(APPEND STATIC_DEPS "${LIB}-NOTFOUND") list(APPEND STATIC_DEPS "${LIB}-NOTFOUND")
endif () endif()
endforeach(LIB) endforeach(LIB)
if (APPLE) if(APPLE)
find_library(SECURITY_LIBRARY Security) find_library(SECURITY_LIBRARY Security)
find_library(SYSTEMCONFIGURATION_LIBRARY SystemConfiguration) find_library(SYSTEMCONFIGURATION_LIBRARY SystemConfiguration)
find_library(COREFOUNDATION_LIBRARY CoreFoundation) find_library(COREFOUNDATION_LIBRARY CoreFoundation)
message("Found library: ${SECURITY_LIBRARY}\n${COREFOUNDATION_LIBRARY}") message("Found library: ${SECURITY_LIBRARY}\n${COREFOUNDATION_LIBRARY}")
list(APPEND STATIC_DEPS ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY} ${SYSTEMCONFIGURATION_LIBRARY}) list(
APPEND
STATIC_DEPS
${COREFOUNDATION_LIBRARY}
${SECURITY_LIBRARY}
${SYSTEMCONFIGURATION_LIBRARY}
)
endif() endif()
message(" -> Found static dependencies:") message(" -> Found static dependencies:")
@ -452,22 +472,17 @@ macro(libmamba_create_target target_name linkage output_name)
message(" - ${LIB}") message(" - ${LIB}")
endforeach(LIB) endforeach(LIB)
if (APPLE) if(APPLE)
set (MAMBA_FORCE_DYNAMIC_LIBS resolv c++abi) set(MAMBA_FORCE_DYNAMIC_LIBS resolv c++abi)
target_link_options(${target_name} PRIVATE -static-libstdc++) target_link_options(${target_name} PRIVATE -static-libstdc++)
elseif (UNIX) elseif(UNIX)
set(MAMBA_FORCE_DYNAMIC_LIBS rt dl resolv) set(MAMBA_FORCE_DYNAMIC_LIBS rt dl resolv)
target_link_options(${target_name} PUBLIC -static-libstdc++ -static-libgcc) target_link_options(${target_name} PUBLIC -static-libstdc++ -static-libgcc)
endif() endif()
target_link_libraries( target_link_libraries(${target_name} PUBLIC ${STATIC_DEPS} ${MAMBA_FORCE_DYNAMIC_LIBS})
${target_name}
PUBLIC
${STATIC_DEPS}
${MAMBA_FORCE_DYNAMIC_LIBS}
)
elseif (WIN32) elseif(WIN32)
set(CMAKE_PREFIX_PATH "$ENV{VCPKG_ROOT}/installed/x64-windows-static-md/") set(CMAKE_PREFIX_PATH "$ENV{VCPKG_ROOT}/installed/x64-windows-static-md/")
@ -486,29 +501,28 @@ macro(libmamba_create_target target_name linkage output_name)
find_library(CHARSET_LIBRARY NAMES libcharset charset) find_library(CHARSET_LIBRARY NAMES libcharset charset)
message("Found: ${LIBXML2_LIBRARY} ${ICONV_LIBRARY} ${CHARSET_LIBRARY}") message("Found: ${LIBXML2_LIBRARY} ${ICONV_LIBRARY} ${CHARSET_LIBRARY}")
target_link_libraries(${target_name} PUBLIC target_link_libraries(
${CRYPTO_LIBRARIES} ${target_name}
${LibArchive_LIBRARY} PUBLIC
${LIBXML2_LIBRARY} ${CRYPTO_LIBRARIES}
${ICONV_LIBRARY} ${LibArchive_LIBRARY}
${CHARSET_LIBRARY} ${LIBXML2_LIBRARY}
zstd::libzstd_static ${ICONV_LIBRARY}
${LZ4_LIBRARY} ${CHARSET_LIBRARY}
${LZO2_LIBRARY} zstd::libzstd_static
${BZIP2_LIBRARIES} ${LZ4_LIBRARY}
${LIBLZMA_LIBRARIES} ${LZO2_LIBRARY}
CURL::libcurl ${BZIP2_LIBRARIES}
${sodium_LIBRARY_RELEASE} ${LIBLZMA_LIBRARIES}
CURL::libcurl
${sodium_LIBRARY_RELEASE}
) )
add_compile_definitions( add_compile_definitions(LIBARCHIVE_STATIC CURL_STATICLIB)
LIBARCHIVE_STATIC
CURL_STATICLIB
)
include_directories($ENV{CONDA_PREFIX}/Library/include/) include_directories($ENV{CONDA_PREFIX}/Library/include/)
include_directories($ENV{VCPKG_ROOT}/installed/x64-windows-static-md/include/) include_directories($ENV{VCPKG_ROOT}/installed/x64-windows-static-md/include/)
endif() endif()
else () else()
message(" -> Dynamically linking against libmamba (shared) dependencies") message(" -> Dynamically linking against libmamba (shared) dependencies")
mamba_target_check_type(yaml-cpp::yaml-cpp SHARED_LIBRARY WARNING) mamba_target_check_type(yaml-cpp::yaml-cpp SHARED_LIBRARY WARNING)
@ -534,29 +548,24 @@ macro(libmamba_create_target target_name linkage output_name)
BZip2::BZip2 BZip2::BZip2
yaml-cpp::yaml-cpp yaml-cpp::yaml-cpp
fmt::fmt fmt::fmt
# Since conda-forge spdlog is built with a bundled version of fmt we use the # Since conda-forge spdlog is built with a bundled version of fmt we use the header
# header only version to avoid chasing after the correct fmt version mathching # only version to avoid chasing after the correct fmt version mathching the one used
# the one used in the bundle # in the bundle
spdlog::spdlog_header_only spdlog::spdlog_header_only
solv::libsolv solv::libsolv
solv::libsolvext solv::libsolvext
PRIVATE PRIVATE reproc reproc++ simdjson::simdjson
reproc
reproc++
simdjson::simdjson
) )
endif () endif()
target_compile_features(${target_name} PUBLIC cxx_std_17) target_compile_features(${target_name} PUBLIC cxx_std_17)
target_include_directories( target_include_directories(
${target_name} ${target_name}
PUBLIC PUBLIC $<BUILD_INTERFACE:${LIBMAMBA_INCLUDE_DIR}> $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${LIBMAMBA_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
) )
if (WIN32) if(WIN32)
find_path( find_path(
WINREG_INCLUDE_DIR WINREG_INCLUDE_DIR
NAMES WinReg.hpp NAMES WinReg.hpp
@ -564,67 +573,62 @@ macro(libmamba_create_target target_name linkage output_name)
) )
endif() endif()
target_include_directories( target_include_directories(${target_name} PRIVATE ${LIBMAMBA_SOURCE_DIR} ${WINREG_INCLUDE_DIR})
${target_name}
PRIVATE
${LIBMAMBA_SOURCE_DIR}
${WINREG_INCLUDE_DIR}
)
if (UNIX) if(UNIX)
math(EXPR LIBMAMBA_BINARY_COMPATIBLE "${LIBMAMBA_BINARY_CURRENT} - ${LIBMAMBA_BINARY_AGE}") math(EXPR LIBMAMBA_BINARY_COMPATIBLE "${LIBMAMBA_BINARY_CURRENT} - ${LIBMAMBA_BINARY_AGE}")
set_target_properties( set_target_properties(
${target_name} ${target_name}
PROPERTIES PROPERTIES
#PUBLIC_HEADER "${LIBMAMBA_PUBLIC_HEADERS}" # PUBLIC_HEADER "${LIBMAMBA_PUBLIC_HEADERS}"
COMPILE_DEFINITIONS "LIBMAMBA_EXPORTS" COMPILE_DEFINITIONS "LIBMAMBA_EXPORTS"
PREFIX "" PREFIX ""
VERSION "${LIBMAMBA_BINARY_COMPATIBLE}.${LIBMAMBA_BINARY_REVISION}.${LIBMAMBA_BINARY_AGE}" VERSION
SOVERSION ${LIBMAMBA_BINARY_COMPATIBLE} "${LIBMAMBA_BINARY_COMPATIBLE}.${LIBMAMBA_BINARY_REVISION}.${LIBMAMBA_BINARY_AGE}"
OUTPUT_NAME "${output_name}" SOVERSION ${LIBMAMBA_BINARY_COMPATIBLE}
OUTPUT_NAME "${output_name}"
) )
else() else()
set_target_properties( set_target_properties(
${target_name} ${target_name}
PROPERTIES PROPERTIES
#PUBLIC_HEADER "${LIBMAMBA_PUBLIC_HEADERS}" # PUBLIC_HEADER "${LIBMAMBA_PUBLIC_HEADERS}"
COMPILE_DEFINITIONS "LIBMAMBA_EXPORTS" COMPILE_DEFINITIONS "LIBMAMBA_EXPORTS"
PREFIX "" PREFIX ""
VERSION ${LIBMAMBA_BINARY_VERSION} VERSION ${LIBMAMBA_BINARY_VERSION}
SOVERSION ${LIBMAMBA_BINARY_CURRENT} SOVERSION ${LIBMAMBA_BINARY_CURRENT}
OUTPUT_NAME "${output_name}" OUTPUT_NAME "${output_name}"
) )
target_compile_definitions(${target_name} PUBLIC GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) target_compile_definitions(${target_name} PUBLIC GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE)
endif() endif()
if (${linkage_upper} STREQUAL "STATIC") if(${linkage_upper} STREQUAL "STATIC")
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
target_link_libraries(${target_name} PUBLIC Threads::Threads) target_link_libraries(${target_name} PUBLIC Threads::Threads)
endif () endif()
list(APPEND libmamba_targets ${target_name}) list(APPEND libmamba_targets ${target_name})
add_library(mamba::${target_name} ALIAS ${target_name}) add_library(mamba::${target_name} ALIAS ${target_name})
endmacro() endmacro()
set(libmamba_targets "") set(libmamba_targets "")
if (BUILD_SHARED) if(BUILD_SHARED)
message(STATUS "Adding shared libmamba target") message(STATUS "Adding shared libmamba target")
libmamba_create_target(libmamba-dyn SHARED libmamba) libmamba_create_target(libmamba-dyn SHARED libmamba)
endif () endif()
if (BUILD_STATIC) if(BUILD_STATIC)
message(STATUS "Adding static libmamba target") message(STATUS "Adding static libmamba target")
# On Windows, a static library should use a different output name # On Windows, a static library should use a different output name to avoid the conflict with the
# to avoid the conflict with the import library of a shared one. # import library of a shared one.
if (CMAKE_HOST_WIN32) if(CMAKE_HOST_WIN32)
libmamba_create_target(libmamba-static STATIC libmamba_static) libmamba_create_target(libmamba-static STATIC libmamba_static)
else () else()
libmamba_create_target(libmamba-static STATIC libmamba) libmamba_create_target(libmamba-static STATIC libmamba)
endif () endif()
endif() endif()
if(BUILD_SHARED_LIBS AND BUILD_SHARED) if(BUILD_SHARED_LIBS AND BUILD_SHARED)
@ -635,10 +639,10 @@ elseif(BUILD_SHARED)
add_library(mamba::libmamba ALIAS libmamba-dyn) add_library(mamba::libmamba ALIAS libmamba-dyn)
else() else()
message(FATAL_ERROR "Select at least a build variant for libmamba") message(FATAL_ERROR "Select at least a build variant for libmamba")
endif () endif()
# Tests # Tests
if (BUILD_LIBMAMBA_TESTS) if(BUILD_LIBMAMBA_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
@ -648,19 +652,27 @@ endif()
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
set(LIBMAMBA_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for libmambaConfig.cmake") set(
LIBMAMBA_CMAKECONFIG_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
CACHE STRING "install path for libmambaConfig.cmake"
)
install(TARGETS ${libmamba_targets} install(
EXPORT ${PROJECT_NAME}-targets TARGETS ${libmamba_targets}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY "${LIBMAMBA_INCLUDE_DIR}/" install(
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" DIRECTORY "${LIBMAMBA_INCLUDE_DIR}/"
FILES_MATCHING DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PATTERN "*.hpp" FILES_MATCHING
PATTERN "*.h") PATTERN "*.hpp"
PATTERN "*.h"
)
# Makes the project importable from the build directory # Makes the project importable from the build directory
export( export(
@ -671,25 +683,36 @@ export(
# Configure 'mambaConfig.cmake' for a build tree # Configure 'mambaConfig.cmake' for a build tree
set(MAMBA_CONFIG_CODE "####### Expanded from \@MAMBA_CONFIG_CODE\@ #######\n") 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}set(CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake;\${CMAKE_MODULE_PATH}\")\n"
)
set(MAMBA_CONFIG_CODE "${MAMBA_CONFIG_CODE}##################################################") set(MAMBA_CONFIG_CODE "${MAMBA_CONFIG_CODE}##################################################")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in configure_package_config_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" ${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}) INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
)
# Configure 'mambaConfig.cmake' for an install tree # Configure 'mambaConfig.cmake' for an install tree
set(MAMBA_CONFIG_CODE "") set(MAMBA_CONFIG_CODE "")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in configure_package_config_file(
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake" ${PROJECT_NAME}Config.cmake.in
INSTALL_DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}) "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}
)
write_basic_package_version_file(
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${MAMBA_VERSION_MAJOR}.${MAMBA_VERSION_MINOR}.${MAMBA_VERSION_PATCH} VERSION ${MAMBA_VERSION_MAJOR}.${MAMBA_VERSION_MINOR}.${MAMBA_VERSION_PATCH}
COMPATIBILITY AnyNewerVersion) COMPATIBILITY AnyNewerVersion
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake )
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake install(
DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}) FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
install(EXPORT ${PROJECT_NAME}-targets ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}
DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}) )
install(
EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}
)

View File

@ -8,8 +8,8 @@ target_compile_features(testing_libmamba_lock PUBLIC cxx_std_17)
mamba_target_add_compile_warnings(testing_libmamba_lock WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR}) mamba_target_add_compile_warnings(testing_libmamba_lock WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR})
set(
set(LIBMAMBA_TEST_SRCS LIBMAMBA_TEST_SRCS
include/mambatests.hpp include/mambatests.hpp
src/test_main.cpp src/test_main.cpp
# C++ wrapping of libsolv # C++ wrapping of libsolv
@ -45,7 +45,6 @@ set(LIBMAMBA_TEST_SRCS
src/specs/test_version_spec.cpp src/specs/test_version_spec.cpp
src/specs/test_channel_spec.cpp src/specs/test_channel_spec.cpp
src/specs/test_repo_data.cpp src/specs/test_repo_data.cpp
../longpath.manifest ../longpath.manifest
src/core/test_activation.cpp src/core/test_activation.cpp
src/core/test_channel.cpp src/core/test_channel.cpp
@ -91,13 +90,8 @@ find_package(Threads REQUIRED)
target_link_libraries( target_link_libraries(
test_libmamba test_libmamba
PUBLIC PUBLIC mamba::libmamba reproc reproc++
mamba::libmamba PRIVATE doctest::doctest Threads::Threads
reproc
reproc++
PRIVATE
doctest::doctest
Threads::Threads
) )
# Copy data directory into binary dir to avoid modifications # Copy data directory into binary dir to avoid modifications
@ -113,4 +107,8 @@ target_compile_definitions(
target_compile_features(test_libmamba PUBLIC cxx_std_17) target_compile_features(test_libmamba PUBLIC cxx_std_17)
add_custom_target(test COMMAND test_libmamba DEPENDS test_libmamba) add_custom_target(
test
COMMAND test_libmamba
DEPENDS test_libmamba
)

View File

@ -18,15 +18,11 @@ endif()
find_package(Python COMPONENTS Interpreter Development) find_package(Python COMPONENTS Interpreter Development)
find_package(pybind11 REQUIRED) find_package(pybind11 REQUIRED)
pybind11_add_module(bindings pybind11_add_module(bindings src/main.cpp longpath.manifest)
src/main.cpp
longpath.manifest
)
mamba_target_add_compile_warnings(bindings WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR}) mamba_target_add_compile_warnings(bindings WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR})
target_link_libraries(bindings PRIVATE pybind11::pybind11 mamba::libmamba) target_link_libraries(bindings PRIVATE pybind11::pybind11 mamba::libmamba)
set_property(TARGET bindings PROPERTY CXX_STANDARD 17) set_property(TARGET bindings PROPERTY CXX_STANDARD 17)
install(TARGETS bindings install(TARGETS bindings LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libmambapy/)
LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libmambapy/)

View File

@ -4,7 +4,7 @@
# #
# The full license is in the file LICENSE, distributed with this software. # The full license is in the file LICENSE, distributed with this software.
cmake_minimum_required (VERSION 3.16) cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0 cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0
cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13 cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13
@ -13,21 +13,19 @@ project(mamba-package)
# Source files # Source files
# ============ # ============
set(MAMBA_PACKAGE_SRCS set(
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp MAMBA_PACKAGE_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/package.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/package.cpp
) )
set(MAMBA_PACKAGE_HEADERS set(MAMBA_PACKAGE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/package.hpp)
${CMAKE_CURRENT_SOURCE_DIR}/src/package.hpp
)
# Dependencies # Dependencies
# ============ # ============
if(NOT TARGET mamba::libmamba) if(NOT TARGET mamba::libmamba)
find_package(libmamba REQUIRED) find_package(libmamba REQUIRED)
endif () endif()
# Build definition # Build definition
# ================ # ================

View File

@ -4,7 +4,7 @@
# #
# The full license is in the file LICENSE, distributed with this software. # The full license is in the file LICENSE, distributed with this software.
cmake_minimum_required (VERSION 3.16) cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0 cmake_policy(SET CMP0025 NEW) # Introduced in cmake 3.0
cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13 cmake_policy(SET CMP0077 NEW) # Introduced in cmake 3.13
project(micromamba) project(micromamba)
@ -13,16 +13,25 @@ project(micromamba)
# ============= # =============
option(BUILD_MICROMAMBA_SERVER "Build the micromamba server" OFF) option(BUILD_MICROMAMBA_SERVER "Build the micromamba server" OFF)
if (BUILD_STATIC AND NOT BUILD_SHARED) if(BUILD_STATIC AND NOT BUILD_SHARED)
set(MICROMAMBA_LINKAGE "STATIC" CACHE STRING "micromamba linkage against libraries") set(
else () MICROMAMBA_LINKAGE
set(MICROMAMBA_LINKAGE "DYNAMIC" CACHE STRING "micromamba linkage against libraries") "STATIC"
endif () CACHE STRING "micromamba linkage against libraries"
)
else()
set(
MICROMAMBA_LINKAGE
"DYNAMIC"
CACHE STRING "micromamba linkage against libraries"
)
endif()
# Source files # Source files
# ============ # ============
set(MICROMAMBA_SRCS set(
MICROMAMBA_SRCS
longpath.manifest longpath.manifest
${CMAKE_CURRENT_SOURCE_DIR}/src/activate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/activate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/clean.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/clean.cpp
@ -47,16 +56,15 @@ set(MICROMAMBA_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp
) )
set(MICROMAMBA_HEADERS set(
MICROMAMBA_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/common_options.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/common_options.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/umamba.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/umamba.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp
) )
if(UNIX AND BUILD_MICROMAMBA_SERVER) if(UNIX AND BUILD_MICROMAMBA_SERVER)
list(APPEND MICROMAMBA_SRCS list(APPEND MICROMAMBA_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp
)
add_definitions(-DMICROMAMBA_SERVER) add_definitions(-DMICROMAMBA_SERVER)
endif() endif()
@ -67,29 +75,22 @@ mamba_target_set_lto(micromamba MODE ${MAMBA_LTO})
if(NOT (TARGET mamba::libmamba-dyn OR TARGET mamba::libmamba-static)) if(NOT (TARGET mamba::libmamba-dyn OR TARGET mamba::libmamba-static))
find_package(libmamba REQUIRED) find_package(libmamba REQUIRED)
endif () endif()
string(TOUPPER "${MICROMAMBA_LINKAGE}" linkage_upper) string(TOUPPER "${MICROMAMBA_LINKAGE}" linkage_upper)
message(STATUS "Micromamba linkage: ${MICROMAMBA_LINKAGE}") message(STATUS "Micromamba linkage: ${MICROMAMBA_LINKAGE}")
if (${MICROMAMBA_LINKAGE} STREQUAL "STATIC") if(${MICROMAMBA_LINKAGE} STREQUAL "STATIC")
set(libmamba_target mamba::libmamba-static) set(libmamba_target mamba::libmamba-static)
else () else()
set(libmamba_target mamba::libmamba-dyn) set(libmamba_target mamba::libmamba-dyn)
endif () endif()
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(reproc REQUIRED) find_package(reproc REQUIRED)
find_package(reproc++ REQUIRED) find_package(reproc++ REQUIRED)
target_link_libraries( target_link_libraries(micromamba PRIVATE ${libmamba_target} Threads::Threads reproc reproc++)
micromamba
PRIVATE
${libmamba_target}
Threads::Threads
reproc
reproc++
)
set_property(TARGET micromamba PROPERTY CXX_STANDARD 17) set_property(TARGET micromamba PROPERTY CXX_STANDARD 17)