-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
51 lines (46 loc) · 1.85 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
project(clang-tidy-wheel)
cmake_minimum_required(VERSION 3.16)
# Include the "single source of truth" for the clang-tidy version
include(clang-tidy_version.cmake)
string(REPLACE "-" "" CLANG_TIDY_VERSION_SHORT "${CLANG_TIDY_VERSION}")
string(REPLACE "." ";" CLANG_TIDY_VERSION_LIST ${CLANG_TIDY_VERSION})
list(GET CLANG_TIDY_VERSION_LIST 0 CLANG_TIDY_VERSION_MAJOR)
# Define a build rule clang-tidy
set(LLVM_DOWNLOAD_URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_TIDY_VERSION}/llvm-project-${CLANG_TIDY_VERSION_SHORT}.src.tar.xz")
include(ExternalProject)
ExternalProject_add(build-clang-tidy
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_ZSTD=OFF -DLLVM_ENABLE_PROJECTS=clang$<SEMICOLON>clang-tools-extra
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target clang-tidy
)
set(clang-tidy-executable ${CMAKE_BINARY_DIR}/llvm/bin/clang-tidy${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-tidy
ALL
COMMAND ${STRIP_EXECUTABLE} ${clang-tidy-executable}
COMMENT "Stripping clang-tidy executable for size reduction"
)
add_dependencies(strip-clang-tidy build-clang-tidy)
endif()
# Define an installation rule that copies the executable to our Python package
install(
PROGRAMS
${clang-tidy-executable}
DESTINATION clang_tidy/data/bin
)
install(
DIRECTORY
${CMAKE_BINARY_DIR}/llvm/lib/clang/${CLANG_TIDY_VERSION_MAJOR}/include
DESTINATION clang_tidy/data/lib/clang/${CLANG_TIDY_VERSION_MAJOR}
)