[dev-libs/libmongocrypt] wire up tests and fix some cmake4isms

This commit is contained in:
2025-11-09 12:02:37 +01:00
parent e1d5dbf030
commit b841574c7b
3 changed files with 87 additions and 94 deletions

View File

@@ -1,8 +1,10 @@
.evergreen/linker_tests_deps/app/CMakeLists.txt | 4 +--
CMakeLists.txt | 34 ++++---------------------
cmake/FetchMongoC.cmake | 8 +++++-
cmake/IntelDFP.cmake | 8 +++++-
cmake/MongoC-Warnings.cmake | 9 +------
kms-message/CMakeLists.txt | 5 ++--
4 files changed, 10 insertions(+), 42 deletions(-)
6 files changed, 24 insertions(+), 44 deletions(-)
diff --git a/.evergreen/linker_tests_deps/app/CMakeLists.txt b/.evergreen/linker_tests_deps/app/CMakeLists.txt
index 1a5abb1d..9b9f907e 100644
@@ -78,6 +80,54 @@ index c768faca..69e99f9d 100644
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CALC_RELEASE_VERSION
RESULT_VARIABLE CALC_RELEASE_VERSION_RESULT
diff --git a/cmake/FetchMongoC.cmake b/cmake/FetchMongoC.cmake
index f4c46985..be56b18c 100644
--- a/cmake/FetchMongoC.cmake
+++ b/cmake/FetchMongoC.cmake
@@ -27,12 +27,18 @@ FetchContent_Declare (
embedded_mcd
URL "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/${MONGOC_FETCH_TAG_FOR_LIBBSON}.tar.gz"
PATCH_COMMAND ${patch_command} --verbose
+ SOURCE_SUBDIR "NO_ADD_SUBDIRECTORY" # add_subdirectory() is handled by ImportBSON.cmake.
)
# Populate it:
FetchContent_GetProperties (embedded_mcd)
if (NOT embedded_mcd_POPULATED)
message (STATUS "Downloading mongo-c-driver ${MONGOC_FETCH_TAG_FOR_LIBBSON} for libbson")
- FetchContent_Populate (embedded_mcd)
+ if("${CMAKE_VERSION}" VERSION_LESS "3.18.0")
+ # SOURCE_SUBDIR is not yet supported.
+ FetchContent_Populate(embedded_mcd)
+ else()
+ FetchContent_MakeAvailable(embedded_mcd)
+ endif()
endif ()
# Store the directory path to the external mongoc project:
get_filename_component (MONGOCRYPT_MONGOC_DIR "${embedded_mcd_SOURCE_DIR}" ABSOLUTE)
diff --git a/cmake/IntelDFP.cmake b/cmake/IntelDFP.cmake
index 74d0eaa0..2f62938c 100644
--- a/cmake/IntelDFP.cmake
+++ b/cmake/IntelDFP.cmake
@@ -44,12 +44,18 @@ FetchContent_Declare (
URL "${_default_url}"
${_hash_arg}
PATCH_COMMAND ${patch_command} --verbose
+ SOURCE_SUBDIR "NO_ADD_SUBDIRECTORY" # Targets are manually defined below.
)
FetchContent_GetProperties (intel_dfp)
if (NOT intel_dfp_POPULATED)
message (STATUS "Obtaining Intel Decimal FP library: ${INTEL_DFP_LIBRARY_URL}")
- FetchContent_Populate (intel_dfp)
+ if("${CMAKE_VERSION}" VERSION_LESS "3.18.0")
+ # SOURCE_SUBDIR is not yet supported.
+ FetchContent_Populate(intel_dfp)
+ else()
+ FetchContent_MakeAvailable(intel_dfp)
+ endif()
endif ()
# This list of sources was generated by copying the MongoDB server and removing any unnecessary.
diff --git a/cmake/MongoC-Warnings.cmake b/cmake/MongoC-Warnings.cmake
index 4784c933..eb104f48 100644
--- a/cmake/MongoC-Warnings.cmake

View File

@@ -1,113 +1,56 @@
https://github.com/mongodb/libmongocrypt/pull/681
cmake/ImportBSON.cmake | 95 +++++++++++++++++++++++++++++---------------------
1 file changed, 55 insertions(+), 40 deletions(-)
cmake/ImportBSON.cmake | 44 ++++++++++++++++----------------------------
1 file changed, 16 insertions(+), 28 deletions(-)
diff --git a/cmake/ImportBSON.cmake b/cmake/ImportBSON.cmake
index c2ca766f..db31c713 100644
index c2ca766f..2c58a088 100644
--- a/cmake/ImportBSON.cmake
+++ b/cmake/ImportBSON.cmake
@@ -105,27 +105,42 @@ if (NOT DEFINED MONGOCRYPT_MONGOC_DIR)
@@ -105,6 +105,15 @@ if (NOT DEFINED MONGOCRYPT_MONGOC_DIR)
include (FetchMongoC)
# The FetchMongoC module defines a MONGOCRYPT_MONGOC_DIR for us to use
endif ()
+if (ENABLE_ONLINE_TESTS AND (MONGOCRYPT_MONGOC_DIR STREQUAL "USE-SYSTEM" OR USE_SHARED_LIBBSON))
+ message (FATAL_ERROR "Online tests requires static local build of libbson")
+find_package (bson-1.0 REQUIRED)
+if (ENABLE_ONLINE_TESTS)
+ find_package (mongoc-1.0 REQUIRED)
+endif ()
+if (ENABLE_ONLINE_TESTS)
+ if(NOT TARGET mongo::bson_static AND NOT TARGET mongo::mongoc_static)
+ message (FATAL_ERROR "Online tests require static build of libbson and libmongoc")
+ endif ()
+
+function (_import_system_libbson target library_type library_name)
+ # import a system libbson
+ # target: target to add library under
+ # library_type: STATIC or SHARED
+ # library_name: filename to seek
+
+ set (lib "_MONGOCRYPT_SYSTEM_LIBBSON_${library_type}")
+
+ find_library (${lib} ${library_name})
+ if (${${lib}} STREQUAL "${lib}-NOTFOUND")
+ message (FATAL_ERROR "system ${library_name} not found")
+endif ()
+ find_path (_MONGOCRYPT_SYSTEM_LIBBSON_INCLUDE_DIR bson/bson.h PATH_SUFFIXES libbson-1.0)
+
+ add_library (${target} ${library_type} IMPORTED)
+
+ set_target_properties (${target} PROPERTIES
+ IMPORTED_CONFIGURATIONS "Release"
+ INTERFACE_INCLUDE_DIRECTORIES "${_MONGOCRYPT_SYSTEM_LIBBSON_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${${lib}}"
+ )
+ set_property (CACHE ${lib} _MONGOCRYPT_SYSTEM_LIBBSON_INCLUDE_DIR PROPERTY ADVANCED TRUE)
+endfunction ()
function (_import_bson)
- if (MONGOCRYPT_MONGOC_DIR STREQUAL "USE-SYSTEM" AND USE_SHARED_LIBBSON AND NOT ENABLE_ONLINE_TESTS)
+ if (MONGOCRYPT_MONGOC_DIR STREQUAL "USE-SYSTEM")
message (STATUS "NOTE: Using system-wide libbson library. This is intended only for package maintainers.")
- find_library (_MONGOCRYPT_SYSTEM_LIBBSON_SHARED "${CMAKE_SHARED_LIBRARY_PREFIX}bson-1.0${CMAKE_SHARED_LIBRARY_SUFFIX}")
- find_library (_MONGOCRYPT_SYSTEM_LIBBSON_STATIC "${CMAKE_STATIC_LIBRARY_PREFIX}bson-static-1.0${CMAKE_STATIC_LIBRARY_SUFFIX}")
- find_path (_MONGOCRYPT_SYSTEM_LIBBSON_INCLUDE_DIR bson/bson.h PATH_SUFFIXES libbson-1.0)
- add_library (bson_shared SHARED IMPORTED)
- add_library (bson_static STATIC IMPORTED)
- set_target_properties (bson_shared bson_static PROPERTIES
- IMPORTED_CONFIGURATIONS "Release"
- INTERFACE_INCLUDE_DIRECTORIES "${_MONGOCRYPT_SYSTEM_LIBBSON_INCLUDE_DIR}"
- )
- set_property (TARGET bson_shared PROPERTY IMPORTED_LOCATION "${_MONGOCRYPT_SYSTEM_LIBBSON_SHARED}")
- set_property (TARGET bson_static PROPERTY IMPORTED_LOCATION "${_MONGOCRYPT_SYSTEM_LIBBSON_STATIC}")
- set_property (
- CACHE _MONGOCRYPT_SYSTEM_LIBBSON_SHARED
- _MONGOCRYPT_SYSTEM_LIBBSON_INCLUDE_DIR
- PROPERTY ADVANCED
- TRUE
- )
+ if (USE_SHARED_LIBBSON)
+ _import_system_libbson (bson_shared SHARED "${CMAKE_SHARED_LIBRARY_PREFIX}bson-1.0${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ else ()
+ _import_system_libbson (bson_static STATIC "${CMAKE_STATIC_LIBRARY_PREFIX}bson-static-1.0${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ endif ()
else ()
message (STATUS "Using [${MONGOCRYPT_MONGOC_DIR}] as a sub-project for libbson")
# Disable AWS_AUTH, to prevent it from building the kms-message symbols, which we build ourselves
@@ -172,6 +187,26 @@ function (_import_bson)
if (DEFINED saved_build_version)
set (BUILD_VERSION "${saved_build_version}")
if (MONGOCRYPT_MONGOC_DIR STREQUAL "USE-SYSTEM" AND USE_SHARED_LIBBSON AND NOT ENABLE_ONLINE_TESTS)
@@ -183,9 +192,6 @@ function (_import_bson)
endif ()
+
+ # Put the libbson dynamic library into the current binary directory (plus possible config suffix).
+ # This ensures that libbson DLL will resolve on Windows when it searches during tests
+ set_property (TARGET bson_shared PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+
+ if (ENABLE_STATIC)
+ # We are going to build a static libmongocrypt. Enable the static library as
+ # part of "all", and install the archive alongside the rest of our static libraries.
+ # (Useful for some users for convenience of static-linking libmongocrypt: CDRIVER-3187)
+ set_target_properties (bson_static PROPERTIES
+ EXCLUDE_FROM_ALL FALSE
+ OUTPUT_NAME bson-static-for-libmongocrypt
+ )
+ install (
+ FILES $<TARGET_FILE:bson_static>
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RENAME ${CMAKE_STATIC_LIBRARY_PREFIX}bson-static-for-libmongocrypt${CMAKE_STATIC_LIBRARY_SUFFIX}
+ )
+ endif ()
+
if (TARGET mongoc_static)
# Workaround: Embedded mongoc_static does not set its INCLUDE_DIRECTORIES for user targets
target_include_directories (mongoc_static
@@ -202,33 +237,13 @@ install (
endfunction ()
-# Do the import in a function to isolate variable scope
-_import_bson ()
-
# Define interface targets to be used to control the libbson used at both build and import time.
# Refer to mongocrypt-config.cmake to see how these targets are used by consumers
add_library (_mongocrypt-libbson_for_static INTERFACE)
@@ -201,34 +207,16 @@ install (
# The mongocrypt-config file will later add the appropriate link library for downstream
# users during find_package()
if (USE_SHARED_LIBBSON)
target_link_libraries (_mongocrypt-libbson_for_shared INTERFACE $<BUILD_INTERFACE:bson_shared>)
+ target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:bson_shared>)
- target_link_libraries (_mongocrypt-libbson_for_shared INTERFACE $<BUILD_INTERFACE:bson_shared>)
+ target_link_libraries (_mongocrypt-libbson_for_shared INTERFACE $<BUILD_INTERFACE:mongo::bson_shared>)
+ target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:mongo::bson_shared>)
else ()
target_link_libraries (_mongocrypt-libbson_for_shared INTERFACE $<BUILD_INTERFACE:bson_static>)
+ target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:bson_static>)
- target_link_libraries (_mongocrypt-libbson_for_shared INTERFACE $<BUILD_INTERFACE:bson_static>)
+ target_link_libraries (_mongocrypt-libbson_for_shared INTERFACE $<BUILD_INTERFACE:mongo::bson_static>)
+ target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:mongo::bson_static>)
endif ()
-# libbson_for_static always links to the static libbson:
-target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:bson_static>)
if (TARGET mongoc_static)
-if (TARGET mongoc_static)
+if (TARGET mongo::mongoc_static)
# And an alias to the mongoc target for use in some test cases
+ add_library (mongoc_static INTERFACE)
+ target_link_libraries (mongoc_static INTERFACE $<BUILD_INTERFACE:mongo::mongoc_static>)
add_library (_mongocrypt::mongoc ALIAS mongoc_static)
endif ()
-

View File

@@ -22,6 +22,7 @@ RDEPEND="
DEPEND="${RDEPEND}
test? (
dev-libs/libbson[static-libs]
dev-libs/mongo-c-driver[static-libs]
)"
PATCHES=(
@@ -34,8 +35,7 @@ src_configure() {
local mycmakeargs=(
-DCMAKE_SKIP_RPATH=ON
-DUSE_SHARED_LIBBSON=ON
-DMONGOCRYPT_MONGOC_DIR=USE-SYSTEM
-DENABLE_ONLINE_TESTS=OFF
-DENABLE_ONLINE_TESTS="$(usex test ON OFF)"
-DBUILD_VERSION=${PV}
-DENABLE_STATIC="$(usex static-libs ON OFF)"
)