Skip to content

Commit

Permalink
Fix cmake format (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
filippobrizzi authored Feb 14, 2024
1 parent caa4248 commit 5420905
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 244 deletions.
88 changes: 88 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,94 @@
# -----------------------------
# Options effecting formatting.
# -----------------------------
with section("parse"):
additional_commands = {
"declare_module": {
"pargs": "*",
"flags": ["ALWAYS_BUILD", "EXCLUDE_FROM_ALL"],
"kwargs": {
"NAME": 1,
"DEPENDS_ON_MODULES": '*',
"DEPENDS_ON_EXTERNAL_PROJECTS": '*',
}
},
"define_module_library": {
"pargs": "*",
"flags": ["NOINSTALL"],
"kwargs": {
"NAME": 1,
"SOURCES": '*',
"PUBLIC_INCLUDE_PATHS": '*',
"PRIVATE_INCLUDE_PATHS": '*',
"SYSTEM_PUBLIC_INCLUDE_PATHS": '*',
"SYSTEM_PRIVATE_INCLUDE_PATHS": '*',
"PUBLIC_LINK_LIBS": '*',
"PRIVATE_LINK_LIBS": '*',
}
},
"define_module_example": {
"pargs": 0,
"flags": [],
"kwargs": {
"NAME": 1,
"SOURCES": '*',
"PUBLIC_INCLUDE_PATHS": '*',
"PRIVATE_INCLUDE_PATHS": '*',
"PUBLIC_LINK_LIBS": '*',
"PRIVATE_LINK_LIBS": '*',
}
},
"define_module_executable": {
"pargs": 0,
"flags": [],
"kwargs": {
"NAME": 1,
"SOURCES": '*',
"PUBLIC_INCLUDE_PATHS": '*',
"PRIVATE_INCLUDE_PATHS": '*',
"PUBLIC_LINK_LIBS": '*',
"PRIVATE_LINK_LIBS": '*',
}
},
"define_module_executable": {
"pargs": 0,
"flags": [],
"kwargs": {
"NAME": 1,
"SOURCES": '*',
"PUBLIC_LINK_LIBS": '*',
"PRIVATE_LINK_LIBS": '*',
}
},
"define_module_test": {
"pargs": 0,
"flags": [],
"kwargs": {
"NAME": 1,
"COMMAND": 1,
"WORKING_DIRECTORY": 1,
"SOURCES": '*',
"PUBLIC_INCLUDE_PATHS": '*',
"PRIVATE_INCLUDE_PATHS": '*',
"PUBLIC_LINK_LIBS": '*',
"PRIVATE_LINK_LIBS": '*',
}
},
"add_cmake_dependency": {
"pargs": 0,
"flags": [],
"kwargs": {
"NAME": 1,
"VERSION": 1,
"GIT_TAG": 1,
"GIT_REPOSITORY": 1,
"SOURCE_SUBDIR": 1,
"CMAKE_ARGS": '*',
"DEPENDS": '*',
}
},
}

with section("format"):

# How wide to allow formatted cmake files
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
cmake_minimum_required(VERSION 3.27.3)
project(eolo LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

# Integrate the Eolo Build System to setup the project
include(${CMAKE_SOURCE_DIR}/cmake/build.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/build.cmake)
9 changes: 4 additions & 5 deletions cmake/01_version.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# =================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# =================================================================================================

# Extract current branch name
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE REPO_BRANCH
ERROR_VARIABLE error_branch_check
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -19,7 +18,7 @@ endif()
# Extract commit hash of the head
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE REPO_HASH
ERROR_VARIABLE error_hash_check
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -32,7 +31,7 @@ endif()
# Extract version information
execute_process(
COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE REPO_TAG
ERROR_VARIABLE error_version_check
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand Down
5 changes: 2 additions & 3 deletions cmake/02_build_config.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# =================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# =================================================================================================

find_package(Git REQUIRED)
Expand All @@ -11,7 +10,7 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
set(FETCHCONTENT_QUIET OFF) # some downloads take long. Be verbose so we know status.

# disallow in-source builds
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(srcdir "${PROJECT_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
if("${srcdir}" STREQUAL "${bindir}")
message(FATAL_ERROR "In-source build is not supported. Create a separate build directory and try again")
Expand Down
3 changes: 1 addition & 2 deletions cmake/03_compiler_config.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# =================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# =================================================================================================

set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # required by source analysis tools
Expand Down
9 changes: 4 additions & 5 deletions cmake/04_code_formatter.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# =================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# =================================================================================================

# --------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -33,21 +32,21 @@ endif()

if(CMAKE_FORMAT_BIN AND ENABLE_FORMATTER)
set(_cmake_files
"${CMAKE_SOURCE_DIR}/CMakeLists.txt;${CMAKE_SOURCE_DIR}/external/CMakeLists.txt;${CMAKE_SOURCE_DIR}/cmake/*.cmake;${CMAKE_SOURCE_DIR}/modules/**/*.txt;toolchains/*.cmake"
"${PROJECT_SOURCE_DIR}/CMakeLists.txt;${PROJECT_SOURCE_DIR}/external/CMakeLists.txt;${PROJECT_SOURCE_DIR}/cmake/*.cmake;${PROJECT_SOURCE_DIR}/modules/**/*.txt;toolchains/*.cmake"
)
if(FORMAT_FAIL_ON_CHANGE)
add_custom_command(
TARGET format
PRE_BUILD
COMMAND ${CMAKE_FORMAT_BIN} --check ${_cmake_files}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
else()
add_custom_command(
TARGET format
PRE_BUILD
COMMAND ${CMAKE_FORMAT_BIN} -i ${_cmake_files}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endif()
endif()
Expand Down
5 changes: 2 additions & 3 deletions cmake/05_modules.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ==================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# ==================================================================================================

include(CMakePackageConfigHelpers)
Expand Down Expand Up @@ -118,7 +117,7 @@ macro(configure_modules)
endforeach()

# Generate input paths for source code documentation DOC_INPUT_PATHS DOC_EXAMPLE_PATHS
set(DOC_INPUT_PATHS ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/README.md)
set(DOC_INPUT_PATHS ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/docs ${PROJECT_SOURCE_DIR}/README.md)
foreach(_module IN LISTS _enabled_modules_list)
set(DOC_INPUT_PATHS ${DOC_INPUT_PATHS} ${MODULE_${_module}_PATH}/include ${MODULE_${_module}_PATH}/docs
${MODULE_${_module}_PATH}/README.md
Expand Down
5 changes: 2 additions & 3 deletions cmake/06_packager_config.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# =================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# =================================================================================================

set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${EOLO_VERSION})
set(CPACK_PACKAGE_VENDOR "Filippo Brizzi")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")

set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
Expand Down
12 changes: 6 additions & 6 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# =================================================================================================
# Copyright (C) 2018 GRAPE Contributors
# Copyright (C) 2023-2024 EOLO Contributors
# Copyright (C) 2018 GRAPE Contributors Copyright (C) 2023-2024 EOLO Contributors
# =================================================================================================

set(CMAKE_CXX_EXTENSIONS OFF)
Expand All @@ -19,7 +18,7 @@ include(${CMAKE_TEMPLATES_DIR}/06_packager_config.cmake)

# -------------------------------------------------------------------------------------------------
# Enumerate all modules and those selected for build (with -DBUILD_MODULES)
enumerate_modules(ROOT_PATH ${CMAKE_SOURCE_DIR}/modules)
enumerate_modules(ROOT_PATH ${PROJECT_SOURCE_DIR}/modules)

# -------------------------------------------------------------------------------------------------
# Build external dependencies before configuring project
Expand All @@ -37,12 +36,13 @@ string(REPLACE ";" "\\;" formatted_external_projects_list "${_external_projects_
# as if it was a separate project. This means: - Variables set there are not shared by the rest of this project - CMake
# parameters must be explicitly passed as if cmake was called on it from the command line
message(STATUS "========= External dependencies: Configuring =========")
list(APPEND EXTERNAL_PREFIX_PATH ${CMAKE_INSTALL_PREFIX} ${CMAKE_PREFIX_PATH})
execute_process(
COMMAND
${CMAKE_COMMAND} -G "Ninja" ${CMAKE_SOURCE_DIR}/external # Use 'Ninja' for parallel build
${CMAKE_COMMAND} -G "Ninja" ${PROJECT_SOURCE_DIR}/external # Use 'Ninja' for parallel build
-DEXTERNAL_PROJECTS_LIST=${formatted_external_projects_list} -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=${EP_DEPLOY_DIR}
-DCMAKE_PREFIX_PATH=${EXTERNAL_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=${EP_DEPLOY_DIR}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_TEMPLATE_DIR=${CMAKE_TEMPLATES_DIR}
Expand All @@ -62,7 +62,7 @@ endif()

# If anything went wrong with external project build, stop and exit
if(NOT ${_result} EQUAL 0)
message(FATAL_ERROR "Error processing ${CMAKE_SOURCE_DIR}/external/CMakeLists.txt")
message(FATAL_ERROR "Error processing ${PROJECT_SOURCE_DIR}/external/CMakeLists.txt")
endif()

list(PREPEND CMAKE_PREFIX_PATH ${EP_DEPLOY_DIR}/)
Expand Down
12 changes: 6 additions & 6 deletions cmake/doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PROJECT_BRIEF =
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
# the logo to the output directory.

PROJECT_LOGO = @CMAKE_SOURCE_DIR@/art/logo.png
PROJECT_LOGO = @PROJECT_SOURCE_DIR@/art/logo.png

# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
# into which the generated documentation will be written. If a relative path is
Expand Down Expand Up @@ -990,10 +990,10 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = @CMAKE_SOURCE_DIR@/build \
@CMAKE_SOURCE_DIR@/third_party \
@CMAKE_SOURCE_DIR@/gbs \
@CMAKE_SOURCE_DIR@/external
EXCLUDE = @PROJECT_SOURCE_DIR@/build \
@PROJECT_SOURCE_DIR@/third_party \
@PROJECT_SOURCE_DIR@/gbs \
@PROJECT_SOURCE_DIR@/external

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down Expand Up @@ -1105,7 +1105,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.

USE_MDFILE_AS_MAINPAGE = @CMAKE_SOURCE_DIR@/README.md
USE_MDFILE_AS_MAINPAGE = @PROJECT_SOURCE_DIR@/README.md

# The Fortran standard specifies that for fixed formatted Fortran code all
# characters from position 72 are to be considered as comment. A common
Expand Down
18 changes: 12 additions & 6 deletions cmake/external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ set(EP_CMAKE_EXTRA_ARGS
-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
)
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})

make_directory(${CMAKE_INSTALL_PREFIX}/bin)
make_directory(${CMAKE_INSTALL_PREFIX}/lib)
make_directory(${CMAKE_INSTALL_PREFIX}/include)

message(STATUS "Dependencies")

# helper macro useful for dependency handling
macro(add_dummy_target)
if(NOT TARGET ${ARGV0})
Expand Down Expand Up @@ -64,28 +67,31 @@ macro(add_cmake_dependency)
set(TARGET_ARG_CMAKE_ARGS "")
endif()

if (NOT TARGET_ARG_SOURCE_SUBDIR)
if(NOT TARGET_ARG_SOURCE_SUBDIR)
set(TARGET_ARG_SOURCE_SUBDIR "./")
endif()

set(CMAKE_ARGS ${EP_CMAKE_EXTRA_ARGS})
list(APPEND CMAKE_ARGS ${TARGET_ARG_CMAKE_ARGS})

if(${TARGET_ARG_NAME} IN_LIST EXTERNAL_PROJECTS_LIST)
find_package(${TARGET_ARG_NAME} ${TARGET_ARG_VERSION} QUIET)
if (${TARGET_ARG_NAME}_FOUND)
if (${TARGET_ARG_NAME}_DIR)
if(${TARGET_ARG_NAME}_FOUND)
if(${TARGET_ARG_NAME}_DIR)
set(TARGET_DIR ${${TARGET_ARG_NAME}_DIR})
else()
set(TARGET_DIR ${${TARGET_ARG_NAME}_LIBRARIES})
endif()
message(STATUS "${TARGET_ARG_NAME}: Using version ${TARGET_ARG_VERSION} from ${TARGET_DIR}")
message(STATUS " ${TARGET_ARG_NAME}: Using version ${TARGET_ARG_VERSION} from ${TARGET_DIR}")
add_dummy_target(${TARGET_ARG_NAME})
else()
message(STATUS "${TARGET_ARG_NAME}: Building ${TARGET_ARG_VERSION} from source")
message(STATUS " ${TARGET_ARG_NAME}: Building ${TARGET_ARG_VERSION} from source")
ExternalProject_Add(
${TARGET_ARG_NAME}
DEPENDS ${TARGET_ARG_GIT_DEPENDS}
GIT_REPOSITORY ${TARGET_ARG_GIT_REPOSITORY}
GIT_TAG ${TARGET_ARG_GIT_TAG}
CMAKE_ARGS ${EP_CMAKE_EXTRA_ARGS} ${TARGET_ARG_CMAKE_ARGS}
CMAKE_ARGS ${CMAKE_ARGS}
GIT_SHALLOW true
GIT_SUBMODULES_RECURSE false
SOURCE_SUBDIR ${TARGET_ARG_SOURCE_SUBDIR}
Expand Down
Loading

0 comments on commit 5420905

Please sign in to comment.