From 4d2989e42f5f2e16835385246b6be509a31e5847 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 9 May 2018 23:31:03 +0300 Subject: [PATCH] Added support for bundled LLVM libraries #2277 --- .gitmodules | 3 + cmake/find_llvm.cmake | 131 +++++++------------------- contrib/CMakeLists.txt | 4 + contrib/llvm | 1 + dbms/src/Server/Compiler-7.0.0bundled | 1 + 5 files changed, 42 insertions(+), 98 deletions(-) create mode 160000 contrib/llvm create mode 120000 dbms/src/Server/Compiler-7.0.0bundled diff --git a/.gitmodules b/.gitmodules index a1ba915b91e..1f392b73c83 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,6 @@ [submodule "contrib/boost"] path = contrib/boost url = https://github.com/ClickHouse-Extras/boost.git +[submodule "contrib/llvm"] + path = contrib/llvm + url = https://github.com/ClickHouse-Extras/llvm diff --git a/cmake/find_llvm.cmake b/cmake/find_llvm.cmake index 8a8ad33a38c..f12798449d7 100644 --- a/cmake/find_llvm.cmake +++ b/cmake/find_llvm.cmake @@ -1,107 +1,42 @@ -option (ENABLE_EMBEDDED_COMPILER "Set to TRUE to enable support for 'compile' option for query execution" ${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." 0) if (ENABLE_EMBEDDED_COMPILER) - # Based on source code of YT. - # Authors: Ivan Puzyrevskiy, Alexey Lukyanchikov, Ruslan Savchenko. - # Find LLVM includes and libraries. - # - # LLVM_VERSION - LLVM version. - # LLVM_INCLUDE_DIRS - Directory containing LLVM headers. - # LLVM_LIBRARY_DIRS - Directory containing LLVM libraries. - # LLVM_CXXFLAGS - C++ compiler flags for files that include LLVM headers. - # LLVM_FOUND - True if LLVM was found. + 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 () - # llvm_map_components_to_libraries - Maps LLVM used components to required libraries. - # Usage: llvm_map_components_to_libraries(REQUIRED_LLVM_LIBRARIES core jit interpreter native ...) + if (NOT USE_INTERNAL_LZ4_LIBRARY) + set (LLVM_PATHS "/usr/local/lib/llvm") - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(LLVM_VERSION_POSTFIX "${COMPILER_POSTFIX}" CACHE STRING "") + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + find_package(LLVM CONFIG PATHS ${LLVM_PATHS}) + else () + find_package(LLVM 5 CONFIG PATHS ${LLVM_PATHS}) + endif () + + if (LLVM_FOUND) + # Remove dynamically-linked zlib and libedit from LLVM's dependencies: + set_target_properties(LLVMSupport PROPERTIES INTERFACE_LINK_LIBRARIES "-lpthread;LLVMDemangle") + set_target_properties(LLVMLineEditor PROPERTIES INTERFACE_LINK_LIBRARIES "LLVMSupport") + + option(LLVM_HAS_RTTI "Enable if LLVM was build with RTTI enabled" ON) + set (USE_EMBEDDED_COMPILER 1) + endif() else() - if (ARCH_FREEBSD) - set(LLVM_VERSION_POSTFIX "50" CACHE STRING "") - else() - set(LLVM_VERSION_POSTFIX "-5.0" CACHE STRING "") - endif() - endif() - - find_program(LLVM_CONFIG_EXECUTABLE - NAMES llvm-config${LLVM_VERSION_POSTFIX} llvm-config llvm-config-devel - PATHS $ENV{LLVM_ROOT}/bin) - - mark_as_advanced(LLVM_CONFIG_EXECUTABLE) - - if(NOT LLVM_CONFIG_EXECUTABLE) - message(WARNING "Cannot find LLVM (looking for `llvm-config${LLVM_VERSION_POSTFIX}`, `llvm-config`, `llvm-config-devel`). Please, provide LLVM_ROOT environment variable.") - else() - set(LLVM_FOUND TRUE) - - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --version - OUTPUT_VARIABLE LLVM_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - - if(LLVM_VERSION VERSION_LESS "5") - message(FATAL_ERROR "LLVM 5+ is required. You have ${LLVM_VERSION} (${LLVM_CONFIG_EXECUTABLE})") - endif() - - message(STATUS "LLVM config: ${LLVM_CONFIG_EXECUTABLE}; version: ${LLVM_VERSION}") - - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir - OUTPUT_VARIABLE LLVM_INCLUDE_DIRS - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir - OUTPUT_VARIABLE LLVM_LIBRARY_DIRS - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --cxxflags - OUTPUT_VARIABLE LLVM_CXXFLAGS - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --targets-built - OUTPUT_VARIABLE LLVM_TARGETS_BUILT - OUTPUT_STRIP_TRAILING_WHITESPACE) - - string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT}") - - if (USE_STATIC_LIBRARIES) - set (LLVM_CONFIG_ADD "--link-static") - endif() - - # Get the link libs we need. - function(llvm_map_components_to_libraries RESULT) - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} ${LLVM_CONFIG_ADD} --libs ${ARGN} - OUTPUT_VARIABLE _tmp - OUTPUT_STRIP_TRAILING_WHITESPACE) - - string(REPLACE " " ";" _libs_module "${_tmp}") - - #message(STATUS "LLVM Libraries for '${ARGN}': ${_libs_module}") - - execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs ${ARGN} - OUTPUT_VARIABLE _libs_system - OUTPUT_STRIP_TRAILING_WHITESPACE) - - string(REPLACE "\n" " " _libs_system "${_libs_system}") - string(REPLACE " " " " _libs_system "${_libs_system}") - string(REPLACE " " ";" _libs_system "${_libs_system}") - - set(${RESULT} ${_libs_module} ${_libs_system} PARENT_SCOPE) - endfunction(llvm_map_components_to_libraries) - - message(STATUS "LLVM Include Directory: ${LLVM_INCLUDE_DIRS}") - message(STATUS "LLVM Library Directory: ${LLVM_LIBRARY_DIRS}") - message(STATUS "LLVM C++ Compiler: ${LLVM_CXXFLAGS}") - endif() - - if (LLVM_FOUND AND LLVM_INCLUDE_DIRS AND LLVM_LIBRARY_DIRS) + set (LLVM_FOUND 1) set (USE_EMBEDDED_COMPILER 1) + set (LLVM_VERSION "7.0.0bundled") + set (LLVM_INCLUDE_DIRS ${ClickHouse_SOURCE_DIR}/contrib/llvm/llvm/include ${ClickHouse_BINARY_DIR}/contrib/llvm/llvm/include) + set (LLVM_LIBRARY_DIRS ${ClickHouse_BINARY_DIR}/contrib/llvm/llvm) + endif() + + 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}") endif() endif() diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 118c7009044..18cdc15b3fd 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -150,3 +150,7 @@ if (USE_INTERNAL_POCO_LIBRARY) target_include_directories(Crypto PUBLIC ${OPENSSL_INCLUDE_DIR}) endif () endif () + +if (USE_INTERNAL_LLVM_LIBRARY) + add_subdirectory (llvm/llvm) +endif () diff --git a/contrib/llvm b/contrib/llvm new file mode 160000 index 00000000000..6b3975cf38d --- /dev/null +++ b/contrib/llvm @@ -0,0 +1 @@ +Subproject commit 6b3975cf38d5c9436e1311b7e54ad93ef1a9aa9c diff --git a/dbms/src/Server/Compiler-7.0.0bundled b/dbms/src/Server/Compiler-7.0.0bundled new file mode 120000 index 00000000000..eeeb5bbc2c0 --- /dev/null +++ b/dbms/src/Server/Compiler-7.0.0bundled @@ -0,0 +1 @@ +Compiler-7.0.0 \ No newline at end of file