From 1cd8380dd02aedf4ba858126cb7df195d8724939 Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Mon, 1 Mar 2021 21:44:06 +0100 Subject: [PATCH] always format cmake files (#22) * always format cmake files * remove debug log * use pip3 * use pip3 on all systems * set ACTIONS_ALLOW_UNSECURE_COMMANDS to true --- .github/workflows/style.yml | 2 +- .github/workflows/unix.yml | 8 ++++---- .github/workflows/windows.yml | 10 ++++++---- CMakeLists.txt | 5 +++-- README.md | 8 ++++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e5da002..5cfdf26 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - name: Install format dependencies - run: pip install cmake_format pyyaml + run: pip3 install cmake_format==0.6.11 pyyaml - name: Check source style run: cmake-format --check ./CMakeLists.txt ./cmake-format.cmake diff --git a/.github/workflows/unix.yml b/.github/workflows/unix.yml index dce7260..bb383c7 100644 --- a/.github/workflows/unix.yml +++ b/.github/workflows/unix.yml @@ -18,7 +18,7 @@ jobs: - name: Configure and build without format dependencies run: | - cmake -Htest -Bbuild -DFORMAT_CHECK_CMAKE=True + cmake -Htest -Bbuild cmake --build build ./build/test ! cmake --build build --target format @@ -26,10 +26,10 @@ jobs: - name: Install format dependencies run: | brew install clang-format - pip install cmake_format pyyaml + pip3 install cmake_format==0.6.11 pyyaml - name: Configure - run: cmake -Htest -Bbuild -DFORMAT_CHECK_CMAKE=True + run: cmake -Htest -Bbuild - name: Run format run: "cmake --build build --target format" @@ -52,7 +52,7 @@ jobs: - name: Configure cmake-format with excluded file run: | git reset --hard HEAD - cmake -Htest -Bbuild -DFORMAT_CHECK_CMAKE=True -DCMAKE_FORMAT_EXCLUDE="(^|/)sample\\.cmake$" + cmake -Htest -Bbuild -DCMAKE_FORMAT_EXCLUDE="(^|/)sample\\.cmake$" - name: Fix cmake-format skipping excluded file run: cmake --build build --target fix-cmake-format diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f1da360..dfaa77a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -19,20 +19,22 @@ jobs: - name: Configure and build without format dependencies shell: bash run: | - cmake -Htest -Bbuild -DFORMAT_CHECK_CMAKE=True + cmake -Htest -Bbuild cmake --build build ./build/Debug/test.exe ! cmake --build build --target format - name: Install format dependencies + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true run: | choco install llvm -y echo "::add-path::C:\\Program Files\\LLVM\\bin" - pip install cmake_format pyyaml + pip3 install cmake_format==0.6.11 pyyaml - name: Configure shell: bash - run: cmake -Htest -Bbuild -DFORMAT_CHECK_CMAKE=True + run: cmake -Htest -Bbuild - name: Run format shell: bash @@ -62,7 +64,7 @@ jobs: # Not using `bash` to prevent regular expression from being treated as a filesystem path run: | git reset --hard HEAD - cmake -Htest -Bbuild -DFORMAT_CHECK_CMAKE=True -DCMAKE_FORMAT_EXCLUDE="(^|/)sample\.cmake$" + cmake -Htest -Bbuild -DCMAKE_FORMAT_EXCLUDE="(^|/)sample\.cmake$" - name: Fix cmake-format skipping excluded file shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index 2021b91..f4d0c61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -option(FORMAT_CHECK_CMAKE "Enable CMake formatting.") +option(FORMAT_SKIP_CMAKE "Skip CMake formatting.") + set(CMAKE_FORMAT_EXCLUDE "" CACHE STRING "CMake formatting file exclusion pattern." @@ -84,7 +85,7 @@ endif() list(APPEND FORMAT_TARGETS clang-format) list(APPEND CHECK_FORMAT_TARGETS check-clang-format) list(APPEND FIX_FORMAT_TARGETS fix-clang-format) -if(FORMAT_CHECK_CMAKE) +if(NOT FORMAT_SKIP_CMAKE) list(APPEND FORMAT_TARGETS cmake-format) list(APPEND CHECK_FORMAT_TARGETS check-cmake-format) list(APPEND FIX_FORMAT_TARGETS fix-cmake-format) diff --git a/README.md b/README.md index d6fbf7c..799b914 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Format.cmake adds three additional targets to your CMake project. To run the targets, invoke CMake with `cmake --build --target `. -To use _cmake_format_ to also format CMake files, enable the cmake option `FORMAT_CHECK_CMAKE`, e.g. by invoking CMake with `-DFORMAT_CHECK_CMAKE=ON`, or enabling the option when [adding the dependency](#how-to-integrate) (recommended). +To disable using _cmake_format_ to format CMake files, set the cmake option `FORMAT_SKIP_CMAKE` to a truthy value, e.g. by invoking CMake with `-DFORMAT_SKIP_CMAKE=YES`, or enabling the option when [adding the dependency](#how-to-integrate) (recommended). ## Demo @@ -39,10 +39,10 @@ include(cmake/CPM.cmake) CPMAddPackage( NAME Format.cmake - VERSION 1.6 + VERSION 1.7.0 GITHUB_REPOSITORY TheLartians/Format.cmake - OPTIONS # enable cmake formatting (optional) - "FORMAT_CHECK_CMAKE ON" + OPTIONS # set to yes skip cmake formatting + "FORMAT_SKIP_CMAKE NO" # path to exclude (optional, supports regular expressions) "CMAKE_FORMAT_EXCLUDE cmake/CPM.cmake" )