From 5b60053ef7c5edaeb27fb9be7b61dc7262b024e4 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Wed, 11 Sep 2019 13:01:38 +0300 Subject: [PATCH] [WIP] --- CMakeLists.txt | 14 ++++-------- cmake/darwin/default_libs.cmake | 4 +--- cmake/darwin/sdk.cmake | 8 +++---- cmake/find/cxx.cmake | 5 +++++ cmake/find/snappy.cmake | 34 +++++++++--------------------- cmake/target.cmake | 3 +++ dbms/src/Common/Allocator.h | 5 ++++- dbms/src/Common/TraceCollector.cpp | 2 +- dbms/src/Common/new_delete.cpp | 4 ++++ 9 files changed, 36 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccfe81567ea..b2949ea1b42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,16 +147,9 @@ if (ARCH_NATIVE) set (COMPILER_FLAGS "${COMPILER_FLAGS} -march=native") endif () -if (CMAKE_VERSION VERSION_LESS "3.8.0") - if (NOT MSVC) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") - endif () -else () - set (CMAKE_CXX_STANDARD 17) - set (CMAKE_CXX_EXTENSIONS 0) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS - set (CMAKE_CXX_STANDARD_REQUIRED ON) - set (CXX_FLAGS_INTERNAL_COMPILER "-std=c++17") -endif () +set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_EXTENSIONS 0) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS +set (CMAKE_CXX_STANDARD_REQUIRED ON) if (COMPILER_GCC OR COMPILER_CLANG) # Enable C++14 sized global deallocation functions. It should be enabled by setting -std=c++14 but I'm not sure. @@ -203,6 +196,7 @@ if (OS_LINUX AND NOT SANITIZE) endif () include(cmake/dbms_glob_sources.cmake) + if (OS_LINUX) include(cmake/linux/default_libs.cmake) elseif (OS_DARWIN) diff --git a/cmake/darwin/default_libs.cmake b/cmake/darwin/default_libs.cmake index b0bb8e5e84d..e684a10a08f 100644 --- a/cmake/darwin/default_libs.cmake +++ b/cmake/darwin/default_libs.cmake @@ -4,7 +4,7 @@ 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") +set (DEFAULT_LIBS "${DEFAULT_LIBS} ${COVERAGE_OPTION} -lc -lm -lpthread -ldl") message(STATUS "Default libraries: ${DEFAULT_LIBS}") @@ -25,9 +25,7 @@ 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) diff --git a/cmake/darwin/sdk.cmake b/cmake/darwin/sdk.cmake index 382b3a31ba2..92a9f8f66e5 100644 --- a/cmake/darwin/sdk.cmake +++ b/cmake/darwin/sdk.cmake @@ -4,8 +4,8 @@ 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_C_FLAGS "${CMAKE_C_FLAGS} -isysroot ${SDK_PATH} -mmacosx-version-min=10.14") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isysroot ${SDK_PATH} -mmacosx-version-min=10.14") -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -isysroot ${SDK_PATH}") -set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -isysroot ${SDK_PATH}") +set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -isysroot ${SDK_PATH} -mmacosx-version-min=10.14") +set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -isysroot ${SDK_PATH} -mmacosx-version-min=10.14") diff --git a/cmake/find/cxx.cmake b/cmake/find/cxx.cmake index 4f2430228d4..9a00269cfc6 100644 --- a/cmake/find/cxx.cmake +++ b/cmake/find/cxx.cmake @@ -6,6 +6,11 @@ endif() if (USE_LIBCXX) set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More checks in debug build. + if (OS_DARWIN) + # Use libcxx from SDK + set (USE_INTERNAL_LIBCXX_LIBRARY OFF) + endif () + if (NOT USE_INTERNAL_LIBCXX_LIBRARY) find_library (LIBCXX_LIBRARY c++) find_library (LIBCXXFS_LIBRARY c++fs) diff --git a/cmake/find/snappy.cmake b/cmake/find/snappy.cmake index 1098bbc3e53..a39139ee363 100644 --- a/cmake/find/snappy.cmake +++ b/cmake/find/snappy.cmake @@ -1,27 +1,13 @@ -option(USE_INTERNAL_SNAPPY_LIBRARY "Set to FALSE to use system snappy library instead of bundled" ${NOT_UNBUNDLED}) +option(USE_SNAPPY "Enable support of snappy library" ON) -if(NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/snappy/snappy.h") - if(USE_INTERNAL_SNAPPY_LIBRARY) - message(WARNING "submodule contrib/snappy is missing. to fix try run: \n git submodule update --init --recursive") - set(USE_INTERNAL_SNAPPY_LIBRARY 0) +if (USE_SNAPPY) + option (USE_INTERNAL_SNAPPY_LIBRARY "Set to FALSE to use system snappy library instead of bundled" ${NOT_UNBUNDLED}) + + if(NOT USE_INTERNAL_SNAPPY_LIBRARY) + find_library(SNAPPY_LIBRARY snappy) + else () + set(SNAPPY_LIBRARY snappy) endif() - set(MISSING_INTERNAL_SNAPPY_LIBRARY 1) -endif() -if(NOT USE_INTERNAL_SNAPPY_LIBRARY) - find_library(SNAPPY_LIBRARY snappy) - find_path(SNAPPY_INCLUDE_DIR NAMES snappy.h PATHS ${SNAPPY_INCLUDE_PATHS}) -endif() - -if(SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR) -elseif(NOT MISSING_INTERNAL_SNAPPY_LIBRARY) - set(SNAPPY_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/snappy) - set(USE_INTERNAL_SNAPPY_LIBRARY 1) - set(SNAPPY_LIBRARY snappy) -endif() - -if(SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR) - set(USE_SNAPPY 1) -endif() - -message(STATUS "Using snappy=${USE_SNAPPY}: ${SNAPPY_INCLUDE_DIR} : ${SNAPPY_LIBRARY}") + message (STATUS "Using snappy: ${SNAPPY_LIBRARY}") +endif () diff --git a/cmake/target.cmake b/cmake/target.cmake index be235a26ce3..85cd1cd8357 100644 --- a/cmake/target.cmake +++ b/cmake/target.cmake @@ -61,4 +61,7 @@ if (CMAKE_CROSSCOMPILING) 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 () + + # Don't know why but CXX_STANDARD doesn't work for cross-compilation + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") endif () diff --git a/dbms/src/Common/Allocator.h b/dbms/src/Common/Allocator.h index ad5b0318c91..e6e2f602894 100644 --- a/dbms/src/Common/Allocator.h +++ b/dbms/src/Common/Allocator.h @@ -179,7 +179,10 @@ protected: // MAP_POPULATE to mmap(). This takes some time, but should be faster // overall than having a hot loop interrupted by page faults. static constexpr int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS - | (mmap_populate ? MAP_POPULATE : 0); +#if defined(OS_LINUX) + | (mmap_populate ? MAP_POPULATE : 0) +#endif + ; private: void * allocNoTrack(size_t size, size_t alignment) diff --git a/dbms/src/Common/TraceCollector.cpp b/dbms/src/Common/TraceCollector.cpp index 9451c3f88e5..bd06a200460 100644 --- a/dbms/src/Common/TraceCollector.cpp +++ b/dbms/src/Common/TraceCollector.cpp @@ -46,7 +46,7 @@ TraceCollector::TraceCollector(std::shared_ptr & trace_log_) if (-1 == fcntl(trace_pipe.fds_rw[1], F_SETFL, flags | O_NONBLOCK)) throwFromErrno("Cannot set non-blocking mode of pipe", ErrorCodes::CANNOT_FCNTL); -#if !defined(__FreeBSD__) +#if defined(OS_LINUX) /** Increase pipe size to avoid slowdown during fine-grained trace collection. */ int pipe_size = fcntl(trace_pipe.fds_rw[1], F_GETPIPE_SZ); diff --git a/dbms/src/Common/new_delete.cpp b/dbms/src/Common/new_delete.cpp index f2a85163035..cbf9b93290e 100644 --- a/dbms/src/Common/new_delete.cpp +++ b/dbms/src/Common/new_delete.cpp @@ -1,4 +1,8 @@ +#if defined(OS_LINUX) #include +#elif defined(OS_DARWIN) +#include +#endif #include #include