Skip to content

Commit ae303e9

Browse files
committed
Add corrections for cmake-format version and documentation
1 parent 32904b9 commit ae303e9

File tree

4 files changed

+62
-19
lines changed

4 files changed

+62
-19
lines changed

CMakeLists.txt

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,38 @@ if(UMF_FORMAT_CODE_STYLE)
217217
find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)
218218
find_program(CMAKE_FORMAT NAMES cmake-format)
219219

220-
if(CLANG_FORMAT AND CMAKE_FORMAT)
220+
if(CLANG_FORMAT)
221221
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
222-
get_program_version_major_minor(${CMAKE_FORMAT} CMAKE_FORMAT_VERSION)
223222
message(STATUS "Found clang-format: ${CLANG_FORMAT} "
224-
"(version: ${CLANG_FORMAT_VERSION})")
225-
message(STATUS "Found cmake-format: ${CMAKE_FORMAT} "
226-
"(version: ${CMAKE_FORMAT_VERSION})")
223+
"(version: ${CLANG_FORMAT_VERSION})")
227224

228225
# Check if clang-format (in correct version) is available for code formatting.
229226
set(CLANG_FORMAT_REQUIRED "15.0")
230227
if(NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED))
231228
message(FATAL_ERROR "Required clang-format version is "
232229
"${CLANG_FORMAT_REQUIRED}")
233230
endif()
234-
else()
235-
message(FATAL_ERROR "UMF_FORMAT_CODE_STYLE=ON, but clang-format or "
236-
"cmake-format not found (required version: "
237-
"${CLANG_FORMAT_REQUIRED})")
231+
endif()
232+
233+
if(CMAKE_FORMAT)
234+
get_program_version_major_minor(${CMAKE_FORMAT} CMAKE_FORMAT_VERSION)
235+
message(STATUS "Found cmake-format: ${CMAKE_FORMAT} "
236+
"(version: ${CMAKE_FORMAT_VERSION})")
237+
238+
# Check if cmake-format (in correct version) is available for code
239+
# formatting.
240+
set(CMAKE_FORMAT_REQUIRED "0.6")
241+
if(NOT (CMAKE_FORMAT_VERSION VERSION_EQUAL CMAKE_FORMAT_REQUIRED))
242+
message(FATAL_ERROR "Required cmake-format version is"
243+
"${CMAKE_FORMAT_REQUIRED}")
244+
endif()
245+
endif()
246+
247+
if(NOT CLANG_FORMAT AND NOT CMAKE_FORMAT)
248+
message(
249+
FATAL_ERROR
250+
"UMF_FORMAT_CODE_STYLE=ON, but neither clang-format (required version: "
251+
"${CLANG_FORMAT_REQUIRED}) nor cmake-format was found.")
238252
endif()
239253

240254
# Obtain files for clang-format check
@@ -283,6 +297,12 @@ if(UMF_FORMAT_CODE_STYLE)
283297
file(GLOB_RECURSE format_cmake_list ${format_cmake_glob})
284298
list(APPEND format_cmake_list "${PROJECT_SOURCE_DIR}/CMakeLists.txt")
285299

300+
# Print the list of files targeted for formatting by cmake-format
301+
message(STATUS "Files to be formatted with cmake-format:")
302+
foreach(file IN LISTS format_cmake_list)
303+
message(STATUS "${file}")
304+
endforeach()
305+
286306
message(STATUS "Adding cmake-format-check and cmake-format-apply make "
287307
"targets")
288308

@@ -295,6 +315,24 @@ if(UMF_FORMAT_CODE_STYLE)
295315
cmake-format-apply
296316
COMMAND ${CMAKE_FORMAT} --in-place ${format_cmake_list}
297317
COMMENT "Format files using cmake-format")
318+
319+
# Add a convenience target for running both clang-format and cmake-format
320+
# checks/apply
321+
add_custom_target(
322+
format-checks
323+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target
324+
clang-format-check
325+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target
326+
cmake-format-check
327+
COMMENT "Running both clang-format-check and cmake-format-check")
328+
329+
add_custom_target(
330+
format-apply
331+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target
332+
clang-format-apply
333+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target
334+
cmake-format-apply
335+
COMMENT "Format files using clang-format and cmake-format")
298336
endif()
299337

300338
# Add license to the installation path

CONTRIBUTING.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,28 @@ To verify correct coding style of your changes execute (assuming `build` is your
7474

7575
```bash
7676
$ cmake -B build -DUMF_FORMAT_CODE_STYLE=ON
77-
$ cmake --build build --target clang-format-check
78-
$ cmake --build build --target cmake-format-check
77+
$ cmake --build build --target format-checks
7978
```
8079

81-
We run this check in our Continuous Integration (CI). So, if any issues were found,
80+
We run these checks in our Continuous Integration (CI). So, if any issues were found,
8281
the Pull Request will be blocked from merging. To apply proper formatting (meaning,
83-
to fix the issues) execute the second available CMake target - run a command:
82+
to fix the issues) you can use the convenience target provided for applying formats:
8483

8584
```bash
86-
$ cmake --build build --target clang-format-apply
87-
$ cmake --build build --target cmake-format-apply
85+
$ cmake --build build --target format-apply
8886

8987
# Remember to review introduced changes
9088
```
9189

92-
**NOTE**: We use specific clang-format version - **15.0** is required. It can be installed,
93-
e.g., with command: `python -m pip install clang-format==15.0.7`.
90+
If you wish to use only `clang-format` or only `cmake-format`, you can execute the corresponding
91+
`clang-format-check` and `clang-format-apply` for source files, or `cmake-format-check` and
92+
`cmake-format-apply` for CMake files, respectively.
93+
94+
**NOTE**: We use specific versions of formatting tools to ensure consistency across the project. The required versions are:
95+
- clang-format version **15.0**, which can be installed with the command: `python -m pip install clang-format==15.0.7`.
96+
- cmake-format version **0.6.13**, which can be installed with the command: `python -m pip install cmake-format==0.6`.
97+
98+
Please ensure you have these specific versions installed before contributing to the project.
9499

95100
### When my PR is merged?
96101

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Required packages:
3030

3131
For development and contributions:
3232
- clang-format-15.0 (can be installed with `python -m pip install clang-format==15.0.7`)
33-
- cmake-format (can be installed with `python -m pip install cmake-format`)
33+
- cmake-format-0.6 (can be installed with `python -m pip install cmake-format==0.6.13`)
3434

3535
For building tests, multithreaded benchmarks and Disjoint Pool:
3636
- C++ compiler with C++17 support

third_party/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Python requirements modules
22
# Formatting the source code
33
clang-format==15.0.7
4-
cmake-format==0.6
4+
cmake-format==0.6.13
55
# Generating HTML documentation
66
pygments==2.5.2
77
sphinxcontrib_applehelp==1.0.4

0 commit comments

Comments
 (0)