thelartians / format.cmake Goto Github PK
View Code? Open in Web Editor NEW๐ Stylize your code! Automatic clang-format and cmake-format targets for CMake.
License: Apache License 2.0
๐ Stylize your code! Automatic clang-format and cmake-format targets for CMake.
License: Apache License 2.0
Would you consider allowing for OPTIONS/ENV that allows for a custom target for old libraries that happen to use the same build target?
I tried various CMake settings to avoid this but nothing seems to work. See CMP0002 using cmake_policy(SET CMP0002 OLD)
and or set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)
didn't work and there are many warnings not to do that.
I don't really want to fork either project just to fix this so I am hoping that because this project is specifically about adding clang-formating and the basis for many cpp projects with ModernCppStarter.
It's worth noting that that I don't have python installed so it's hitting
Line 43 in 15b0454
The full error:
CMake Error at cmake-build-debug/_deps/format.cmake-src/CMakeLists.txt:42 (add_custom_target):
add_custom_target cannot create target "clang-format" because another
target with the same name already exists. The existing target is a custom
target created in source directory
"C:/mosiac/all/cmake-build-debug/_deps/libzmq-src".
See documentation for policy CMP0002 for more details.
The CPM I am adding is
CPMAddPackage(
NAME libzmq
GIT_TAG v4.3.5
GITHUB_REPOSITORY zeromq/libzmq
OPTIONS
"BUILD_SHARED OFF"
)
Their target can be found in this file:
https://github.com/zeromq/libzmq/blob/2a75ef07be0ba76f86592e10b999331cd6124d52/builds/cmake/Modules/ClangFormat.cmake#L18
If a project uses CPM to pull in LLVM and builds the clang
project of LLVM, then the target names clang-format
and check-clang-format
will conflict. Locally I fixed this by adding run-
prefixes to each target.
Due to a combination of PEP 394 and newer operating systems shipping with only Python 3.x (such as Ubuntu 20.04), Format.cmake
may fail on this line. The failure is due to the python
executable not existing. Using CMake's FindPython
module might make Format.cmake
more portable and robust.
In the meantime, without installing Python 2.x, some workarounds are:
python
to python3
, e.g.echo 'alias python=python3' | sudo tee -a /etc/environment > /dev/null
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
I have problems with check-format target failing, even though fix-format is not making any changes.
I have a file in a subdir where cmake-format should be disabled. Therefore I have places a file called ".cmake-format" containing:
disable: true
This is disables the fix-format actions. But check-format is still failing with this error:
CMake Error at cmake/modules/Format.cmake/cmake-format.cmake:58 (message):
cmake/modules/CodeCoverage.cmake needs to be reformatted
CodeCoverage.cmake is the file that I want to have ignored.
Helli, @TheLartians!
Thank you for a lot of useful projects you have provide to the community!
Currently, I'm facing an issue with excluding subdirectories.
Assume, that I have the following directory structure:
.
โโโ ...
โโโ ...
โโโ foo
โโโ bar
I need to exclude both foo
and bar
from format checking.
I add this package in the following way:
CPMAddPackage(
NAME Format.cmake
GITHUB_REPOSITORY TheLartians/Format.cmake
VERSION 1.6
OPTIONS
"CMAKE_FORMAT_EXCLUDE (^foo/.*)|(^bar/.*)"
)
What's wrong with my regular expression? Maybe, I missed some additional escaping that should be applied...
Thanks!
I'm not sure if it's your intention to have this script be cross platform but the check format build target fails on Windows (by default) because grep
is not available.
Another side effect of this is that your CMake project template will fail a build all
action due to this format check.
I'm not sure how this would work, or if it's technically feasible, but I'm going to describe my issue through a hypothetical project.
Let's assume we have projects A and B. Project A depends on project B and pulls it in with CPM
.
Both projects use Format.cmake
; project A does not allow Cmake formatting, but project B does have that enabled.
Right now, when running "check-format" from project A, it will always fail because Format.cmake
thinks that the CMakeLists files need to be formated even though FORMAT_SKIP_CMAKE
is set to YES
in project A.
Is there any way to work around this?
When Format.cmake used as submodule https://github.com/TheLartians/Format.cmake#using-git-submodules-not-suited-for-libraries its directory path appear in arguments that passed to cmake-format.
Traceback (most recent call last):
File ".../.local/bin/cmake-format", line 8, in <module>
sys.exit(main())
File ".../.local/lib/python3.8/site-packages/cmake_format/__main__.py", line 625, in main
return inner_main()
File ".../.local/lib/python3.8/site-packages/cmake_format/__main__.py", line 608, in inner_main
onefile_main(infile_path, args, argparse_dict)
File ".../.local/lib/python3.8/site-packages/cmake_format/__main__.py", line 512, in onefile_main
infile = io.open(
FileNotFoundError: [Errno 2] No such file or directory: 'Format.cmake'
How to reproduce:
fix-format
This doesn't fail when running it locally, only on CI.
Local run:
[TerraGen]$ cmake --build build --target check-format
[0/2] Re-checking globbed directories...
[2/2] cd /home/kyle/Documents/TerraGen && /usr/bin/python3.9 /home/kyle/Documents/TerraGen/build/_deps/...ke-src/git-clang-format.py --binary=/usr/bin/clang-format --ci 4b825dc642cb6eb9a060e54bf8d69288fbee4904
clang-format did not modify any files
CI run:
cmake --build /home/runner/work/TerraGen/TerraGen/build --target check-format --config Debug
shell: /usr/bin/bash -e {0}
env:
BUILD_TYPE: Debug
CMake Error at build/_deps/format.cmake-src/cmake-format.cmake:53 (message):
cmake/CPM.cmake needs to be reformatted
Any idea what I'm doing wrong here?
The readme doesn't specify how to properly set the option. Should the list be semicolon-delimited, space-delimited? Currently both delimiters don't get errored in CMake, but neither work.
Please add a bit more information about the option in the readme.
Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.