forked from OSchip/llvm-project
[CMake][Standalone] Rewrite standalone build based on llvm-config. CLANG_PATH_TO_LLVM_*(s) are deprecated.
Checked on VS10(multiconfig) and some singleconfig builders. * Assumptions - You should specify llvm-config as LLVM_CONFIG. CMake could find one in $PATH by default. - ENABLE_ASSERTIONS obeys LLVM's. * Use cases a) With LLVM build tree Assume llvm-config is in your build tree. Everything should work as ever. b) With *installed* LLVM Assume distributions. The source tree can be optional. b1) The source tree is provided on the location `llvm-config --src-root` - Test utils, FileCheck &c., are imported and built in the new tree. - Gtest is built in the tree if gtest library is not found. - Lit is used in $(SRCROOT)/utils/lit/lit.py. b2) The source tree is not provided - clang and utilities can be built. - All tests, unittests and check-clang are invalidated and not built. llvm-svn: 197697
This commit is contained in:
parent
8e918c3c4d
commit
e6d79ec0eb
|
@ -4,62 +4,112 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
||||||
project(Clang)
|
project(Clang)
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
set(CLANG_PATH_TO_LLVM_SOURCE "" CACHE PATH
|
# Rely on llvm-config.
|
||||||
"Path to LLVM source code. Not necessary if using an installed LLVM.")
|
set(CONFIG_OUTPUT)
|
||||||
set(CLANG_PATH_TO_LLVM_BUILD "" CACHE PATH
|
find_program(LLVM_CONFIG "llvm-config")
|
||||||
"Path to the directory where LLVM was built or installed.")
|
if(LLVM_CONFIG)
|
||||||
|
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
||||||
if( CLANG_PATH_TO_LLVM_SOURCE )
|
execute_process(
|
||||||
if( NOT EXISTS "${CLANG_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake" )
|
COMMAND ${LLVM_CONFIG}
|
||||||
message(FATAL_ERROR "Please set CLANG_PATH_TO_LLVM_SOURCE to the root directory of LLVM source code.")
|
"--assertion-mode"
|
||||||
|
"--bindir"
|
||||||
|
"--libdir"
|
||||||
|
"--includedir"
|
||||||
|
"--prefix"
|
||||||
|
"--src-root"
|
||||||
|
OUTPUT_VARIABLE CONFIG_OUTPUT
|
||||||
|
)
|
||||||
|
string(REGEX REPLACE
|
||||||
|
"[ \t]*[\r\n]+[ \t]*" ";"
|
||||||
|
CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
||||||
else()
|
else()
|
||||||
get_filename_component(LLVM_MAIN_SRC_DIR ${CLANG_PATH_TO_LLVM_SOURCE}
|
message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}")
|
||||||
ABSOLUTE)
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (EXISTS "${CLANG_PATH_TO_LLVM_BUILD}/bin/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
|
||||||
set (PATH_TO_LLVM_CONFIG "${CLANG_PATH_TO_LLVM_BUILD}/bin/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
|
||||||
elseif (EXISTS "${CLANG_PATH_TO_LLVM_BUILD}/bin/Debug/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
|
||||||
# Looking for bin/Debug/llvm-config is a complete hack. How can we get
|
list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
|
||||||
# around this?
|
list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
|
||||||
set (PATH_TO_LLVM_CONFIG "${CLANG_PATH_TO_LLVM_BUILD}/bin/Debug/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
|
||||||
|
|
||||||
|
if(NOT MSVC_IDE)
|
||||||
|
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
|
||||||
|
CACHE BOOL "Enable assertions")
|
||||||
|
# Assertions should follow llvm-config's.
|
||||||
|
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
|
||||||
|
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")
|
||||||
|
|
||||||
|
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR})
|
||||||
|
|
||||||
|
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake")
|
||||||
|
set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
|
||||||
|
if(EXISTS ${LLVMCONFIG_FILE})
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
|
||||||
|
include(${LLVMCONFIG_FILE})
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Please set CLANG_PATH_TO_LLVM_BUILD to a directory containing a LLVM build.")
|
message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CLANG_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
|
||||||
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
|
||||||
get_filename_component(PATH_TO_LLVM_BUILD ${CLANG_PATH_TO_LLVM_BUILD}
|
|
||||||
ABSOLUTE)
|
|
||||||
|
|
||||||
set(LLVM_RUNTIME_OUTPUT_INTDIR ${PATH_TO_LLVM_BUILD}/bin/${CMAKE_CFG_INTDIR})
|
|
||||||
set(LLVM_LIBRARY_OUTPUT_INTDIR ${PATH_TO_LLVM_BUILD}/lib/${CMAKE_CFG_INTDIR})
|
|
||||||
|
|
||||||
option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
|
option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
|
||||||
|
|
||||||
include(AddLLVM)
|
include(AddLLVM)
|
||||||
include(TableGen)
|
include(TableGen)
|
||||||
include("${CLANG_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
|
|
||||||
include(HandleLLVMOptions)
|
include(HandleLLVMOptions)
|
||||||
|
|
||||||
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
||||||
|
|
||||||
set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
|
|
||||||
set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
|
|
||||||
|
|
||||||
if (NOT DEFINED LLVM_INCLUDE_TESTS)
|
if (NOT DEFINED LLVM_INCLUDE_TESTS)
|
||||||
set(LLVM_INCLUDE_TESTS ON)
|
set(LLVM_INCLUDE_TESTS ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
include_directories("${PATH_TO_LLVM_BUILD}/include" "${LLVM_MAIN_INCLUDE_DIR}")
|
include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
|
||||||
link_directories("${PATH_TO_LLVM_BUILD}/lib")
|
link_directories("${LLVM_LIBRARY_DIR}")
|
||||||
|
|
||||||
exec_program("${PATH_TO_LLVM_CONFIG} --bindir" OUTPUT_VARIABLE LLVM_TOOLS_BINARY_DIR)
|
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
|
||||||
set(LLVM_TABLEGEN_EXE "${LLVM_TOOLS_BINARY_DIR}/llvm-tblgen${CMAKE_EXECUTABLE_SUFFIX}")
|
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
|
||||||
|
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
|
||||||
|
|
||||||
|
if(LLVM_INCLUDE_TESTS)
|
||||||
|
# Check prebuilt llvm/utils.
|
||||||
|
if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
|
||||||
|
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
|
||||||
|
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
|
||||||
|
set(LLVM_UTILS_PROVIDED ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
||||||
|
set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
||||||
|
if(NOT LLVM_UTILS_PROVIDED)
|
||||||
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
|
||||||
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
|
||||||
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
|
||||||
|
set(LLVM_UTILS_PROVIDED ON)
|
||||||
|
set(CLANG_TEST_DEPS FileCheck count not)
|
||||||
|
endif()
|
||||||
|
set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
||||||
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
|
||||||
|
AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||||
|
AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
|
||||||
|
add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
# Seek installed Lit.
|
||||||
|
find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit
|
||||||
|
DOC "Path to lit.py")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(LLVM_LIT)
|
||||||
# Define the default arguments to use with 'lit', and an option for the user
|
# Define the default arguments to use with 'lit', and an option for the user
|
||||||
# to override.
|
# to override.
|
||||||
set(LIT_ARGS_DEFAULT "-sv")
|
set(LIT_ARGS_DEFAULT "-sv")
|
||||||
|
@ -72,10 +122,10 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
||||||
if( WIN32 AND NOT CYGWIN )
|
if( WIN32 AND NOT CYGWIN )
|
||||||
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
|
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
|
||||||
endif()
|
endif()
|
||||||
|
else()
|
||||||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
|
set(LLVM_INCLUDE_TESTS OFF)
|
||||||
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
|
endif()
|
||||||
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
|
endif()
|
||||||
|
|
||||||
set( CLANG_BUILT_STANDALONE 1 )
|
set( CLANG_BUILT_STANDALONE 1 )
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
# Test runner infrastructure for Clang. This configures the Clang test trees
|
# Test runner infrastructure for Clang. This configures the Clang test trees
|
||||||
# for use by Lit, and delegates to LLVM's lit test handlers.
|
# for use by Lit, and delegates to LLVM's lit test handlers.
|
||||||
#
|
|
||||||
# If this is a stand-alone Clang build, we fake up our own Lit support here
|
|
||||||
# rather than relying on LLVM's.
|
|
||||||
|
|
||||||
if (CMAKE_CFG_INTDIR STREQUAL ".")
|
if (CMAKE_CFG_INTDIR STREQUAL ".")
|
||||||
set(LLVM_BUILD_MODE ".")
|
set(LLVM_BUILD_MODE ".")
|
||||||
|
@ -43,51 +40,16 @@ if( NOT CLANG_BUILT_STANDALONE )
|
||||||
llvm-config
|
llvm-config
|
||||||
llc opt FileCheck count not llvm-symbolizer
|
llc opt FileCheck count not llvm-symbolizer
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_lit_testsuite(check-clang "Running the Clang regression tests"
|
add_lit_testsuite(check-clang "Running the Clang regression tests"
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
LIT ${LLVM_LIT}
|
||||||
PARAMS ${CLANG_TEST_PARAMS}
|
PARAMS ${CLANG_TEST_PARAMS}
|
||||||
DEPENDS ${CLANG_TEST_DEPS}
|
DEPENDS ${CLANG_TEST_DEPS}
|
||||||
ARGS ${CLANG_TEST_EXTRA_ARGS}
|
ARGS ${CLANG_TEST_EXTRA_ARGS}
|
||||||
)
|
)
|
||||||
set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
|
set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
|
||||||
|
|
||||||
else()
|
|
||||||
|
|
||||||
include(FindPythonInterp)
|
|
||||||
if(PYTHONINTERP_FOUND)
|
|
||||||
if( LLVM_MAIN_SRC_DIR )
|
|
||||||
set(LIT "${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py")
|
|
||||||
else()
|
|
||||||
set(LIT "${PATH_TO_LLVM_BUILD}/bin/${CMAKE_CFG_INTDIR}/llvm-lit")
|
|
||||||
# Installed LLVM does not contain ${CMAKE_CFG_INTDIR} in paths.
|
|
||||||
if( NOT EXISTS ${LIT} )
|
|
||||||
set(LIT "${PATH_TO_LLVM_BUILD}/bin/llvm-lit")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(LIT_ARGS "${CLANG_TEST_EXTRA_ARGS} ${LLVM_LIT_ARGS}")
|
|
||||||
separate_arguments(LIT_ARGS)
|
|
||||||
|
|
||||||
list(APPEND CLANG_TEST_PARAMS build_mode=${CMAKE_CFG_INTDIR})
|
|
||||||
|
|
||||||
foreach(param ${CLANG_TEST_PARAMS})
|
|
||||||
list(APPEND LIT_ARGS --param ${param})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
add_custom_target(check-clang
|
|
||||||
COMMAND ${PYTHON_EXECUTABLE}
|
|
||||||
${LIT}
|
|
||||||
${LIT_ARGS}
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
${CLANG_TEST_EXTRA_ARGS}
|
|
||||||
COMMENT "Running Clang regression tests"
|
|
||||||
DEPENDS ${CLANG_TEST_DEPS}
|
|
||||||
)
|
|
||||||
set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Add a legacy target spelling: clang-test
|
# Add a legacy target spelling: clang-test
|
||||||
add_custom_target(clang-test)
|
add_custom_target(clang-test)
|
||||||
|
|
Loading…
Reference in New Issue