Skip to content

Commit

Permalink
Merge pull request #807 from lukaszstolarczuk/ext-cmake
Browse files Browse the repository at this point in the history
Update top-level CMake
  • Loading branch information
pbalcer committed Aug 21, 2023
2 parents 21aaf94 + 00131b8 commit 342f100
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
46 changes: 21 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()

find_package(Python3 COMPONENTS Interpreter)
find_package(Python3 COMPONENTS Interpreter REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

# Build Options
option(UR_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF)
option(UR_BUILD_TESTS "Build unit tests." ON)
option(UR_BUILD_TOOLS "build ur tools" ON)
option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF)
option(UR_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF)
option(UR_USE_ASAN "enable AddressSanitizer" OFF)
option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
option(UR_USE_MSAN "enable MemorySanitizer" OFF)
option(UR_USE_TSAN "enable ThreadSanitizer" OFF)
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
option(UR_BUILD_TOOLS "build ur tools" ON)
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -130,23 +130,15 @@ if(UR_USE_MSAN)
add_sanitizer_flag(memory)
endif()

# Allow custom third_party folder
if(NOT DEFINED THIRD_PARTY_DIR)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
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 All @@ -155,7 +147,7 @@ if(UR_FORMAT_CPP_STYLE)
endif()
endif()

# Obtain files for clang-format
# Obtain files for clang-format and license check
set(format_glob)
set(license_glob)
foreach(dir examples include source test tools)
Expand All @@ -180,7 +172,7 @@ endforeach()
file(GLOB_RECURSE format_src ${format_glob})
file(GLOB_RECURSE license_src ${license_glob})

# check for licence
# Add license check target
list(FILTER license_src EXCLUDE REGEX "registry.yml")
add_custom_target(verify-licenses
COMMAND ${Python3_EXECUTABLE}
Expand All @@ -191,9 +183,13 @@ add_custom_target(verify-licenses

# Add code formatter target
add_custom_target(cppformat)
# ... and all source files to the formatter
add_cppformat(all-sources ${format_src})

# Add files to the formatter
add_cppformat(src-formatter ${format_src})
# Allow custom third_party folder
if(NOT DEFINED THIRD_PARTY_DIR)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
endif()

add_subdirectory(${THIRD_PARTY_DIR})

Expand Down Expand Up @@ -273,5 +269,5 @@ if(UR_FORMAT_CPP_STYLE)
DEPENDS generate
)
else()
message(WARNING "UR_FORMAT_CPP_STYLE not set. Targets: 'generate' and 'check-generated' and not available")
message(STATUS " UR_FORMAT_CPP_STYLE not set. Targets: 'generate' and 'check-generated' are not available")
endif()
8 changes: 7 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,14 @@ 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
- Python v3.6.6 or later

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 342f100

Please sign in to comment.