[PATCH] D27386: build: add support for standalone lld build

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 3 15:02:54 PST 2016


I love the idea, so LGTM for the feature if someone more familiar with
CMake LGTM the changes.


Saleem Abdulrasool via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> compnerd created this revision.
> compnerd added reviewers: beanz, ruiu.
> compnerd added a subscriber: llvm-commits.
> compnerd set the repository for this revision to rL LLVM.
> compnerd added a project: lld.
> Herald added a subscriber: mgorny.
>
> Enable building lld as a standalone project.  This is motivated by the desire to package lld for inclusion in a linux distribution.  This allows building lld against an existing paired llvm installation.  Now that lld is usable on x86_64, it makes sense to revive this configuration to allow distributions to package it.
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D27386
>
> Files:
>   CMakeLists.txt
>   COFF/CMakeLists.txt
>   ELF/CMakeLists.txt
>
> Index: ELF/CMakeLists.txt
> ===================================================================
> --- ELF/CMakeLists.txt
> +++ ELF/CMakeLists.txt
> @@ -2,6 +2,10 @@
>  tablegen(LLVM Options.inc -gen-opt-parser-defs)
>  add_public_tablegen_target(ELFOptionsTableGen)
>  
> +if(NOT LLD_BUILT_STANDALONE)
> +  set(tablegen_deps intrinsics_gen)
> +endif()
> +
>  add_lld_library(lldELF
>    Driver.cpp
>    DriverUtils.cpp
> @@ -54,5 +58,5 @@
>  
>    DEPENDS
>    ELFOptionsTableGen
> -  intrinsics_gen
> +  ${tablegen_deps}
>    )
> Index: COFF/CMakeLists.txt
> ===================================================================
> --- COFF/CMakeLists.txt
> +++ COFF/CMakeLists.txt
> @@ -2,6 +2,10 @@
>  tablegen(LLVM Options.inc -gen-opt-parser-defs)
>  add_public_tablegen_target(COFFOptionsTableGen)
>  
> +if(NOT LLD_BUILT_STANDALONE)
> +  set(tablegen_deps intrinsics_gen)
> +endif()
> +
>  add_lld_library(lldCOFF
>    Chunks.cpp
>    DLL.cpp
> @@ -39,5 +43,5 @@
>  
>    DEPENDS
>    COFFOptionsTableGen
> -  intrinsics_gen
> +  ${tablegen_deps}
>    )
> Index: CMakeLists.txt
> ===================================================================
> --- CMakeLists.txt
> +++ CMakeLists.txt
> @@ -1,3 +1,62 @@
> +# Check if lld is built as a standalone project.
> +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
> +  project(lld)
> +  cmake_minimum_required(VERSION 3.4.3)
> +
> +  if(NOT LLVM_CONFIG_PATH)
> +    find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary")
> +    if(NOT LLVM_CONFIG_PATH)
> +      message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH")
> +    endif()
> +  endif()
> +
> +  execute_process(COMMAND "${LLVM_CONFIG_PATH}" "--obj-root" "--bindir" "--src-root" "--includedir" "--libdir"
> +                  RESULT_VARIABLE HAD_ERROR
> +                  OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT
> +                  OUTPUT_STRIP_TRAILING_WHITESPACE)
> +  if(HAD_ERROR)
> +    message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
> +  endif()
> +
> +  string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" LLVM_CONFIG_OUTPUT ${LLVM_CONFIG_OUTPUT})
> +  list(GET LLVM_CONFIG_OUTPUT 0 OBJ_ROOT)
> +  list(GET LLVM_CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
> +  list(GET LLVM_CONFIG_OUTPUT 2 MAIN_SRC_DIR)
> +  list(GET LLVM_CONFIG_OUTPUT 3 MAIN_INCLUDE_DIR)
> +  list(GET LLVM_CONFIG_OUTPUT 4 LIBRARY_DIR)
> +
> +  set(LLVM_OBJ_ROOT ${OBJ_ROOT} CACHE PATH "path to LLVM build tree")
> +  set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "path to LLVM tools")
> +  set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "path to LLVM source tree")
> +  set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "path to LLVM includes")
> +  set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "path to LLVM libraries")
> +
> +  find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
> +
> +  file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR)
> +  set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
> +
> +  if(NOT EXISTS "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
> +    message(FATAL_ERROR "LLVMConfig.cmake not found")
> +  endif()
> +  include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
> +
> +  set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
> +
> +  list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
> +
> +  include(AddLLVM)
> +  include(TableGen)
> +
> +  set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
> +
> +  set(CMAKE_INCLUDE_CURRENT_DIR ON)
> +  include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
> +  link_directories("${LLVM_LIBRARY_DIR}")
> +
> +  set(LLD_BUILT_STANDALONE TRUE)
> +endif()
> +
>  set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
>  set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
>  set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list