From e692a88196c921a5d578afd7487aa8012809cf21 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Mon, 9 Sep 2019 21:19:43 +0300 Subject: [PATCH] CMake now works Example: -DCMAKE_SYSTEM_NAME=Darwin -DSDK_PATH=${HOME}/stuff/MacOSX10.12.sdk -DLINKER_NAME=${HOME}/.local/bin/ld64 --- CMakeLists.txt | 3 +++ cmake/darwin/default_libs.cmake | 39 +++++++++++++++++++++++++++++++++ cmake/darwin/sdk.cmake | 11 ++++++++++ cmake/find/cxx.cmake | 16 +------------- cmake/target.cmake | 28 ++++++++++++++--------- dbms/src/Common/StackTrace.cpp | 1 + 6 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 cmake/darwin/default_libs.cmake create mode 100644 cmake/darwin/sdk.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 91ccbcb2406..ccfe81567ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,6 +205,9 @@ endif () include(cmake/dbms_glob_sources.cmake) if (OS_LINUX) include(cmake/linux/default_libs.cmake) +elseif (OS_DARWIN) + include(cmake/darwin/sdk.cmake) + include(cmake/darwin/default_libs.cmake) endif () ###################################### diff --git a/cmake/darwin/default_libs.cmake b/cmake/darwin/default_libs.cmake new file mode 100644 index 00000000000..b0bb8e5e84d --- /dev/null +++ b/cmake/darwin/default_libs.cmake @@ -0,0 +1,39 @@ +set (DEFAULT_LIBS "-nodefaultlibs") + +if (NOT COMPILER_CLANG) + message (FATAL_ERROR "Darwin build is supported only for Clang") +endif () + +set (DEFAULT_LIBS "${DEFAULT_LIBS} ${COVERAGE_OPTION} -lc -lm -lrt -lpthread -ldl") + +message(STATUS "Default libraries: ${DEFAULT_LIBS}") + +set(CMAKE_CXX_STANDARD_LIBRARIES ${DEFAULT_LIBS}) +set(CMAKE_C_STANDARD_LIBRARIES ${DEFAULT_LIBS}) + +# Global libraries + +add_library(global-libs INTERFACE) + +# Unfortunately '-pthread' doesn't work with '-nodefaultlibs'. +# Just make sure we have pthreads at all. +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + +include (cmake/find/cxx.cmake) + +add_library(global-group INTERFACE) + +target_link_libraries(global-group INTERFACE + -Wl,--start-group + $ + -Wl,--end-group +) + +link_libraries(global-group) + +# FIXME: remove when all contribs will get custom cmake lists +install( + TARGETS global-group global-libs + EXPORT global +) diff --git a/cmake/darwin/sdk.cmake b/cmake/darwin/sdk.cmake new file mode 100644 index 00000000000..382b3a31ba2 --- /dev/null +++ b/cmake/darwin/sdk.cmake @@ -0,0 +1,11 @@ +option (SDK_PATH "Path to the SDK to build with" "") + +if (NOT EXISTS "${SDK_PATH}/SDKSettings.plist") + message (FATAL_ERROR "Wrong SDK path provided: ${SDK_PATH}") +endif () + +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isysroot ${SDK_PATH}") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isysroot ${SDK_PATH}") + +set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -isysroot ${SDK_PATH}") +set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -isysroot ${SDK_PATH}") diff --git a/cmake/find/cxx.cmake b/cmake/find/cxx.cmake index f84a76183ec..4f2430228d4 100644 --- a/cmake/find/cxx.cmake +++ b/cmake/find/cxx.cmake @@ -1,25 +1,11 @@ -if (OS_LINUX AND COMPILER_CLANG) +if (COMPILER_CLANG) option (USE_LIBCXX "Use libc++ and libc++abi instead of libstdc++" ON) option (USE_INTERNAL_LIBCXX_LIBRARY "Set to FALSE to use system libcxx and libcxxabi libraries instead of bundled" ${NOT_UNBUNDLED}) endif() if (USE_LIBCXX) set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More checks in debug build. -endif () -# FIXME: make better check for submodule presence -if (USE_INTERNAL_LIBCXX_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcxx/include/vector") - message (WARNING "submodule contrib/libcxx is missing. to fix try run: \n git submodule update --init --recursive") - set (USE_INTERNAL_LIBCXX_LIBRARY 0) -endif () - -# FIXME: make better check for submodule presence -if (USE_INTERNAL_LIBCXX_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcxxabi/src") - message (WARNING "submodule contrib/libcxxabi is missing. to fix try run: \n git submodule update --init --recursive") - set (USE_INTERNAL_LIBCXX_LIBRARY 0) -endif () - -if (USE_LIBCXX) if (NOT USE_INTERNAL_LIBCXX_LIBRARY) find_library (LIBCXX_LIBRARY c++) find_library (LIBCXXFS_LIBRARY c++fs) diff --git a/cmake/target.cmake b/cmake/target.cmake index 8bbdce87109..be235a26ce3 100644 --- a/cmake/target.cmake +++ b/cmake/target.cmake @@ -30,13 +30,18 @@ endif () string(REGEX MATCH "-?[0-9]+(.[0-9]+)?$" COMPILER_POSTFIX ${CMAKE_CXX_COMPILER}) -find_program (LLD_PATH NAMES "lld${COMPILER_POSTFIX}" "lld") -find_program (GOLD_PATH NAMES "gold") +if (OS_LINUX) + find_program (LLD_PATH NAMES "lld${COMPILER_POSTFIX}" "lld") + find_program (GOLD_PATH NAMES "gold") +endif() -if (COMPILER_CLANG AND LLD_PATH AND NOT LINKER_NAME) - set (LINKER_NAME "lld") -elseif (GOLD_PATH) - set (LINKER_NAME "gold") +option (LINKER_NAME "Linker name or full path") +if (NOT LINKER_NAME) + if (COMPILER_CLANG AND LLD_PATH) + set (LINKER_NAME "lld") + elseif (GOLD_PATH) + set (LINKER_NAME "gold") + endif () endif () if (LINKER_NAME) @@ -45,12 +50,15 @@ if (LINKER_NAME) endif () if (CMAKE_CROSSCOMPILING) - if (NOT COMPILER_CLANG OR NOT LINKER_NAME MATCHES "lld") - message (FATAL "Cross-compilation supported only for Clang compiler and LLD linker") - endif () - if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set (CMAKE_SYSTEM_PROCESSOR x86_64) set (CMAKE_C_COMPILER_TARGET x86_64-apple-darwin) set (CMAKE_CXX_COMPILER_TARGET x86_64-apple-darwin) + + set (HAS_PRE_1970_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE) + set (HAS_PRE_1970_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE) + + set( HAS_POST_2038_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE) + set( HAS_POST_2038_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE) endif () endif () diff --git a/dbms/src/Common/StackTrace.cpp b/dbms/src/Common/StackTrace.cpp index 9981d0941aa..9694e33a2dd 100644 --- a/dbms/src/Common/StackTrace.cpp +++ b/dbms/src/Common/StackTrace.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include