diff --git a/CMakeLists.txt b/CMakeLists.txt index a1eb1406d7..25b5c11b0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "Fabian_Froehlich@hms.harvard.edu") diff --git a/cmake/cmakelang-tools.cmake b/cmake/cmakelang-tools.cmake new file mode 100644 index 0000000000..ad489500bc --- /dev/null +++ b/cmake/cmakelang-tools.cmake @@ -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()