r346732 - CMake: Deprecate using llvm-config to detect llvm installation
Tom Stellard via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 12 19:42:46 PST 2018
Author: tstellar
Date: Mon Nov 12 19:42:46 2018
New Revision: 346732
URL: http://llvm.org/viewvc/llvm-project?rev=346732&view=rev
Log:
CMake: Deprecate using llvm-config to detect llvm installation
Summary:
clang currently uses llvm-config to determine the installation paths
for llvm's headers and binaries. clang is also using LLVM's cmake
files to determine other information about the LLVM build, like
LLVM_LIBDIR_SUFFIX, LLVM_VERSION_*, etc. Since the installation
paths are also available via the cmake files, we can simplify the code
by only relying on information from cmake about the LLVM install and
dropping the use of llvm-config altogether.
In addition to simplifying the code, the cmake files have more
accurate information about the llvm installation paths. llvm-config
assumes that the lib, bin, and cmake directories are always located
in the same place relative to the path of the llvm-config executable.
This can be wrong if a user decides to install headers, binaries
or libraries to a non-standard location: e.g. static libraries
installed to /usr/lib/llvm6.0/
This patch takes the first step towards dropping llvm-config by
removing the automatic detection of llvm-config (users can still
manually supply a path to llvm-config by passing
-DLLVM_CONFIG=/usr/bin/llvm-config to cmake) and adding a
deprecation warning when users try to use this option.
Reviewers: chandlerc, beanz, mgorny, chapuni
Subscribers: mehdi_amini, dexonsmith, cfe-commits
Differential Revision: https://reviews.llvm.org/D51714
Modified:
cfe/trunk/CMakeLists.txt
Modified: cfe/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=346732&r1=346731&r2=346732&view=diff
==============================================================================
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Mon Nov 12 19:42:46 2018
@@ -11,9 +11,14 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
# Rely on llvm-config.
set(CONFIG_OUTPUT)
- find_program(LLVM_CONFIG "llvm-config")
if(LLVM_CONFIG)
+ set (LLVM_CONFIG_FOUND 1)
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
+ message(DEPRECATION "Using llvm-config to detect the LLVM installation is \
+ deprecated. The installed cmake files should be used \
+ instead. CMake should be able to detect your LLVM install \
+ automatically, but you can also use LLVM_DIR to specify \
+ the path containing LLVMConfig.cmake.")
set(CONFIG_COMMAND ${LLVM_CONFIG}
"--assertion-mode"
"--bindir"
@@ -36,17 +41,20 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
message(STATUS "${CONFIG_COMMAND_STR}")
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
endif()
- else()
- message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}")
+
+ 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_PATH)
+
+ # Normalize LLVM_CMAKE_PATH. --cmakedir might contain backslashes.
+ # CMake assumes slashes as PATH.
+ file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_PATH} LLVM_CMAKE_PATH)
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_PATH)
if(NOT MSVC_IDE)
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
@@ -55,22 +63,29 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
endif()
+ find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")
+ list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
+
+ # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets
+ # LLVM_CONFIG.
+ if (NOT LLVM_CONFIG_FOUND)
+ # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
+ # path is removed.
+ 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_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")
- # Normalize LLVM_CMAKE_PATH. --cmakedir might contain backslashes.
- # CMake assumes slashes as PATH.
- file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_PATH} LLVM_CMAKE_PATH)
-
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
- find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")
- list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
-
# They are used as destination of target generators.
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
More information about the cfe-commits
mailing list