LLVM config bug fixes + structure changes #4863
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The provided CMake code appears to be checking for the presence of the LLVM library and setting up the necessary include directories and libraries for a project. There are a few potential issues and improvements that were made:
Redundant
find_package(LLVM CONFIG ...)
blocks:The code redundantly repeats the same
find_package(LLVM CONFIG ...)
block multiple times with different LLVM versions. It's better to use a loop or a function to avoid repetitive code.Redundant
if(NOT LLVM_FOUND)
checks:The code redundantly checks for
LLVM_FOUND
after eachfind_package(LLVM CONFIG ...)
block. Since the code continues to search for LLVM with different versions, these checks can be removed.Repetitive
find_package(LLVM CONFIG ...)
without version check:The code uses
find_package(LLVM CONFIG ...)
without specifying a version in the last block. It's recommended to always specify the required LLVM version to avoid unexpected issues.Use of
LLVM_LIBRARY_DIR
:The code uses the variable
${LLVM_LIBRARY_DIR}
infind_library
calls. Ensure that this variable is defined or set appropriately before using it.Use of
find_library
withNO_SYSTEM_ENVIRONMENT_PATH
andNO_CMAKE_SYSTEM_PATH
:These options may prevent the library from being found in standard system paths or paths set by the environment. Consider removing these options if they are causing issues.
find_llvm_libs
function behavior:The function
find_llvm_libs
seems to be searching for LLVM libraries and setting theLLVM_LIBS
variable. However, it doesn't appear to be used in the provided code. Ensure that this function is called and its results are utilized elsewhere in your CMakeLists.txt file.This revision uses a loop to find the first available LLVM version, removes redundant checks, and addresses some of the issues mentioned. Adjust the LLVM libraries in the
find_llvm_libs
function according to your project's requirements.