brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.2 KiB · 25f7970 Raw
178 lines · plain
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 8function (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()14endfunction()15 16function (set_instrument_and_final_stage_var name value type)17  # This sets the varaible for the final stage in non-PGO builds and in18  # 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()24endfunction()25 26# General Options:27# If you want to override any of the LLVM_RELEASE_* variables you can set them28# on the command line via -D, but you need to do this before you pass this29# cache file to CMake via -C. e.g.30#31# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake32 33set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir")34# bolt only supports ELF, so only enable it for Linux.35if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")36  list(APPEND DEFAULT_PROJECTS "bolt")37endif()38 39# Don't build flang on Darwin due to:40# https://github.com/llvm/llvm-project/issues/16054641if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")42  list(APPEND DEFAULT_PROJECTS "flang")43endif()44 45set (DEFAULT_RUNTIMES "compiler-rt;libcxx")46if (NOT WIN32)47  list(APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind")48endif()49set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")50set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")51set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")52set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")53 54# This option enables linking stage2 clang statically with the runtimes55# (libc++ and compiler-rt) from stage1.  In theory this will give the56# binaries better performance and make them more portable.  However,57# this configuration is not well tested and causes build failures with58# the flang-rt tests cases, since the -stclib=libc++ flag does not59# get propagated to the runtimes build.  There is also a separate60# issue on Darwin where clang will use the local libc++ headers, but61# link with system libc++ which can cause some incompatibilities.62# See https://github.com/llvm/llvm-project/issues/7765363# Because of these problems, this option will default to OFF.64set(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES OFF CACHE BOOL "")65 66# Note we don't need to add install here, since it is one of the pre-defined67# steps.68set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")69set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")70 71# Stage 1 Options72set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")73set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")74 75set(STAGE1_PROJECTS "clang")76 77# Need to build compiler-rt in order to use PGO for later stages.78set(STAGE1_RUNTIMES "compiler-rt")79# Build all runtimes so we can statically link them into the stage2 compiler.80if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)81  list(APPEND STAGE1_RUNTIMES "libcxx;libcxxabi;libunwind")82endif()83 84if (LLVM_RELEASE_ENABLE_PGO)85  list(APPEND STAGE1_PROJECTS "lld")86  set(tmp_targets87    generate-profdata88    stage2-package89    stage2-clang90    stage291    stage2-install92    stage2-check-all93    stage2-check-llvm94    stage2-check-clang)95 96  foreach(X IN LISTS LLVM_RELEASE_FINAL_STAGE_TARGETS)97    list(APPEND tmp_targets "stage2-${X}")98  endforeach()99  list(REMOVE_DUPLICATES tmp_targets)100 101  set(CLANG_BOOTSTRAP_TARGETS "${tmp_targets}" CACHE STRING "")102 103  # Configuration for stage2-instrumented104  set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")105  # This enables the build targets for the final stage which is called stage2.106  set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")107  set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE STRING "")108  set(BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt" CACHE STRING "")109  set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")110 111else()112  if (LLVM_RELEASE_ENABLE_LTO)113    list(APPEND STAGE1_PROJECTS "lld")114  endif()115  # Any targets added here will be given the target name stage2-${target}, so116  # if you want to run them you can just use:117  # ninja -C $BUILDDIR stage2-${target}118  set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")119endif()120 121if (LLVM_RELEASE_ENABLE_LTO)122  # Enable LTO for the runtimes.  We need to configure stage1 clang to default123  # to using lld as the linker because the stage1 toolchain will be used to124  # build and link the runtimes.125  # FIXME: We can't use LLVM_ENABLE_LTO=Thin here, because it causes the CMake126  # step for the libcxx build to fail.  CMAKE_INTERPROCEDURAL_OPTIMIZATION does127  # enable ThinLTO, though.128  set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_FATLTO=ON" CACHE STRING "")129endif()130 131# Stage 1 Common Config132set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "")133set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")134set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "")135 136# stage2-instrumented and Final Stage Config:137# Options that need to be set in both the instrumented stage (if we are doing138# a pgo build) and the final stage.139set_instrument_and_final_stage_var(CMAKE_POSITION_INDEPENDENT_CODE "ON" STRING)140set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}" STRING)141if (LLVM_RELEASE_ENABLE_LTO)142  set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)143endif()144if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)145  set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)146  set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)147  set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")148  if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")149    set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")150  endif()151endif()152 153# Set flags for bolt154if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")155  set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")156endif()157 158if (RELEASE_LINKER_FLAGS)159  set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)160  set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)161  set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)162endif()163 164# Final Stage Config (stage2)165set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)166set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS}" STRING)167if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")168  set_final_stage_var(CLANG_BOLT "INSTRUMENT" STRING)169endif()170set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)171set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)172 173set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)174if (LLVM_RELEASE_ENABLE_LTO)175  set_final_stage_var(LLVM_ENABLE_FATLTO "ON" BOOL)176  set_final_stage_var(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/release_cpack_pre_build_strip_lto.cmake" STRING)177endif()178