-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCMakeLists.txt
59 lines (55 loc) · 2.17 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
cmake_minimum_required(VERSION 3.16...3.31)
project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION})
message(STATUS "clang-format-wheel version: ${SKBUILD_PROJECT_VERSION}")
string(REGEX MATCH "^([0-9]+)\.([0-9]+)\.([0-9]+)" CLANG_FORMAT_VERSION "${SKBUILD_PROJECT_VERSION}")
message(STATUS "clang-format version: ${CLANG_FORMAT_VERSION}")
# Define a build rule clang-format
set(LLVM_DOWNLOAD_URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_FORMAT_VERSION}/llvm-project-${CLANG_FORMAT_VERSION}.src.tar.xz")
include(ExternalProject)
ExternalProject_add(build-clang-format
URL "${LLVM_DOWNLOAD_URL}"
SOURCE_SUBDIR llvm
SOURCE_DIR ${CMAKE_BINARY_DIR}/llvm-project
BINARY_DIR ${CMAKE_BINARY_DIR}/llvm
UPDATE_COMMAND ""
INSTALL_COMMAND ""
USES_TERMINAL_DOWNLOAD 1
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target clang-format --config Release
)
set(config-subfolder "")
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(config-subfolder "Release")
endif()
set(clang-format-executable ${CMAKE_BINARY_DIR}/llvm/${config-subfolder}/bin/clang-format${CMAKE_EXECUTABLE_SUFFIX})
# Reduce the size of the executable by executing strip if it is present on the system
find_program(STRIP_EXECUTABLE strip)
if(STRIP_EXECUTABLE)
add_custom_target(
strip-clang-format
ALL
COMMAND ${STRIP_EXECUTABLE} ${clang-format-executable}
COMMENT "Stripping clang-format executable for size reduction"
)
add_dependencies(strip-clang-format build-clang-format)
endif()
# Define an installation rule that copies the executable to our Python package
install(
PROGRAMS
${clang-format-executable}
DESTINATION clang_format/data/bin
)
install(
PROGRAMS
${CMAKE_BINARY_DIR}/llvm-project/clang/tools/clang-format/clang-format-diff.py
RENAME clang_format_diff.py
DESTINATION clang_format
)
install(
PROGRAMS
${CMAKE_BINARY_DIR}/llvm-project/clang/tools/clang-format/git-clang-format
RENAME git_clang_format.py
DESTINATION clang_format
)