forked from OSchip/llvm-project
[clang][cmake] Rearrange top-level CMakeLists.txt for D116492
In that revision, I make LLD match Clang in deprecating `llvm-config`. This patch isn't to worthwhile on its own --- there isn't a sense in which the new order is "better" in isolation --- but by putting the steps that LLD also neeeds to do first, I make the diff between LLD and Clang's top-level `CMakeLists.txt` very legible. Longer term I hope: 1. We can remove calling `llvm-config` altogether, and just go strait to finding the CMake config file. This is what Flang does, at least. 2. Hopefully the diffable part is smaller then --- i.e. there is less duplicated boilerplate. 3. Any duplicate boilerplate that remains can be factored out. I didn't both trying to factor anything out in e.g. the top level common CMake Utility modules because this deprecated-but-not-removed state is a merely transitional. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D116548
This commit is contained in:
parent
a44ef999fb
commit
a3ab2c94a2
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13.4)
|
|||
|
||||
# If we are not building as a part of LLVM, build Clang as an
|
||||
# standalone project, using LLVM as an external library:
|
||||
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
project(Clang)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
|
||||
|
@ -10,7 +10,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|||
set(CMAKE_CXX_EXTENSIONS NO)
|
||||
|
||||
# Rely on llvm-config.
|
||||
set(CONFIG_OUTPUT)
|
||||
set(LLVM_CONFIG_OUTPUT)
|
||||
if(LLVM_CONFIG)
|
||||
set (LLVM_CONFIG_FOUND 1)
|
||||
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
||||
|
@ -20,35 +20,36 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|||
automatically, but you can also use LLVM_DIR to specify \
|
||||
the path containing LLVMConfig.cmake.")
|
||||
set(CONFIG_COMMAND ${LLVM_CONFIG}
|
||||
"--assertion-mode"
|
||||
"--bindir"
|
||||
"--libdir"
|
||||
"--includedir"
|
||||
"--prefix"
|
||||
"--src-root"
|
||||
"--cmakedir")
|
||||
"--cmakedir"
|
||||
"--bindir"
|
||||
"--libdir"
|
||||
"--assertion-mode"
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CONFIG_COMMAND}
|
||||
RESULT_VARIABLE HAD_ERROR
|
||||
OUTPUT_VARIABLE CONFIG_OUTPUT
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT
|
||||
)
|
||||
if(NOT HAD_ERROR)
|
||||
string(REGEX REPLACE
|
||||
"[ \t]*[\r\n]+[ \t]*" ";"
|
||||
CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
||||
LLVM_CONFIG_OUTPUT ${LLVM_CONFIG_OUTPUT})
|
||||
else()
|
||||
string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
|
||||
message(STATUS "${CONFIG_COMMAND_STR}")
|
||||
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
||||
endif()
|
||||
|
||||
list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
|
||||
list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
|
||||
list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
|
||||
list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
|
||||
list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
|
||||
list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
|
||||
list(GET CONFIG_OUTPUT 6 LLVM_CONFIG_CMAKE_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 0 MAIN_INCLUDE_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
|
||||
list(GET LLVM_CONFIG_OUTPUT 2 MAIN_SRC_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 3 LLVM_CONFIG_CMAKE_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 4 TOOLS_BINARY_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 5 LIBRARY_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 6 ENABLE_ASSERTIONS)
|
||||
|
||||
# Normalize LLVM_CMAKE_DIR. --cmakedir might contain backslashes.
|
||||
# CMake assumes slashes as PATH.
|
||||
|
@ -71,17 +72,17 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|||
if (NOT LLVM_CONFIG_FOUND)
|
||||
# Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
|
||||
# path is removed.
|
||||
set(MAIN_INCLUDE_DIR ${LLVM_INCLUDE_DIR})
|
||||
set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
|
||||
set(TOOLS_BINARY_DIR ${LLVM_TOOLS_BINARY_DIR})
|
||||
set(LIBRARY_DIR ${LLVM_LIBRARY_DIR})
|
||||
set(INCLUDE_DIR ${LLVM_INCLUDE_DIR})
|
||||
set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
|
||||
set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
|
||||
set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
|
||||
set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
|
||||
set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
|
||||
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
||||
set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
|
||||
set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
|
||||
|
||||
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
||||
NO_DEFAULT_PATH)
|
||||
|
@ -184,11 +185,12 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|||
endif()
|
||||
endif()
|
||||
|
||||
set( CLANG_BUILT_STANDALONE 1 )
|
||||
set(CLANG_BUILT_STANDALONE TRUE)
|
||||
|
||||
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
else()
|
||||
set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
|
||||
endif()
|
||||
endif() # standalone
|
||||
|
||||
# Make sure that our source directory is on the current cmake module path so that
|
||||
# we can include cmake files from this directory.
|
||||
|
|
Loading…
Reference in New Issue