
Summary: This patch contains the following changes: 1. Require that libc++ can find a LLVM source directory. This is done the same way as `libc++abi` currently does. 2. Cleanup ugly configuration code in CMakeLists.txt by using `add_flags`, `add_flags_if`, and `add_flags_if_supported` macros. The goals for this patch are: 1. Help libc++ be more consistent with how LLVM handles CMake options (see PR23670 PR23671). 2. Make it easier to use sanitizers using the `LLVM_USE_SANITIZER` option. 3. Make libc++'s CMakeLists.txt file easier to understand and change. 4. Move towards allowing libc++ to create Sphinx documentation (see http://efcs.ca/libcxx-docs). 5. Move towards allowing libc++ to use other LLVM utilities such as `not` and `FileCheck`. Reviewers: mclow.lists, jroelofs, danalbert Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11308 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@243503 91177308-0d34-0410-b5e6-96231b3b80d8
80 lines
2.8 KiB
CMake
80 lines
2.8 KiB
CMake
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
# Rely on llvm-config.
|
|
set(CONFIG_OUTPUT)
|
|
find_program(LLVM_CONFIG "llvm-config")
|
|
if(DEFINED LLVM_PATH)
|
|
set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
|
|
set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
|
|
set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
|
|
set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
|
|
elseif(LLVM_CONFIG)
|
|
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
|
set(CONFIG_COMMAND ${LLVM_CONFIG}
|
|
"--includedir"
|
|
"--prefix"
|
|
"--src-root")
|
|
execute_process(
|
|
COMMAND ${CONFIG_COMMAND}
|
|
RESULT_VARIABLE HAD_ERROR
|
|
OUTPUT_VARIABLE CONFIG_OUTPUT
|
|
)
|
|
if(NOT HAD_ERROR)
|
|
string(REGEX REPLACE
|
|
"[ \t]*[\r\n]+[ \t]*" ";"
|
|
CONFIG_OUTPUT ${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 INCLUDE_DIR)
|
|
list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
|
|
list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR)
|
|
|
|
set(LLVM_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")
|
|
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake")
|
|
else()
|
|
message(FATAL_ERROR "llvm-config not found and LLVM_MAIN_SRC_DIR not defined. "
|
|
"Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
|
|
"or -DLLVM_PATH=path/to/llvm-source-root.")
|
|
endif()
|
|
|
|
if (NOT EXISTS ${LLVM_MAIN_SRC_DIR})
|
|
message(FATAL_ERROR "Not found: ${LLVM_MAIN_SRC_DIR}")
|
|
endif()
|
|
|
|
if(NOT EXISTS ${LLVM_CMAKE_PATH})
|
|
message(FATAL_ERROR "Not found: ${LLVM_CMAKE_PATH}")
|
|
endif()
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
|
|
|
|
|
|
if(LLVM_LIT)
|
|
# Define the default arguments to use with 'lit', and an option for the user
|
|
# to override.
|
|
set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
|
|
if (MSVC OR XCODE)
|
|
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
|
endif()
|
|
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
|
|
|
# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
|
|
if( WIN32 AND NOT CYGWIN )
|
|
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
|
|
endif()
|
|
else()
|
|
set(LLVM_INCLUDE_TESTS OFF)
|
|
endif()
|
|
|
|
set(LIBCXX_BUILT_STANDALONE 1)
|
|
else()
|
|
set(LLVM_MAIN_SRC_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "Path to LLVM source tree")
|
|
set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
|
|
endif()
|