-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update LLVM/Clang support to 14.0+, add LLVM 19 handling
- Loading branch information
1 parent
d0b033a
commit 5a86780
Showing
3 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
#============================================================================= | ||
# SPDX-FileCopyrightText: 2014-2015 Kevin Funk <[email protected]> | ||
# SPDX-FileCopyrightText: 2024 Shivan Kunwar <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
#============================================================================= | ||
|
@@ -32,10 +33,6 @@ endif () | |
set(CLANG_FOUND FALSE) | ||
|
||
if (LLVM_FOUND AND LLVM_LIBRARY_DIRS) | ||
macro(FIND_CLANG_LIB _libname_) | ||
string(TOUPPER ${_libname_} _prettylibname_) | ||
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS}) | ||
endmacro(FIND_CLANG_LIB) | ||
macro(FIND_AND_ADD_CLANG_LIB _libname_) | ||
string(TOUPPER ${_libname_} _prettylibname_) | ||
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS}) | ||
|
@@ -47,12 +44,11 @@ if (LLVM_FOUND AND LLVM_LIBRARY_DIRS) | |
# note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too | ||
find_library(CLANG_LIBCLANG_LIB NAMES clang libclang HINTS ${LLVM_LIBRARY_DIRS}) # LibClang: high-level C interface | ||
|
||
FIND_CLANG_LIB(clang-cpp) | ||
FIND_AND_ADD_CLANG_LIB(clang-cpp) | ||
FIND_AND_ADD_CLANG_LIB(clangFrontend) | ||
FIND_AND_ADD_CLANG_LIB(clangDriver) | ||
FIND_AND_ADD_CLANG_LIB(clangCodeGen) | ||
FIND_AND_ADD_CLANG_LIB(clangSema) | ||
FIND_AND_ADD_CLANG_LIB(clangChecker) | ||
FIND_AND_ADD_CLANG_LIB(clangAnalysis) | ||
FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend) | ||
FIND_AND_ADD_CLANG_LIB(clangRewrite) | ||
|
@@ -64,15 +60,27 @@ if (LLVM_FOUND AND LLVM_LIBRARY_DIRS) | |
FIND_AND_ADD_CLANG_LIB(clangARCMigrate) | ||
FIND_AND_ADD_CLANG_LIB(clangEdit) | ||
FIND_AND_ADD_CLANG_LIB(clangFrontendTool) | ||
FIND_AND_ADD_CLANG_LIB(clangRewrite) | ||
FIND_AND_ADD_CLANG_LIB(clangSerialization) | ||
FIND_AND_ADD_CLANG_LIB(clangTooling) | ||
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers) | ||
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore) | ||
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend) | ||
FIND_AND_ADD_CLANG_LIB(clangSema) | ||
FIND_AND_ADD_CLANG_LIB(clangRewriteCore) | ||
FIND_AND_ADD_CLANG_LIB(clangAPINotes) | ||
|
||
if (LLVM_VERSION VERSION_GREATER_EQUAL "15.0") | ||
FIND_AND_ADD_CLANG_LIB(clangSupport) | ||
endif() | ||
|
||
# LLVM 19 specific libraries | ||
if (LLVM_VERSION VERSION_GREATER_EQUAL "19.0") | ||
FIND_AND_ADD_CLANG_LIB(clangASTMatchers) | ||
FIND_AND_ADD_CLANG_LIB(clangTransformer) | ||
FIND_AND_ADD_CLANG_LIB(clangToolingCore) | ||
FIND_AND_ADD_CLANG_LIB(clangToolingInclusions) | ||
FIND_AND_ADD_CLANG_LIB(clangToolingRefactoring) | ||
FIND_AND_ADD_CLANG_LIB(clangToolingSyntax) | ||
FIND_AND_ADD_CLANG_LIB(clangDependencyScanning) | ||
endif() | ||
endif() | ||
|
||
if(CLANG_LIBS OR CLANG_LIBCLANG_LIB OR CLANG_CLANG-CPP_LIB) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
#============================================================================= | ||
# SPDX-FileCopyrightText: 2014 Kevin Funk <[email protected]> | ||
# SPDX-FileCopyrightText: 2024 Shivan Kunwar <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
#============================================================================= | ||
|
@@ -30,14 +31,10 @@ endif() | |
if (LLVM_ROOT) | ||
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config HINTS ${LLVM_ROOT}/bin DOC "llvm-config executable" NO_DEFAULT_PATH) | ||
else() | ||
# find llvm-config, prefer the one with a version suffix, e.g. llvm-config-3.5 | ||
# note: FreeBSD installs llvm-config as llvm-config35 and so on | ||
# note: on some distributions, only 'llvm-config' is shipped, so let's always try to fallback on that | ||
# find llvm-config, prefer the one with a version suffix, e.g. llvm-config-14 | ||
string(REPLACE "." "" LLVM_FIND_VERSION_CONCAT ${LLVM_FIND_VERSION}) | ||
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config-${LLVM_FIND_VERSION} llvm-config${LLVM_FIND_VERSION_CONCAT} llvm-config DOC "llvm-config executable") | ||
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config-${LLVM_FIND_VERSION} llvm-config${LLVM_FIND_VERSION_CONCAT} llvm-config-14 llvm-config-15 llvm-config-16 llvm-config-17 llvm-config-18 llvm-config-19 llvm-config DOC "llvm-config executable") | ||
|
||
# other distributions don't ship llvm-config, but only some llvm-config-VERSION binary | ||
# try to deduce installed LLVM version by looking up llvm-nm in PATH and *then* find llvm-config-VERSION via that | ||
if (NOT LLVM_CONFIG_EXECUTABLE) | ||
find_program(_llvmNmExecutable llvm-nm) | ||
if (_llvmNmExecutable) | ||
|
@@ -58,7 +55,7 @@ if (LLVM_CONFIG_EXECUTABLE) | |
|
||
if (NOT LLVM_VERSION) | ||
set(_LLVM_ERROR_MESSAGE "Failed to parse version from llvm-config") | ||
elseif (LLVM_FIND_VERSION VERSION_GREATER LLVM_VERSION) | ||
elseif (LLVM_VERSION VERSION_LESS "14.0") | ||
set(_LLVM_ERROR_MESSAGE "LLVM version too old: ${LLVM_VERSION}") | ||
else() | ||
set(LLVM_FOUND TRUE) | ||
|
@@ -103,7 +100,7 @@ if (LLVM_FOUND) | |
OUTPUT_VARIABLE LLVM_LIBS | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
string(REPLACE " " ";" LLVM_LIBS ${LLVM_LIBS}) # Make it consistent with --libs | ||
string(REPLACE " " ";" LLVM_LIBS ${LLVM_LIBS}) | ||
|
||
execute_process( | ||
COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs | ||
|
@@ -144,6 +141,17 @@ if (LLVM_FOUND) | |
if (NOT _llvmIsInstalled) | ||
list(APPEND LLVM_INCLUDE_DIRS "${LLVM_INSTALL_PREFIX}/include") | ||
endif() | ||
|
||
# LLVM 19 specific handling | ||
if (LLVM_VERSION VERSION_GREATER_EQUAL "19.0") | ||
execute_process( | ||
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs all | ||
OUTPUT_VARIABLE LLVM_LIBS_19 | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
string(REPLACE " " ";" LLVM_LIBS_19 ${LLVM_LIBS_19}) | ||
list(APPEND LLVM_LIBS ${LLVM_LIBS_19}) | ||
endif() | ||
endif() | ||
|
||
if (LLVM_FIND_REQUIRED AND NOT LLVM_FOUND) | ||
|
@@ -157,4 +165,38 @@ if (LLVM_FOUND) | |
message(STATUS " Include dirs: ${LLVM_INCLUDE_DIRS}") | ||
message(STATUS " LLVM libraries: ${LLVM_LIBS}") | ||
message(STATUS " LLVM System libraries: ${LLVM_SYSTEM_LIBS}") | ||
|
||
if (LLVM_VERSION VERSION_GREATER_EQUAL "19.0") | ||
message(STATUS " LLVM 19+ detected, additional libraries may be available") | ||
endif() | ||
endif() | ||
|
||
execute_process( | ||
COMMAND ${LLVM_CONFIG_EXECUTABLE} --cxxflags | ||
OUTPUT_VARIABLE LLVM_DEFINITIONS | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
string(REGEX REPLACE "[ \t]+" ";" LLVM_DEFINITIONS "${LLVM_DEFINITIONS}") | ||
|
||
if(LLVM_FIND_COMPONENTS) | ||
foreach(component ${LLVM_FIND_COMPONENTS}) | ||
string(TOUPPER ${component} component_upcase) | ||
set(LLVM_${component_upcase}_FOUND TRUE) | ||
set(LLVM_${component_upcase}_LIBRARY ${component}) | ||
endforeach() | ||
endif() | ||
|
||
if (LLVM_VERSION VERSION_GREATER_EQUAL "14.0") | ||
execute_process( | ||
COMMAND ${LLVM_CONFIG_EXECUTABLE} --has-rtti | ||
OUTPUT_VARIABLE LLVM_HAS_RTTI | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
if (LLVM_HAS_RTTI) | ||
message(STATUS " LLVM built with RTTI: ${LLVM_HAS_RTTI}") | ||
endif() | ||
endif() | ||
|
||
set(LLVM_VERSION "${LLVM_VERSION}" CACHE STRING "LLVM version") | ||
|
||
mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARY_DIRS LLVM_CFLAGS LLVM_LFLAGS LLVM_MODULE_LIBS LLVM_LIBS LLVM_DEFINITIONS) |