Skip to content

Commit

Permalink
[CMake] Look for clang-format only if UR_FORMAT_CPP_STYLE is on
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszstolarczuk committed Aug 17, 2023
1 parent 2161dfa commit abfdadd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,15 @@ if(UR_USE_MSAN)
add_sanitizer_flag(memory)
endif()

find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)

set(CLANG_FORMAT_REQUIRED "15.0")
# Check if clang-format (in correct version) is available for Cpp code formatting.
if(UR_FORMAT_CPP_STYLE)
find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)

if(CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")
endif()
if(CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")

# Check if the correct version of clang-format is available
if(UR_FORMAT_CPP_STYLE)
if(CLANG_FORMAT)
set(CLANG_FORMAT_REQUIRED "15.0")
if(NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED))
message(FATAL_ERROR "required clang-format version is ${CLANG_FORMAT_REQUIRED}")
endif()
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Weekly tags](#weekly-tags)
3. [Third-Party tools](#third-party-tools)
4. [Building](#building)
- [Requirements](#requirements)
- [Windows](#windows)
- [Linux](#linux)
- [CMake standard options](#cmake-standard-options)
Expand Down Expand Up @@ -71,9 +72,13 @@ Tools can be acquired via instructions in [third_party](/third_party/README.md).

## Building

Requirements:
### Requirements

Required packages:
- C++ compiler with C++17 support
- [CMake](https://cmake.org/) >= 3.14.0

For development and contributions:
- clang-format-15.0 (can be installed with `python -m pip install clang-format==15.0.7`)

### Windows
Expand Down

0 comments on commit abfdadd

Please sign in to comment.