-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrepareClangHeaders.cmake
81 lines (67 loc) · 2.6 KB
/
PrepareClangHeaders.cmake
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
include(ProcessorCount)
set(build_dir ${CMAKE_CURRENT_SOURCE_DIR}/headers-clang)
list(APPEND llvm_versions
19.1.0-rc2
18.1.8
17.0.6
16.0.6
15.0.7
14.0.6
# 13.0.1
# 12.0.1
# 11.1.0
# 10.0.1
)
foreach (version IN LISTS llvm_versions)
string(REGEX MATCH "^([0-9]+)\\." major_version_match ${version})
set(major_version ${CMAKE_MATCH_1})
set(archive "${build_dir}/llvm-project-${version}.src.tar.xz")
set(source "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/llvm-project-${version}.src.tar.xz")
if (NOT EXISTS "${archive}")
message(STATUS "Downloading LLVM ${major_version}: ${source} -> ${archive}")
file(DOWNLOAD
"${source}"
"${archive}"
SHOW_PROGRESS
)
file(ARCHIVE_EXTRACT INPUT "${archive}" DESTINATION "${build_dir}")
else ()
message(STATUS "Using cached LLVM ${major_version} archive: ${archive}")
endif ()
execute_process(
COMMAND ${CMAKE_COMMAND}
-S "${build_dir}/llvm-project-${version}.src/llvm"
-B "${build_dir}/build/llvm-${major_version}-build"
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=OFF
-DLLVM_ENABLE_PROJECTS=clang
-DLLVM_INCLUDE_BENCHMARKS=OFF
-DLLVM_INCLUDE_TESTS=OFF
-DLLVM_INCLUDE_DOCS=OFF
-DLLVM_INCLUDE_EXAMPLES=OFF
-DLLVM_BUILD_TESTS=OFF
-DLLVM_BUILD_DOCS=OFF
-DLLVM_BUILD_EXAMPLES=OFF
"-DLLVM_TARGETS_TO_BUILD=X86\;AArch64" # not really important, just include the host platforms
"-DCMAKE_INSTALL_PREFIX=${build_dir}/llvm-${major_version}"
WORKING_DIRECTORY ${build_dir}
RESULT_VARIABLE result)
if (NOT result EQUAL "0")
message(FATAL_ERROR "LLVM ${major_version} configure did not succeed")
else ()
message(STATUS "LLVM ${major_version} configuration complete, starting include targets")
endif ()
ProcessorCount(nproc)
execute_process(
COMMAND ${CMAKE_COMMAND}
--build "${build_dir}/build/llvm-${major_version}-build"
--target install-llvm-headers install-clang-headers
-- -j ${nproc}
WORKING_DIRECTORY ${build_dir}
RESULT_VARIABLE result)
if (NOT result EQUAL "0")
message(FATAL_ERROR "LLVM ${major_version} header build did not succeed")
else ()
message(STATUS "LLVM ${major_version} header complete")
endif ()
endforeach ()