Skip to content

Commit

Permalink
always format cmake files (#22)
Browse files Browse the repository at this point in the history
* always format cmake files

* remove debug log

* use pip3

* use pip3 on all systems

* set ACTIONS_ALLOW_UNSECURE_COMMANDS to true
  • Loading branch information
TheLartians authored Mar 1, 2021
1 parent 4f660d6 commit 1cd8380
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ 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
- 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"
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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."
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Format.cmake adds three additional targets to your CMake project.

To run the targets, invoke CMake with `cmake --build <build directory> --target <target name>`.

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

Expand All @@ -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"
)
Expand Down

0 comments on commit 1cd8380

Please sign in to comment.