Skip to content

Fix building with external LLVM #13420

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
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ else()
if (${PACKAGE_VERSION} MATCHES "${ROOT_LLVM_VERSION_REQUIRED_MAJOR}\\.0(|\\.[0-9]+)")
message(STATUS "Using LLVM external library - ${PACKAGE_VERSION}")
else()
message(FATAL_ERROR "LLVM version different from ROOT supported, please try ${ROOT_LLVM_VERSION_REQUIRED_MAJOR}.0.x")
message(FATAL_ERROR "LLVM version ${LLVM_PACKAGE_VERSION} different from ROOT supported, please try ${ROOT_LLVM_VERSION_REQUIRED_MAJOR}.0.x")
endif()

if (NOT DEFINED LLVM_INCLUDE_TESTS)
Expand Down Expand Up @@ -440,6 +440,9 @@ Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
# install-clang-cpp target defined by LLVM's cmake module
set(CLANG_LINKS_TO_CREATE clang++ clang-cl)

# Disable linking against shared LLVM
set(LLVM_LINK_LLVM_DYLIB OFF)

add_subdirectory(llvm-project/clang EXCLUDE_FROM_ALL)
endif(builtin_clang)

Expand Down Expand Up @@ -500,6 +503,7 @@ if (builtin_cling)
string(APPEND CMAKE_C_FLAGS " -fPIC")
endif(LLVM_ENABLE_PIC AND NOT MSVC)
# Avoid cling being installed under ROOTSYS/include.
set(CLING_ROOT_BUILD ON)
add_subdirectory(cling EXCLUDE_FROM_ALL)
add_dependencies(CLING ${CLING_LIBRARIES})

Expand Down
15 changes: 10 additions & 5 deletions interpreter/cling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")

set( CLING_BUILT_STANDALONE 1 )
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
else() # Building as part of LLVM
elseif(DEFINED CLING_ROOT_BUILD)
message(STATUS "Building Cling as part of ROOT")
# we do not need to include LLVMConfig again, already done
else()
message(STATUS "Building Cling as part of LLVM")
set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
# Try finding the LLVMConfig.cmake if we build against prebuilt LLVM
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
Expand Down Expand Up @@ -195,7 +199,7 @@ endif()
set(CLING_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CLING_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LLVM_TOOLS_BINARY_DIR "${LLVM_BINARY_DIR}/bin")
if(DEFINED ROOT_BINARY_DIR)
if(DEFINED CLING_ROOT_BUILD)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${LLVM_TOOLS_BINARY_DIR}")
endif()

Expand Down Expand Up @@ -295,7 +299,7 @@ endif ()
# The package needs to be compiler without RTTI information
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -GR-")
if(NOT DEFINED ROOT_BINARY_DIR)
if(NOT DEFINED CLING_ROOT_BUILD)
# Add the /std:c++XX flag for Visual Studio if not building as part of ROOT
if(MSVC_VERSION GREATER_EQUAL 1920)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++17")
Expand Down Expand Up @@ -327,7 +331,7 @@ file (STRINGS "VERSION" CLING_VERSION)
string(REGEX REPLACE "([0-9]).[0-9]+~[a-zA-Z]+" "\\1" CLING_VERSION_MAJOR ${CLING_VERSION})
string(REGEX REPLACE "[0-9].([0-9]+)~[a-zA-Z]+" "\\1" CLING_VERSION_MINOR ${CLING_VERSION})

if(DEFINED ROOT_BINARY_DIR)
if(DEFINED CLING_ROOT_BUILD)
# Building as part of ROOT; visibility is "inherited" from ROOT/interpreter.
set(CLING_VERSION ROOT_${CLING_VERSION})
else()
Expand Down Expand Up @@ -417,7 +421,8 @@ macro(add_cling_library name)
endif()
endif()

llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
# Set DISABLE_LLVM_LINK_LLVM_DYLIB to disable linking against shared LLVM
llvm_add_library(${name} ${ARG_ENABLE_SHARED} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARG_UNPARSED_ARGUMENTS} ${srcs})

if (MSVC AND cling_ex_file_match)
# /EHs because cling_runtime_internal_throwIfInvalidPointer is extern “C”
Expand Down