# A full-featured bootstrapped build of LLVM, Clang and friends for FNAL.

set(PACKAGE_VENDOR FNAL CACHE STRING "")

set(LLVM_ENABLE_PROJECTS
  "clang;clang-tools-extra;libclc;lld;llgo;openmp;polly"
  CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "all" CACHE STRING "")

set(LLVM_TARGETS_TO_BUILD "X86;ARM;AArch64;AMDGPU;NVPTX;BPF;PowerPC"
  CACHE STRING "")

set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "--rtlib=compiler-rt -O3 -gline-tables-only -DNDEBUG"
  CACHE STRING "")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "--stdlib=libc++ --rtlib=compiler-rt -O3 -gline-tables-only -DNDEBUG"
  CACHE STRING "")

# setup toolchain
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
set(LLVM_TOOLCHAIN_TOOLS
  dsymutil
  llvm-cov
  llvm-cxxfilt
  llvm-dwarfdump
  llvm-profdata
  llvm-objdump
  llvm-nm
  llvm-size
  CACHE STRING "")

if (APPLE)
  set(COMPILER_RT_ENABLE_IOS ON CACHE BOOL "Build iOS Compiler-RT libraries")
  set(LLVM_CREATE_XCODE_TOOLCHAIN ON CACHE BOOL
    "Generate targets to create and install an Xcode compatible toolchain")
  set(LLVM_EXTERNALIZE_DEBUGINFO OFF CACHE BOOL "External debuginfo files")
endif()

set(CMAKE_C_FLAGS
  "-fno-stack-protector -fno-common -Wno-profile-instr-unprofiled"
  CACHE STRING "")
set(CMAKE_CXX_FLAGS
  "-fno-stack-protector -fno-common -Wno-profile-instr-unprofiled"
  CACHE STRING "")

set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LINK_POLLY_INTO_TOOLS ON CACHE BOOL "")
set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
set(LLVM_ENABLE_FFI ON CACHE BOOL "")
set(LLVM_ENABLE_LTO Full CACHE STRING "")
set(LLVM_ENABLE_MODULES ON CACHE BOOL "")
set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
set(LLVM_LINK_LLVM_DYLIB ON CACHE BOOL "")
set(WITH_POLLY ON CACHE BOOL "")
