2020-08-14 00:36:38 +00:00
if ( APPLE OR SPLIT_SHARED_LIBRARIES OR NOT ARCH_AMD64 )
set ( ENABLE_EMBEDDED_COMPILER OFF CACHE INTERNAL "" )
endif ( )
2021-04-30 07:31:12 +00:00
option ( ENABLE_EMBEDDED_COMPILER "Enable support for 'compile_expressions' option for query execution" ON )
2020-08-14 00:36:38 +00:00
# Broken in macos. TODO: update clang, re-test, enable on Apple
if ( ENABLE_EMBEDDED_COMPILER AND NOT SPLIT_SHARED_LIBRARIES AND ARCH_AMD64 AND NOT ( SANITIZE STREQUAL "undefined" ) )
2019-12-18 19:50:12 +00:00
option ( USE_INTERNAL_LLVM_LIBRARY "Use bundled or system LLVM library." ${ NOT_UNBUNDLED } )
2020-08-14 00:36:38 +00:00
endif ( )
2017-11-12 12:58:40 +00:00
2020-08-14 15:44:04 +00:00
if ( NOT ENABLE_EMBEDDED_COMPILER )
if ( USE_INTERNAL_LLVM_LIBRARY )
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Cannot use internal LLVM library with ENABLE_EMBEDDED_COMPILER=OFF" )
endif ( )
return ( )
endif ( )
2017-11-12 12:58:40 +00:00
2020-08-14 00:36:38 +00:00
if ( NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/llvm/llvm/CMakeLists.txt" )
if ( USE_INTERNAL_LLVM_LIBRARY )
message ( WARNING "submodule contrib/llvm is missing. to fix try run: \n git submodule update --init --recursive" )
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Can't fidd internal LLVM library" )
endif ( )
set ( MISSING_INTERNAL_LLVM_LIBRARY 1 )
2020-08-14 15:44:04 +00:00
endif ( )
2017-11-12 12:58:40 +00:00
2020-08-14 15:44:04 +00:00
if ( NOT USE_INTERNAL_LLVM_LIBRARY )
2021-05-01 05:09:20 +00:00
set ( LLVM_PATHS "/usr/local/lib/llvm" "/usr/lib/llvm" )
2018-07-20 23:44:31 +00:00
2021-05-01 05:08:36 +00:00
foreach ( llvm_v 11.1 11 )
if ( NOT LLVM_FOUND )
find_package ( LLVM ${ llvm_v } CONFIG PATHS ${ LLVM_PATHS } )
endif ( )
endforeach ( )
2018-05-07 08:59:24 +00:00
2020-08-14 15:44:04 +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-08-10 04:16:20 +00:00
2020-08-14 15:44:04 +00:00
option ( LLVM_HAS_RTTI "Enable if LLVM was build with RTTI enabled" ON )
set ( USE_EMBEDDED_COMPILER 1 )
2018-05-09 20:31:03 +00:00
else ( )
2020-08-14 15:44:04 +00:00
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Can't find system LLVM" )
set ( USE_EMBEDDED_COMPILER 0 )
2017-11-12 12:58:40 +00:00
endif ( )
2018-02-26 18:34:22 +00:00
2020-08-18 18:03:37 +00:00
if ( LLVM_FOUND AND OS_LINUX AND USE_LIBCXX AND NOT FORCE_LLVM_WITH_LIBCXX )
message ( WARNING "Option USE_INTERNAL_LLVM_LIBRARY is not set but the LLVM library from OS packages "
" i n L i n u x i s i n c o m p a t i b l e w i t h l i b c + + A B I . L L V M W i l l b e d i s a b l e d . F o r c e : - D F O R C E _ L L V M _ W I T H _ L I B C X X = O N " )
2020-08-14 15:44:04 +00:00
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Unsupported LLVM configuration, cannot enable LLVM" )
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
endif ( )
2020-08-14 00:36:38 +00:00
endif ( )
if ( NOT LLVM_FOUND AND NOT MISSING_INTERNAL_LLVM_LIBRARY )
2020-08-14 15:44:04 +00:00
if ( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR )
2020-08-14 00:36:38 +00:00
message ( WARNING "Option ENABLE_EMBEDDED_COMPILER is set but internal LLVM library cannot build if build directory is the same as source directory." )
2020-08-14 15:44:04 +00:00
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.
2020-08-14 00:36:38 +00:00
message ( WARNING "Option USE_INTERNAL_LLVM_LIBRARY is not compatible with SPLIT_SHARED_LIBRARIES. Build of LLVM will be disabled." )
2020-08-14 15:44:04 +00:00
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
elseif ( NOT ARCH_AMD64 )
# It's not supported yet, but you can help.
2020-08-14 00:36:38 +00:00
message ( WARNING "Option USE_INTERNAL_LLVM_LIBRARY is only available for x86_64. Build of LLVM will be disabled." )
2020-08-14 15:44:04 +00:00
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.
2020-08-14 00:36:38 +00:00
message ( WARNING "Option USE_INTERNAL_LLVM_LIBRARY does not work with UBSan, because 'llvm-tblgen' tool from LLVM has undefined behaviour. Build of LLVM will be disabled." )
2020-08-14 15:44:04 +00:00
set ( LLVM_FOUND 0 )
set ( USE_EMBEDDED_COMPILER 0 )
else ( )
2020-08-14 00:36:38 +00:00
set ( USE_INTERNAL_LLVM_LIBRARY ON )
2020-08-14 15:44:04 +00:00
set ( LLVM_FOUND 1 )
set ( USE_EMBEDDED_COMPILER 1 )
set ( LLVM_VERSION "9.0.0bundled" )
set ( LLVM_INCLUDE_DIRS
2020-08-14 00:36:38 +00:00
" $ { 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 "
2020-08-14 15:44:04 +00:00
)
2020-08-14 00:36:38 +00:00
set ( LLVM_LIBRARY_DIRS "${ClickHouse_BINARY_DIR}/contrib/llvm/llvm" )
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
2020-08-14 15:44:04 +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}" )
else ( )
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Can't enable LLVM" )
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 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()