From 945f0bb27e916607bf3ccd4b62585a6faf15de59 Mon Sep 17 00:00:00 2001
From: Guilhem Saurel <guilhem.saurel@laas.fr>
Date: Wed, 3 May 2023 17:04:09 +0200
Subject: [PATCH] cmake format

---
 .pre-commit-config.yaml                   |  4 ++
 CMakeLists.txt                            | 83 ++++++++++++-----------
 include/example-robot-data/CMakeLists.txt |  5 +-
 python/CMakeLists.txt                     | 17 ++---
 unittest/CMakeLists.txt                   | 21 +++---
 5 files changed, 69 insertions(+), 61 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 2012a81..5b4624a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -30,3 +30,7 @@ repos:
     rev: 6.0.0
     hooks:
     -   id: flake8
+-   repo: https://github.com/cheshirekow/cmake-format-precommit
+    rev: v0.6.13
+    hooks:
+    - id: cmake-format
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 10b18df..78be3ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,51 +1,56 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
+cmake_minimum_required(VERSION 3.1)
 
 # Project properties
-SET(PROJECT_ORG gepetto)
-SET(PROJECT_NAME example-robot-data)
-SET(PROJECT_DESCRIPTION "Set of robot URDFs for benchmarking and developed examples.")
-SET(PROJECT_URL https://github.com/${PROJECT_ORG}/${PROJECT_NAME})
+set(PROJECT_ORG gepetto)
+set(PROJECT_NAME example-robot-data)
+set(PROJECT_DESCRIPTION
+    "Set of robot URDFs for benchmarking and developed examples.")
+set(PROJECT_URL https://github.com/${PROJECT_ORG}/${PROJECT_NAME})
 
 # Project options
-OPTION(BUILD_PYTHON_INTERFACE "Build the python unit tests and helpers" ON)
-OPTION(INSTALL_PYTHON_INTERFACE_ONLY "Install *ONLY* the python interface" OFF)
+option(BUILD_PYTHON_INTERFACE "Build the python unit tests and helpers" ON)
+option(INSTALL_PYTHON_INTERFACE_ONLY "Install *ONLY* the python interface" OFF)
 
 # Project configuration
-IF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
-  SET(PROJECT_USE_CMAKE_EXPORT TRUE)
-ENDIF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
-SET(CUSTOM_HEADER_DIR ${PROJECT_NAME})
-SET(PROJECT_COMPATIBILITY_VERSION AnyNewerVersion)
+if(NOT INSTALL_PYTHON_INTERFACE_ONLY)
+  set(PROJECT_USE_CMAKE_EXPORT TRUE)
+endif(NOT INSTALL_PYTHON_INTERFACE_ONLY)
+set(CUSTOM_HEADER_DIR ${PROJECT_NAME})
+set(PROJECT_COMPATIBILITY_VERSION AnyNewerVersion)
 
 # JRL-cmakemodule setup
-INCLUDE(cmake/base.cmake)
+include(cmake/base.cmake)
 
 # Print initial message
-MESSAGE(STATUS "${PROJECT_DESCRIPTION}, version ${PROJECT_VERSION}")
-MESSAGE(STATUS "Copyright (C) 2018-2021 LAAS-CNRS, University of Edinburgh")
-MESSAGE(STATUS "All rights reserved.")
-MESSAGE(STATUS "Released under the BSD 3-Clause License.")
+message(STATUS "${PROJECT_DESCRIPTION}, version ${PROJECT_VERSION}")
+message(STATUS "Copyright (C) 2018-2021 LAAS-CNRS, University of Edinburgh")
+message(STATUS "All rights reserved.")
+message(STATUS "Released under the BSD 3-Clause License.")
 
 # Project definition
-COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
-PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
-
-IF(BUILD_PYTHON_INTERFACE)
-  ADD_PROJECT_DEPENDENCY(eigenpy 2.7.11 REQUIRED)
-  ADD_PROJECT_DEPENDENCY(pinocchio REQUIRED)
-  STRING(REGEX REPLACE "-" "_" PY_NAME ${PROJECT_NAME})
-  ADD_SUBDIRECTORY(python)
-  IF(BUILD_TESTING)
-    ADD_SUBDIRECTORY(unittest)
-  ENDIF(BUILD_TESTING)
-ENDIF(BUILD_PYTHON_INTERFACE)
-
-IF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
-  ADD_LIBRARY(${PROJECT_NAME} INTERFACE)
-  TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE $<INSTALL_INTERFACE:include>)
-  INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
-
-  ADD_SUBDIRECTORY(include/${CUSTOM_HEADER_DIR})
-  INSTALL(DIRECTORY robots DESTINATION share/${PROJECT_NAME})
-  INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})
-ENDIF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
+compute_project_args(PROJECT_ARGS LANGUAGES CXX)
+project(${PROJECT_NAME} ${PROJECT_ARGS})
+
+if(BUILD_PYTHON_INTERFACE)
+  add_project_dependency(eigenpy 2.7.11 REQUIRED)
+  add_project_dependency(pinocchio REQUIRED)
+  string(REGEX REPLACE "-" "_" PY_NAME ${PROJECT_NAME})
+  add_subdirectory(python)
+  if(BUILD_TESTING)
+    add_subdirectory(unittest)
+  endif(BUILD_TESTING)
+endif(BUILD_PYTHON_INTERFACE)
+
+if(NOT INSTALL_PYTHON_INTERFACE_ONLY)
+  add_library(${PROJECT_NAME} INTERFACE)
+  target_include_directories(${PROJECT_NAME}
+                             INTERFACE $<INSTALL_INTERFACE:include>)
+  install(
+    TARGETS ${PROJECT_NAME}
+    EXPORT ${TARGETS_EXPORT_NAME}
+    DESTINATION lib)
+
+  add_subdirectory(include/${CUSTOM_HEADER_DIR})
+  install(DIRECTORY robots DESTINATION share/${PROJECT_NAME})
+  install(FILES package.xml DESTINATION share/${PROJECT_NAME})
+endif(NOT INSTALL_PYTHON_INTERFACE_ONLY)
diff --git a/include/example-robot-data/CMakeLists.txt b/include/example-robot-data/CMakeLists.txt
index 34f2f23..c5c4185 100644
--- a/include/example-robot-data/CMakeLists.txt
+++ b/include/example-robot-data/CMakeLists.txt
@@ -1,2 +1,3 @@
-CONFIGURE_FILE(path.hpp.in path.hpp)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/path.hpp DESTINATION include/${CUSTOM_HEADER_DIR})
+configure_file(path.hpp.in path.hpp)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/path.hpp
+        DESTINATION include/${CUSTOM_HEADER_DIR})
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index ce69528..6f889dc 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -1,12 +1,9 @@
-SET(${PROJECT_NAME}_PYTHON_FILES
-  robots_loader.py
-  __main__.py
-  __init__.py
-  )
+set(${PROJECT_NAME}_PYTHON_FILES robots_loader.py __main__.py __init__.py)
 
-FOREACH(python ${${PROJECT_NAME}_PYTHON_FILES})
-  PYTHON_INSTALL_ON_SITE(${PY_NAME} ${python})
-ENDFOREACH(python ${${PROJECT_NAME}_PYTHON_FILES})
+foreach(python ${${PROJECT_NAME}_PYTHON_FILES})
+  python_install_on_site(${PY_NAME} ${python})
+endforeach(python ${${PROJECT_NAME}_PYTHON_FILES})
 
-CONFIGURE_FILE(${PY_NAME}/path.py.in ${PY_NAME}/path.py)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PY_NAME}/path.py DESTINATION "${PYTHON_SITELIB}/${PY_NAME}")
+configure_file(${PY_NAME}/path.py.in ${PY_NAME}/path.py)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PY_NAME}/path.py
+        DESTINATION "${PYTHON_SITELIB}/${PY_NAME}")
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
index 18fe801..a157b67 100644
--- a/unittest/CMakeLists.txt
+++ b/unittest/CMakeLists.txt
@@ -1,12 +1,13 @@
-IF(NOT pinocchio_FOUND)
-  MESSAGE(FATAL_ERROR "Pinocchio is required to build unit tests\n"
-  "please either install Pinocchio or reconfigure without unit tests (-DBUILD_TESTING=OFF)")
-ENDIF(NOT pinocchio_FOUND)
-
-SET(${PROJECT_NAME}_PYTHON_TESTS
-  load
+if(NOT pinocchio_FOUND)
+  message(
+    FATAL_ERROR
+      "Pinocchio is required to build unit tests\n"
+      "please either install Pinocchio or reconfigure without unit tests (-DBUILD_TESTING=OFF)"
   )
+endif(NOT pinocchio_FOUND)
+
+set(${PROJECT_NAME}_PYTHON_TESTS load)
 
-FOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
-  ADD_PYTHON_UNIT_TEST("py-${TEST}" "unittest/test_${TEST}.py" python)
-ENDFOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
+foreach(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
+  add_python_unit_test("py-${TEST}" "unittest/test_${TEST}.py" python)
+endforeach(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
-- 
GitLab