From e8464d61f1bfd8d592ec524194173460ce67b03b Mon Sep 17 00:00:00 2001 From: Denis Glazachev Date: Fri, 9 Apr 2021 04:28:24 +0400 Subject: [PATCH] Fix vanilla GCC compilation in macOS --- base/daemon/SentryWriter.cpp | 1 + cmake/darwin/default_libs.cmake | 8 ++++---- cmake/find/amqpcpp.cmake | 5 +++++ cmake/find/cassandra.cmake | 5 +++++ contrib/boringssl-cmake/CMakeLists.txt | 2 +- contrib/libcxx-cmake/CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 5 +++++ src/Common/StackTrace.h | 4 +++- 8 files changed, 29 insertions(+), 6 deletions(-) diff --git a/base/daemon/SentryWriter.cpp b/base/daemon/SentryWriter.cpp index 29430b65983..1b7d0064b99 100644 --- a/base/daemon/SentryWriter.cpp +++ b/base/daemon/SentryWriter.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/cmake/darwin/default_libs.cmake b/cmake/darwin/default_libs.cmake index 79ac675f234..6c298106c6b 100644 --- a/cmake/darwin/default_libs.cmake +++ b/cmake/darwin/default_libs.cmake @@ -1,11 +1,11 @@ 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 -lpthread -ldl") +if (COMPILER_GCC) + set (DEFAULT_LIBS "${DEFAULT_LIBS} -lgcc_eh") +endif () + message(STATUS "Default libraries: ${DEFAULT_LIBS}") set(CMAKE_CXX_STANDARD_LIBRARIES ${DEFAULT_LIBS}) diff --git a/cmake/find/amqpcpp.cmake b/cmake/find/amqpcpp.cmake index 4191dce26bb..e3eaaf33ddb 100644 --- a/cmake/find/amqpcpp.cmake +++ b/cmake/find/amqpcpp.cmake @@ -1,3 +1,8 @@ +if (OS_DARWIN AND COMPILER_GCC) + # AMQP-CPP requires libuv which cannot be built with GCC in macOS due to a bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93082 + set (ENABLE_AMQPCPP OFF CACHE INTERNAL "") +endif() + option(ENABLE_AMQPCPP "Enalbe AMQP-CPP" ${ENABLE_LIBRARIES}) if (NOT ENABLE_AMQPCPP) diff --git a/cmake/find/cassandra.cmake b/cmake/find/cassandra.cmake index 037d6c3f131..ded25a5bf41 100644 --- a/cmake/find/cassandra.cmake +++ b/cmake/find/cassandra.cmake @@ -1,3 +1,8 @@ +if (OS_DARWIN AND COMPILER_GCC) + # Cassandra requires libuv which cannot be built with GCC in macOS due to a bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93082 + set (ENABLE_CASSANDRA OFF CACHE INTERNAL "") +endif() + option(ENABLE_CASSANDRA "Enable Cassandra" ${ENABLE_LIBRARIES}) if (NOT ENABLE_CASSANDRA) diff --git a/contrib/boringssl-cmake/CMakeLists.txt b/contrib/boringssl-cmake/CMakeLists.txt index 017a8a64c0e..adfee82dda4 100644 --- a/contrib/boringssl-cmake/CMakeLists.txt +++ b/contrib/boringssl-cmake/CMakeLists.txt @@ -16,7 +16,7 @@ endif() if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti") - if(APPLE) + if(APPLE AND CLANG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") endif() diff --git a/contrib/libcxx-cmake/CMakeLists.txt b/contrib/libcxx-cmake/CMakeLists.txt index 3b5d53cd1c0..59d23b2cd9e 100644 --- a/contrib/libcxx-cmake/CMakeLists.txt +++ b/contrib/libcxx-cmake/CMakeLists.txt @@ -56,6 +56,11 @@ if (USE_UNWIND) target_compile_definitions(cxx PUBLIC -DSTD_EXCEPTION_HAS_STACK_TRACE=1) endif () +# Override the deduced attribute support that causes error. +if (OS_DARWIN AND COMPILER_GCC) + add_compile_definitions(_LIBCPP_INIT_PRIORITY_MAX) +endif () + target_compile_options(cxx PUBLIC $<$:-nostdinc++>) # Third party library may have substandard code. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 295cf4904c3..43f6ae8fea5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -508,5 +508,10 @@ if (ENABLE_TESTS AND USE_GTEST) clickhouse_common_zookeeper string_utils) + # For __udivmodti4 referenced in Core/tests/gtest_DecimalFunctions.cpp + if (OS_DARWIN AND COMPILER_GCC) + target_link_libraries(unit_tests_dbms PRIVATE gcc) + endif () + add_check(unit_tests_dbms) endif () diff --git a/src/Common/StackTrace.h b/src/Common/StackTrace.h index 35df77b6b8a..ef90a0d587d 100644 --- a/src/Common/StackTrace.h +++ b/src/Common/StackTrace.h @@ -11,7 +11,9 @@ #ifdef __APPLE__ // ucontext is not available without _XOPEN_SOURCE -# pragma clang diagnostic ignored "-Wreserved-id-macro" +# ifdef __clang__ +# pragma clang diagnostic ignored "-Wreserved-id-macro" +# endif # define _XOPEN_SOURCE 700 #endif #include