Skip to content

Commit

Permalink
[cmake] Propagate the LLVM_VERSION cmake option to the way we find cl…
Browse files Browse the repository at this point in the history
…ang. (#673)

We can specify cmake -DLLVM_VERSION=... and before that patch we will pick up
the latest version of clang which made our setup incompatible. This patch tries
harder to find the corresponding clang version to the specified version of llvm.
  • Loading branch information
vgvassilev authored Dec 8, 2023
1 parent 2ee6b06 commit ed3e7d6
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,15 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
## Find supported Clang

if (DEFINED CLANG_VERSION)
if (CLANG_VERSION VERSION_GREATER_EQUAL CLANG_VERSION_UPPER_BOUND)
set(CLANG_VERSION ${CLANG_VERSION_UPPER_BOUND})
endif()
if (CLANG_VERSION VERSION_LESS CLANG_MIN_SUPPORTED)
set(CLANG_VERSION ${CLANG_MIN_SUPPORTED})
endif()

if (DEFINED Clang_DIR)
set(extra_hints HINTS ${Clang_DIR} "${Clang_DIR}/lib/cmake/clang" "${Clang_DIR}/cmake")
endif()

find_package(Clang ${CLANG_VERSION} REQUIRED CONFIG ${extra_hints})
message(FATAL_ERROR "Clang's configuration is not versioned. Please set LLVM_VERSION instead.")
endif(DEFINED CLANG_VERSION)

# We have specified -DLLVM_VERSION and we must find matching clang. However,
# ClangConfig.cmake is not versioned and we will need to work harder to find
# the correct package.
if (DEFINED LLVM_VERSION AND NOT DEFINED Clang_DIR)
set(extra_hints HINTS ${Clang_DIR} "${LLVM_BINARY_DIR}/lib/cmake/clang" "${LLVM_BINARY_DIR}/cmake")
find_package(Clang REQUIRED CONFIG ${extra_hints} NO_DEFAULT_PATH)
endif()

if (NOT Clang_FOUND AND DEFINED Clang_DIR)
Expand Down

0 comments on commit ed3e7d6

Please sign in to comment.