2018-10-16 09:30:51 +00:00
# Broken in macos. TODO: update clang, re-test, enable
if ( NOT APPLE )
2019-12-18 00:13:45 +00:00
option ( ENABLE_EMBEDDED_COMPILER "Set to TRUE to enable support for 'compile_expressions' option for query execution" ${ ENABLE_LIBRARIES } )
2019-12-18 19:50:12 +00:00
option ( USE_INTERNAL_LLVM_LIBRARY "Use bundled or system LLVM library." ${ NOT_UNBUNDLED } )
2018-10-16 09:30:51 +00:00
endif ( )
2017-11-12 12:58:40 +00:00
2020-08-13 20:10:06 +00:00
if ( ENABLE_EMBEDDED_COMPILER )
if ( USE_INTERNAL_LLVM_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/llvm/llvm/CMakeLists.txt" )
message ( WARNING "submodule contrib/llvm is missing. to fix try run: \n git submodule update --init --recursive" )
set ( USE_INTERNAL_LLVM_LIBRARY 0 )
endif ( )
2017-11-12 12:58:40 +00:00
2020-08-13 20:10:06 +00:00
if ( NOT USE_INTERNAL_LLVM_LIBRARY )
set ( LLVM_PATHS "/usr/local/lib/llvm" )
2017-11-12 12:58:40 +00:00
2020-08-13 20:10:06 +00:00
foreach ( llvm_v 9 8 )
if ( NOT LLVM_FOUND )
find_package ( LLVM ${ llvm_v } CONFIG PATHS ${ LLVM_PATHS } )
endif ( )
endforeach ( )
2018-07-20 23:44:31 +00:00
2020-08-13 20:10:06 +00:00
if ( LLVM_FOUND )
# Remove dynamically-linked zlib and libedit from LLVM's dependencies:
set_target_properties ( LLVMSupport PROPERTIES INTERFACE_LINK_LIBRARIES "-lpthread;LLVMDemangle;${ZLIB_LIBRARIES}" )
set_target_properties ( LLVMLineEditor PROPERTIES INTERFACE_LINK_LIBRARIES "LLVMSupport" )
2018-05-07 08:59:24 +00:00
2020-08-13 20:10:06 +00:00
option ( LLVM_HAS_RTTI "Enable if LLVM was build with RTTI enabled" ON )
set ( USE_EMBEDDED_COMPILER 1 )
else ( )
set ( USE_EMBEDDED_COMPILER 0 )
endif ( )
2018-08-10 04:16:20 +00:00
2020-08-13 20:10:06 +00:00
if ( LLVM_FOUND AND OS_LINUX AND USE_LIBCXX )
message ( WARNING "Option USE_INTERNAL_LLVM_LIBRARY is not set but the LLVM library from OS packages in Linux is incompatible with libc++ ABI. LLVM Will be disabled." )
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
endif ( )
2018-05-09 20:31:03 +00:00
else ( )
2020-08-13 20:10:06 +00:00
if ( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR )
message ( WARNING "Option ENABLE_EMBEDDED_COMPILER is set but LLVM library cannot build if build directory is the same as source directory." )
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
elseif ( SPLIT_SHARED_LIBRARIES )
# llvm-tablegen cannot find shared libraries that we build. Probably can be easily fixed.
message ( WARNING "Option ENABLE_EMBEDDED_COMPILER is not compatible with SPLIT_SHARED_LIBRARIES. Build of LLVM will be disabled." )
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
elseif ( NOT ARCH_AMD64 )
# It's not supported yet, but you can help.
message ( WARNING "Option ENABLE_EMBEDDED_COMPILER is only available for x86_64. Build of LLVM will be disabled." )
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
elseif ( SANITIZE STREQUAL "undefined" )
# llvm-tblgen, that is used during LLVM build, doesn't work with UBSan.
message ( WARNING "Option ENABLE_EMBEDDED_COMPILER does not work with UBSan, because 'llvm-tblgen' tool from LLVM has undefined behaviour. Build of LLVM will be disabled." )
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
else ( )
set ( LLVM_FOUND 1 )
set ( USE_EMBEDDED_COMPILER 1 )
set ( LLVM_VERSION "9.0.0bundled" )
set ( LLVM_INCLUDE_DIRS
$ { C l i c k H o u s e _ S O U R C E _ D I R } / c o n t r i b / l l v m / l l v m / i n c l u d e
$ { C l i c k H o u s e _ B I N A R Y _ D I R } / c o n t r i b / l l v m / l l v m / i n c l u d e
)
set ( LLVM_LIBRARY_DIRS ${ ClickHouse_BINARY_DIR } /contrib/llvm/llvm )
endif ( )
2017-11-12 12:58:40 +00:00
endif ( )
2018-02-26 18:34:22 +00:00
2020-08-13 20:10:06 +00:00
if ( LLVM_FOUND )
message ( STATUS "LLVM include Directory: ${LLVM_INCLUDE_DIRS}" )
message ( STATUS "LLVM library Directory: ${LLVM_LIBRARY_DIRS}" )
message ( STATUS "LLVM C++ compiler flags: ${LLVM_CXXFLAGS}" )
2018-02-26 18:34:22 +00:00
endif ( )
2017-11-12 12:58:40 +00:00
endif ( )
2018-05-29 17:54:48 +00:00
2019-12-18 16:08:11 +00:00
# This list was generated by listing all LLVM libraries, compiling the binary and removing all libraries while it still compiles.
2019-12-18 16:15:03 +00:00
set ( REQUIRED_LLVM_LIBRARIES
2019-12-18 16:08:11 +00:00
L L V M O r c J I T
L L V M E x e c u t i o n E n g i n e
L L V M R u n t i m e D y l d
L L V M X 8 6 C o d e G e n
L L V M X 8 6 D e s c
L L V M X 8 6 I n f o
L L V M X 8 6 U t i l s
L L V M A s m P r i n t e r
L L V M D e b u g I n f o D W A R F
L L V M G l o b a l I S e l
L L V M S e l e c t i o n D A G
L L V M M C D i s a s s e m b l e r
L L V M P a s s e s
L L V M C o d e G e n
L L V M i p o
L L V M B i t W r i t e r
L L V M I n s t r u m e n t a t i o n
L L V M S c a l a r O p t s
L L V M A g g r e s s i v e I n s t C o m b i n e
L L V M I n s t C o m b i n e
L L V M V e c t o r i z e
L L V M T r a n s f o r m U t i l s
L L V M T a r g e t
L L V M A n a l y s i s
L L V M P r o f i l e D a t a
L L V M O b j e c t
L L V M B i t R e a d e r
L L V M C o r e
L L V M R e m a r k s
L L V M B i t s t r e a m R e a d e r
L L V M M C P a r s e r
L L V M M C
L L V M B i n a r y F o r m a t
L L V M D e b u g I n f o C o d e V i e w
L L V M S u p p o r t
L L V M D e m a n g l e
)
#function(llvm_libs_all REQUIRED_LLVM_LIBRARIES)
# llvm_map_components_to_libnames (result all)
# if (USE_STATIC_LIBRARIES OR NOT "LLVM" IN_LIST result)
# list (REMOVE_ITEM result "LTO" "LLVM")
# else()
# set (result "LLVM")
# endif ()
# list (APPEND result ${CMAKE_DL_LIBS} ${ZLIB_LIBRARIES})
# set (${REQUIRED_LLVM_LIBRARIES} ${result} PARENT_SCOPE)
#endfunction()