From 7ad062b9d622c1aff50d56bc4ad15c7c779df3c2 Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Sun, 6 Aug 2023 21:48:35 +0200 Subject: [PATCH 1/2] [cmake] Explicitly disable linking against shared LLVM --- interpreter/CMakeLists.txt | 3 +++ interpreter/cling/CMakeLists.txt | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 38eaf748bc2ae..d5b80a7f540e8 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -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) diff --git a/interpreter/cling/CMakeLists.txt b/interpreter/cling/CMakeLists.txt index 795445f9fa258..a3fdd4b5c9a86 100644 --- a/interpreter/cling/CMakeLists.txt +++ b/interpreter/cling/CMakeLists.txt @@ -417,7 +417,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ā€ From 66f562d8598bf8d4729aca3d3175308fd179d93c Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Tue, 8 Aug 2023 22:17:43 +0200 Subject: [PATCH 2/2] [cmake] Improve interface for external LLVM --- interpreter/CMakeLists.txt | 3 ++- interpreter/cling/CMakeLists.txt | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index d5b80a7f540e8..d939c324016b4 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -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) @@ -503,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}) diff --git a/interpreter/cling/CMakeLists.txt b/interpreter/cling/CMakeLists.txt index a3fdd4b5c9a86..258946791b446 100644 --- a/interpreter/cling/CMakeLists.txt +++ b/interpreter/cling/CMakeLists.txt @@ -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") @@ -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() @@ -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") @@ -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()