Index: lldb/cmake/modules/LLDBConfig.cmake =================================================================== --- lldb/cmake/modules/LLDBConfig.cmake +++ lldb/cmake/modules/LLDBConfig.cmake @@ -250,6 +250,30 @@ endif() endif() + +# If LLDB is building against a prebuilt Clang, then the Clang resource +# directory that LLDB is using for its embedded Clang instance needs to point +# to the resource directory of the used Clang installation. +if (NOT TARGET clang-resource-headers) + set(LLDB_CLANG_RESOURCE_DIR_NAME "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" + "${LLVM_BUILD_LIBRARY_DIR}" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") + if (IS_DIRECTORY "${CANDIDATE_RESOURCE_DIR}") + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR "${CANDIDATE_RESOURCE_DIR}") + break() + endif() + endforeach() + + if (NOT LLDB_EXTERNAL_CLANG_RESOURCE_DIR) + message(FATAL_ERROR "Expected directory for clang-resource headers not found: ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}") + endif() +endif() + # Find Apple-specific libraries or frameworks that may be needed. if (APPLE) if(NOT APPLE_EMBEDDED) Index: lldb/cmake/modules/LLDBFramework.cmake =================================================================== --- lldb/cmake/modules/LLDBFramework.cmake +++ lldb/cmake/modules/LLDBFramework.cmake @@ -110,20 +110,7 @@ add_dependencies(liblldb clang-resource-headers) set(clang_resource_headers_dir $) else() - # In standalone builds try the best possible guess - if(Clang_DIR) - set(clang_lib_dir ${Clang_DIR}/../..) - elseif(LLVM_DIR) - set(clang_lib_dir ${LLVM_DIR}/../..) - elseif(LLVM_LIBRARY_DIRS) - set(clang_lib_dir ${LLVM_LIBRARY_DIRS}) - elseif(LLVM_BUILD_LIBRARY_DIR) - set(clang_lib_dir ${LLVM_BUILD_LIBRARY_DIR}) - elseif(LLVM_BINARY_DIR) - set(clang_lib_dir ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) - endif() - set(clang_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}) - set(clang_resource_headers_dir ${clang_lib_dir}/clang/${clang_version}/include) + set(clang_resource_headers_dir ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}/include) if(NOT EXISTS ${clang_resource_headers_dir}) message(WARNING "Expected directory for clang-resource headers not found: ${clang_resource_headers_dir}") endif() Index: lldb/source/API/CMakeLists.txt =================================================================== --- lldb/source/API/CMakeLists.txt +++ lldb/source/API/CMakeLists.txt @@ -195,8 +195,27 @@ ) endif() -if (NOT LLDB_BUILT_STANDALONE) +# The Clang expression parser in LLDB requires the Clang resource directory to function. +if (TARGET clang-resource-headers) + # If building alongside Clang, just add a dependency to ensure it is build together with liblldb. add_dependencies(liblldb clang-resource-headers) +else() + # In a standalone build create a symlink from the LLDB library directory that points to the + # resource directory in the Clang library directory. LLDB searches relative to its install path, + # and the symlink is created in the same relative path as the resource directory of Clang when + # building alongside Clang. + # When building the LLDB framework, this isn't necessary as there we copy everything we need into + # the framework (including the Clang resourece directory). + if(NOT LLDB_BUILD_FRAMEWORK) + set(LLDB_CLANG_RESOURCE_DIR_PARENT "$/clang") + file(MAKE_DIRECTORY "${LLDB_CLANG_RESOURCE_DIR_PARENT}") + add_custom_command(TARGET liblldb POST_BUILD + COMMENT "Linking Clang resource dir into LLDB build directory: ${LLDB_CLANG_RESOURCE_DIR_PARENT}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${LLDB_CLANG_RESOURCE_DIR_PARENT}" + COMMAND ${CMAKE_COMMAND} -E create_symlink "${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}" + "${LLDB_CLANG_RESOURCE_DIR_PARENT}/${LLDB_CLANG_RESOURCE_DIR_NAME}" + ) + endif() endif() if(LLDB_BUILD_FRAMEWORK)