Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -128,18 +128,22 @@ set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS}) endif() foreach(proj ${LLVM_ENABLE_PROJECTS}) - set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") + string(TOUPPER "${proj}" upper_proj) + STRING(REGEX REPLACE "-" "_" upper_proj ${upper_proj}) + if(NOT LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR) + set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") + endif() + set(PROJ_DIR "${LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR}") if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}") message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}") endif() - string(TOUPPER "${proj}" upper_proj) - STRING(REGEX REPLACE "-" "_" upper_proj ${upper_proj}) - set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") # There is a widely spread opinion that clang-tools-extra should be merged # into clang. The following simulates it by always enabling clang-tools-extra # when enabling clang. if (proj STREQUAL "clang") - set(LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../clang-tools-extra") + if(NOT LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR) + set(LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../clang-tools-extra") + endif() endif() endforeach()