@@ -49,6 +49,16 @@ function(runtime_register_component name)
4949 set_property (GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name} )
5050endfunction ()
5151
52+ # This file can be used in two ways: it is either called from llvm/CMakeLists.txt
53+ # where case we reuse the build tree of the top-level build or directly invoked
54+ # in this directory. In that case we might be building against a LLVM install
55+ # tree and might not have a valid build tree set up yet.
56+ set (RUNTIMES_STANDALONE_BUILD OFF )
57+ if ("${CMAKE_SOURCE_DIR} " STREQUAL "${CMAKE_CURRENT_LIST_DIR} " )
58+ message (STATUS "Performing standalone runtimes build." )
59+ set (RUNTIMES_STANDALONE_BUILD ON )
60+ endif ()
61+
5262find_package (LLVM PATHS "${LLVM_BINARY_DIR} " NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
5363find_package (Clang PATHS "${LLVM_BINARY_DIR} " NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
5464
@@ -68,8 +78,13 @@ endif()
6878
6979# Setting these variables will allow the sub-build to put their outputs into
7080# the library and bin directories of the top-level build.
71- set (LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR} )
72- set (LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR} )
81+ if (RUNTIMES_STANDALONE_BUILD)
82+ set (LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR} /lib${LLVM_LIBDIR_SUFFIX} )
83+ set (LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR} /bin)
84+ else ()
85+ set (LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR} )
86+ set (LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR} )
87+ endif ()
7388
7489# This variable makes sure that e.g. llvm-lit is found.
7590set (LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} /../llvm)
@@ -239,6 +254,21 @@ foreach(entry ${runtimes})
239254endforeach ()
240255
241256if (LLVM_INCLUDE_TESTS)
257+ # If built with the runtimes build (rooted at runtimes/CMakeLists.txt), we
258+ # won't have llvm-lit. If built with the bootstrapping build (rooted at
259+ # llvm/CMakeLists.txt), the top-level llvm CMake invocation already generated
260+ # the llvm-lit script.
261+ if (RUNTIMES_STANDALONE_BUILD)
262+ # Ensure that the appropriate variables for lit are set before adding any
263+ # runtimes since their CMake tests configuration might depend on lit being
264+ # present. This ensures that the testsuites use a local lit from the build
265+ # dir rather than ${LLVM_INSTALL_DIR}/bin/llvm-lit (which may not exist if
266+ # LLVM_BINARY_DIR points at an installed LLVM tree rather than a build tree).
267+ set (LLVM_LIT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} /bin)
268+ get_llvm_lit_path(_base_dir _file_name)
269+ set (LLVM_EXTERNAL_LIT "${_base_dir} /${_file_name} " CACHE STRING "Command used to spawn lit" FORCE)
270+ endif ()
271+
242272 set (LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported" )
243273 if (MSVC OR XCODE)
244274 set (LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar" )
@@ -276,6 +306,8 @@ if(LLVM_INCLUDE_TESTS)
276306 # If built by manually invoking cmake on this directory, we don't have
277307 # llvm-lit. If invoked via llvm/runtimes, the toplevel llvm cmake
278308 # invocation already generated the llvm-lit script.
309+ # NOTE: this must be called fater all testsuites have been added, since
310+ # otherwise the generated llvm-lit does not have all required path mappings.
279311 add_subdirectory (${LLVM_MAIN_SRC_DIR} /utils/llvm-lit
280312 ${CMAKE_CURRENT_BINARY_DIR} /llvm-lit)
281313 endif ()
@@ -309,10 +341,10 @@ if(SUB_COMPONENTS)
309341 if (LLVM_RUNTIMES_TARGET)
310342 configure_file (
311343 ${CMAKE_CURRENT_SOURCE_DIR} /Components.cmake.in
312- ${LLVM_BINARY_DIR } /runtimes/${LLVM_RUNTIMES_TARGET} /Components.cmake)
344+ ${CMAKE_CURRENT_BINARY_DIR } /runtimes/${LLVM_RUNTIMES_TARGET} /Components.cmake)
313345 else ()
314346 configure_file (
315347 ${CMAKE_CURRENT_SOURCE_DIR} /Components.cmake.in
316- ${LLVM_BINARY_DIR } /runtimes/Components.cmake)
348+ ${CMAKE_CURRENT_BINARY_DIR } /runtimes/Components.cmake)
317349 endif ()
318350endif ()
0 commit comments