Skip to content
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

build: Allow building Cling using the Clang shared library. #433

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
"--libdir"
"--includedir"
"--prefix"
"--shared-mode"
"--src-root")
execute_process(
COMMAND ${CONFIG_COMMAND}
Expand All @@ -47,7 +48,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
list(GET CONFIG_OUTPUT 5 LLVM_LIB_IS_SHARED)
list(GET CONFIG_OUTPUT 6 MAIN_SRC_DIR)

if(NOT MSVC_IDE)
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
Expand Down Expand Up @@ -427,7 +429,11 @@ macro(add_cling_library name)
endif()

if(TARGET ${name})
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
if(LLVM_LIB_IS_SHARED)
target_link_libraries(${name} PUBLIC LLVM)
else()
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
endif()

if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libcling")
install(TARGETS ${name}
Expand Down
40 changes: 23 additions & 17 deletions lib/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@
# LICENSE.TXT for details.
#------------------------------------------------------------------------------

set(LIBS
clingUtils
clangCodeGen
clangDriver
clangFrontend
clangParse
clangSema
clangAnalysis
clangEdit
clangRewrite
clangRewriteFrontend
clangSerialization
clangAST
clangBasic
clangLex
)
if (LLVM_LIB_IS_SHARED)
set(LIBS
clang-cpp
clingUtils)
else()
set(LIBS
clingUtils
clangCodeGen
clangDriver
clangFrontend
clangParse
clangSema
clangAnalysis
clangEdit
clangRewrite
clangRewriteFrontend
clangSerialization
clangAST
clangBasic
clangLex
)
endif()

set(LLVM_LINK_COMPONENTS
analysis
Expand Down Expand Up @@ -369,4 +375,4 @@ if ((NOT builtin_llvm) AND builtin_clang)
get_property(P SOURCE TransactionUnloader.cpp PROPERTY INCLUDE_DIRECTORIES)
list(INSERT P 0 ${FixInclude})
set_property(SOURCE TransactionUnloader.cpp PROPERTY INCLUDE_DIRECTORIES "${P}")
endif()
endif()
16 changes: 11 additions & 5 deletions lib/MetaProcessor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ set( LLVM_LINK_COMPONENTS
core
support
binaryformat
)
)

if (LLVM_LIB_IS_SHARED)
set(LIBS clang-cpp)
else()
set(LIBS
clangLex
clangAST
clangBasic)
endif()

add_cling_library(clingMetaProcessor OBJECT
Display.cpp
Expand All @@ -21,10 +30,7 @@ add_cling_library(clingMetaProcessor OBJECT
MetaSema.cpp

LINK_LIBS
clangLex
clangAST
clangBasic

${LIBS}
clingInterpreter
clingUtils
)
34 changes: 19 additions & 15 deletions lib/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
)

set(LIBS
clangCodeGen
clangDriver
clangFrontend
clangParse
clangSema
clangAnalysis
clangEdit
clangRewrite
clangRewriteFrontend
clangSerialization
clangAST
clangBasic
clangLex
)
if (LLVM_LIB_IS_SHARED)
set(LIBS clang-cpp)
else()
set(LIBS
clangCodeGen
clangDriver
clangFrontend
clangParse
clangSema
clangAnalysis
clangEdit
clangRewrite
clangRewriteFrontend
clangSerialization
clangAST
clangBasic
clangLex
)
endif()

find_library(DL_LIBRARY_PATH dl)
if (DL_LIBRARY_PATH)
Expand Down
11 changes: 10 additions & 1 deletion tools/Jupyter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ else()
endif()
endif()

if (LLVM_LIB_IS_SHARED)
set(LIBS
clang-cpp
clingUserInterface
clingMetaProcessor
${INTERPRETER}
clingUtils)
else()
set(LIBS
clangAST
clangBasic
Expand All @@ -54,7 +62,8 @@ set(LIBS
clingMetaProcessor
${INTERPRETER}
clingUtils
)
)
endif()

if( LLVM_ENABLE_PIC )
set(ENABLE_SHARED SHARED)
Expand Down
16 changes: 3 additions & 13 deletions tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@
# Keep symbols for JIT resolution
set(LLVM_NO_DEAD_STRIP 1)

if(BUILD_SHARED_LIBS)
set(LIBS
LLVMSupport

clangFrontendTool

clingInterpreter
clingMetaProcessor
clingUserInterface
clingUtils
)
if(LLVM_LIB_IS_SHARED)
set(LIBS clang-cpp clingUserInterface)
add_cling_executable(cling
cling.cpp
)
else()
set(LIBS
LLVMSupport

clangASTMatchers
clangFrontendTool
Expand All @@ -38,7 +28,7 @@ else()
$<TARGET_OBJECTS:obj.clingMetaProcessor>
$<TARGET_OBJECTS:obj.clingUtils>
)
endif(BUILD_SHARED_LIBS)
endif(LLVM_LIB_IS_SHARED)

set_target_properties(cling
PROPERTIES ENABLE_EXPORTS 1)
Expand Down
38 changes: 19 additions & 19 deletions tools/libcling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@ set(SOURCES
ADDITIONAL_HEADERS
)

set(LIBS
clangAnalysis
clangDriver
clangFrontend
clangParse
clangSema
clangAST
clangLex
clangSerialization
clangCodeGen
clangBasic
clangEdit

clingUtils
)
if (LLVM_LIB_IS_SHARED)
set(LIBS clang-cpp)
else()
set(LIBS
clangAnalysis
clangDriver
clangFrontend
clangParse
clangSema
clangAST
clangLex
clangSerialization
clangCodeGen
clangBasic
clangEdit

clingUtils
)
endif()

set( LLVM_LINK_COMPONENTS
analysis
Expand Down Expand Up @@ -63,10 +67,6 @@ option(LIBCLING_BUILD_STATIC
# set(LLVM_EXPORTED_SYMBOL_FILE)
#endif()

if( LLVM_ENABLE_PIC )
set(ENABLE_SHARED SHARED)
endif()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious, why did you disable shared libcling? AFAIK it's used by xeus-cling

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC that mode is officially unsupported; it predates the global LLVM.so dynamic library feature that this patch relies on:

One very important note: Distributions should never be built using the BUILD_SHARED_LIBS CMake option. That option exists for optimizing developer workflow only. Due to design and implementation decisions, LLVM relies on global data which can end up being duplicated across shared libraries resulting in bugs. As such this is not a safe way to distribute LLVM or LLVM-based tools.

Source: https://llvm.org/docs/BuildingADistribution.html#general-distribution-guidance

if((NOT LLVM_ENABLE_PIC OR LIBCLING_BUILD_STATIC) AND NOT WIN32)
set(ENABLE_STATIC STATIC)
endif()
Expand Down