Using libcxx as a submodule [#CLICKHOUSE-2]

This commit is contained in:
Alexey Milovidov 2018-12-28 06:24:03 +03:00
parent 3777ded5b6
commit 130b427ff7
6 changed files with 73 additions and 64 deletions

View File

@ -151,7 +151,44 @@ set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 ${
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3 -ggdb3 -fno-inline ${CMAKE_C_FLAGS_ADD}") set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3 -ggdb3 -fno-inline ${CMAKE_C_FLAGS_ADD}")
include (cmake/use_libcxx.cmake) # Uses MAKE_STATIC_LIBRARIES
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads)
include (cmake/test_compiler.cmake)
include (cmake/arch.cmake)
if (OS_LINUX AND COMPILER_CLANG)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
option (USE_LIBCXX "Use libc++ and libc++abi instead of libstdc++ (only make sense on Linux with Clang)" ${HAVE_LIBCXX})
if (USE_LIBCXX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") # Ok for clang6, for older can cause 'not used option' warning
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More checks in debug build.
endif ()
endif ()
if (USE_LIBCXX)
set (STATIC_STDLIB_FLAGS "")
else ()
set (STATIC_STDLIB_FLAGS "-static-libgcc -static-libstdc++")
endif ()
if (MAKE_STATIC_LIBRARIES AND NOT APPLE AND NOT (COMPILER_CLANG AND OS_FREEBSD))
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STATIC_STDLIB_FLAGS}")
# Along with executables, we also build example of shared library for "library dictionary source"; and it also should be self-contained.
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${STATIC_STDLIB_FLAGS}")
endif ()
if (USE_STATIC_LIBRARIES AND HAVE_NO_PIE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG_NO_PIE}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG_NO_PIE}")
endif ()
if (NOT MAKE_STATIC_LIBRARIES) if (NOT MAKE_STATIC_LIBRARIES)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)

View File

@ -16,7 +16,7 @@ if (LIBCXX_LIBRARY AND LIBCXX_INCLUDE_DIR)
else () else ()
set (LIBCXX_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx/include) set (LIBCXX_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx/include)
set (USE_INTERNAL_LIBCXX_LIBRARY 1) set (USE_INTERNAL_LIBCXX_LIBRARY 1)
set (LIBCXX_LIBRARY cxx) set (LIBCXX_LIBRARY cxx_static)
endif () endif ()
message (STATUS "Using libcxx: ${LIBCXX_INCLUDE_DIR} : ${LIBCXX_LIBRARY}") message (STATUS "Using libcxx: ${LIBCXX_INCLUDE_DIR} : ${LIBCXX_LIBRARY}")

View File

@ -16,7 +16,7 @@ if (LIBCXXABI_LIBRARY AND LIBCXXABI_INCLUDE_DIR)
else () else ()
set (LIBCXXABI_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxxabi/include) set (LIBCXXABI_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxxabi/include)
set (USE_INTERNAL_LIBCXXABI_LIBRARY 1) set (USE_INTERNAL_LIBCXXABI_LIBRARY 1)
set (LIBCXXABI_LIBRARY cxxabi) set (LIBCXXABI_LIBRARY cxxabi_static)
endif () endif ()
message (STATUS "Using libcxxabi: ${LIBCXXABI_INCLUDE_DIR} : ${LIBCXXABI_LIBRARY}") message (STATUS "Using libcxxabi: ${LIBCXXABI_INCLUDE_DIR} : ${LIBCXXABI_LIBRARY}")

View File

@ -1,49 +0,0 @@
# Uses MAKE_STATIC_LIBRARIES
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads)
include (cmake/test_compiler.cmake)
include (cmake/arch.cmake)
if (OS_LINUX AND COMPILER_CLANG)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
option (USE_LIBCXX "Use libc++ and libc++abi instead of libstdc++ (only make sense on Linux with Clang)" ${HAVE_LIBCXX})
set (LIBCXX_PATH "" CACHE STRING "Use custom path for libc++. It should be used for MSan.")
if (USE_LIBCXX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") # Ok for clang6, for older can cause 'not used option' warning
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More checks in debug build.
if (MAKE_STATIC_LIBRARIES)
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.builtins-${CMAKE_SYSTEM_PROCESSOR}.a OUTPUT_VARIABLE BUILTINS_LIB_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
link_libraries (-nodefaultlibs -Wl,-Bstatic -stdlib=libc++ c++ c++abi gcc_eh ${BUILTINS_LIB_PATH} rt -Wl,-Bdynamic dl pthread m c)
else ()
link_libraries (-stdlib=libc++ c++ c++abi)
endif ()
if (LIBCXX_PATH)
# include_directories (SYSTEM BEFORE "${LIBCXX_PATH}/include" "${LIBCXX_PATH}/include/c++/v1")
link_directories ("${LIBCXX_PATH}/lib")
endif ()
endif ()
endif ()
if (USE_LIBCXX)
set (STATIC_STDLIB_FLAGS "")
else ()
set (STATIC_STDLIB_FLAGS "-static-libgcc -static-libstdc++")
endif ()
if (MAKE_STATIC_LIBRARIES AND NOT APPLE AND NOT (COMPILER_CLANG AND OS_FREEBSD))
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STATIC_STDLIB_FLAGS}")
# Along with executables, we also build example of shared library for "library dictionary source"; and it also should be self-contained.
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${STATIC_STDLIB_FLAGS}")
endif ()
if (USE_STATIC_LIBRARIES AND HAVE_NO_PIE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG_NO_PIE}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG_NO_PIE}")
endif ()

View File

@ -193,18 +193,8 @@ if (USE_INTERNAL_LLVM_LIBRARY)
add_subdirectory (llvm/llvm) add_subdirectory (llvm/llvm)
endif () endif ()
if (USE_INTERNAL_LIBCXX_LIBRARY)
set (LIBCXX_STANDALONE_BUILD 1)
set (PACKAGE_NAME libcxx)
set (PACKAGE_VERSION 8.0.0svn)
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set (PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
set (LIBCXX_ENABLE_SHARED 0)
set (LIBCXX_ENABLE_STATIC 1)
add_subdirectory(libcxx)
endif()
if (USE_INTERNAL_LIBCXXABI_LIBRARY) if (USE_INTERNAL_LIBCXXABI_LIBRARY)
set (LIBCXXABI_USE_COMPILER_RT 1 CACHE INTERNAL "")
set (PACKAGE_NAME libcxxabi) set (PACKAGE_NAME libcxxabi)
set (PACKAGE_VERSION 8.0.0svn) set (PACKAGE_VERSION 8.0.0svn)
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
@ -215,6 +205,21 @@ if (USE_INTERNAL_LIBCXXABI_LIBRARY)
add_subdirectory(libcxxabi) add_subdirectory(libcxxabi)
endif() endif()
if (USE_INTERNAL_LIBCXX_LIBRARY)
set (LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libcxx")
set (LIBCXXABI_USE_COMPILER_RT 1 CACHE INTERNAL "")
set (LIBCXX_CXX_ABI "libcxxabi" CACHE INTERNAL "")
set (LIBCXX_STANDALONE_BUILD 1)
set (LIBCXX_USE_COMPILER_RT 1)
set (PACKAGE_NAME libcxx)
set (PACKAGE_VERSION 8.0.0svn)
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set (PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
set (LIBCXX_ENABLE_SHARED 0)
set (LIBCXX_ENABLE_STATIC 1)
add_subdirectory(libcxx)
endif()
if (USE_INTERNAL_LIBGSASL_LIBRARY) if (USE_INTERNAL_LIBGSASL_LIBRARY)
add_subdirectory(libgsasl) add_subdirectory(libgsasl)
endif() endif()

View File

@ -95,6 +95,20 @@ if (NOT USE_INTERNAL_BOOST_LIBRARY)
target_include_directories (common BEFORE PUBLIC ${Boost_INCLUDE_DIRS}) target_include_directories (common BEFORE PUBLIC ${Boost_INCLUDE_DIRS})
endif () endif ()
if (USE_LIBCXX)
if (MAKE_STATIC_LIBRARIES)
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.builtins-${CMAKE_SYSTEM_PROCESSOR}.a
OUTPUT_VARIABLE BUILTINS_LIB_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
set (DEFAULT_LIBS -nodefaultlibs
-Wl,-Bstatic -stdlib=libc++ ${LIBCXX_LIBRARY} ${LIBCXXABI_LIBRARY} gcc_eh ${BUILTINS_LIB_PATH} rt
-Wl,-Bdynamic dl pthread m c)
endif ()
endif()
target_link_libraries (common target_link_libraries (common
PRIVATE PRIVATE
pocoext pocoext
@ -107,9 +121,11 @@ target_link_libraries (common
PUBLIC PUBLIC
${Boost_SYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}
PRIVATE PRIVATE
${DEFAULT_LIBS}
${MALLOC_LIBRARIES} ${MALLOC_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${MEMCPY_LIBRARIES}) ${MEMCPY_LIBRARIES}
)
if (RT_LIBRARY) if (RT_LIBRARY)
target_link_libraries (common PRIVATE ${RT_LIBRARY}) target_link_libraries (common PRIVATE ${RT_LIBRARY})