Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -9,82 +9,34 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) project(Clang) - # Rely on llvm-config. - set(CONFIG_OUTPUT) - 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" - "--libdir" - "--includedir" - "--prefix" - "--src-root" - "--cmakedir") - 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 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() - - - 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() - - find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}") + find_package(LLVM REQUIRED CONFIG NO_CMAKE_FIND_ROOT_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() + if(CMAKE_CROSSCOMPILING) + set(LLVM_NATIVE_BUILD "${LLVM_BINARY_DIR}/NATIVE") + if(NOT EXISTS "${LLVM_NATIVE_BUILD}") + message(FATAL_ERROR + "Attempting to cross-compile Clang standalone but no native LLVM build + found. Please cross-compile LLVM as well.") + 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") + if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) + set(HOST_EXECUTABLE_SUFFIX ".exe") + endif() - find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} - NO_DEFAULT_PATH) + if(NOT CMAKE_CONFIGURATION_TYPES) + find_program(LLVM_TABLEGEN_EXE + "${LLVM_NATIVE_BUILD}/bin/llvm-tblgen${HOST_EXECUTABLE_SUFFIX}") + else() + # NOTE: LLVM NATIVE build is always built Release, as is specified in + # CrossCompile.cmake + find_program(LLVM_TABLEGEN_EXE + "${LLVM_NATIVE_BUILD_DIR}/Release/bin/llvm-tblgen${HOST_EXECUTABLE_SUFFIX}") + endif() + else() + find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} + NO_DEFAULT_PATH) + endif() # They are used as destination of target generators. set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) @@ -116,7 +68,7 @@ set(LLVM_INCLUDE_TESTS ON) endif() - include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") + include_directories("${LLVM_INCLUDE_DIRS}") link_directories("${LLVM_LIBRARY_DIR}") set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) @@ -144,20 +96,20 @@ set(LLVM_UTILS_PROVIDED ON) endif() - if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) + if(EXISTS ${LLVM_BUILD_MAIN_SRC_DIR}/utils/lit/lit.py) # Note: path not really used, except for checking if lit was found - set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) - if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit) - add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit) + set(LLVM_LIT ${LLVM_BUILD_MAIN_SRC_DIR}/utils/lit/lit.py) + if(EXISTS ${LLVM_BUILD_MAIN_SRC_DIR}/utils/llvm-lit) + add_subdirectory(${LLVM_BUILD_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit) endif() 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) + add_subdirectory(${LLVM_BUILD_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck) + add_subdirectory(${LLVM_BUILD_MAIN_SRC_DIR}/utils/count utils/count) + add_subdirectory(${LLVM_BUILD_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) + set(UNITTEST_DIR ${LLVM_BUILD_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) @@ -167,7 +119,7 @@ # Seek installed Lit. find_program(LLVM_LIT NAMES llvm-lit lit.py lit - PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit" + PATHS "${LLVM_BUILD_MAIN_SRC_DIR}/utils/lit" DOC "Path to lit.py") endif() @@ -507,7 +459,7 @@ if( CLANG_INCLUDE_TESTS ) - if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) + if(EXISTS ${LLVM_BUILD_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) add_subdirectory(unittests) list(APPEND CLANG_TEST_DEPS ClangUnitTests) list(APPEND CLANG_TEST_PARAMS Index: lib/Basic/CMakeLists.txt =================================================================== --- lib/Basic/CMakeLists.txt +++ lib/Basic/CMakeLists.txt @@ -4,7 +4,7 @@ Support ) -find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}") +find_first_existing_vc_file(llvm_vc "${LLVM_BUILD_MAIN_SRC_DIR}") find_first_existing_vc_file(clang_vc "${CLANG_SOURCE_DIR}") # The VC revision include that we want to generate. @@ -17,7 +17,7 @@ add_custom_command(OUTPUT "${version_inc}" DEPENDS "${llvm_vc}" "${clang_vc}" "${get_svn_script}" COMMAND - ${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${LLVM_MAIN_SRC_DIR}" + ${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${LLVM_BUILD_MAIN_SRC_DIR}" "-DFIRST_NAME=LLVM" "-DSECOND_SOURCE_DIR=${CLANG_SOURCE_DIR}" "-DSECOND_NAME=SVN" Index: runtime/CMakeLists.txt =================================================================== --- runtime/CMakeLists.txt +++ runtime/CMakeLists.txt @@ -22,7 +22,7 @@ endif() endfunction() -set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt) +set(COMPILER_RT_SRC_ROOT ${LLVM_BUILD_MAIN_SRC_DIR}/projects/compiler-rt) # Fallback to the external path, if the other one isn't available. # This is the same behavior (try "internal", then check the LLVM_EXTERNAL_... # variable) as in add_llvm_external_project