Skip to content

Commit

Permalink
Add cmake target for cmake-format & cmake-lint (#1909)
Browse files Browse the repository at this point in the history
* Add cmake target for cmake-format

Everybody likes clean CMake files...

* cmake-lint, cleanup
  • Loading branch information
dweindl authored Dec 11, 2022
1 parent 59c7255 commit 38166c6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ if($ENV{ENABLE_GCOV_COVERAGE})
endif()

include(clang-tools)
include(cmakelang-tools)

set(AUTHORS "Fabian Froehlich, Jan Hasenauer, Daniel Weindl and Paul Stapor")
set(AUTHOR_EMAIL "[email protected]")
Expand Down
41 changes: 41 additions & 0 deletions cmake/cmakelang-tools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# --- Add targets for cmake-format https://cmake-format.readthedocs.io/ ---

# Find all CMakeFiles files
set(ALL_CMAKE_FILES
CMakeLists.txt
python/CMakeLists.txt
swig/CMakeLists.txt
tests/cpp/CMakeLists.txt
tests/cpp/unittests/CMakeLists.txt
${CMAKE_MODULE_PATH}/cmakelang-tools.cmake
${CMAKE_MODULE_PATH}/clang-tools.cmake
${CMAKE_MODULE_PATH}/version.cmake)
list(JOIN ALL_CMAKE_FILES " " ALL_CMAKE_FILES)

# --- cmake-format ---

# Try to find cmake-format and add target if successful
find_program(CMAKE_FORMAT "cmake-format")
if(CMAKE_FORMAT)
add_custom_target(
cmake-format
COMMAND bash -c "${CMAKE_FORMAT} -i ${ALL_CMAKE_FILES}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running cmake-format")
else()
message(STATUS "cmake-format was not found")
endif()

# --- cmake-lint ---

# Try to find cmake-lint and add target if successful
find_program(CMAKE_LINT "cmake-lint")
if(CMAKE_LINT)
add_custom_target(
cmake-lint
COMMAND bash -c "${CMAKE_LINT} ${ALL_CMAKE_FILES}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running cmake-lint")
else()
message(STATUS "cmake-lint was not found")
endif()

0 comments on commit 38166c6

Please sign in to comment.