TheLartians/Format.cmake

How to exclude subdirectories?

alexprogrammr opened this issue · 4 comments

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!

Hey @alexprogrammr, thanks for the issue!

Tbh the regex looks good to me, then again I'm no regex wizard myself. We currently use git ls-files --cached --exclude-standard from CMake's source directory to determine the paths. Are you specifying those paths relative to the top-level CMakeLists.txt?

Otherwise I'm not really sure what the mistake is, or if it's a bug on our side. You could try logging the filtered list in your local Format.cmake/cmake-format.cmake for debugging.

Thanks for such a quick response! I will try to debug it.

@TheLartians, I have misunderstood the purpose of CMAKE_FORMAT_EXCLUDE option. It is used to exclude CMakeLists files. I needed to exclude exact sources (c/c++) from format checking in specified directories. To achieve this behaviour I need to create .clang-format files in foo/ and bar/ directories with the following content:

DisableFormat: true
SortIncludes: false

Excuse me for troubling.
Have a good day!

Ah yeah, the regex only applies to cmake-format, as it didn't allow this functionality in the past. Happy you could resolve it!