Code Monkey home page Code Monkey logo

format.cmake's People

Contributors

developerpaul123 avatar jecassis avatar johelegp avatar krypty avatar rath3t avatar thelartians avatar thelongrunsmoke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

format.cmake's Issues

Add more information about `CMAKE_FORMAT_EXCLUDE`

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!

Check Format Fails on Windows

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.

Fix failure on systems with only Python 3.x

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:

  1. Alias python to python3, e.g.
echo 'alias python=python3' | sudo tee -a /etc/environment > /dev/null
  1. Use alternatives to do the same, e.g.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

Respect Skipping CMake Formatting Based on Setting in Top Level Project

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?

Format.cmake directory path appears in the list of cmake-format arguments

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:

  1. Include as submodule.
  2. Build any target, ex. fix-format

`clang-format` target conflicts with other libraries

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

add_custom_target(clang-format ${CLANG_FORMAT_NOT_FOUND_COMMAND_ARGS})

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

fix-format and check-format does not give same result

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.

CI failing with `cmake --build build --target check-format`, complains about CPM.cmake even though it is excluded

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?

How to exclude subdirectories?

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.