diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 94231301..0037fe48 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -191,9 +191,6 @@ jobs: - name: Install fftw3 run: sudo apt-get install -yq libfftw3-dev pkg-config - - - name: Install Bear - run: sudo apt-get install -yq bear - name: configure pcms run : | @@ -219,27 +216,12 @@ jobs: -DKokkosKernels_DIR=${{ runner.temp }}/build-kokkos-kernels-openmpi/install/lib/cmake/KokkosKernels/ \ -DPCMS_TEST_DATA_DIR=$PWD/pcms_testcases - - name: Configure pcms with Bear - run: | - cd ${{ runner.temp }}/build-pcms - bear -- make - - name: Install clang-tidy run: | sudo apt-get update sudo apt-get install -yq clang-tidy-18 + # TODO need to capture the error code from this - name: Run clang-tidy run: | - EXIT_CODE=0 - while read file; do - if ! clang-tidy -p ${{ runner.temp }}/build-pcms "$file" --quiet; then - echo "$file has clang-tidy issues" - EXIT_CODE=1 - fi - done < <(find src -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" -o -name "*.cc" -o -name "*.cxx" | grep -v 'src/pcms/capi/' | grep -v 'src/pcms/fortranapi/') - if [ $EXIT_CODE -eq 1 ]; then - echo "Some C/C++ files have clang-tidy issues. Please fix them with clang-tidy-18." - exit 1 - fi - echo "All C/C++ files pass clang-tidy checks" + cmake --build ${{ runner.temp }}/build-pcms -t run-clang-tidy diff --git a/CMakeLists.txt b/CMakeLists.txt index d9c519ca..3cf5fa68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,28 @@ if(PCMS_ENABLE_ASAN AND CMAKE_COMPILER_IS_GNUCXX MATCHES 1) set(PCMS_HAS_ASAN ON) endif() +# based on Professional CMake: A Practical Guide +# this approach works around some issues with CMakes internal handling using co-compilation +# this approach affords a separate clang-tidy run step in the CI +if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + + find_program(CLANG_TIDY_EXECUTABLE clang-tidy REQUIRED) + find_program(RUN_CLANG_TIDY_EXECUTABLE run-clang-tidy REQUIRED) + + set(CLANG_TIDY_CONFIG_FILE ${CMAKE_CURRENT_LIST_DIR}/.clang-tidy) + + message(STATUS "CLANG_TIDY_EXECUTABLE=${CLANG_TIDY_EXECUTABLE}") + message(STATUS "RUN_CLANG_TIDY_EXECUTABLE= ${RUN_CLANG_TIDY_EXECUTABLE}") + message(STATUS "CLANG_TIDY_CONFIG_FILE=${CLANG_TIDY_CONFIG_FILE}") + add_custom_target(run-clang-tidy + COMMAND ${RUN_CLANG_TIDY_EXECUTABLE} + -clang-tidy-binary ${CLANG_TIDY_EXECUTABLE} + -p ${CMAKE_BINARY_DIR} + -config-file ${CLANG_TIDY_CONFIG_FILE} + ) +endif() + option(PCMS_ENABLE_SERVER "enable the coupling server implementation" ON) option(PCMS_ENABLE_CLIENT "enable the coupling client implementation" ON)