Skip to content

Commit 040977f

Browse files
authored
Merge pull request #657 from ManifoldFR/topic/format-cmake-listfiles
Add formatting to CMake listfiles using gersemi
2 parents 8d47200 + 92a0299 commit 040977f

11 files changed

+473
-292
lines changed

.gersemirc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
definitions: [./CMakeLists.txt,./cmake,./python,./src,./test]
2+
line_length: 80
3+
indent: 2
4+
warn_about_unknown_commands: false

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ febfbcbe9c98cdb4e0c7bbf4554a6925b391834b
88
58dee5ae90eded5125825a2da0fe76a5031f3334
99
# black . (Guilhem Saurel, 2023-10-24)
1010
889ff8d1ca00b9e317e1da4136e233bb49a049df
11+
# pre-commit run -all (ManifoldFR, 2025-02-12)
12+
3c3494086db02747bf858142bc3be5cbc244385f

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ci:
22
autoupdate_branch: devel
33
autofix_prs: false
44
autoupdate_schedule: quarterly
5+
submodules: true
56
repos:
67
- repo: https://github.com/astral-sh/ruff-pre-commit
78
rev: v0.8.6
@@ -21,3 +22,7 @@ repos:
2122
rev: v5.0.0
2223
hooks:
2324
- id: trailing-whitespace
25+
- repo: https://github.com/BlankSpruce/gersemi
26+
rev: 0.19.0
27+
hooks:
28+
- id: gersemi

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Changed
10+
- Formatted all CMake listfiles using gersemi, add gersemi to pre-commit configuration ([#657](https://github.com/coal-library/coal/pull/657/files))
11+
912
## [3.0.1] - 2025-02-12
1013

1114
### Fixed

CMakeLists.txt

+123-72
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,41 @@ set(CXX_DISABLE_WERROR TRUE)
3737

3838
set(PROJECT_NAME coal)
3939
set(PROJECT_ORG "coal-library")
40-
set(PROJECT_DESCRIPTION
40+
set(
41+
PROJECT_DESCRIPTION
4142
"Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library"
42-
)
43+
)
4344
set(PROJECT_URL "https://github.com/coal-library/coal")
44-
SET(PROJECT_USE_CMAKE_EXPORT TRUE)
45-
SET(PROJECT_COMPATIBILITY_VERSION AnyNewerVersion)
45+
set(PROJECT_USE_CMAKE_EXPORT TRUE)
46+
set(PROJECT_COMPATIBILITY_VERSION AnyNewerVersion)
4647
# To enable jrl-cmakemodules compatibility with workspace we must define the two
4748
# following lines
4849
set(PROJECT_AUTO_RUN_FINALIZE FALSE)
4950
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
5051

51-
SET(PROJECT_USE_KEYWORD_LINK_LIBRARIES TRUE)
52-
SET(DOXYGEN_USE_TEMPLATE_CSS TRUE)
52+
set(PROJECT_USE_KEYWORD_LINK_LIBRARIES TRUE)
53+
set(DOXYGEN_USE_TEMPLATE_CSS TRUE)
5354

5455
# ----------------------------------------------------
5556
# --- OPTIONS ---------------------------------------
5657
# Need to be set before including base.cmake
5758
# ----------------------------------------------------
5859
option(INSTALL_DOCUMENTATION "Generate and install the documentation" OFF)
59-
option(COAL_TURN_ASSERT_INTO_EXCEPTION "Turn some critical Coal asserts to exception." FALSE)
60-
option(COAL_ENABLE_LOGGING "Activate logging for warnings or error messages. Turned on by default in Debug." FALSE)
61-
option(COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL "Make Coal retro-compatible with HPP-FCL." FALSE)
60+
option(
61+
COAL_TURN_ASSERT_INTO_EXCEPTION
62+
"Turn some critical Coal asserts to exception."
63+
FALSE
64+
)
65+
option(
66+
COAL_ENABLE_LOGGING
67+
"Activate logging for warnings or error messages. Turned on by default in Debug."
68+
FALSE
69+
)
70+
option(
71+
COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL
72+
"Make Coal retro-compatible with HPP-FCL."
73+
FALSE
74+
)
6275

6376
# Check if the submodule cmake have been initialized
6477
set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake")
@@ -70,22 +83,24 @@ else()
7083
get_property(
7184
JRL_CMAKE_MODULES
7285
TARGET jrl-cmakemodules::jrl-cmakemodules
73-
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
86+
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
87+
)
7488
message(STATUS "JRL cmakemodules found on system at ${JRL_CMAKE_MODULES}")
7589
elseif(${CMAKE_VERSION} VERSION_LESS "3.14.0")
7690
message(
7791
FATAL_ERROR
78-
"\nCan't find jrl-cmakemodules. Please either:\n"
79-
" - use git submodule: 'git submodule update --init'\n"
80-
" - or install https://github.com/jrl-umi3218/jrl-cmakemodules\n"
81-
" - or upgrade your CMake version to >= 3.14 to allow automatic fetching\n"
92+
"\nCan't find jrl-cmakemodules. Please either:\n"
93+
" - use git submodule: 'git submodule update --init'\n"
94+
" - or install https://github.com/jrl-umi3218/jrl-cmakemodules\n"
95+
" - or upgrade your CMake version to >= 3.14 to allow automatic fetching\n"
8296
)
8397
else()
8498
message(STATUS "JRL cmakemodules not found. Let's fetch it.")
8599
include(FetchContent)
86100
FetchContent_Declare(
87101
"jrl-cmakemodules"
88-
GIT_REPOSITORY "https://github.com/jrl-umi3218/jrl-cmakemodules.git")
102+
GIT_REPOSITORY "https://github.com/jrl-umi3218/jrl-cmakemodules.git"
103+
)
89104
FetchContent_MakeAvailable("jrl-cmakemodules")
90105
FetchContent_GetProperties("jrl-cmakemodules" SOURCE_DIR JRL_CMAKE_MODULES)
91106
endif()
@@ -94,60 +109,76 @@ endif()
94109
# Use BoostConfig module distributed by boost library instead of using FindBoost module distributed
95110
# by CMake.
96111
# There is one unresolved issue with FindBoost and clang-cl so we deactivate it in this case.
97-
IF(NOT WIN32 OR NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
98-
IF(POLICY CMP0167)
99-
CMAKE_POLICY(SET CMP0167 NEW)
112+
if(NOT WIN32 OR NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
113+
if(POLICY CMP0167)
114+
cmake_policy(SET CMP0167 NEW)
100115
# Set a default value to this policy to avoid issue with find_dependency
101116
# macro redefinition with different policy in some modules.
102-
SET(CMAKE_POLICY_DEFAULT_CMP0167 NEW)
103-
ENDIF()
104-
ENDIF()
117+
set(CMAKE_POLICY_DEFAULT_CMP0167 NEW)
118+
endif()
119+
endif()
105120

106121
include("${JRL_CMAKE_MODULES}/base.cmake")
107122
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
108-
PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
123+
project(${PROJECT_NAME} ${PROJECT_ARGS})
109124

110125
include("${JRL_CMAKE_MODULES}/boost.cmake")
111126
include("${JRL_CMAKE_MODULES}/python.cmake")
112127
include("${JRL_CMAKE_MODULES}/apple.cmake")
113128
include("${JRL_CMAKE_MODULES}/ide.cmake")
114129
include(CMakeDependentOption)
115130

116-
SET(CMAKE_MODULE_PATH
131+
set(
132+
CMAKE_MODULE_PATH
117133
${JRL_CMAKE_MODULES}/find-external/assimp/
118-
${CMAKE_MODULE_PATH})
134+
${CMAKE_MODULE_PATH}
135+
)
119136

120-
FUNCTION(set_standard_output_directory target)
121-
SET_TARGET_PROPERTIES(
137+
function(set_standard_output_directory target)
138+
set_target_properties(
122139
${target}
123140
PROPERTIES
124141
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
125142
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
126143
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
127144
)
128-
ENDFUNCTION()
145+
endfunction()
129146

130-
set_default_cmake_build_type("RelWithDebInfo")
147+
SET_DEFAULT_CMAKE_BUILD_TYPE("RelWithDebInfo")
131148

132149
# If needed, fix CMake policy for APPLE systems
133150
APPLY_DEFAULT_APPLE_CONFIGURATION()
134151

135-
OPTION(BUILD_PYTHON_INTERFACE "Build the python bindings" ON)
136-
CMAKE_DEPENDENT_OPTION(GENERATE_PYTHON_STUBS "Generate the Python stubs associated to the Python library" OFF BUILD_PYTHON_INTERFACE OFF)
152+
option(BUILD_PYTHON_INTERFACE "Build the python bindings" ON)
153+
cmake_dependent_option(
154+
GENERATE_PYTHON_STUBS
155+
"Generate the Python stubs associated to the Python library"
156+
OFF
157+
BUILD_PYTHON_INTERFACE
158+
OFF
159+
)
137160

138161
ADD_PROJECT_DEPENDENCY(Eigen3 REQUIRED PKG_CONFIG_REQUIRES "eigen3 >= 3.0.0")
139162

140163
if(BUILD_PYTHON_INTERFACE)
141-
SET(PYTHON_COMPONENTS Interpreter Development NumPy)
164+
set(PYTHON_COMPONENTS Interpreter Development NumPy)
142165
FINDPYTHON(REQUIRED)
143166
ADD_PROJECT_PRIVATE_DEPENDENCY(eigenpy 2.9.2 REQUIRED)
144167
endif()
145168

146169
# Required dependencies
147170
SET_BOOST_DEFAULT_OPTIONS()
148171
EXPORT_BOOST_DEFAULT_OPTIONS()
149-
ADD_PROJECT_DEPENDENCY(Boost REQUIRED chrono thread date_time serialization filesystem)
150-
if (COAL_ENABLE_LOGGING)
172+
ADD_PROJECT_DEPENDENCY(
173+
Boost
174+
REQUIRED
175+
chrono
176+
thread
177+
date_time
178+
serialization
179+
filesystem
180+
)
181+
if(COAL_ENABLE_LOGGING)
151182
ADD_PROJECT_DEPENDENCY(Boost REQUIRED log)
152183
endif()
153184
if(BUILD_PYTHON_INTERFACE)
@@ -165,14 +196,14 @@ endif()
165196
# Optional dependencies
166197
ADD_PROJECT_DEPENDENCY(octomap PKG_CONFIG_REQUIRES "octomap >= 1.6")
167198
if(octomap_FOUND)
168-
SET(COAL_HAS_OCTOMAP TRUE)
199+
set(COAL_HAS_OCTOMAP TRUE)
169200
string(REPLACE "." ";" VERSION_LIST ${octomap_VERSION})
170201
list(GET VERSION_LIST 0 OCTOMAP_MAJOR_VERSION)
171202
list(GET VERSION_LIST 1 OCTOMAP_MINOR_VERSION)
172203
list(GET VERSION_LIST 2 OCTOMAP_PATCH_VERSION)
173204
message(STATUS "COAL uses Octomap")
174205
else()
175-
SET(COAL_HAS_OCTOMAP FALSE)
206+
set(COAL_HAS_OCTOMAP FALSE)
176207
message(STATUS "COAL does not use Octomap")
177208
endif()
178209

@@ -183,30 +214,37 @@ if(COAL_HAS_QHULL)
183214
set(COAL_USE_SYSTEM_QHULL TRUE)
184215
message(STATUS "COAL uses system Qhull")
185216
else()
186-
message(STATUS "Qhullcpp not found: it will be build from sources, if Qhull_r is found")
217+
message(
218+
STATUS
219+
"Qhullcpp not found: it will be build from sources, if Qhull_r is found"
220+
)
187221
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third-parties)
188-
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
189-
${PROJECT_SOURCE_DIR}/third-parties/qhull/src/libqhullcpp
190-
${PROJECT_BINARY_DIR}/third-parties/libqhullcpp
191-
)
222+
execute_process(
223+
COMMAND
224+
${CMAKE_COMMAND} -E create_symlink
225+
${PROJECT_SOURCE_DIR}/third-parties/qhull/src/libqhullcpp
226+
${PROJECT_BINARY_DIR}/third-parties/libqhullcpp
227+
)
192228
set(Qhullcpp_PREFIX ${PROJECT_BINARY_DIR}/third-parties)
193-
find_path(Qhull_r_INCLUDE_DIR
229+
find_path(
230+
Qhull_r_INCLUDE_DIR
194231
NAMES libqhull_r/libqhull_r.h
195232
PATHS ${Qhull_PREFIX}
196-
)
197-
find_library(Qhull_r_LIBRARY
198-
NAMES libqhull_r.so
199-
PATHS ${Qhull_PREFIX}
200-
)
233+
)
234+
find_library(Qhull_r_LIBRARY NAMES libqhull_r.so PATHS ${Qhull_PREFIX})
201235
if(NOT Qhull_r_LIBRARY)
202-
message(FATAL_ERROR "Qhull_r not found, please install it or turn COAL_HAS_QHULL OFF")
236+
message(
237+
FATAL_ERROR
238+
"Qhull_r not found, please install it or turn COAL_HAS_QHULL OFF"
239+
)
203240
endif()
204241
endif()
205242
endif()
206243

207-
FIND_PACKAGE(assimp REQUIRED)
244+
find_package(assimp REQUIRED)
208245

209-
SET(${PROJECT_NAME}_HEADERS
246+
set(
247+
${PROJECT_NAME}_HEADERS
210248
include/coal/collision_data.h
211249
include/coal/BV/kIOS.h
212250
include/coal/BV/BV.h
@@ -325,10 +363,11 @@ SET(${PROJECT_NAME}_HEADERS
325363
include/coal/serialization/quadrilateral.h
326364
include/coal/serialization/triangle.h
327365
include/coal/timings.h
328-
)
366+
)
329367

330368
if(COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL)
331-
SET(HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS
369+
set(
370+
HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS
332371
include/hpp/fcl/broadphase/broadphase_bruteforce.h
333372
include/hpp/fcl/broadphase/broadphase_callbacks.h
334373
include/hpp/fcl/broadphase/broadphase_collision_manager.h
@@ -454,48 +493,60 @@ if(COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL)
454493
include/hpp/fcl/shape/geometric_shape_to_BVH_model.h
455494
include/hpp/fcl/timings.h
456495
include/hpp/fcl/warning.hh
457-
)
458-
LIST(APPEND ${PROJECT_NAME}_HEADERS ${HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS})
459-
HEADER_INSTALL(COMPONENT hpp-fcl-compatibility ${HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS})
496+
)
497+
list(APPEND ${PROJECT_NAME}_HEADERS ${HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS})
498+
HEADER_INSTALL(
499+
COMPONENT hpp-fcl-compatibility
500+
${HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS}
501+
)
460502
endif()
461503

462-
IF(COAL_HAS_OCTOMAP)
463-
LIST(APPEND ${PROJECT_NAME}_HEADERS
504+
if(COAL_HAS_OCTOMAP)
505+
list(
506+
APPEND
507+
${PROJECT_NAME}_HEADERS
464508
include/coal/octree.h
465509
include/coal/serialization/octree.h
466510
include/coal/internal/traversal_node_octree.h
467511
)
468-
ENDIF(COAL_HAS_OCTOMAP)
512+
endif(COAL_HAS_OCTOMAP)
469513

470514
add_subdirectory(doc)
471515
add_subdirectory(src)
472-
if (BUILD_PYTHON_INTERFACE)
516+
if(BUILD_PYTHON_INTERFACE)
473517
add_subdirectory(python)
474-
endif ()
518+
endif()
475519
if(BUILD_TESTING)
476520
add_subdirectory(test)
477521
endif(BUILD_TESTING)
478522

479-
pkg_config_append_libs("coal")
480-
IF(COAL_HAS_OCTOMAP)
523+
PKG_CONFIG_APPEND_LIBS("coal")
524+
if(COAL_HAS_OCTOMAP)
481525
# FCL_HAVE_OCTOMAP kept for backward compatibility reasons.
482526
PKG_CONFIG_APPEND_CFLAGS(
483-
"-DCOAL_HAS_OCTOMAP -DCOAL_HAVE_OCTOMAP -DFCL_HAVE_OCTOMAP -DOCTOMAP_MAJOR_VERSION=${OCTOMAP_MAJOR_VERSION} -DOCTOMAP_MINOR_VERSION=${OCTOMAP_MINOR_VERSION} -DOCTOMAP_PATCH_VERSION=${OCTOMAP_PATCH_VERSION}")
484-
ENDIF(COAL_HAS_OCTOMAP)
527+
"-DCOAL_HAS_OCTOMAP -DCOAL_HAVE_OCTOMAP -DFCL_HAVE_OCTOMAP -DOCTOMAP_MAJOR_VERSION=${OCTOMAP_MAJOR_VERSION} -DOCTOMAP_MINOR_VERSION=${OCTOMAP_MINOR_VERSION} -DOCTOMAP_PATCH_VERSION=${OCTOMAP_PATCH_VERSION}"
528+
)
529+
endif(COAL_HAS_OCTOMAP)
485530

486531
# Install catkin package.xml
487-
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})
532+
install(FILES package.xml DESTINATION share/${PROJECT_NAME})
488533

489534
if(COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL)
490535
include(CMakePackageConfigHelpers)
491-
write_basic_package_version_file(hpp-fclConfigVersion.cmake
492-
VERSION 3.0.0
493-
COMPATIBILITY AnyNewerVersion)
494-
install(FILES hpp-fclConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/hpp-fclConfigVersion.cmake
495-
DESTINATION lib/cmake/hpp-fcl
496-
COMPONENT hpp-fcl-compatibility)
536+
write_basic_package_version_file(
537+
hpp-fclConfigVersion.cmake
538+
VERSION 3.0.0
539+
COMPATIBILITY AnyNewerVersion
540+
)
541+
install(
542+
FILES
543+
hpp-fclConfig.cmake
544+
${CMAKE_CURRENT_BINARY_DIR}/hpp-fclConfigVersion.cmake
545+
DESTINATION lib/cmake/hpp-fcl
546+
COMPONENT hpp-fcl-compatibility
547+
)
497548
include("${JRL_CMAKE_MODULES}/install-helpers.cmake")
498-
add_install_target(NAME hpp-fcl-compatibility COMPONENT hpp-fcl-compatibility)
549+
ADD_INSTALL_TARGET(NAME hpp-fcl-compatibility COMPONENT hpp-fcl-compatibility)
499550
endif()
500551

501-
setup_project_finalize()
552+
SETUP_PROJECT_FINALIZE()

0 commit comments

Comments
 (0)