Skip to content

Commit

Permalink
Apply cmake-format
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Nov 7, 2023
1 parent e8607ba commit 2549198
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 297 deletions.
44 changes: 29 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# 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 CMP0077 NEW) # Introduced in cmake 3.13

Expand All @@ -19,25 +19,39 @@ option(BUILD_LIBMAMBA_TESTS "Build libmamba C++ tests" OFF)
option(BUILD_MICROMAMBA "Build micromamba" OFF)
option(BUILD_MAMBA_PACKAGE "Build mamba package utility" 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/LinkTimeOptimization.cmake")
include("cmake/Checks.cmake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")

if (MSVC)
# NOMINMAX : prevent tons of code to be included when having to `#include <windows.h>`
# /EHsc : enable C++ exceptions (otherwise exceptions do not work)
# /Zc:__cplusplus : makes sure `__cplusplus` is set to the current C++ version language. Otherwise it is always set to an incorrect wrong value.
# /MP : enable multi-process build with MSBuild (it should be on by default but CMake generates the project files without the right params).
# /external:I $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}")
if(MSVC)
# NOMINMAX : prevent tons of code to be included when having to `#include <windows.h>` /EHsc :
# enable C++ exceptions (otherwise exceptions do not work) /Zc:__cplusplus : makes sure
# `__cplusplus` is set to the current C++ version language. Otherwise it is always set to an
# incorrect wrong value. /MP : enable multi-process build with MSBuild (it should be on by
# default but CMake generates the project files without the right params). /external:I
# $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
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")
set(
CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
CMAKE_MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
CACHE STRING "MSVC runtime library"
)
endif()
Expand All @@ -46,21 +60,21 @@ endif()
# ========

# libmamba library and tests
if (BUILD_LIBMAMBA)
if(BUILD_LIBMAMBA)
add_subdirectory(libmamba)
endif()

# Python bindings of libmamba
if (BUILD_LIBMAMBAPY)
if(BUILD_LIBMAMBAPY)
add_subdirectory(libmambapy)
endif()

# micromamba
if (BUILD_MICROMAMBA)
if(BUILD_MICROMAMBA)
add_subdirectory(micromamba)
endif()

# mamba package tarball utility
if (BUILD_MAMBA_PACKAGE)
if(BUILD_MAMBA_PACKAGE)
add_subdirectory(mamba_package)
endif()
3 changes: 1 addition & 2 deletions cmake/Checks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

# Check that the target has the proper type.
#
# This is useful for targets that can be either static or dynamic but have the
# same name.
# This is useful for targets that can be either static or dynamic but have the same name.
function(mamba_target_check_type target expected_type log_level)
get_target_property(actual_type ${target} TYPE)
if(NOT actual_type STREQUAL expected_type)
Expand Down
8 changes: 4 additions & 4 deletions cmake/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ function(mamba_target_add_compile_warnings target)
# Extra arguments not accounted for
if(ARG_UNPARSED_ARGUMENTS)
message(
AUTHOR_WARNING
"Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: "
"${ARG_UNPARSED_ARGUMENTS}"
AUTHOR_WARNING "Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: "
"${ARG_UNPARSED_ARGUMENTS}"
)
endif()

set(
msvc_warnings
# External sever warnings
/experimental:external /external:W1
/experimental:external
/external:W1
# Baseline reasonable warnings
/W4
# "identfier": conversion from "type1" to "type1", possible loss of data
Expand Down
49 changes: 32 additions & 17 deletions cmake/LinkTimeOptimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

include(CheckIPOSupported)


# Detect is setting Link Time Optimization is recommended.
#
# Currenlty checks if LTO is supported and if the build is a release.
Expand All @@ -17,38 +16,55 @@ function(mamba_should_lto)
# Extra arguments not accounted for
if(arg_UNPARSED_ARGUMENTS)
message(
AUTHOR_WARNING
"Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: "
"${ARG_UNPARSED_ARGUMENTS}"
AUTHOR_WARNING "Unrecoginzed options passed to ${CMAKE_CURRENT_FUNCTION}: "
"${ARG_UNPARSED_ARGUMENTS}"
)
endif()

# Check if we are building in a release-like build
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
set(valid_release_names "release" "relwithdebinfo")
if(NOT ${build_type_lower} IN_LIST valid_release_names)
set(${arg_RESULT} FALSE PARENT_SCOPE)
set(${arg_OUTPUT} "the build type is not a release" PARENT_SCOPE)
set(
${arg_RESULT}
FALSE
PARENT_SCOPE
)
set(
${arg_OUTPUT}
"the build type is not a release"
PARENT_SCOPE
)
return()
endif()

# Check if LTO is supported by compiler
check_ipo_supported(RESULT lto_is_supported OUTPUT lto_not_supported_reason)
if(NOT lto_is_supported)
set(${arg_RESULT} FALSE PARENT_SCOPE)
set(${arg_OUTPUT} "${lto_not_supported_reason}" PARENT_SCOPE)
set(
${arg_RESULT}
FALSE
PARENT_SCOPE
)
set(
${arg_OUTPUT}
"${lto_not_supported_reason}"
PARENT_SCOPE
)
endif()

set(${arg_RESULT} TRUE PARENT_SCOPE)
set(
${arg_RESULT}
TRUE
PARENT_SCOPE
)
endfunction()


# Set Link Time Optimization on a given target.
#
# MODE parameter takes the possible values
# - A false constant: deactivate LTO
# - A true constant: activate LTO, fails if this is not supported by the compiler
# - "Default" or "Auto": set LTO if supported and the build type is a release.
# MODE parameter takes the possible values - A false constant: deactivate LTO - A true constant:
# activate LTO, fails if this is not supported by the compiler - "Default" or "Auto": set LTO if
# supported and the build type is a release.
function(mamba_target_set_lto target)
# Names of option parameters (without arguments)
set(options)
Expand All @@ -60,9 +76,8 @@ function(mamba_target_set_lto target)
# Extra arguments not accounted for
if(arg_UNPARSED_ARGUMENTS)
message(
AUTHOR_WARNING
"Unrecoginzed parameter passed to ${CMAKE_CURRENT_FUNCTION}: "
"'${arg_UNPARSED_ARGUMENTS}'"
AUTHOR_WARNING "Unrecoginzed parameter passed to ${CMAKE_CURRENT_FUNCTION}: "
"'${arg_UNPARSED_ARGUMENTS}'"
)
return()
endif()
Expand Down
58 changes: 33 additions & 25 deletions cmake/modules/FindLibsolv.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
find_package(PkgConfig)
pkg_check_modules(PC_Libsolv QUIET libsolv)

find_path(Libsolv_INCLUDE_DIR
find_path(
Libsolv_INCLUDE_DIR
NAMES solv/pool.h solvversion.h
PATHS ${PC_Libsolv_INCLUDE_DIRS}
)

find_path(Libsolvext_INCLUDE_DIR
find_path(
Libsolvext_INCLUDE_DIR
NAMES solv/repo_conda.h repo_conda.h
PATHS ${PC_Libsolv_INCLUDE_DIRS}
)

find_library(Libsolv_LIBRARY
find_library(
Libsolv_LIBRARY
NAMES libsolv.so libsolv.dylib solv.lib
PATHS ${PC_Libsolv_LIBRARY_DIRS}
)
find_library(Libsolv_static_LIBRARY
find_library(
Libsolv_static_LIBRARY
NAMES libsolv.a solv_static
PATHS ${PC_Libsolv_LIBRARY_DIRS}
)

find_library(Libsolvext_LIBRARY
find_library(
Libsolvext_LIBRARY
NAMES libsolvext.so libsolvext.dylib solvext.lib
PATHS ${PC_Libsolv_LIBRARY_DIRS}
)
find_library(Libsolvext_static_LIBRARY
find_library(
Libsolvext_static_LIBRARY
NAMES libsolvext.a solvext_static
PATHS ${PC_Libsolv_LIBRARY_DIRS}
)
Expand All @@ -44,10 +50,11 @@ if(Libsolv_FOUND)
if(NOT TARGET solv::libsolv_static AND Libsolv_static_LIBRARY)
add_library(solv::libsolv_static STATIC IMPORTED)
set_target_properties(
solv::libsolv_static PROPERTIES
IMPORTED_LOCATION "${Libsolv_static_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}"
solv::libsolv_static
PROPERTIES
IMPORTED_LOCATION "${Libsolv_static_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}"
)
endif()
if(NOT TARGET solv::libsolv AND Libsolv_LIBRARY)
Expand All @@ -57,20 +64,22 @@ if(Libsolv_FOUND)
add_library(solv::libsolv UNKNOWN IMPORTED)
endif()
set_target_properties(
solv::libsolv PROPERTIES
IMPORTED_LOCATION "${Libsolv_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}"
solv::libsolv
PROPERTIES
IMPORTED_LOCATION "${Libsolv_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolv_INCLUDE_DIR}"
)
endif()

if(NOT TARGET solv::libsolvext_static AND Libsolvext_static_LIBRARY)
add_library(solv::libsolvext_static STATIC IMPORTED)
set_target_properties(
solv::libsolvext_static PROPERTIES
IMPORTED_LOCATION "${Libsolvext_static_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}"
solv::libsolvext_static
PROPERTIES
IMPORTED_LOCATION "${Libsolvext_static_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}"
)
endif()
if(NOT TARGET solv::libsolvext AND Libsolvext_LIBRARY)
Expand All @@ -80,12 +89,11 @@ if(Libsolv_FOUND)
add_library(solv::libsolvext UNKNOWN IMPORTED)
endif()
set_target_properties(
solv::libsolvext PROPERTIES
IMPORTED_LOCATION "${Libsolvext_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}"
solv::libsolvext
PROPERTIES
IMPORTED_LOCATION "${Libsolvext_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libsolv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libsolvext_INCLUDE_DIR}"
)
endif()
endif(

)
endif()
Loading

0 comments on commit 2549198

Please sign in to comment.