Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -110,7 +110,10 @@ if( LLVM_ENABLE_PROJECTS STREQUAL "all" ) set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS}) endif() +set(LLVM_ENABLE_PROJECTS_USED OFF CACHE BOOL "") +mark_as_advanced(LLVM_ENABLE_PROJECTS_USED) foreach(proj ${LLVM_ENABLE_PROJECTS}) + set(LLVM_ENABLE_PROJECTS_USED ON CACHE BOOL "" FORCE) set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") 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}") @@ -125,6 +128,37 @@ set(LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../clang-tools-extra") endif() endforeach() +if (LLVM_ENABLE_PROJECTS_USED) + # If the user decides to use the `LLVM_ENABLE_PROJECTS` CMake option then we + # switch to using that as the single "source of truth" for the projects to + # build and force the `LLVM_TOOL__BUILD` variables to take on the + # appropriate values. This means that if the user tries to use the + # `LLVM_TOOL__BUILD` variables, then their value will be ignored. + # If the user never sets `LLVM_ENABLE_PROJECTS` then they can continue + # to use the `LLVM_TOOL__BUILD` variables as before. + # + # Unfortunately there's no good way to handle or even detect when the user + # tries to use `LLVM_ENABLE_PROJECTS` and `LLVM_TOOL_ _BUILD` + # together so we just use `LLVM_ENABLE_PROJECTS`. + foreach(proj ${LLVM_ALL_PROJECTS}) + list(FIND LLVM_ENABLE_PROJECTS "${proj}" index) + if (${index} EQUAL -1) + set(SHOULD_ENABLE_PROJ FALSE) + else() + set(SHOULD_ENABLE_PROJ TRUE) + endif() + string(TOUPPER "${proj}" upper_proj) + string(REGEX REPLACE "-" "_" upper_proj ${upper_proj}) + message( + STATUS + "Setting LLVM_TOOL_${upper_proj}_BUILD to ${SHOULD_ENABLE_PROJ}") + set(LLVM_TOOL_${upper_proj}_BUILD + ${SHOULD_ENABLE_PROJ} + CACHE + BOOL "Whether to build ${upper_proj} as part of LLVM" FORCE + ) + endforeach() +endif() # Build llvm with ccache if the package is present set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")