@@ -11,11 +11,12 @@ getDefinedVersion(VERSION_MAJOR)
1111getDefinedVersion (VERSION_MINOR )
1212getDefinedVersion (VERSION_PATCH )
1313set (VERSION "${VERSION_MAJOR} .${VERSION_MINOR} .${VERSION_PATCH} " )
14- MESSAGE ("Detected version: ${VERSION} " )
14+ message ("Detected libvalkey version: ${VERSION} " )
1515
16- PROJECT (valkey LANGUAGES "C" VERSION "${VERSION} " )
16+ project (libvalkey LANGUAGES "C" VERSION "${VERSION} " )
1717INCLUDE (GNUInstallDirs )
1818
19+ option (ENABLE_THREADS "Enable thread-safe initialization" ON )
1920OPTION (BUILD_SHARED_LIBS "Build shared libraries" ON )
2021OPTION (ENABLE_TLS "Build valkey_tls for TLS support" OFF )
2122OPTION (DISABLE_TESTS "If tests should be compiled or not" OFF )
@@ -70,18 +71,36 @@ set_target_properties(valkey PROPERTIES
7071 SOVERSION "${VERSION_MAJOR} "
7172 VERSION "${VERSION} " )
7273
73- IF (MSVC )
74- SET_TARGET_PROPERTIES (valkey
75- PROPERTIES COMPILE_FLAGS /Z7 )
76- ENDIF ()
74+ if (MSVC )
75+ # Produce object files that contain debug info.
76+ target_compile_options (valkey PRIVATE /Z7 )
77+ endif ()
78+
79+ set (valkey_link_libraries)
80+ set (valkey_compile_definitions)
81+
7782IF (WIN32 )
78- TARGET_LINK_LIBRARIES ( valkey PUBLIC ws2_32 crypt32 )
83+ list ( APPEND valkey_link_libraries ws2_32 crypt32)
7984ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
80- TARGET_LINK_LIBRARIES ( valkey PUBLIC m )
85+ list ( APPEND valkey_link_libraries m)
8186ELSEIF (CMAKE_SYSTEM_NAME MATCHES "SunOS" )
82- TARGET_LINK_LIBRARIES ( valkey PUBLIC socket )
87+ list ( APPEND valkey_link_libraries socket)
8388ENDIF ()
8489
90+ if (ENABLE_THREADS)
91+ find_package (Threads REQUIRED )
92+ list (APPEND valkey_link_libraries Threads::Threads)
93+ list (APPEND valkey_compile_definitions VALKEY_USE_THREADS)
94+ endif ()
95+
96+ if (valkey_link_libraries)
97+ target_link_libraries (valkey PUBLIC ${valkey_link_libraries} )
98+ endif ()
99+
100+ if (valkey_compile_definitions)
101+ target_compile_definitions (valkey PRIVATE ${valkey_compile_definitions} )
102+ endif ()
103+
85104TARGET_INCLUDE_DIRECTORIES (valkey
86105 PUBLIC
87106 $<INSTALL_INTERFACE :include >
@@ -94,8 +113,9 @@ TARGET_INCLUDE_DIRECTORIES(valkey
94113CONFIGURE_FILE (valkey.pc.in valkey.pc @ONLY )
95114
96115set (CPACK_PACKAGE_VENDOR "Valkey" )
116+ set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Minimalistic C client library for Valkey" )
97117set (CPACK_PACKAGE_DESCRIPTION "\
98- Libvalkey is a minimalistic C client library for the Valkey, KeyDB, and Redis databases
118+ Libvalkey is a minimalistic C client library for the Valkey, KeyDB, and Redis databases.
99119
100120It is minimalistic because it just adds minimal support for the protocol, \
101121but at the same time it uses a high level printf-alike API in order to make \
@@ -107,7 +127,7 @@ reply parser that is decoupled from the I/O layer. It is a stream parser designe
107127for easy reusability, which can for instance be used in higher level language bindings \
108128for efficient reply parsing.
109129
110- valkey only supports the binary-safe RESP protocol, so you can use it with any Redis \
130+ Libvalkey only supports the binary-safe RESP protocol, so you can use it with any Redis \
111131compatible server >= 1.2.0.
112132
113133The library comes with multiple APIs. There is the synchronous API, the asynchronous API \
@@ -116,7 +136,9 @@ set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/valkey-io/libvalkey")
116136set (CPACK_PACKAGE_CONTACT "michael dot grunder at gmail dot com" )
117137set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )
118138set (CPACK_RPM_PACKAGE_AUTOREQPROV ON )
119-
139+ set (CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION} " )
140+ set (CPACK_RPM_PACKAGE_GROUP "Productivity/Databases/Clients" )
141+ set (CPACK_RPM_PACKAGE_LICENSE "BSD-3-Clause" )
120142include (CPack )
121143
122144INSTALL (TARGETS valkey
@@ -125,17 +147,23 @@ INSTALL(TARGETS valkey
125147 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
126148 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
127149
128- if (MSVC AND BUILD_SHARED_LIBS )
129- INSTALL (FILES $<TARGET_PDB_FILE :valkey >
130- DESTINATION ${CMAKE_INSTALL_BINDIR}
131- CONFIGURATIONS Debug RelWithDebInfo)
150+ if (MSVC AND BUILD_SHARED_LIBS )
151+ # Install linker generated program database file.
152+ install (FILES $<TARGET_PDB_FILE :valkey >
153+ DESTINATION ${CMAKE_INSTALL_BINDIR}
154+ CONFIGURATIONS Debug RelWithDebInfo)
132155endif ()
133156
134157# Install public headers
135158install (DIRECTORY include/valkey
136159 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
137160 PATTERN "tls.h" EXCLUDE
138- PATTERN "rdma.h" EXCLUDE)
161+ PATTERN "rdma.h" EXCLUDE
162+ PATTERN "adapters/macosx.h" EXCLUDE)
163+ if (APPLE )
164+ install (FILES include/valkey/adapters/macosx.h
165+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /valkey/adapters)
166+ endif ()
139167
140168INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR} /valkey.pc
141169 DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig)
@@ -187,23 +215,16 @@ IF(ENABLE_TLS)
187215 $<BUILD_INTERFACE :${SDS_INCLUDE_DIR} >
188216 )
189217
190- IF (APPLE AND BUILD_SHARED_LIBS )
191- SET_PROPERTY (TARGET valkey_tls PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup" )
192- ENDIF ()
193-
194218 set_target_properties (valkey_tls PROPERTIES
195219 C_VISIBILITY_PRESET hidden
196220 WINDOWS_EXPORT_ALL_SYMBOLS TRUE
197221 SOVERSION "${VERSION_MAJOR} "
198222 VERSION "${VERSION} " )
199- IF (MSVC )
200- SET_TARGET_PROPERTIES (valkey_tls
201- PROPERTIES COMPILE_FLAGS /Z7 )
202- ENDIF ()
203- TARGET_LINK_LIBRARIES (valkey_tls PRIVATE OpenSSL::SSL )
204- if (WIN32 OR CYGWIN )
205- target_link_libraries (valkey_tls PRIVATE valkey )
223+ if (MSVC )
224+ # Produce object files that contain debug info.
225+ target_compile_options (valkey_tls PRIVATE /Z7 )
206226 endif ()
227+ target_link_libraries (valkey_tls PRIVATE valkey::valkey OpenSSL::SSL )
207228 CONFIGURE_FILE (valkey_tls.pc.in valkey_tls.pc @ONLY )
208229
209230 INSTALL (TARGETS valkey_tls
@@ -216,10 +237,11 @@ IF(ENABLE_TLS)
216237 install (FILES include/valkey/tls.h
217238 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /valkey)
218239
219- if (MSVC AND BUILD_SHARED_LIBS )
220- INSTALL (FILES $<TARGET_PDB_FILE :valkey_tls >
221- DESTINATION ${CMAKE_INSTALL_BINDIR}
222- CONFIGURATIONS Debug RelWithDebInfo)
240+ if (MSVC AND BUILD_SHARED_LIBS )
241+ # Install linker generated program database file.
242+ install (FILES $<TARGET_PDB_FILE :valkey_tls >
243+ DESTINATION ${CMAKE_INSTALL_BINDIR}
244+ CONFIGURATIONS Debug RelWithDebInfo)
223245 endif ()
224246
225247 INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR} /valkey_tls.pc
@@ -254,7 +276,7 @@ if(ENABLE_RDMA)
254276 add_library (valkey_rdma ${valkey_rdma_sources} )
255277 add_library (valkey::valkey_rdma ALIAS valkey_rdma )
256278
257- target_link_libraries (valkey_rdma LINK_PRIVATE ${RDMACM_LIBRARIES} ${IBVERBS_LIBRARIES} )
279+ target_link_libraries (valkey_rdma PRIVATE valkey::valkey ${RDMACM_LIBRARIES} ${IBVERBS_LIBRARIES} )
258280 target_include_directories (valkey_rdma
259281 PRIVATE
260282 $<INSTALL_INTERFACE :include >
@@ -303,26 +325,32 @@ endif()
303325
304326# Add tests
305327if (NOT DISABLE_TESTS)
306- if ( BUILD_SHARED_LIBS )
307- # Test using a static library since symbols are not hidden then .
308- # Use same source, include dirs and dependencies as the shared library.
309- add_library ( valkey_unittest STATIC ${valkey_sources} )
310- get_target_property ( include_directories valkey::valkey INCLUDE_DIRECTORIES )
311- target_include_directories ( valkey_unittest PUBLIC ${include_directories} )
312- get_target_property ( link_libraries valkey::valkey LINK_LIBRARIES )
313- if (link_libraries)
314- target_link_libraries ( valkey_unittest PUBLIC ${link_libraries} )
315- endif ( )
316- # Create libvalkey_unittest.a in the tests directory.
317- set_target_properties ( valkey_unittest PROPERTIES
318- ARCHIVE_OUTPUT_DIRECTORY " ${CMAKE_CURRENT_BINARY_DIR} /tests" )
319- else ()
320- # Target is an alias for the static library.
321- add_library (valkey_unittest ALIAS valkey )
328+ # Unit tests uses a static library to ensure all symbols are visible.
329+ # This single library also bundles TLS and RDMA when enabled .
330+ add_library ( valkey_unittest STATIC ${valkey_sources} ${valkey_tls_sources} ${valkey_rdma_sources} )
331+
332+ # Mirror the include directories.
333+ get_target_property ( include_directories valkey::valkey INCLUDE_DIRECTORIES )
334+ target_include_directories ( valkey_unittest PUBLIC ${include_directories} )
335+
336+ if (valkey_compile_definitions )
337+ target_compile_definitions ( valkey_unittest PRIVATE ${valkey_compile_definitions} )
338+ endif ()
339+ if (valkey_link_libraries)
340+ target_link_libraries ( valkey_unittest PUBLIC ${valkey_link_libraries} )
341+ endif ()
342+ if (ENABLE_TLS)
343+ target_link_libraries (valkey_unittest PRIVATE OpenSSL::SSL )
322344 endif ()
345+ if (ENABLE_RDMA)
346+ target_link_libraries (valkey_unittest PRIVATE ${RDMACM_LIBRARIES} ${IBVERBS_LIBRARIES} )
347+ endif ()
348+
349+ # Create libvalkey_unittest.a in the tests directory.
350+ set_target_properties (valkey_unittest PROPERTIES
351+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /tests" )
323352
324353 # Make sure ctest prints the output when a test fails.
325- # Must be set before including CTest.
326354 set (CMAKE_CTEST_ARGUMENTS "--output-on-failure" )
327355 include (CTest )
328356 add_subdirectory (tests )
0 commit comments