-
Notifications
You must be signed in to change notification settings - Fork 1.8k
CMakeLists.txt: respect BUILD_SHARED_LIBS #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) | ||
|
||
OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON) | ||
OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF) | ||
OPTION(DISABLE_TESTS "If tests should be compiled or not" OFF) | ||
OPTION(ENABLE_SSL_TESTS "Should we test SSL connections" OFF) | ||
|
@@ -44,35 +45,49 @@ IF(WIN32) | |
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN) | ||
ENDIF() | ||
|
||
ADD_LIBRARY(hiredis SHARED ${hiredis_sources}) | ||
ADD_LIBRARY(hiredis_static STATIC ${hiredis_sources}) | ||
ADD_LIBRARY(hiredis::hiredis ALIAS hiredis) | ||
ADD_LIBRARY(hiredis::hiredis_static ALIAS hiredis_static) | ||
SET(HIREDIS_DEFAULT_LIBRARY hiredis_static) | ||
SET(HIREDIS_TARGETS hiredis_static) | ||
|
||
IF(NOT MSVC) | ||
SET_TARGET_PROPERTIES(hiredis_static | ||
PROPERTIES OUTPUT_NAME hiredis) | ||
ENDIF() | ||
|
||
SET_TARGET_PROPERTIES(hiredis | ||
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE | ||
VERSION "${HIREDIS_SONAME}") | ||
IF(BUILD_SHARED_LIBS) | ||
ADD_LIBRARY(hiredis SHARED ${hiredis_sources}) | ||
ADD_LIBRARY(hiredis::hiredis ALIAS hiredis) | ||
SET(HIREDIS_DEFAULT_LIBRARY hiredis) | ||
SET(HIREDIS_TARGETS ${HIREDIS_TARGETS} hiredis) | ||
SET_TARGET_PROPERTIES(hiredis | ||
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE | ||
VERSION "${HIREDIS_SONAME}") | ||
ENDIF() | ||
IF(MSVC) | ||
SET_TARGET_PROPERTIES(hiredis_static | ||
PROPERTIES COMPILE_FLAGS /Z7) | ||
ENDIF() | ||
IF(WIN32 OR MINGW) | ||
TARGET_LINK_LIBRARIES(hiredis PUBLIC ws2_32 crypt32) | ||
IF(BUILD_SHARED_LIBS) | ||
TARGET_LINK_LIBRARIES(hiredis PUBLIC ws2_32 crypt32) | ||
ENDIF() | ||
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC ws2_32 crypt32) | ||
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") | ||
TARGET_LINK_LIBRARIES(hiredis PUBLIC m) | ||
IF(BUILD_SHARED_LIBS) | ||
TARGET_LINK_LIBRARIES(hiredis PUBLIC m) | ||
ENDIF() | ||
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC m) | ||
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "SunOS") | ||
TARGET_LINK_LIBRARIES(hiredis PUBLIC socket) | ||
IF(BUILD_SHARED_LIBS) | ||
TARGET_LINK_LIBRARIES(hiredis PUBLIC socket) | ||
ENDIF() | ||
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC socket) | ||
ENDIF() | ||
|
||
TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) | ||
IF(BUILD_SHARED_LIBS) | ||
TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) | ||
ENDIF() | ||
TARGET_INCLUDE_DIRECTORIES(hiredis_static PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) | ||
|
||
CONFIGURE_FILE(hiredis.pc.in hiredis.pc @ONLY) | ||
|
@@ -103,13 +118,13 @@ set(CPACK_RPM_PACKAGE_AUTOREQPROV ON) | |
|
||
include(CPack) | ||
|
||
INSTALL(TARGETS hiredis hiredis_static | ||
INSTALL(TARGETS ${HIREDIS_TARGETS} | ||
EXPORT hiredis-targets | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
|
||
if (MSVC) | ||
if (MSVC AND BUILD_SHARED_LIBS) | ||
INSTALL(FILES $<TARGET_PDB_FILE:hiredis> | ||
DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
CONFIGURATIONS Debug RelWithDebInfo) | ||
|
@@ -161,45 +176,58 @@ IF(ENABLE_SSL) | |
FIND_PACKAGE(OpenSSL REQUIRED) | ||
SET(hiredis_ssl_sources | ||
ssl.c) | ||
ADD_LIBRARY(hiredis_ssl SHARED | ||
${hiredis_ssl_sources}) | ||
|
||
ADD_LIBRARY(hiredis_ssl_static STATIC | ||
${hiredis_ssl_sources}) | ||
SET(HIREDIS_SSL_DEFAULT_LIBRARY hiredis_ssl_static) | ||
SET(HIREDIS_SSL_TARGETS hiredis_ssl_static) | ||
IF(BUILD_SHARED_LIBS) | ||
ADD_LIBRARY(hiredis_ssl SHARED | ||
${hiredis_ssl_sources}) | ||
SET(HIREDIS_SSL_DEFAULT_LIBRARY hiredis_ssl) | ||
SET(HIREDIS_SSL_TARGETS ${HIREDIS_SSL_TARGETS} hiredis_ssl) | ||
ENDIF() | ||
IF(NOT MSVC) | ||
SET_TARGET_PROPERTIES(hiredis_ssl_static | ||
PROPERTIES OUTPUT_NAME hiredis_ssl) | ||
ENDIF() | ||
|
||
IF (APPLE) | ||
IF (APPLE AND BUILD_SHARED_LIBS) | ||
SET_PROPERTY(TARGET hiredis_ssl PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup") | ||
ENDIF() | ||
|
||
SET_TARGET_PROPERTIES(hiredis_ssl | ||
PROPERTIES | ||
WINDOWS_EXPORT_ALL_SYMBOLS TRUE | ||
VERSION "${HIREDIS_SONAME}") | ||
IF(BUILD_SHARED_LIBS) | ||
SET_TARGET_PROPERTIES(hiredis_ssl | ||
PROPERTIES | ||
WINDOWS_EXPORT_ALL_SYMBOLS TRUE | ||
VERSION "${HIREDIS_SONAME}") | ||
ENDIF() | ||
IF(MSVC) | ||
SET_TARGET_PROPERTIES(hiredis_ssl_static | ||
PROPERTIES COMPILE_FLAGS /Z7) | ||
ENDIF() | ||
|
||
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}") | ||
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl_static PRIVATE "${OPENSSL_INCLUDE_DIR}") | ||
IF(BUILD_SHARED_LIBS) | ||
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}") | ||
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES}) | ||
ENDIF() | ||
|
||
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES}) | ||
IF (WIN32 OR MINGW) | ||
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE hiredis) | ||
IF (BUILD_SHARED_LIBS) | ||
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE hiredis) | ||
ENDIF() | ||
TARGET_LINK_LIBRARIES(hiredis_ssl_static PUBLIC hiredis_static) | ||
ENDIF() | ||
CONFIGURE_FILE(hiredis_ssl.pc.in hiredis_ssl.pc @ONLY) | ||
|
||
INSTALL(TARGETS hiredis_ssl hiredis_ssl_static | ||
INSTALL(TARGETS ${HIREDIS_SSL_TARGETS} | ||
EXPORT hiredis_ssl-targets | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
|
||
if (MSVC) | ||
if (MSVC AND BUILD_SHARED_LIBS) | ||
INSTALL(FILES $<TARGET_PDB_FILE:hiredis_ssl> | ||
DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
CONFIGURATIONS Debug RelWithDebInfo) | ||
|
@@ -236,10 +264,10 @@ ENDIF() | |
IF(NOT DISABLE_TESTS) | ||
ENABLE_TESTING() | ||
ADD_EXECUTABLE(hiredis-test test.c) | ||
TARGET_LINK_LIBRARIES(hiredis-test hiredis) | ||
TARGET_LINK_LIBRARIES(hiredis-test ${HIREDIS_DEFAULT_LIBRARY}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the same change is needed in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..and a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, I'll update the PR |
||
IF(ENABLE_SSL_TESTS) | ||
ADD_DEFINITIONS(-DHIREDIS_TEST_SSL=1) | ||
TARGET_LINK_LIBRARIES(hiredis-test hiredis_ssl) | ||
TARGET_LINK_LIBRARIES(hiredis-test ${HIREDIS_SSL_DEFAULT_LIBRARY}) | ||
ENDIF() | ||
IF(ENABLE_ASYNC_TESTS) | ||
ADD_DEFINITIONS(-DHIREDIS_TEST_ASYNC=1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed two others;
hiredis_ssl
on line 228hiredis_ssl
on line 217 (which in legacy is a bit weird, but maybe needed)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I updated the PR