Skip to content

Commit

Permalink
Merge pull request ClickHouse#219 from Jihadist/separateSharedStaticLibs
Browse files Browse the repository at this point in the history
Separate building static and shared libs
  • Loading branch information
Enmk authored Feb 1, 2023
2 parents 29a40fb + 3f3c7d7 commit df4ae9f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ INCLUDE (cmake/openssl.cmake)

OPTION (BUILD_BENCHMARK "Build benchmark" OFF)
OPTION (BUILD_TESTS "Build tests" OFF)
OPTION (BUILD_SHARED_LIBS "Build shared libs" OFF)
OPTION (WITH_OPENSSL "Use OpenSSL for TLS connections" OFF)

PROJECT (CLICKHOUSE-CLIENT)
Expand All @@ -27,6 +28,12 @@ PROJECT (CLICKHOUSE-CLIENT)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-declarations")
ENDIF ()

IF (APPLE OR MSVC)
IF(BUILD_SHARED_LIBS)
MESSAGE(FATAL "Does not support shared on this platform")
ENDIF()
ENDIF()

SUBDIRS (
clickhouse
contrib/absl
Expand Down
24 changes: 8 additions & 16 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ IF (WITH_OPENSSL)
LIST(APPEND clickhouse-cpp-lib-src base/sslsocket.cpp)
ENDIF ()

ADD_LIBRARY (clickhouse-cpp-lib SHARED ${clickhouse-cpp-lib-src})
SET_TARGET_PROPERTIES(clickhouse-cpp-lib PROPERTIES LINKER_LANGUAGE CXX)
ADD_LIBRARY (clickhouse-cpp-lib ${clickhouse-cpp-lib-src})
SET_TARGET_PROPERTIES (clickhouse-cpp-lib PROPERTIES LINKER_LANGUAGE CXX)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib
absl-lib
cityhash-lib
Expand All @@ -49,15 +49,10 @@ TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib
PUBLIC ${PROJECT_SOURCE_DIR}
)

ADD_LIBRARY (clickhouse-cpp-lib-static STATIC ${clickhouse-cpp-lib-src})
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
absl-lib
cityhash-lib
lz4-lib
)
TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib-static
PUBLIC ${PROJECT_SOURCE_DIR}
)
IF (NOT BUILD_SHARED_LIBS)
ADD_LIBRARY (clickhouse-cpp-lib-static ALIAS clickhouse-cpp-lib)
ENDIF()


IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
INCLUDE (CheckCXXSourceCompiles)
Expand All @@ -77,16 +72,15 @@ IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# /usr/bin/ld: /lib/x86_64-linux-gnu/libgcc_s.so.1: error adding symbols: DSO missing from command line
# FIXME: that workaround breaks clang build on mingw
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib gcc_s)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static gcc_s)
ENDIF ()
ENDIF ()

INSTALL (TARGETS clickhouse-cpp-lib clickhouse-cpp-lib-static

INSTALL (TARGETS clickhouse-cpp-lib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)


# general
INSTALL(FILES block.h DESTINATION include/clickhouse/)
INSTALL(FILES client.h DESTINATION include/clickhouse/)
Expand Down Expand Up @@ -137,10 +131,8 @@ INSTALL(FILES types/types.h DESTINATION include/clickhouse/types/)

IF (WITH_OPENSSL)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib OpenSSL::SSL)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static OpenSSL::SSL)
ENDIF ()

IF (WIN32 OR MINGW)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib wsock32 ws2_32)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static wsock32 ws2_32)
ENDIF ()
2 changes: 1 addition & 1 deletion tests/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ADD_EXECUTABLE (simple-test
)

TARGET_LINK_LIBRARIES (simple-test
clickhouse-cpp-lib-static
clickhouse-cpp-lib
)

IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down
2 changes: 1 addition & 1 deletion ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ADD_EXECUTABLE (clickhouse-cpp-ut
)

TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
clickhouse-cpp-lib-static
clickhouse-cpp-lib
gtest-lib
)
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down

0 comments on commit df4ae9f

Please sign in to comment.