2018-10-16 09:30:51 +00:00
# Broken in macos. TODO: update clang, re-test, enable
if ( NOT APPLE )
option ( ENABLE_EMBEDDED_COMPILER "Set to TRUE to enable support for 'compile' option for query execution" 1 )
option ( USE_INTERNAL_LLVM_LIBRARY "Use bundled or system LLVM library. Default: system library for quicker developer builds." ${ APPLE } )
endif ( )
2017-11-12 12:58:40 +00:00
2018-02-26 18:34:22 +00:00
if ( ENABLE_EMBEDDED_COMPILER )
2018-05-09 20:31:03 +00:00
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 )
2018-04-26 15:36:27 +00:00
endif ( )
2017-11-12 12:58:40 +00:00
2018-05-09 20:38:03 +00:00
if ( NOT USE_INTERNAL_LLVM_LIBRARY )
2018-05-09 20:31:03 +00:00
set ( LLVM_PATHS "/usr/local/lib/llvm" )
2017-11-12 12:58:40 +00:00
2018-05-13 10:34:29 +00:00
if ( LLVM_VERSION )
find_package ( LLVM ${ LLVM_VERSION } CONFIG PATHS ${ LLVM_PATHS } )
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
find_package ( LLVM ${ CMAKE_CXX_COMPILER_VERSION } CONFIG PATHS ${ LLVM_PATHS } )
2018-05-09 20:31:03 +00:00
else ( )
2018-11-16 12:22:51 +00:00
find_package ( LLVM 7 CONFIG PATHS ${ LLVM_PATHS } )
2018-05-13 10:34:29 +00:00
if ( NOT LLVM_FOUND )
2018-11-16 12:22:51 +00:00
find_package ( LLVM 6 CONFIG PATHS ${ LLVM_PATHS } )
2018-05-13 10:34:29 +00:00
endif ( )
if ( NOT LLVM_FOUND )
2018-11-16 12:22:51 +00:00
find_package ( LLVM 5 CONFIG PATHS ${ LLVM_PATHS } )
2018-05-13 10:34:29 +00:00
endif ( )
2018-05-09 20:31:03 +00:00
endif ( )
2018-05-07 08:59:24 +00:00
2018-07-20 23:44:31 +00:00
if ( LLVM_FOUND )
2018-07-21 00:11:41 +00:00
find_library ( LLD_LIBRARY_TEST lldCore PATHS ${ LLVM_LIBRARY_DIRS } )
2018-07-23 18:20:54 +00:00
find_path ( LLD_INCLUDE_DIR_TEST NAMES lld/Core/AbsoluteAtom.h PATHS ${ LLVM_INCLUDE_DIRS } )
2018-07-20 23:44:31 +00:00
if ( NOT LLD_LIBRARY_TEST OR NOT LLD_INCLUDE_DIR_TEST )
set ( LLVM_FOUND 0 )
2018-07-23 16:50:23 +00:00
message ( WARNING "liblld (${LLD_LIBRARY_TEST}, ${LLD_INCLUDE_DIR_TEST}) not found in ${LLVM_INCLUDE_DIRS} ${LLVM_LIBRARY_DIRS}. Disabling internal compiler." )
2018-07-20 23:44:31 +00:00
endif ( )
endif ( )
2018-05-09 20:31:03 +00:00
if ( LLVM_FOUND )
# Remove dynamically-linked zlib and libedit from LLVM's dependencies:
2018-06-18 21:13:11 +00:00
set_target_properties ( LLVMSupport PROPERTIES INTERFACE_LINK_LIBRARIES "-lpthread;LLVMDemangle;${ZLIB_LIBRARIES}" )
2018-05-09 20:31:03 +00:00
set_target_properties ( LLVMLineEditor PROPERTIES INTERFACE_LINK_LIBRARIES "LLVMSupport" )
2018-05-07 08:59:24 +00:00
2018-05-09 20:31:03 +00:00
option ( LLVM_HAS_RTTI "Enable if LLVM was build with RTTI enabled" ON )
set ( USE_EMBEDDED_COMPILER 1 )
2018-06-14 23:29:29 +00:00
else ( )
set ( USE_EMBEDDED_COMPILER 0 )
2017-11-12 12:58:40 +00:00
endif ( )
2018-08-10 04:16:20 +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 ( )
set ( LLVM_FOUND 1 )
2018-04-25 05:59:48 +00:00
set ( USE_EMBEDDED_COMPILER 1 )
2018-05-09 20:31:03 +00:00
set ( LLVM_VERSION "7.0.0bundled" )
2018-05-09 21:07:52 +00:00
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
$ { 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 / c l a n g / 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 / c l a n g / i n c l u d e
2018-05-09 21:12:15 +00:00
$ { 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 / t o o l s / c l a n g / i n c l u d e
2018-05-09 21:07:52 +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 d / i n c l u d e
2018-05-09 21:12:15 +00:00
$ { 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 d / 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 / t o o l s / l l d / i n c l u d e )
2018-05-09 20:31:03 +00:00
set ( LLVM_LIBRARY_DIRS ${ ClickHouse_BINARY_DIR } /contrib/llvm/llvm )
2017-11-12 12:58:40 +00:00
endif ( )
2018-02-26 18:34:22 +00:00
2018-05-09 20:31:03 +00:00
if ( LLVM_FOUND )
message ( STATUS "LLVM version: ${LLVM_PACKAGE_VERSION}" )
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
function ( llvm_libs_all REQUIRED_LLVM_LIBRARIES )
llvm_map_components_to_libnames ( result all )
2019-01-06 03:52:50 +00:00
if ( USE_STATIC_LIBRARIES OR NOT "LLVM" IN_LIST result )
list ( REMOVE_ITEM result "LTO" "LLVM" )
else ( )
set ( result "LLVM" )
endif ( )
2018-05-29 17:54:48 +00:00
if ( TERMCAP_LIBRARY )
list ( APPEND result ${ TERMCAP_LIBRARY } )
endif ( )
2018-06-18 21:13:11 +00:00
list ( APPEND result ${ CMAKE_DL_LIBS } ${ ZLIB_LIBRARIES } )
2018-05-29 17:54:48 +00:00
set ( ${ REQUIRED_LLVM_LIBRARIES } ${ result } PARENT_SCOPE )
endfunction ( )