Drop custom Find* modules and use upstream ClangConfig.cmake
This eliminates a maintenance burden of maintaining the custom CMake modules in general and adding each new released Clang version into FindClang.cmake in particular. Without this change KDevelop does not compile against current Clang git main version because FindClang.cmake executes `${LLVM_CONFIG_EXECUTABLE} --src-root` and this option was recently removed in https://github.com/llvm/llvm-project/commit/c061892fcdbdfe46884c54a7a7bfe6df54d1df12 There seems to be no way to require minimum package version in the Config mode of find_package(). The comment in LLVMConfigVersion.cmake: # LLVM is API-compatible only with matching major.minor versions # and patch versions not less than that requested. Resort to informing users of the minimum required version in the Clang package DESCRIPTION. Update the contents of clangSearchHint with information based on results of my experiments. Improve readability of clangSearchHint by splitting a single long line. Print LLVM version, LLVM and Clang CMake directory paths as the example in the upstream LLVM documentation does: https://www.llvm.org/docs/CMake.html#embedding-llvm-in-your-project Also print library, include and builtin include directories as the removed custom module FindClang.cmake did. This output allows to determine which LLVM and Clang version KDevelop is built against. Rename our custom library, now alias: Clang::clang => Clang::libclang. The upstream name is "libclang", so the alias only encloses it in a Clang namespace now. When the "libclang" target does not exist, CMake configure step fails with a descriptive error message: CMake Error at plugins/CMakeLists.txt:59 (add_library): add_library cannot create ALIAS target "Clang::libclang" because target "libclang" does not already exist. Remove the no longer necessary check and FATAL_ERROR when libclang is unavailable. The upstream LLVM documentation's example linked to above includes ${LLVM_INCLUDE_DIRS} directories and adds LLVM definitions. Unfortunately, I couldn't find similar Clang documentation. Keep the existing `include_directories(${CLANG_INCLUDE_DIRS})` line and explain in a comment why it is still needed in practice. ClangConfig.cmake does not define any definition variables. I suppose that definitions should be added if LLVM is used, but not libclang. Therefore this commit removes the `add_definitions(${LLVM_CFLAGS})` line from plugins/clang/CMakeLists.txt. Move the lengthy CMake code that looks for CLANG_BUILTIN_DIR from cmake/modules/FindClang.cmake into a new module plugins/clang/Locate_CLANG_BUILTIN_DIR.cmake to avoid cluttering plugins/clang/CMakeLits.txt. Besides, the new CMake module is general enough to be reusable in other projects. Enclose in quotes ${CLANG_BUILTIN_DIR} in the get_filename_component command. This variable contains a single path, and so should be quoted.
parent
fafb3ec9
Please register or sign in to comment