Skip to content

Commit

Permalink
Add cmake-lint to pre-commit hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
  • Loading branch information
nahueespinosa committed Jul 7, 2023
1 parent ae824d8 commit 861d977
Show file tree
Hide file tree
Showing 22 changed files with 403 additions and 162 deletions.
15 changes: 15 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):
# Force vertical layout if an argument group contains more than this many sub-groups.
max_subgroups_hwrap = 2
# Force vertical layout if a positional argument group contains more than this many arguments.
max_pargs_hwrap = 3

# ------------------------------------------------
# Options affecting comment reflow and formatting.
# ------------------------------------------------
with section("markup"):
# Disable comment markup parsing and reflow.
enable_markup = False
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
name: fix copyright
description: Check that files have a copyright notice.
entry: tools/check_copyright.py --fix
types_or: [c++, python]
types_or: [c++, python, cmake]
language: python
language_version: python3

Expand All @@ -44,3 +44,9 @@ repos:
- id: black
name: "fix python format"
entry: black --skip-string-normalization

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-lint
- id: cmake-format
73 changes: 47 additions & 26 deletions beluga/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.16)

project(beluga VERSION 1.0)
Expand All @@ -6,12 +20,21 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Build type" FORCE)
endif()

add_library(beluga_compile_options INTERFACE)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(beluga_compile_options INTERFACE -Wall -Wconversion -Werror -Wextra -Wpedantic -Wno-gnu-zero-variadic-macro-arguments)
target_compile_options(
beluga_compile_options
INTERFACE -Wall
-Wconversion
-Werror
-Wextra
-Wpedantic
-Wno-gnu-zero-variadic-macro-arguments)
endif()

find_package(Eigen3 REQUIRED NO_MODULE)
Expand All @@ -20,17 +43,24 @@ find_package(Sophus REQUIRED)
find_package(TBB REQUIRED)

add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${PROJECT_NAME}
INTERFACE Eigen3::Eigen Sophus::Sophus TBB::tbb range-v3::range-v3)
target_include_directories(
${PROJECT_NAME}
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(
${PROJECT_NAME}
INTERFACE Eigen3::Eigen
Sophus::Sophus
TBB::tbb
range-v3::range-v3)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_compile_definitions(${PROJECT_NAME} INTERFACE EIGEN_NO_DEBUG SOPHUS_USE_BASIC_LOGGING)
target_compile_definitions(${PROJECT_NAME} INTERFACE EIGEN_NO_DEBUG
SOPHUS_USE_BASIC_LOGGING)

add_executable(clang_tidy_findable)
target_sources(clang_tidy_findable PRIVATE src/clang_tidy_findable.cpp)
target_link_libraries(clang_tidy_findable PRIVATE ${PROJECT_NAME} beluga_compile_options)
target_link_libraries(clang_tidy_findable PRIVATE ${PROJECT_NAME}
beluga_compile_options)

option(BUILD_TESTING "Build the testing tree." ON)
if(BUILD_TESTING)
Expand All @@ -47,39 +77,30 @@ endif()

set(INSTALL_CMAKEDIR ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/cmake)

install(
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
)
install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})

install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
RUNTIME DESTINATION bin)

install(
EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${INSTALL_CMAKEDIR}
)
DESTINATION ${INSTALL_CMAKEDIR})

include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${INSTALL_CMAKEDIR}
)
INSTALL_DESTINATION ${INSTALL_CMAKEDIR})
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion )
COMPATIBILITY SameMajorVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKEDIR}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKEDIR})
25 changes: 20 additions & 5 deletions beluga/docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

find_package(Doxygen)

if(DOXYGEN_FOUND)
Expand All @@ -6,14 +20,15 @@ if(DOXYGEN_FOUND)
FetchContent_Declare(
doxygen-awesome-css
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css
GIT_TAG v2.2.0
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome
)
GIT_TAG v2.2.0
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome)

FetchContent_MakeAvailable(doxygen-awesome-css)

add_custom_target(beluga_docs
ALL
# cmake-lint: disable=C0301
# Line too long
add_custom_target(
beluga_docs ALL
COMMAND
DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR}
DOXYGEN_HTML_STYLESHEET=${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome/doxygen-awesome.css
Expand Down
41 changes: 32 additions & 9 deletions beluga/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
# Copyright 2023 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

find_package(GTest MODULE)
if(NOT TARGET GTest::gmock_main)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 03597a01ee50ed33e9dfd640b249b4be3799d395)
# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(GTEST_FORCE_SHARED_CRT
ON
CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()

find_package(benchmark REQUIRED)
if(NOT TARGET benchmark::benchmark_main)
include(FetchContent)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
# cmake-lint: disable=C0103
# Invalid INTERNAL variable name doesn't match `_[A-Z][0-9A-Z_]+`
set(BENCHMARK_ENABLE_GTEST_TESTS
OFF
CACHE INTERNAL "")
FetchContent_Declare(
benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.7.1.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
URL https://github.com/google/benchmark/archive/refs/tags/v1.7.1.zip)
# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(GTEST_FORCE_SHARED_CRT
ON
CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(benchmark)
endif()

Expand Down
20 changes: 18 additions & 2 deletions beluga/test/beluga/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
add_executable(test_beluga
# Copyright 2023 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_executable(
test_beluga
algorithm/raycasting/test_bresenham.cpp
algorithm/test_distance_map.cpp
algorithm/test_estimation.cpp
Expand All @@ -23,7 +38,8 @@ add_executable(test_beluga
test_storage.cpp
type_traits/test_strongly_typed_numeric.cpp)

target_link_libraries(test_beluga PRIVATE ${PROJECT_NAME} beluga_compile_options GTest::gmock_main)
target_link_libraries(
test_beluga PRIVATE ${PROJECT_NAME} beluga_compile_options GTest::gmock_main)
target_include_directories(test_beluga PRIVATE include)
target_compile_options(test_beluga PRIVATE -Wno-sign-compare)

Expand Down
30 changes: 23 additions & 7 deletions beluga/test/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# Copyright 2023 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

option(BELUGA_RUN_PERFORMANCE_TESTS
"Enable performance tests instead of unconditionally skipping them" OFF)
"Enable performance tests instead of unconditionally skipping them" OFF)

add_executable(benchmark_beluga
add_executable(
benchmark_beluga
benchmark_likelihood_field_model.cpp
benchmark_raycasting.cpp
benchmark_sampling.cpp
benchmark_spatial_hash.cpp
benchmark_tuple_vector.cpp
benchmark_main.cpp)
target_include_directories(benchmark_beluga PRIVATE ../beluga/include)
target_link_libraries(benchmark_beluga
target_link_libraries(
benchmark_beluga
PUBLIC benchmark::benchmark
PRIVATE ${PROJECT_NAME} beluga_compile_options)
set(TEST_RESULTS_DIR "${CMAKE_BINARY_DIR}/test_results/${PROJECT_NAME}")
file(MAKE_DIRECTORY ${TEST_RESULTS_DIR})

set(benchmark_out "${TEST_RESULTS_DIR}/benchmark_beluga.google_benchmark.json")
set(BENCHMARK_OUT "${TEST_RESULTS_DIR}/benchmark_beluga.google_benchmark.json")
if(BELUGA_RUN_PERFORMANCE_TESTS)
add_test(
NAME benchmark_beluga
COMMAND benchmark_beluga "--benchmark_out_format=json" "--benchmark_out=${benchmark_out}")
add_test(NAME benchmark_beluga
COMMAND benchmark_beluga "--benchmark_out_format=json"
"--benchmark_out=${BENCHMARK_OUT}")
endif()
25 changes: 23 additions & 2 deletions beluga_amcl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.16)

project(beluga_amcl)
Expand All @@ -6,11 +20,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Build type" FORCE)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wconversion -Wextra -Werror -Wpedantic)
add_compile_options(
-Wall
-Wconversion
-Wextra
-Werror
-Wpedantic)
endif()

set(ROS_VERSION $ENV{ROS_VERSION})
Expand Down
Loading

0 comments on commit 861d977

Please sign in to comment.