Debian Codegraph @

clang/cmake/caches/Release.cmake

raw
1 # Plain options configure the first build.
2 # BOOTSTRAP_* options configure the second build.
3 # BOOTSTRAP_BOOTSTRAP_* options configure the third build.
4 # PGO Builds have 3 stages (stage1, stage2-instrumented, stage2)
5 # non-PGO Builds have 2 stages (stage1, stage2)
6
7
8 function (set_final_stage_var name value type)
9 if (LLVM_RELEASE_ENABLE_PGO)
10 set(BOOTSTRAP_BOOTSTRAP_${name} ${value} CACHE ${type} "")
11 else()
12 set(BOOTSTRAP_${name} ${value} CACHE ${type} "")
13 endif()
14 endfunction()
15
16 function (set_instrument_and_final_stage_var name value type)
17 # This sets the varaible for the final stage in non-PGO builds and in
18 # the stage2-instrumented stage for PGO builds.
19 set(BOOTSTRAP_${name} ${value} CACHE ${type} "")
20 if (LLVM_RELEASE_ENABLE_PGO)
21 # Set the variable in the final stage for PGO builds.
22 set(BOOTSTRAP_BOOTSTRAP_${name} ${value} CACHE ${type} "")
23 endif()
24 endfunction()
25
26 # General Options:
27 # If you want to override any of the LLVM_RELEASE_* variables you can set them
28 # on the command line via -D, but you need to do this before you pass this
29 # cache file to CMake via -C. e.g.
30 #
31 # cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake
32
33 set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir")
34 # bolt only supports ELF, so only enable it for Linux.
35 if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
36 list(APPEND DEFAULT_PROJECTS "bolt")
37 endif()
38
39 set (DEFAULT_RUNTIMES "compiler-rt;libcxx;openmp")
40 # Don't build flang on Darwin due to:
41 # https://github.com/llvm/llvm-project/issues/160546
42 if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
43 list(APPEND DEFAULT_PROJECTS "flang")
44 list(APPEND DEFAULT_RUNTIMES "flang-rt")
45 endif()
46
47 if (NOT WIN32)
48 list(APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind")
49 endif()
50 set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
51 set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
52 set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
53 set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
54
55 # This option enables linking stage2 clang statically with the runtimes
56 # (libc++ and compiler-rt) from stage1. In theory this will give the
57 # binaries better performance and make them more portable. However,
58 # this configuration is not well tested and causes build failures with
59 # the flang-rt tests cases, since the -stclib=libc++ flag does not
60 # get propagated to the runtimes build. There is also a separate
61 # issue on Darwin where clang will use the local libc++ headers, but
62 # link with system libc++ which can cause some incompatibilities.
63 # See https://github.com/llvm/llvm-project/issues/77653
64 # Because of these problems, this option will default to OFF.
65 set(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES OFF CACHE BOOL "")
66
67 # Note we don't need to add install here, since it is one of the pre-defined
68 # steps.
69 set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
70 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
71
72 # Stage 1 Options
73 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
74 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
75
76 set(STAGE1_PROJECTS "clang")
77
78 # Need to build compiler-rt in order to use PGO for later stages.
79 set(STAGE1_RUNTIMES "compiler-rt")
80 # Build all runtimes so we can statically link them into the stage2 compiler.
81 if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
82 list(APPEND STAGE1_RUNTIMES "libcxx;libcxxabi;libunwind")
83 endif()
84
85 if (LLVM_RELEASE_ENABLE_PGO)
86 list(APPEND STAGE1_PROJECTS "lld")
87 set(tmp_targets
88 generate-profdata
89 stage2-package
90 stage2-clang
91 stage2
92 stage2-install
93 stage2-check-all
94 stage2-check-llvm
95 stage2-check-clang)
96
97 foreach(X IN LISTS LLVM_RELEASE_FINAL_STAGE_TARGETS)
98 list(APPEND tmp_targets "stage2-${X}")
99 endforeach()
100 list(REMOVE_DUPLICATES tmp_targets)
101
102 set(CLANG_BOOTSTRAP_TARGETS "${tmp_targets}" CACHE STRING "")
103
104 # Configuration for stage2-instrumented
105 set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")
106 # This enables the build targets for the final stage which is called stage2.
107 set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")
108 set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE STRING "")
109 set(BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt" CACHE STRING "")
110 set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
111
112 else()
113 if (LLVM_RELEASE_ENABLE_LTO)
114 list(APPEND STAGE1_PROJECTS "lld")
115 endif()
116 # Any targets added here will be given the target name stage2-${target}, so
117 # if you want to run them you can just use:
118 # ninja -C $BUILDDIR stage2-${target}
119 set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")
120 endif()
121
122 if (LLVM_RELEASE_ENABLE_LTO)
123 # Enable LTO for the runtimes. We need to configure stage1 clang to default
124 # to using lld as the linker because the stage1 toolchain will be used to
125 # build and link the runtimes.
126 # FIXME: We can't use LLVM_ENABLE_LTO=Thin here, because it causes the CMake
127 # step for the libcxx build to fail. CMAKE_INTERPROCEDURAL_OPTIMIZATION does
128 # enable ThinLTO, though.
129 set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_FATLTO=ON" CACHE STRING "")
130 endif()
131
132 # Stage 1 Common Config
133 set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "")
134 set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")
135 set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "")
136
137 # stage2-instrumented and Final Stage Config:
138 # Options that need to be set in both the instrumented stage (if we are doing
139 # a pgo build) and the final stage.
140 set_instrument_and_final_stage_var(CMAKE_POSITION_INDEPENDENT_CODE "ON" STRING)
141 set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}" STRING)
142 if (LLVM_RELEASE_ENABLE_LTO)
143 set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)
144 endif()
145 if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
146 set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
147 set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
148 set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")
149 if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
150 set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
151 endif()
152 endif()
153
154 # Set flags for bolt
155 if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
156 set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")
157 endif()
158
159 if (RELEASE_LINKER_FLAGS)
160 set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
161 set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
162 set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
163 endif()
164
165 # Final Stage Config (stage2)
166 set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)
167 set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS}" STRING)
168 if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
169 set_final_stage_var(CLANG_BOLT "INSTRUMENT" STRING)
170 endif()
171 set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
172 set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)
173
174 set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
175 if (LLVM_RELEASE_ENABLE_LTO)
176 set_final_stage_var(LLVM_ENABLE_FATLTO "ON" BOOL)
177 set_final_stage_var(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/release_cpack_pre_build_strip_lto.cmake" STRING)
178 endif()