Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmake-format #2962

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .cmake-format.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
54 changes: 29 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
exclude: libmamba/tests/data/repodata_json_cache*
repos:
- repo: https://github.com/psf/black
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
- id: blacken-docs
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
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: trailing-whitespace
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: check-yaml
- id: check-yaml
exclude: ^.+(/tests/|/recipe/).+$
- id: check-toml
- id: check-json
- id: check-merge-conflict
- id: pretty-format-json
- id: check-toml
- id: check-json
- id: check-merge-conflict
- id: pretty-format-json
args: [--autofix]
- id: debug-statements
- id: debug-statements
language_version: python3
- repo: https://github.com/pre-commit/mirrors-isort
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
exclude: tests/data
- repo: https://github.com/PyCQA/flake8
- id: isort
exclude: tests/data
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
- id: flake8
language_version: python3
additional_dependencies:
- flake8-typing-imports==1.15.0
- flake8-builtins==2.1.0
- flake8-bugbear==23.9.16
- flake8-isort==6.1.0
- repo: https://github.com/pre-commit/mirrors-clang-format
- flake8-typing-imports==1.15.0
- flake8-builtins==2.1.0
- flake8-bugbear==23.9.16
- flake8-isort==6.1.0
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
- id: clang-format
args: [--style=file]
exclude: ".json"
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
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
Loading