Skip to content

Commit abc1ae5

Browse files
committed
CMake: Search for Clang in CMAKE_LIBRARY_PATH, CMAKE_PREFIX_PATH, and CMAKE_FRAMEWORK_PATH
On some systems (esp. systems that use unique hashed file-paths for library-versions like Nix), we can't expect LLVM and Clang to share lib/bin directories. The best we can do is find the matching clang libraries in the CMAKE_LIBRARY_PATH provided by the environment
1 parent 5337934 commit abc1ae5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cmake/Findclang.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
1111
HINTS ${LLVM_INCLUDE_DIRS}
12-
NO_DEFAULT_PATH # Only look for clang next to LLVM
12+
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
13+
NO_SYSTEM_ENVIRONMENT_PATH
14+
NO_CMAKE_SYSTEM_PATH
1315
)
1416

1517
if(${LLVM_LINK_MODE} STREQUAL "shared")
@@ -21,14 +23,18 @@ if(${LLVM_LINK_MODE} STREQUAL "shared")
2123
clang-cpp
2224
NAMES_PER_DIR
2325
HINTS "${LLVM_LIBDIRS}"
24-
NO_DEFAULT_PATH # Only look for Clang next to LLVM
26+
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
27+
NO_SYSTEM_ENVIRONMENT_PATH
28+
NO_CMAKE_SYSTEM_PATH
2529
)
2630
else()
2731
macro(FIND_AND_ADD_CLANG_LIB _libname_)
2832
string(TOUPPER ${_libname_} _prettylibname_)
2933
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
3034
HINTS "${LLVM_LIBDIRS}"
31-
NO_DEFAULT_PATH # Only look for Clang next to LLVM
35+
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
36+
NO_SYSTEM_ENVIRONMENT_PATH
37+
NO_CMAKE_SYSTEM_PATH
3238
)
3339
if(CLANG_${_prettylibname_}_LIB)
3440
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})

0 commit comments

Comments
 (0)