@@ -720,10 +720,10 @@ set_property(TARGET _mongoc-dependencies PROPERTY EXPORT_NAME dependencies)
720
720
721
721
if (ENABLE_SRV )
722
722
# Interface target defined by ResSearch.cmake:
723
- if (NOT TARGET mongo::c:: detail::resolve )
723
+ if (NOT TARGET mongo::detail::c_resolve )
724
724
message (SEND_ERROR "ENABLE_SRV is “${ENABLE_SRV} ”, but we were unable to find a name resolution library" )
725
725
endif ()
726
- target_link_libraries (_mongoc-dependencies INTERFACE mongo::c:: detail::resolve )
726
+ target_link_libraries (_mongoc-dependencies INTERFACE mongo::detail::c_resolve )
727
727
endif ()
728
728
729
729
if (WIN32 )
@@ -786,8 +786,12 @@ target_include_directories (
786
786
$< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /../../src/common>
787
787
)
788
788
789
- set_target_properties (mongoc_shared PROPERTIES VERSION 0.0.0 SOVERSION 0 )
790
- set_target_properties (mongoc_shared PROPERTIES OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME} -${MONGOC_API_VERSION} " )
789
+ set_target_properties (mongoc_shared PROPERTIES
790
+ OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME} -${MONGOC_API_VERSION} "
791
+ VERSION 0.0.0
792
+ SOVERSION 0
793
+ pc_REQUIRES "libbson-1.0"
794
+ )
791
795
792
796
if (MONGOC_ENABLE_STATIC_BUILD )
793
797
add_library (mongoc_static STATIC ${SOURCES} ${HEADERS} ${HEADERS_FORWARDING} )
@@ -800,6 +804,10 @@ if (MONGOC_ENABLE_STATIC_BUILD)
800
804
target_compile_options (mongoc_static PUBLIC -fPIC )
801
805
message (STATUS "Adding -fPIC to compilation of mongoc_static components" )
802
806
endif ()
807
+ if (ENABLE_SRV AND RESOLVE_LIB_NAME )
808
+ # The static library needs to link to the resolver in pkg-config:
809
+ set_property (TARGET mongoc_static APPEND PROPERTY pc_LIBS "-l${RESOLVE_LIB_NAME} " )
810
+ endif ()
803
811
target_include_directories (mongoc_static PRIVATE ${ZLIB_INCLUDE_DIRS} )
804
812
target_include_directories (mongoc_static PRIVATE ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES} )
805
813
if (MONGOC_ENABLE_MONGODB_AWS_AUTH )
@@ -827,8 +835,11 @@ if (MONGOC_ENABLE_STATIC_BUILD)
827
835
$< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /../../src>
828
836
$< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /../../src/common>
829
837
)
830
- set_target_properties (mongoc_static PROPERTIES VERSION 0.0.0 )
831
- set_target_properties (mongoc_static PROPERTIES OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME} -static-${MONGOC_API_VERSION} " )
838
+ set_target_properties (mongoc_static PROPERTIES
839
+ VERSION 0.0.0
840
+ OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME} -static-${MONGOC_API_VERSION} "
841
+ pc_REQUIRES "libbson-static-1.0"
842
+ )
832
843
endif ()
833
844
834
845
if (ENABLE_APPLE_FRAMEWORK )
@@ -1193,44 +1204,109 @@ set (VERSION "${MONGOC_VERSION}")
1193
1204
set (prefix "${CMAKE_INSTALL_PREFIX} " )
1194
1205
set (libdir "\$ {prefix}/${CMAKE_INSTALL_LIBDIR} " )
1195
1206
1196
- foreach (
1197
- FLAG
1198
- ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES}
1199
- ${THREAD_LIB} ${ZLIB_LIBRARIES} ${SNAPPY_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${ICU_LIBRARIES}
1207
+ # Collect link items for the static library to be inserted into the pkg-config
1208
+ if (TARGET mongoc_static )
1209
+ set (link_options
1210
+ ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${THREAD_LIB} ${ZLIB_LIBRARIES}
1211
+ ${SNAPPY_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${ICU_LIBRARIES}
1200
1212
${LIBMONGOCRYPT_LIBRARY} )
1213
+ # Replace all absolute paths with search-dir link-file options:
1214
+ list (TRANSFORM link_options
1215
+ REPLACE "^(.+)/lib([^/]+)\\ .[a-z]+$"
1216
+ "-L\\ 1;-l\\ 2"
1217
+ REGEX "^/" )
1218
+ # Prepend "-l" to all bare names:
1219
+ list (TRANSFORM link_options PREPEND "-l" REGEX "^[^-]" )
1220
+ list (REMOVE_DUPLICATES link_options )
1221
+ message (DEBUG "Computed static library link options: ${link_options} " )
1222
+ set_property (TARGET mongoc_static APPEND PROPERTY pc_LIBS ${link_options} )
1223
+ endif ()
1201
1224
1202
- if (IS_ABSOLUTE "${FLAG} " )
1203
- get_filename_component (FLAG_DIR "${FLAG} " DIRECTORY )
1204
- get_filename_component (FLAG_FILE "${FLAG} " NAME_WE )
1205
- STRING (REGEX REPLACE "^lib" "" FLAG_FILE "${FLAG_FILE} " )
1206
- set (MONGOC_LIBRARIES "${MONGOC_LIBRARIES} -L${FLAG_DIR} -l${FLAG_FILE} " )
1207
- elseif (FLAG MATCHES "^-.*" )
1208
- # Flag starts with dash, add it as-is.
1209
- set (MONGOC_LIBRARIES "${MONGOC_LIBRARIES} ${FLAG} " )
1210
- else ()
1211
- # Flag doesn't start with dash, add it with a dash.
1212
- set (MONGOC_LIBRARIES "${MONGOC_LIBRARIES} -l${FLAG} " )
1213
- endif ()
1214
- endforeach ()
1225
+ # More pkg-config properties:
1226
+ set_target_properties (${TARGETS_TO_INSTALL} PROPERTIES
1227
+ pc_NAME "libmongoc"
1228
+ pc_DESCRIPTION "The libmongoc MongoDB client library."
1229
+ pc_VERSION "${VERSION} " )
1230
+ # Relative include-path will be given the install prefix:
1231
+ set_property (TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pc_INCLUDE_DIRECTORIES "${MONGOC_HEADER_INSTALL_DIR} " )
1232
+
1233
+ #[[
1234
+ Utility for configuring a file and then evaluating generator expressions on it.
1235
+ The content of the file has a tiny templating DSL for writing generator
1236
+ expressions. Expansion takes place as follows:
1237
+ 1. Delete any content starting at hash-tilde "#~" until the next newline
1238
+ 2. Search for any lines of the form "%define foo bar". For each instance,
1239
+ replace "foo" with "bar" in the remainder of the file. The "% foo bar"
1240
+ line is deleted.
1241
+ 3. If a tilde "~" appears adjacent to any of "$,<:>@", delete the tilde and
1242
+ all adjacent whitespace.
1243
+ 4. Run string(CONFIGURE ... @ONLY) on the result to replace variable
1244
+ references. Special replacements @space@, @newline, and @empty@ are also
1245
+ available for adjusting whitespace after ~ trimming.
1246
+ 5. Run file(GENERATE).
1247
+ ]]
1248
+ function (_mongoc_configure_and_generate_file input output )
1249
+ set (CMAKE_MESSAGE_CONTEXT _mongoc_configure_and_generate_file )
1250
+ # If given a relative input path, make it relative to the current source dir:
1251
+ get_filename_component (abs_in "${input} " ABSOLUTE )
1252
+ file (READ "${input} " content )
1253
+ # Some convenience values for @expansion@ in the file:
1254
+ set (space " " )
1255
+ set (newline "\n " )
1256
+ set (empty "" )
1257
+ # Delete "#~" comments:
1258
+ string (REGEX REPLACE "#~[^\n ]*" "" content "${content} " )
1259
+ # Replace our simple "%define <name> <value>" macros:
1260
+ while (content MATCHES "(.*)\n *%define *([a-zA-Z_\\ $<>:-]+) *([^\n ]*)\n (.*)" )
1261
+ set (before "${CMAKE_MATCH_1} " )
1262
+ set (after "${CMAKE_MATCH_4} " )
1263
+ set (def "${CMAKE_MATCH_2} " )
1264
+ set (val "${CMAKE_MATCH_3} " )
1265
+ message (TRACE "Replace “${def} ” with “${val} ”" )
1266
+ # Only perform the replacment on the remainder of the file following that
1267
+ # line:
1268
+ string (REPLACE "${def} " "${val} " after "${after} " )
1269
+ # Splice the results:
1270
+ set (content "${before} \n ${after} " )
1271
+ endwhile ()
1272
+ # Whitespace trimming. right-trim when tilde is to the right of special chars:
1273
+ string (REGEX REPLACE "([,><:@])~[ \n\t ]*" "\\ 1" content "${content} " )
1274
+ # Same thing, but on the left-hand side:
1275
+ string (REGEX REPLACE "[ \n\t ]*~([^ \t\n ])" "\\ 1" content "${content} " )
1276
+ # Replace @varables@:
1277
+ string (CONFIGURE "${content} " content @ONLY )
1278
+ # If given a relative output path, make it relative to the current binary dir:
1279
+ if (NOT IS_ABSOLUTE "${output} " )
1280
+ get_filename_component (output "${CMAKE_CURRENT_BINARY_DIR} /${output} " ABSOLUTE )
1281
+ endif ()
1282
+ message (DEBUG "Configure+generate file [${input} ] -> [${output} ]" )
1283
+ message (TRACE "Content:\n ${content} " )
1284
+ # Generate it:
1285
+ file (GENERATE OUTPUT "${output} " CONTENT "${content} " ${ARGN} )
1286
+ endfunction ()
1287
+
1288
+ # Generate pkg-config for mongoc_shared
1289
+ if (TARGET mongoc_shared )
1290
+ set (GENERATE_TARGET mongoc_shared )
1291
+ _mongoc_configure_and_generate_file (
1292
+ src/libmongoc.pc.in
1293
+ src/libmongoc-1.0.pc )
1294
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /src/libmongoc-1.0.pc
1295
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig )
1296
+ endif ()
1297
+
1298
+ # Now one for mongoc_static:
1299
+ if (TARGET mongoc_static )
1300
+ set (GENERATE_TARGET mongoc_static )
1301
+ _mongoc_configure_and_generate_file (
1302
+ src/libmongoc.pc.in
1303
+ src/libmongoc-static-1.0.pc )
1304
+ if (MONGOC_ENABLE_STATIC_INSTALL )
1305
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /src/libmongoc-static-1.0.pc
1306
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig )
1307
+ endif ()
1308
+ endif ()
1215
1309
1216
- configure_file (
1217
- ${CMAKE_CURRENT_SOURCE_DIR} /src/libmongoc-1.0.pc.in
1218
- ${CMAKE_CURRENT_BINARY_DIR} /src/libmongoc-1.0.pc
1219
- @ONLY )
1220
- install (
1221
- FILES ${CMAKE_CURRENT_BINARY_DIR} /src/libmongoc-1.0.pc
1222
- DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
1223
- )
1224
- if (MONGOC_ENABLE_STATIC_INSTALL )
1225
- configure_file (
1226
- ${CMAKE_CURRENT_SOURCE_DIR} /src/libmongoc-static-1.0.pc.in
1227
- ${CMAKE_CURRENT_BINARY_DIR} /src/libmongoc-static-1.0.pc
1228
- @ONLY )
1229
- install (
1230
- FILES ${CMAKE_CURRENT_BINARY_DIR} /src/libmongoc-static-1.0.pc
1231
- DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
1232
- )
1233
- endif ()
1234
1310
# Deprecated alias for libmongoc-1.0.pc, see CDRIVER-2086.
1235
1311
if (MONGOC_ENABLE_SSL )
1236
1312
configure_file (
0 commit comments