Skip to content

Import llvmconfig using cmake module path instead of finding abs path #3199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions cmake/modules/SwiftSharedCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,24 @@ macro(swift_common_standalone_build_config product is_cross_compiling)

precondition_translate_flag(${product}_PATH_TO_LLVM_SOURCE PATH_TO_LLVM_SOURCE)
precondition_translate_flag(${product}_PATH_TO_LLVM_BUILD PATH_TO_LLVM_BUILD)
set(PATH_TO_LLVM_TOOLS_BINARY_DIR "${PATH_TO_LLVM_BUILD}/bin")

if(NOT ${is_cross_compiling})
set(${product}_NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
endif()

find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
NO_DEFAULT_PATH)

set(LLVM_CMAKE_PATHS
set(SWIFT_LLVM_CMAKE_PATHS
"${PATH_TO_LLVM_BUILD}/share/llvm/cmake"
"${PATH_TO_LLVM_BUILD}/lib/cmake/llvm")

set(LLVMCONFIG_FILE)
foreach(CMAKE_PATH ${LLVM_CMAKE_PATHS})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PATH}")

if(EXISTS "${CMAKE_PATH}/LLVMConfig.cmake")
set(LLVMCONFIG_FILE "${CMAKE_PATH}/LLVMConfig.cmake")
break()
endif()
# Add all LLVM CMake paths to our cmake module path.
foreach(path ${SWIFT_LLVM_CMAKE_PATHS})
list(APPEND CMAKE_MODULE_PATH ${path})
endforeach()

if(${LLVMCONFIG_FILE} STREQUAL "")
message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
endif()

# If we already have a cached value for LLVM_ENABLE_ASSERTIONS, save the value.
if (DEFINED LLVM_ENABLE_ASSERTIONS)
set(LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS}")
endif()

# Then we import LLVMCONFIG_FILE. This is going to override whatever cached
# value we have for LLVM_ENABLE_ASSERTIONS.
include(${LLVMCONFIG_FILE})
# Then we import LLVMConfig. This is going to override whatever cached value
# we have for LLVM_ENABLE_ASSERTIONS.
include(LLVMConfig)

# If we did not have a cached value for LLVM_ENABLE_ASSERTIONS, set
# LLVM_ENABLE_ASSERTIONS_saved to be the ENABLE_ASSERTIONS value from LLVM so
Expand Down Expand Up @@ -126,6 +108,18 @@ macro(swift_common_standalone_build_config product is_cross_compiling)

list(APPEND CMAKE_MODULE_PATH "${${product}_PATH_TO_LLVM_BUILD}/share/llvm/cmake")

if(${is_cross_compiling})
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
NO_DEFAULT_PATH)
if ("${LLVM_TABLEGEN_EXE}" STREQUAL "LLVM_TABLEGEN_EXE-NOTFOUND")
message(FATAL_ERROR "Failed to find tablegen in ${${product}_NATIVE_LLVM_TOOLS_PATH}")
endif()
else()
set(LLVM_TABLEGEN_EXE llvm-tblgen)
set(${product}_NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
endif()

include(AddLLVM)
include(TableGen)
include(HandleLLVMOptions)
Expand Down