From dc6abf05733e47682c6e2eac6bd1c5d22edbe491 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 27 Mar 2025 21:53:12 -0600 Subject: [PATCH 01/26] Add CTest cases to test pkg-config importing These use the TestProject module to define test cases that run a CMake build, but that CMake project uses `pkg-config` to import the libraries rather than `find_package`. This allows us to test `pkg-config` while relying on CMake to do the heavy lifting around compiler detection and search path handling. --- src/libmongoc/tests/import-tests.cmake | 35 +++++++++++++++++++ .../tests/pkg-config-import/CMakeLists.txt | 32 +++++++++++++++++ src/libmongoc/tests/pkg-config-import/app.c | 4 +++ .../tests/pkg-config-import/use-bson.c | 22 ++++++++++++ .../tests/pkg-config-import/use-mongoc.c | 22 ++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 src/libmongoc/tests/pkg-config-import/CMakeLists.txt create mode 100644 src/libmongoc/tests/pkg-config-import/app.c create mode 100644 src/libmongoc/tests/pkg-config-import/use-bson.c create mode 100644 src/libmongoc/tests/pkg-config-import/use-mongoc.c diff --git a/src/libmongoc/tests/import-tests.cmake b/src/libmongoc/tests/import-tests.cmake index a9c7d0928e..7f303b95d5 100644 --- a/src/libmongoc/tests/import-tests.cmake +++ b/src/libmongoc/tests/import-tests.cmake @@ -112,3 +112,38 @@ add_test_cmake_project( "FIND_BSON_ARGS=REQUIRED;OPTIONAL_COMPONENTS;foo" "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" ) + +add_test_cmake_project( + mongoc/pkg-config/bson-import-shared src/libmongoc/tests/pkg-config-import + INSTALL_PARENT + SETTINGS + PKG_CONFIG_SEARCH=libbson-1.0 + "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" +) + +add_test_cmake_project( + mongoc/pkg-config/bson-import-static src/libmongoc/tests/pkg-config-import + INSTALL_PARENT + SETTINGS + PKG_CONFIG_SEARCH=libbson-static-1.0 + "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" + EXPECT_BSON_STATIC=1 +) + +add_test_cmake_project( + mongoc/pkg-config/mongoc-import-shared src/libmongoc/tests/pkg-config-import + INSTALL_PARENT + SETTINGS + PKG_CONFIG_SEARCH=libmongoc-1.0 + "EXPECT_MONGOC_VERSION=${mongo-c-driver_VERSION_FULL}" +) + +add_test_cmake_project( + mongoc/pkg-config/mongoc-import-static src/libmongoc/tests/pkg-config-import + INSTALL_PARENT + SETTINGS + PKG_CONFIG_SEARCH=libmongoc-static-1.0 + "EXPECT_MONGOC_VERSION=${mongo-c-driver_VERSION_FULL}" + EXPECT_BSON_STATIC=1 + EXPECT_MONGOC_STATIC=1 +) diff --git a/src/libmongoc/tests/pkg-config-import/CMakeLists.txt b/src/libmongoc/tests/pkg-config-import/CMakeLists.txt new file mode 100644 index 0000000000..a04abac5a5 --- /dev/null +++ b/src/libmongoc/tests/pkg-config-import/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.15) +project(pkg-config-import-test LANGUAGES C) + +# This is a test case that tries to build against bson/mongoc using pkg-config. +# Even though this is a CMake project, we import by talking to `pkg-config` + +include(CTest) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(thing REQUIRED IMPORTED_TARGET "${PKG_CONFIG_SEARCH}") + +add_compile_definitions( + "EXPECT_BSON_VERSION=\"${EXPECT_BSON_VERSION}\"" + "EXPECT_MONGOC_VERSION=\"${EXPECT_MONGOC_VERSION}\"" + EXPECT_BSON_STATIC=$ + EXPECT_MONGOC_STATIC=$ + ) + +add_executable(my-app app.c) +target_link_libraries(my-app PRIVATE PkgConfig::thing) + +if(EXPECT_BSON_VERSION) + add_executable(use-bson use-bson.c) + target_link_libraries(use-bson PRIVATE PkgConfig::thing) + add_test(use-bson use-bson) +endif() + +if(EXPECT_MONGOC_VERSION) + add_executable(use-mongoc use-mongoc.c) + target_link_libraries(use-mongoc PRIVATE PkgConfig::thing) + add_test(use-mongoc use-mongoc) +endif() diff --git a/src/libmongoc/tests/pkg-config-import/app.c b/src/libmongoc/tests/pkg-config-import/app.c new file mode 100644 index 0000000000..57d7f69ffe --- /dev/null +++ b/src/libmongoc/tests/pkg-config-import/app.c @@ -0,0 +1,4 @@ +int +main () +{ +} \ No newline at end of file diff --git a/src/libmongoc/tests/pkg-config-import/use-bson.c b/src/libmongoc/tests/pkg-config-import/use-bson.c new file mode 100644 index 0000000000..4c795f706c --- /dev/null +++ b/src/libmongoc/tests/pkg-config-import/use-bson.c @@ -0,0 +1,22 @@ +#include +#include + +#ifndef EXPECT_BSON_VERSION +#error This file requires EXPECT_BSON_VERSION to be defined +#define EXPECT_BSON_VERSION "" +#endif + +#if EXPECT_BSON_STATIC != defined(BSON_STATIC) +#error Static/dynamic mismatch +#endif + +int +main (void) +{ + if (strcmp (BSON_VERSION_S, EXPECT_BSON_VERSION)) { + fprintf ( + stderr, "Wrong BSON_MAJOR_VERSION found (Expected “%s”, but got “%s”)", EXPECT_BSON_VERSION, BSON_VERSION_S); + return 2; + } + return 0; +} diff --git a/src/libmongoc/tests/pkg-config-import/use-mongoc.c b/src/libmongoc/tests/pkg-config-import/use-mongoc.c new file mode 100644 index 0000000000..3f16843c68 --- /dev/null +++ b/src/libmongoc/tests/pkg-config-import/use-mongoc.c @@ -0,0 +1,22 @@ +#include +#include + +#ifndef EXPECT_MONGOC_VERSION +#error This file requires EXPECT_MONGOC_VERSION to be defined +#define EXPECT_MONGOC_VERSION "" +#endif + +int +main (void) +{ + mongoc_client_t *const cl = mongoc_client_new ("mongodb://foo"); + mongoc_client_destroy (cl); + if (strcmp (MONGOC_VERSION_S, EXPECT_MONGOC_VERSION)) { + fprintf (stderr, + "Wrong MONGOC_MAJOR_VERSION found (Expected “%s”, but got “%s”)", + EXPECT_MONGOC_VERSION, + MONGOC_VERSION_S); + return 2; + } + return 0; +} From 3e2c73ae3ceac5225bfd6dbbeb507089408ee96d Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 27 Mar 2025 21:54:42 -0600 Subject: [PATCH 02/26] Set CMAKE_PREFIX_PATH in TestProject When building a TestProject, we want to set CMAKE_PREFIX_PATH to point to the directory that received the parent project installation. --- build/cmake/TestProject.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/build/cmake/TestProject.cmake b/build/cmake/TestProject.cmake index d8f0790810..938dcc3947 100644 --- a/build/cmake/TestProject.cmake +++ b/build/cmake/TestProject.cmake @@ -160,6 +160,7 @@ function(__do_test_project) set(tmp_install_prefix "${TEST_PROJECT_PARENT_BINARY_DIR}/TestProject-install/${test_name_hash}") file(REMOVE_RECURSE "${tmp_install_prefix}") list(APPEND TEST_PROJECT_SETTINGS/CMAKE_INSTALL_PREFIX "${tmp_install_prefix}") + list(APPEND TEST_PROJECT_SETTINGS/CMAKE_PREFIX_PATH "${tmp_install_prefix}") if(TEST_PROJECT_INSTALL_PARENT) cmake_path(ABSOLUTE_PATH tmp_install_prefix NORMALIZE) From c47335455008d8905b73bd973777a0309f6010cf Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 27 Mar 2025 22:04:16 -0600 Subject: [PATCH 03/26] Change the link line for pkg-config static libs Previously, pkg-config generated a `-l` with a library stem, and it would only coincidentally name a static library with a `.a` suffix. Instead, for static libraries, specify the path to the actual static library archive file. Only rely on `-l` searching for shared libraries. --- build/cmake/GeneratePkgConfig.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build/cmake/GeneratePkgConfig.cmake b/build/cmake/GeneratePkgConfig.cmake index e4c1408e65..409f9916bd 100644 --- a/build/cmake/GeneratePkgConfig.cmake +++ b/build/cmake/GeneratePkgConfig.cmake @@ -278,8 +278,11 @@ function(_generate_pkg_config_content out) set(libs) # Link options: set(gx_libs - "-L\${libdir}" - "-l$" + $,STATIC_LIBRARY>, + # If linking static, emit the full path to the static library file + -l\${libdir}/$, + # Otherwise, link to the dynamic library namelink + -L\${libdir} -l$> $> $> ) From 6c1a8d944e403b554edc9cc6b52ba2008b7df801 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 27 Mar 2025 22:35:23 -0600 Subject: [PATCH 04/26] Rename libbson pkg-config files --- src/libbson/CMakeLists.txt | 4 ++-- src/libmongoc/CMakeLists.txt | 8 ++++---- src/libmongoc/tests/import-tests.cmake | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 3c50b72a09..7ad9cca2b2 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -340,11 +340,11 @@ endfunction() if(ENABLE_STATIC_LIBBSON_INSTALL AND TARGET bson_static) install_export_target(bson_static) - mongo_generate_pkg_config(bson_static FILENAME libbson-static-1.0.pc INSTALL) + mongo_generate_pkg_config(bson_static FILENAME bson${PROJECT_VERSION_MAJOR}-static.pc INSTALL) endif() if(ENABLE_SHARED_LIBBSON_INSTALL AND TARGET bson_shared) install_export_target(bson_shared) - mongo_generate_pkg_config(bson_shared FILENAME libbson-1.0.pc INSTALL) + mongo_generate_pkg_config(bson_shared FILENAME bson${PROJECT_VERSION_MAJOR}.pc INSTALL) endif() # Install all headers by doing a recursive directory-install. diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index fc175686f3..896caa14d0 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -899,9 +899,9 @@ if (ENABLE_SHARED) OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-${MONGOC_API_VERSION}" VERSION 0.0.0 SOVERSION 0 - pkg_config_REQUIRES "libbson-1.0" + pkg_config_REQUIRES "bson${PROJECT_VERSION_MAJOR}" ) - mongo_generate_pkg_config(mongoc_shared INSTALL RENAME libmongoc-${MONGOC_API_VERSION}.pc) + mongo_generate_pkg_config(mongoc_shared INSTALL RENAME mongoc${PROJECT_VERSION_MAJOR}.pc) if (ENABLE_APPLE_FRAMEWORK) set_target_properties (mongoc_shared PROPERTIES @@ -976,10 +976,10 @@ if (MONGOC_ENABLE_STATIC_BUILD) set_target_properties (mongoc_static PROPERTIES VERSION 0.0.0 OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-static-${MONGOC_API_VERSION}" - pkg_config_REQUIRES "libbson-static-1.0" + pkg_config_REQUIRES "bson${PROJECT_VERSION_MAJOR}-static" ) if(MONGOC_ENABLE_STATIC_INSTALL) - mongo_generate_pkg_config (mongoc_static FILENAME libmongoc-static-${MONGOC_API_VERSION}.pc INSTALL) + mongo_generate_pkg_config (mongoc_static FILENAME mongoc${PROJECT_VERSION_MAJOR}-static.pc INSTALL) endif() endif () diff --git a/src/libmongoc/tests/import-tests.cmake b/src/libmongoc/tests/import-tests.cmake index 7f303b95d5..46deb35e51 100644 --- a/src/libmongoc/tests/import-tests.cmake +++ b/src/libmongoc/tests/import-tests.cmake @@ -117,7 +117,7 @@ add_test_cmake_project( mongoc/pkg-config/bson-import-shared src/libmongoc/tests/pkg-config-import INSTALL_PARENT SETTINGS - PKG_CONFIG_SEARCH=libbson-1.0 + PKG_CONFIG_SEARCH=bson${PROJECT_VERSION_MAJOR} "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" ) @@ -125,7 +125,7 @@ add_test_cmake_project( mongoc/pkg-config/bson-import-static src/libmongoc/tests/pkg-config-import INSTALL_PARENT SETTINGS - PKG_CONFIG_SEARCH=libbson-static-1.0 + PKG_CONFIG_SEARCH=bson${PROJECT_VERSION_MAJOR}-static "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" EXPECT_BSON_STATIC=1 ) @@ -134,7 +134,7 @@ add_test_cmake_project( mongoc/pkg-config/mongoc-import-shared src/libmongoc/tests/pkg-config-import INSTALL_PARENT SETTINGS - PKG_CONFIG_SEARCH=libmongoc-1.0 + PKG_CONFIG_SEARCH=mongoc1 "EXPECT_MONGOC_VERSION=${mongo-c-driver_VERSION_FULL}" ) @@ -142,7 +142,7 @@ add_test_cmake_project( mongoc/pkg-config/mongoc-import-static src/libmongoc/tests/pkg-config-import INSTALL_PARENT SETTINGS - PKG_CONFIG_SEARCH=libmongoc-static-1.0 + PKG_CONFIG_SEARCH=mongoc1-static "EXPECT_MONGOC_VERSION=${mongo-c-driver_VERSION_FULL}" EXPECT_BSON_STATIC=1 EXPECT_MONGOC_STATIC=1 From 656500e8d2096d7930a8e8ab283f5e3656d18ac4 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 27 Mar 2025 23:05:47 -0600 Subject: [PATCH 05/26] [fixup] pkg-config generation for static libs --- build/cmake/GeneratePkgConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/cmake/GeneratePkgConfig.cmake b/build/cmake/GeneratePkgConfig.cmake index 409f9916bd..8e9d77f17c 100644 --- a/build/cmake/GeneratePkgConfig.cmake +++ b/build/cmake/GeneratePkgConfig.cmake @@ -280,7 +280,7 @@ function(_generate_pkg_config_content out) set(gx_libs $,STATIC_LIBRARY>, # If linking static, emit the full path to the static library file - -l\${libdir}/$, + \${libdir}/$, # Otherwise, link to the dynamic library namelink -L\${libdir} -l$> $> From 81fcf66eb24c5d60d98f699e79cd3e3d1dd58573 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 27 Mar 2025 23:11:21 -0600 Subject: [PATCH 06/26] Update libbson file names and install paths This change is BREAKING and changes the names of generated files for libbson (libmongoc TBD). - Headers are installed in a directory qualified by the project version. - The generated dynamic library has a property version suffix now (instead of 0.0.0). - We set the SOVERSION property to generate a new SONAME for the emitted bson library. - The bson-1.0 CMake packages are removed. - The pkg-config files are now named `bson1` and `bson1-static`. - Both the static and dynamic library file stems are now `libbson1` (no `-static` suffix). - The project now imports the system libbson using the name "bson" instead of `bson-1.0` (as well as the generated mongoc config-file package) --- .../scripts/check-installed-files-bson.bat | 29 ++--- .evergreen/scripts/check-installed-files.bat | 13 ++- .../scripts/link-sample-program-bson.sh | 75 ++++++------- .../link-sample-program-mingw-bson.cmd | 11 +- .../scripts/link-sample-program-mingw.cmd | 4 +- .evergreen/scripts/link-sample-program.sh | 38 ++++--- CMakeLists.txt | 35 ++---- build/cmake/MongoPlatform.cmake | 10 +- src/libbson/CMakeLists.txt | 103 ++++++++---------- src/libbson/etc/bsonConfig.cmake | 49 ++++----- .../compile-with-pkg-config-static.sh | 2 +- .../examples/compile-with-pkg-config.sh | 2 +- src/libbson/src/bson-config.cmake | 13 --- src/libmongoc/CMakeLists.txt | 12 +- .../compile-with-pkg-config-static.sh | 2 +- .../examples/compile-with-pkg-config.sh | 2 +- src/libmongoc/src/mongoc-config.cmake | 2 +- 17 files changed, 174 insertions(+), 228 deletions(-) delete mode 100644 src/libbson/src/bson-config.cmake diff --git a/.evergreen/scripts/check-installed-files-bson.bat b/.evergreen/scripts/check-installed-files-bson.bat index bc3bb27b57..4f4c2b0916 100644 --- a/.evergreen/scripts/check-installed-files-bson.bat +++ b/.evergreen/scripts/check-installed-files-bson.bat @@ -5,14 +5,15 @@ echo off rem Notice that the dll goes in "bin". set DLL=%INSTALL_DIR%\bin\bson-1.0.dll -set LIB_DLL=%INSTALL_DIR%\bin\libbson-1.0.dll -set LIB_LIB=%INSTALL_DIR%\lib\libbson-1.0.lib +set major=1 +set LIB_DLL=%INSTALL_DIR%\bin\libbson%major%.dll +set LIB_LIB=%INSTALL_DIR%\lib\libbson%major%.lib if "%MINGW%"=="1" ( if not exist %LIB_DLL% ( echo %LIB_DLL% is missing! exit /B 1 ) else ( - echo libbson-1.0.dll check ok + echo %LIB_DLL% check ok ) if exist %DLL% ( echo %DLL% is present and should not be! @@ -23,20 +24,20 @@ if "%MINGW%"=="1" ( echo %DLL% is missing! exit /B 1 ) else ( - echo bson-1.0.dll check ok + echo %DLL% check ok ) if exist %LIB_LIB% ( echo %LIB_LIB% is present and should not be! exit /B 1 ) else ( - echo libbson-1.0.lib check ok + echo %LIB_LIB% check ok ) ) -if not exist %INSTALL_DIR%\lib\pkgconfig\libbson-1.0.pc ( - echo libbson-1.0.pc missing! +if not exist %INSTALL_DIR%\lib\pkgconfig\bson%major%.pc ( + echo bson%major%.pc missing! exit /B 1 ) else ( - echo libbson-1.0.pc check ok + echo bson%major%.pc check ok ) if not exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-1.0-config.cmake ( echo bson-1.0-config.cmake missing! @@ -58,18 +59,18 @@ if not exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-targets.cmake ( ) if "%LINK_STATIC%"=="1" ( - if not exist %INSTALL_DIR%\lib\pkgconfig\libbson-static-1.0.pc ( - echo libbson-static-1.0.pc missing! + if not exist %INSTALL_DIR%\lib\pkgconfig\bson%major%-static.pc ( + echo bson%major%-static.pc missing! exit /B 1 ) else ( - echo libbson-static-1.0.pc check ok + echo bson%major%-static.pc check ok ) ) else ( - if exist %INSTALL_DIR%\lib\pkgconfig\libbson-static-1.0.pc ( - echo libbson-static-1.0.pc should not have been installed! + if exist %INSTALL_DIR%\lib\pkgconfig\bson%major%-static.pc ( + echo bson%major%-static.pc should not have been installed! exit /B 1 ) else ( - echo libbson-static-1.0.pc missing, as expected + echo bson%major%-static.pc missing, as expected ) ) diff --git a/.evergreen/scripts/check-installed-files.bat b/.evergreen/scripts/check-installed-files.bat index f75d365a4a..02e0db0c64 100644 --- a/.evergreen/scripts/check-installed-files.bat +++ b/.evergreen/scripts/check-installed-files.bat @@ -7,6 +7,7 @@ rem Notice that the dll goes in "bin". set DLL=%INSTALL_DIR%\bin\mongoc-1.0.dll set LIB_DLL=%INSTALL_DIR%\bin\libmongoc-1.0.dll set LIB_LIB=%INSTALL_DIR%\lib\libmongoc-1.0.lib +set major=1 if "%MINGW%"=="1" ( if not exist %LIB_DLL% ( echo %LIB_DLL% is missing! @@ -32,11 +33,11 @@ if "%MINGW%"=="1" ( echo libmongoc-1.0.lib check ok ) ) -if not exist %INSTALL_DIR%\lib\pkgconfig\libmongoc-1.0.pc ( - echo libmongoc-1.0.pc missing! +if not exist %INSTALL_DIR%\lib\pkgconfig\mongoc%major%.pc ( + echo mongoc%major%.pc missing! exit /B 1 ) else ( - echo libmongoc-1.0.pc check ok + echo mongoc%major%.pc check ok ) if not exist %INSTALL_DIR%\lib\cmake\mongoc-1.0\mongoc-1.0-config.cmake ( echo mongoc-1.0-config.cmake missing! @@ -56,11 +57,11 @@ if not exist %INSTALL_DIR%\lib\cmake\mongoc-1.0\mongoc-targets.cmake ( ) else ( echo mongoc-targets.cmake check ok ) -if not exist %INSTALL_DIR%\lib\pkgconfig\libmongoc-static-1.0.pc ( - echo libmongoc-static-1.0.pc missing! +if not exist %INSTALL_DIR%\lib\pkgconfig\mongoc%major%-static.pc ( + echo mongoc%major%-static.pc missing! exit /B 1 ) else ( - echo libmongoc-static-1.0.pc check ok + echo mongoc%major%-static.pc check ok ) echo on diff --git a/.evergreen/scripts/link-sample-program-bson.sh b/.evergreen/scripts/link-sample-program-bson.sh index 7ab94d76dc..384229f49e 100755 --- a/.evergreen/scripts/link-sample-program-bson.sh +++ b/.evergreen/scripts/link-sample-program-bson.sh @@ -4,27 +4,33 @@ set -o errexit # Exit the script with error if any of the commands fail # Supported/used environment variables: # LINK_STATIC Whether to statically link to libbson # BUILD_SAMPLE_WITH_CMAKE Link program w/ CMake. Default: use pkg-config. -# BUILD_SAMPLE_WITH_CMAKE_DEPRECATED If BUILD_SAMPLE_WITH_CMAKE is set, then use deprecated CMake scripts instead. -echo "LINK_STATIC=$LINK_STATIC BUILD_SAMPLE_WITH_CMAKE=$BUILD_SAMPLE_WITH_CMAKE BUILD_SAMPLE_WITH_CMAKE_DEPRECATED=$BUILD_SAMPLE_WITH_CMAKE_DEPRECATED" +echo "LINK_STATIC=$LINK_STATIC BUILD_SAMPLE_WITH_CMAKE=$BUILD_SAMPLE_WITH_CMAKE" DIR=$(dirname $0) . $DIR/find-cmake-latest.sh CMAKE=$(find_cmake_latest) . $DIR/check-symlink.sh +# The major version of the project. Appears in certain install filenames. +_full_version=$(cat "$DIR/../../VERSION_CURRENT") +version="${_full_version%-*}" # 1.2.3-dev → 1.2.3 +major="${version%%.*}" # 1.2.3 → 1 +echo "major version: $version" +echo " full version: $major" + # Get the kernel name, lowercased OS=$(uname -s | tr '[:upper:]' '[:lower:]') echo "OS: $OS" if [ "$OS" = "darwin" ]; then SO=dylib - LIB_SO=libbson-1.0.0.dylib + LIB_SO=libbson$major.$version.dylib LDD="otool -L" else SO=so - LIB_SO=libbson-1.0.so.0.0.0 + LIB_SO=libbson$major.so.$version LDD=ldd fi @@ -52,11 +58,11 @@ fi if [ "$LINK_STATIC" ]; then # Our CMake system builds shared and static by default. - $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DENABLE_TESTS=OFF "$SCRATCH_DIR" + $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_TESTING=OFF -DENABLE_TESTS=OFF -DENABLE_MONGOC=OFF "$SCRATCH_DIR" $CMAKE --build . --parallel $CMAKE --build . --parallel --target install else - $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DENABLE_TESTS=OFF -DENABLE_STATIC=OFF "$SCRATCH_DIR" + $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_TESTING=OFF -DENABLE_TESTS=OFF -DENABLE_MONGOC=OFF -DENABLE_STATIC=OFF "$SCRATCH_DIR" $CMAKE --build . --parallel $CMAKE --build . --parallel --target install @@ -90,10 +96,10 @@ set +o xtrace # libbson-1.0.so.0.0.0 if [ "$OS" != "darwin" ]; then # From check-symlink.sh - check_symlink libbson-1.0.so libbson-1.0.so.0 - check_symlink libbson-1.0.so.0 libbson-1.0.so.0.0.0 + check_symlink libbson$major.so libbson$major.so.$major + check_symlink libbson$major.so.$major libbson$major.so.$version SONAME=$(objdump -p $INSTALL_DIR/lib/$LIB_SO|grep SONAME|awk '{print $2}') - EXPECTED_SONAME="libbson-1.0.so.0" + EXPECTED_SONAME="libbson$major.so.$major" if [ "$SONAME" != "$EXPECTED_SONAME" ]; then echo "SONAME should be $EXPECTED_SONAME, not $SONAME" exit 1 @@ -110,55 +116,44 @@ else fi fi -if test ! -f $INSTALL_DIR/lib/pkgconfig/libbson-1.0.pc; then - echo "libbson-1.0.pc missing!" - exit 1 -else - echo "libbson-1.0.pc check ok" -fi -if test ! -f $INSTALL_DIR/lib/cmake/bson-1.0/bson-1.0-config.cmake; then - echo "bson-1.0-config.cmake missing!" +if test ! -f $INSTALL_DIR/lib/pkgconfig/bson$major.pc; then + echo "bson$major.pc missing!" exit 1 else - echo "bson-1.0-config.cmake check ok" + echo "bson$major.pc check ok" fi -if test ! -f $INSTALL_DIR/lib/cmake/bson-1.0/bson-1.0-config-version.cmake; then - echo "bson-1.0-config-version.cmake missing!" +if test ! -f $INSTALL_DIR/lib/cmake/bson-$version/bsonConfig.cmake; then + echo "bsonConfig.cmake missing!" exit 1 else - echo "bson-1.0-config-version.cmake check ok" + echo "bsonConfig.cmake check ok" fi -if test ! -f $INSTALL_DIR/lib/cmake/bson-1.0/bson-targets.cmake; then - echo "bson-targets.cmake missing!" +if test ! -f $INSTALL_DIR/lib/cmake/bson-$version/bsonConfig.cmake; then + echo "bsonConfig.cmake missing!" exit 1 else - echo "bson-targets.cmake check ok" + echo "bsonConfig.cmake check ok" fi if [ "$LINK_STATIC" ]; then - if test ! -f $INSTALL_DIR/lib/libbson-static-1.0.a; then - echo "libbson-static-1.0.a missing!" + if test ! -f $INSTALL_DIR/lib/libbson$major.a; then + echo "libbson$major.a missing!" exit 1 else - echo "libbson-static-1.0.a check ok" + echo "libbson$major.a check ok" fi - if test ! -f $INSTALL_DIR/lib/pkgconfig/libbson-static-1.0.pc; then - echo "libbson-static-1.0.pc missing!" + if test ! -f $INSTALL_DIR/lib/pkgconfig/bson$major-static.pc; then + echo "bson$major-static.pc missing!" exit 1 else - echo "libbson-static-1.0.pc check ok" + echo "bson$major-static.pc check ok" fi fi cd $SRCROOT if [ "$BUILD_SAMPLE_WITH_CMAKE" ]; then - # Test our CMake package config file with CMake's find_package command. - if [ "$BUILD_SAMPLE_WITH_CMAKE_DEPRECATED" ]; then - EXAMPLE_DIR=$SRCROOT/src/libbson/examples/cmake-deprecated/find_package - else - EXAMPLE_DIR=$SRCROOT/src/libbson/examples/cmake/find_package - fi + EXAMPLE_DIR=$SRCROOT/src/libbson/examples/cmake/find_package if [ "$LINK_STATIC" ]; then EXAMPLE_DIR="${EXAMPLE_DIR}_static" @@ -174,12 +169,12 @@ else if [ "$LINK_STATIC" ]; then echo "pkg-config output:" - echo $(pkg-config --libs --cflags libbson-static-1.0) - ./compile-with-pkg-config-static.sh + echo $(pkg-config --libs --cflags bson$major-static) + env major=$major ./compile-with-pkg-config-static.sh else echo "pkg-config output:" - echo $(pkg-config --libs --cflags libbson-1.0) - ./compile-with-pkg-config.sh + echo $(pkg-config --libs --cflags bson$major) + env major=$major ./compile-with-pkg-config.sh fi fi diff --git a/.evergreen/scripts/link-sample-program-mingw-bson.cmd b/.evergreen/scripts/link-sample-program-mingw-bson.cmd index 3a0f0c74e8..14c69263f0 100644 --- a/.evergreen/scripts/link-sample-program-mingw-bson.cmd +++ b/.evergreen/scripts/link-sample-program-mingw-bson.cmd @@ -19,6 +19,9 @@ mkdir %INSTALL_DIR% set PATH=%PATH%;%INSTALL_DIR%\bin +set major=1 +set version=1.31.0 + cd %BUILD_DIR% robocopy "%SRCROOT%" "%BUILD_DIR%" /E /XD ".git" "%BUILD_DIR%" "_build" "cmake-build" /NP /NFL /NDL @@ -41,11 +44,11 @@ if errorlevel 1 ( ) set MINGW= -if not exist %INSTALL_DIR%\lib\libbson-static-1.0.a ( - echo libbson-static-1.0.a missing! +if not exist %INSTALL_DIR%\lib\libbson%major%.a ( + echo libbson%major%.a missing! exit /B 1 ) else ( - echo libbson-static-1.0.a check ok + echo libbson%major%.a check ok ) cd %SRCROOT% @@ -60,7 +63,7 @@ exit /B 0 set PKG_CONFIG_PATH=%INSTALL_DIR%\lib\pkgconfig rem http://stackoverflow.com/questions/2323292 -for /f %%i in ('pkg-config --libs --cflags libbson-1.0') do set PKG_CONFIG_OUT=%%i +for /f %%i in ('pkg-config --libs --cflags bson%major%') do set PKG_CONFIG_OUT=%%i echo PKG_CONFIG_OUT is %PKG_CONFIG_OUT% diff --git a/.evergreen/scripts/link-sample-program-mingw.cmd b/.evergreen/scripts/link-sample-program-mingw.cmd index a6e29cf591..ff9bf8417f 100644 --- a/.evergreen/scripts/link-sample-program-mingw.cmd +++ b/.evergreen/scripts/link-sample-program-mingw.cmd @@ -20,6 +20,8 @@ mkdir %INSTALL_DIR% set PATH=%PATH%;%INSTALL_DIR%\bin +set major=1 + cd %BUILD_DIR% robocopy "%SRCROOT%" "%BUILD_DIR%" /E /XD ".git" "%BUILD_DIR%" "_build" "cmake-build" /NP /NFL /NDL @@ -61,7 +63,7 @@ exit /B 0 set PKG_CONFIG_PATH=%INSTALL_DIR%\lib\pkgconfig rem http://stackoverflow.com/questions/2323292 -for /f %%i in ('pkg-config --libs --cflags libmongoc-1.0') do set PKG_CONFIG_OUT=%%i +for /f %%i in ('pkg-config --libs --cflags mongoc%major%') do set PKG_CONFIG_OUT=%%i echo PKG_CONFIG_OUT is %PKG_CONFIG_OUT% diff --git a/.evergreen/scripts/link-sample-program.sh b/.evergreen/scripts/link-sample-program.sh index 031d5b3e36..987749645b 100755 --- a/.evergreen/scripts/link-sample-program.sh +++ b/.evergreen/scripts/link-sample-program.sh @@ -4,19 +4,25 @@ set -o errexit # Exit the script with error if any of the commands fail # Supported/used environment variables: # LINK_STATIC Whether to statically link to libmongoc # BUILD_SAMPLE_WITH_CMAKE Link program w/ CMake. Default: use pkg-config. -# BUILD_SAMPLE_WITH_CMAKE_DEPRECATED If BUILD_SAMPLE_WITH_CMAKE is set, then use deprecated CMake scripts instead. # ENABLE_SSL Set -DENABLE_SSL # ENABLE_SNAPPY Set -DENABLE_SNAPPY # CMAKE Path to cmake executable. -echo "LINK_STATIC=$LINK_STATIC BUILD_SAMPLE_WITH_CMAKE=$BUILD_SAMPLE_WITH_CMAKE BUILD_SAMPLE_WITH_CMAKE_DEPRECATED=$BUILD_SAMPLE_WITH_CMAKE_DEPRECATED" +echo "LINK_STATIC=$LINK_STATIC BUILD_SAMPLE_WITH_CMAKE=$BUILD_SAMPLE_WITH_CMAKE" DIR=$(dirname $0) . $DIR/find-cmake-latest.sh CMAKE=$(find_cmake_latest) . $DIR/check-symlink.sh +# The major version of the project. Appears in certain install filenames. +_full_version=$(cat "$DIR/../../VERSION_CURRENT") +version="${_full_version%-*}" # 1.2.3-dev → 1.2.3 +major="${version%%.*}" # 1.2.3 → 1 +echo "major version: $version" +echo " full version: $major" + # Get the kernel name, lowercased OS=$(uname -s | tr '[:upper:]' '[:lower:]') echo "OS: $OS" @@ -82,7 +88,7 @@ if [[ -f $DIR/find-ccache.sh ]]; then fi fi -$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $SSL_CMAKE_OPTION $SNAPPY_CMAKE_OPTION $STATIC_CMAKE_OPTION -DENABLE_ZSTD=$ZSTD "$SCRATCH_DIR" +$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake -DBUILD_TESTING=OFF $SSL_CMAKE_OPTION $SNAPPY_CMAKE_OPTION $STATIC_CMAKE_OPTION -DENABLE_ZSTD=$ZSTD "$SCRATCH_DIR" $CMAKE --build . --parallel $CMAKE --build . --parallel --target install @@ -120,11 +126,11 @@ else fi -if test ! -f $INSTALL_DIR/lib/pkgconfig/libmongoc-1.0.pc; then - echo "libmongoc-1.0.pc missing!" +if test ! -f $INSTALL_DIR/lib/pkgconfig/mongoc$major.pc; then + echo "mongoc$major.pc missing!" exit 1 else - echo "libmongoc-1.0.pc check ok" + echo "mongoc$major.pc check ok" fi if test ! -f $INSTALL_DIR/lib/cmake/mongoc-1.0/mongoc-1.0-config.cmake; then echo "mongoc-1.0-config.cmake missing!" @@ -153,11 +159,11 @@ if [ "$LINK_STATIC" ]; then else echo "libmongoc-static-1.0.a check ok" fi - if test ! -f $INSTALL_DIR/lib/pkgconfig/libmongoc-static-1.0.pc; then - echo "libmongoc-static-1.0.pc missing!" + if test ! -f $INSTALL_DIR/lib/pkgconfig/mongoc1-static.pc; then + echo "mongoc1-static.pc missing!" exit 1 else - echo "libmongoc-static-1.0.pc check ok" + echo "mongoc1-static.pc check ok" fi else if test -f $INSTALL_DIR/lib/libmongoc-static-1.0.a; then @@ -168,13 +174,13 @@ else echo "libmongoc-1.0.a shouldn't have been installed" exit 1 fi - if test -f $INSTALL_DIR/lib/pkgconfig/libmongoc-static-1.0.pc; then - echo "libmongoc-static-1.0.pc shouldn't have been installed" + if test -f $INSTALL_DIR/lib/pkgconfig/mongoc1-static.pc; then + echo "mongoc1-static.pc shouldn't have been installed" exit 1 fi fi -if [ "$OS" = "darwin" && "${HOSTTYPE:?}" != "arm64" ]; then +if [ "$OS" = "darwin" ] && [ "${HOSTTYPE:?}" != "arm64" ]; then if test -f $INSTALL_DIR/bin/mongoc-stat; then echo "mongoc-stat shouldn't have been installed" exit 1 @@ -210,12 +216,12 @@ else if [ "$LINK_STATIC" ]; then echo "pkg-config output:" - echo $(pkg-config --libs --cflags libmongoc-static-1.0) - ./compile-with-pkg-config-static.sh + echo $(pkg-config --libs --cflags mongoc$major-static) + env major=$major ./compile-with-pkg-config-static.sh else echo "pkg-config output:" - echo $(pkg-config --libs --cflags libmongoc-1.0) - ./compile-with-pkg-config.sh + echo $(pkg-config --libs --cflags mongoc$major) + env major=$major ./compile-with-pkg-config.sh fi fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 85a219488a..90f2813089 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,31 +308,17 @@ mongo_pick(MONGOC_ENABLE_STATIC_INSTALL 1 0 [[ENABLE_STATIC AND NOT ENABLE_STATIC STREQUAL "BUILD_ONLY"]]) if (USE_SYSTEM_LIBBSON) - # The input variable BSON_ROOT_DIR is respected for backwards compatibility, - # but you should use the standard CMAKE_PREFIX_PATH instead. - message (STATUS "Searching for libbson CMake packages") - find_package (bson-1.0 - "${PROJECT_VERSION}" - HINTS - ${BSON_ROOT_DIR}) - - if (NOT bson-1.0_FOUND) - message (FATAL_ERROR "System libbson not found") - endif () - - message (STATUS "libbson found version \"${bson-1.0_VERSION}\"") - message (STATUS "disabling test-libmongoc since using system libbson") - SET (ENABLE_TESTS OFF) + find_package (bson "${PROJECT_VERSION}" REQUIRED) + # Disable test-libmongoc since we are using a system libbson + set (ENABLE_TESTS OFF) set (USING_SYSTEM_BSON TRUE) - if (NOT TARGET mongo::bson_shared) - message (FATAL_ERROR "System libbson built without shared library target") + if (NOT TARGET bson::shared) + message (FATAL_ERROR "System libbson built without shared library target") endif () - set (BSON_LIBRARIES mongo::bson_shared) - if (NOT TARGET mongo::bson_static) - message (FATAL_ERROR "System libbson built without static library target") + if (NOT TARGET bson::static) + message (FATAL_ERROR "System libbson built without static library target") endif () - set (BSON_STATIC_LIBRARIES mongo::bson_static) endif () set (BUILD_SOURCE_DIR ${CMAKE_BINARY_DIR}) @@ -405,14 +391,7 @@ add_subdirectory (src/common) if (NOT USING_SYSTEM_BSON) message (STATUS "Using bundled libbson") - add_subdirectory (src/libbson) - # Defined in src/libbson/CMakeLists.txt - set (BSON_STATIC_LIBRARIES bson_static) - set (BSON_LIBRARIES bson_shared) - set (BSON_STATIC_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/libbson/src" "${PROJECT_BINARY_DIR}/src/libbson/src") - set (BSON_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/libbson/src" "${PROJECT_BINARY_DIR}/src/libbson/src") - set (BSON_STATIC_PUBLIC_DEFINITIONS "BSON_STATIC") endif () if (MSVC) diff --git a/build/cmake/MongoPlatform.cmake b/build/cmake/MongoPlatform.cmake index d5e5d1075d..e5dccab3ad 100644 --- a/build/cmake/MongoPlatform.cmake +++ b/build/cmake/MongoPlatform.cmake @@ -8,9 +8,9 @@ Use mongo_platform_compile_options and mongo_platform_link_options to add usage requirements to this library. The mongo::detail::c_platform library is installed and exported with the -bson-targets export set as an implementation detail. It is installed with this +mongo-platform-targets export set as an implementation detail. It is installed with this export set so that it is available to both libbson and libmongoc (attempting to -install this target in both bson-targets and mongoc-targets export sets would +install this target in both mongo-platform-targets and mongoc-targets export sets would lead to duplicate definitions of mongo::detail::c_platform for downstream users). @@ -23,9 +23,9 @@ else () # The system libbson exports the `mongo::detail::c_platform` target. # Do not define the `mongo::detail::c_platform` target, to prevent an "already defined" error. endif () -set_property(TARGET _mongo-platform PROPERTY EXPORT_NAME detail::c_platform) -install(TARGETS _mongo-platform EXPORT bson-targets) - +set_property(TARGET _mongo-platform PROPERTY EXPORT_NAME mongo::detail::c_platform) +# This export set is installed as part of libbson. Search: PLATFORM-EXPORT-TARGET-INSTALL +install(TARGETS _mongo-platform EXPORT mongo-platform-targets) #[[ Define additional platform-support compile options diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 7ad9cca2b2..7e1d260bf9 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -29,15 +29,10 @@ set(libbson_VERSION_FULL ${mongo-c-driver_VERSION_FULL}) set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) -# A tag attached to libbson artifacts, denoting the *major* API version, used to -# potentially co-locate additional future major versions. -set (BSON_API_VERSION 1.0) - if (APPLE) cmake_policy (SET CMP0042 OLD) endif () - # .d8888b. 888 888 d8b # d88P Y88b 888 888 Y8P # Y88b. 888 888 @@ -178,13 +173,12 @@ set(bson_libs) if(ENABLE_STATIC) add_library(bson_static STATIC ${all_sources}) + add_library(bson::static ALIAS bson_static) + set_property(TARGET bson_static PROPERTY EXPORT_NAME bson::static) list(APPEND bson_libs bson_static) - # Define `BSON_STATIC` when building to suppress the annotation __declspec(dllexport). - # This prevents consumers of bson_static from exporting the symbols. - target_compile_definitions(bson_static PRIVATE BSON_STATIC) - # When consumers link against bson_static, suppress the annotation __declspec(dllimport), - # since those symbols will be available immediately at the link step: - target_compile_definitions(bson_static INTERFACE BSON_STATIC) + # Define `BSON_STATIC` to suppress __declspec(dllexport/dllimport) when compiling + # and consuming the static library + target_compile_definitions(bson_static PUBLIC BSON_STATIC) if(ENABLE_PIC) # User wants static libs to use PIC code. @@ -193,7 +187,9 @@ if(ENABLE_STATIC) endif() if(ENABLE_SHARED) - add_library(bson_shared SHARED ${all_sources}) + add_library(bson_shared SHARED ${all_sources}) + add_library(bson::shared ALIAS bson_shared) + set_property(TARGET bson_shared PROPERTY EXPORT_NAME bson::shared) if(WIN32) # Add resource-definition script for Windows shared library (.dll). configure_file(libbson.rc.in libbson.rc) @@ -235,13 +231,10 @@ mongo_target_requirements( ) set_target_properties(${bson_libs} PROPERTIES - VERSION "0.0.0" - SOVERSION "0" - OUTPUT_NAME "${BSON_OUTPUT_BASENAME}-${BSON_API_VERSION}" + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" + OUTPUT_NAME "${BSON_OUTPUT_BASENAME}${PROJECT_VERSION_MAJOR}" ) -if(TARGET bson_static) - set_property(TARGET bson_static PROPERTY OUTPUT_NAME "${BSON_OUTPUT_BASENAME}-static-${BSON_API_VERSION}") -endif() if (ENABLE_APPLE_FRAMEWORK) set_target_properties(bson_shared PROPERTIES @@ -310,12 +303,22 @@ endif () # ENABLE_EXAMPLES # 888 888 888 X88 Y88b. 888 888 888 888 # 8888888 888 888 88888P' "Y888 "Y888888 888 888 -set (BSON_HEADER_INSTALL_DIR - "${CMAKE_INSTALL_INCLUDEDIR}/libbson-${BSON_API_VERSION}" +# Prefix directory for all libbson headers. +if(NOT DEFINED BSON_INSTALL_INCLUDEDIR) + set(BSON_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/bson-${PROJECT_VERSION}") +endif() +# Prefix directory for all libbson CMake package files +if(NOT DEFINED BSON_INSTALL_CMAKEDIR) + set(BSON_INSTALL_CMAKEDIR "${MONGOC_INSTALL_CMAKEDIR}/bson-${PROJECT_VERSION}") +endif() + +# pkg-config properties: +set_directory_properties(PROPERTIES + pkg_config_INCLUDE_DIRECTORIES "${BSON_INSTALL_INCLUDEDIR}" + pkg_config_NAME "bson" ) + function(install_export_target target) - # Tell pkg-config where the headers are going: - set_property(TARGET ${target} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${BSON_HEADER_INSTALL_DIR}") # Install the target: install( TARGETS "${target}" @@ -324,17 +327,16 @@ function(install_export_target target) LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - INCLUDES DESTINATION "${BSON_HEADER_INSTALL_DIR}" + INCLUDES DESTINATION "${BSON_INSTALL_INCLUDEDIR}" FRAMEWORK DESTINATION "${CMAKE_INSTALL_BINDIR}" ) # Install the unique export set into a file that is qualified by the name of # the target itself. The main config-file package will search for the - # possibly-installed exported targets for the known targets. See: bson-config.cmake + # possibly-installed exported targets for the known targets. install( EXPORT "${target}-targets" - NAMESPACE mongo:: FILE "${target}-targets.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/bson-${BSON_API_VERSION}" + DESTINATION "${BSON_INSTALL_CMAKEDIR}" ) endfunction() @@ -347,20 +349,23 @@ if(ENABLE_SHARED_LIBBSON_INSTALL AND TARGET bson_shared) mongo_generate_pkg_config(bson_shared FILENAME bson${PROJECT_VERSION_MAJOR}.pc INSTALL) endif() -# Install all headers by doing a recursive directory-install. +# Install all headers by doing a recursive directory-install. In the future, this +# can be better handled by installing the headers as a file set via target_sources() install( DIRECTORY # Trailing "/" requests directory contents, not the dir itself: - src/bson/ + src/ # Also get the generated dir: - ${PROJECT_BINARY_DIR}/src/bson/ - DESTINATION "${BSON_HEADER_INSTALL_DIR}/bson" + ${PROJECT_BINARY_DIR}/src/ + DESTINATION "${BSON_INSTALL_INCLUDEDIR}" # Only grab the *public* headers. FILES_MATCHING PATTERN "*.h" PATTERN "*-private.h" EXCLUDE # Don't generate an empty "modules" directory PATTERN "modules" EXCLUDE + # Don't install jsonsl headers + PATTERN "jsonsl" EXCLUDE ) if (ENABLE_APPLE_FRAMEWORK) @@ -370,37 +375,15 @@ if (ENABLE_APPLE_FRAMEWORK) ) endif () -# Generate the config-file package -include (CMakePackageConfigHelpers) -write_basic_package_version_file ( - "${CMAKE_CURRENT_BINARY_DIR}/bson/bson-${BSON_API_VERSION}-config-version.cmake" - VERSION ${BSON_VERSION} - COMPATIBILITY AnyNewerVersion -) - -configure_file (src/bson-config.cmake - "${CMAKE_CURRENT_BINARY_DIR}/bson/bson-${BSON_API_VERSION}-config.cmake" - COPYONLY -) - -install ( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/bson/bson-${BSON_API_VERSION}-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/bson/bson-${BSON_API_VERSION}-config-version.cmake" - DESTINATION - ${CMAKE_INSTALL_LIBDIR}/cmake/bson-${BSON_API_VERSION} - COMPONENT - Devel -) - -# Install the base targets. (Prior targets were installed above) -install (EXPORT bson-targets - NAMESPACE mongo:: - FILE bson-targets.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bson-${BSON_API_VERSION} +# Install the platform libraries from MongoPlatform.cmake. Search: PLATFORM-EXPORT-TARGET-INSTALL +install(EXPORT mongo-platform-targets + # The "00" prefix forces the file to sort to the top during globbing, because + # we want it to be included first before the libbson targets + FILE 00-mongo-platform-targets.cmake + DESTINATION "${BSON_INSTALL_CMAKEDIR}" ) -set(bson_cmake_prefix "${MONGOC_INSTALL_CMAKEDIR}/bson-${PROJECT_VERSION}") +# Install the CMake config-mode package configure_file( ${mongo-c-driver_SOURCE_DIR}/build/cmake/packageConfigVersion.cmake.in bsonConfigVersion.cmake @@ -408,7 +391,7 @@ configure_file( ) install( FILES etc/bsonConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/bsonConfigVersion.cmake" - DESTINATION "${bson_cmake_prefix}" + DESTINATION "${BSON_INSTALL_CMAKEDIR}" ) include (CPack) diff --git a/src/libbson/etc/bsonConfig.cmake b/src/libbson/etc/bsonConfig.cmake index 7274bf3964..3233ef6c84 100644 --- a/src/libbson/etc/bsonConfig.cmake +++ b/src/libbson/etc/bsonConfig.cmake @@ -1,16 +1,15 @@ #[[ - This is a transitional CMake package config file to allow compatibility - between libbson 1.x and libbson 2.x CMake packages. + CMake package file for the BSON library. - When distributed with libbson 1.x, this file is mostly just a shim for - the `bson-1.0` CMake packages. + This file globs and includes all "*-targets.cmake" files in the containing + directory, and intends that those files define the actual libbson targets. - This file imports "bson-1.0" and generates alias targets for it: + This file also defines a `bson::bson` target, which redirects to either + `bson::static` or `bson::shared` depending on what type of library is + available and can be controlled with an import-time CMake setting. - • `bson::shared` → `mongo::bson_shared` - • `bson::static` → `mongo::bson_static` - • `bson::bson` → Points to either `bson::shared` or `bson::static`, - controlled by `BSON_DEFAULT_IMPORTED_LIBRARY_TYPE` + If the installation has a static library, it is named `bson::static`. If + the installation has a shared (dynamic) library, it is named `bson::shared`. ]] # Check for missing components before proceeding. We don't provide any, so we @@ -31,35 +30,29 @@ if(missing_required_components) endif() include(CMakeFindDependencyMacro) +find_dependency(Threads) # Required for Threads::Threads -# We are installed alongside the `bson-1.0` packages. Forcibly prevent find_package -# from considering any other `bson-1.0` package that might live elsewhere on the system -# by setting HINTS and NO_DEFAULT_PATH -get_filename_component(parent_dir "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) -find_dependency(bson-1.0 HINTS ${parent_dir} NO_DEFAULT_PATH) +# Import the target files that will be install alongside this file. Only the +# targets of libraries that were actually installed alongside this file will be imported +file(GLOB __targets_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") +foreach(__file IN LISTS __targets_files) + include("${__file}") +endforeach() # The library type that is linked with `bson::bson` -set(_default_lib_type) -# Add compat targets for the bson-1.0 package targets -if(TARGET mongo::bson_shared AND NOT TARGET bson::shared) - add_library(bson::shared IMPORTED INTERFACE) - set_property(TARGET bson::shared APPEND PROPERTY INTERFACE_LINK_LIBRARIES mongo::bson_shared) - set(_default_lib_type SHARED) -endif() -if(TARGET mongo::bson_static AND NOT TARGET bson::static) - add_library(bson::static IMPORTED INTERFACE) - set_property(TARGET bson::static APPEND PROPERTY INTERFACE_LINK_LIBRARIES mongo::bson_static) +set(__default_lib_type SHARED) +if(TARGET bson::static) # If static is available, set it as the default library type - set(_default_lib_type STATIC) + set(__default_lib_type STATIC) endif() # Allow the user to tweak what library type is linked for `bson::bson` -set(BSON_DEFAULT_IMPORTED_LIBRARY_TYPE "${_default_lib_type}" +set(BSON_DEFAULT_IMPORTED_LIBRARY_TYPE "${__default_lib_type}" CACHE STRING "The default library type that is used when linking against 'bson::bson' (either SHARED or STATIC, requires that the package was built with the appropriate library type)") set_property(CACHE BSON_DEFAULT_IMPORTED_LIBRARY_TYPE PROPERTY STRINGS SHARED STATIC) if(NOT TARGET bson::bson) # Don't redefine the target if we were already included - string(TOLOWER "${BSON_DEFAULT_IMPORTED_LIBRARY_TYPE}" _type) + string(TOLOWER "${BSON_DEFAULT_IMPORTED_LIBRARY_TYPE}" __type) add_library(bson::bson IMPORTED INTERFACE) - set_property(TARGET bson::bson APPEND PROPERTY INTERFACE_LINK_LIBRARIES bson::${_type}) + set_property(TARGET bson::bson APPEND PROPERTY INTERFACE_LINK_LIBRARIES bson::${__type}) endif() diff --git a/src/libbson/examples/compile-with-pkg-config-static.sh b/src/libbson/examples/compile-with-pkg-config-static.sh index 9a6142a5f7..dd84504415 100755 --- a/src/libbson/examples/compile-with-pkg-config-static.sh +++ b/src/libbson/examples/compile-with-pkg-config-static.sh @@ -3,4 +3,4 @@ set -o errexit # Exit the script with error if any of the commands fail # -- sphinx-include-start -- -gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags libbson-static-1.0) +gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags bson$major-static) diff --git a/src/libbson/examples/compile-with-pkg-config.sh b/src/libbson/examples/compile-with-pkg-config.sh index c1df9646f4..9e4ed5239c 100755 --- a/src/libbson/examples/compile-with-pkg-config.sh +++ b/src/libbson/examples/compile-with-pkg-config.sh @@ -3,4 +3,4 @@ set -o errexit # Exit the script with error if any of the commands fail # -- sphinx-include-start -- -gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags libbson-1.0) +gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags bson$major) diff --git a/src/libbson/src/bson-config.cmake b/src/libbson/src/bson-config.cmake deleted file mode 100644 index 388681f300..0000000000 --- a/src/libbson/src/bson-config.cmake +++ /dev/null @@ -1,13 +0,0 @@ -include(CMakeFindDependencyMacro) -find_dependency(Threads) # Required for Threads::Threads - -# Import common targets first: -include("${CMAKE_CURRENT_LIST_DIR}/bson-targets.cmake") - -# Now import the targets of each link-kind that's available. Only the targets of -# libbson libraries that were actually installed alongside this file will be -# imported. -file(GLOB target_files "${CMAKE_CURRENT_LIST_DIR}/bson_*-targets.cmake") -foreach(inc IN LISTS target_files) - include("${inc}") -endforeach() diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 896caa14d0..a6b56d7b36 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -834,14 +834,13 @@ if (MONGOC_ENABLE_MONGODB_AWS_AUTH) endif() endif () -if (MONGOC_ENABLE_STATIC_BUILD) +if (TARGET bson::static) add_library (mcd_rpc STATIC EXCLUDE_FROM_ALL ${PROJECT_SOURCE_DIR}/src/mongoc/mcd-rpc.c) target_include_directories (mcd_rpc PUBLIC ${PROJECT_SOURCE_DIR}/src) - target_link_libraries (mcd_rpc PUBLIC ${BSON_STATIC_LIBRARIES}) + target_link_libraries (mcd_rpc PUBLIC bson::static) if (NOT WIN32 AND ENABLE_PIC) target_compile_options (mcd_rpc PUBLIC -fPIC) endif () - target_compile_definitions (mcd_rpc PUBLIC ${BSON_STATIC_PUBLIC_DEFINITIONS}) set_target_properties (mcd_rpc PROPERTIES OUTPUT_NAME "mcd-rpc") endif () @@ -858,7 +857,7 @@ if (ENABLE_SHARED) target_sources(mongoc_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/libmongoc.rc) endif() set_target_properties (mongoc_shared PROPERTIES CMAKE_CXX_VISIBILITY_PRESET hidden) - target_link_libraries (mongoc_shared PRIVATE ${LIBRARIES} PUBLIC ${BSON_LIBRARIES} mongo::detail::c_dependencies) + target_link_libraries (mongoc_shared PRIVATE ${LIBRARIES} PUBLIC bson::shared mongo::detail::c_dependencies) target_include_directories (mongoc_shared PRIVATE ${ZLIB_INCLUDE_DIRS}) target_include_directories (mongoc_shared PRIVATE ${UTF8PROC_INCLUDE_DIRS}) target_include_directories (mongoc_shared PRIVATE ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES}) @@ -929,7 +928,7 @@ endif () # ENABLE_SHARED if (MONGOC_ENABLE_STATIC_BUILD) add_library (mongoc_static STATIC ${SOURCES} ${HEADERS}) - target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} ${BSON_STATIC_LIBRARIES} mongo::detail::c_dependencies) + target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} bson::static mongo::detail::c_dependencies) if (NOT WIN32 AND ENABLE_PIC) target_compile_options (mongoc_static PUBLIC -fPIC) message (STATUS "Adding -fPIC to compilation of mongoc_static components") @@ -953,7 +952,6 @@ if (MONGOC_ENABLE_STATIC_BUILD) target_compile_definitions (mongoc_static PUBLIC MONGOC_STATIC - ${BSON_STATIC_PUBLIC_DEFINITIONS} PRIVATE MONGOC_COMPILATION ${KMS_MSG_DEFINITIONS} @@ -1162,7 +1160,6 @@ if (ENABLE_TESTS) target_include_directories (test-libmongoc-lib PRIVATE ${PROJECT_SOURCE_DIR}/tests - ${BSON_STATIC_INCLUDE_DIRS} ${UTHASH_INCLUDE_DIR} ) target_compile_definitions (test-libmongoc-lib @@ -1190,7 +1187,6 @@ if (ENABLE_TESTS) target_include_directories (${test} PRIVATE ${PROJECT_SOURCE_DIR}/tests - ${BSON_STATIC_INCLUDE_DIRS} ) target_compile_definitions (${test} PUBLIC diff --git a/src/libmongoc/examples/compile-with-pkg-config-static.sh b/src/libmongoc/examples/compile-with-pkg-config-static.sh index 58d3db7a05..e8d86aa038 100755 --- a/src/libmongoc/examples/compile-with-pkg-config-static.sh +++ b/src/libmongoc/examples/compile-with-pkg-config-static.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # -- sphinx-include-start -- -gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags libmongoc-static-1.0) +gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags mongoc$major-static) diff --git a/src/libmongoc/examples/compile-with-pkg-config.sh b/src/libmongoc/examples/compile-with-pkg-config.sh index ba0d5a284c..b7f55b3831 100755 --- a/src/libmongoc/examples/compile-with-pkg-config.sh +++ b/src/libmongoc/examples/compile-with-pkg-config.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # -- sphinx-include-start -- -gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags libmongoc-1.0) +gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags mongoc$major) diff --git a/src/libmongoc/src/mongoc-config.cmake b/src/libmongoc/src/mongoc-config.cmake index 8aa000ba28..b836b874ad 100644 --- a/src/libmongoc/src/mongoc-config.cmake +++ b/src/libmongoc/src/mongoc-config.cmake @@ -1,5 +1,5 @@ include(CMakeFindDependencyMacro) -find_dependency(bson-1.0 @libmongoc_VERSION@) +find_dependency(bson "@libmongoc_VERSION@") # If we need to import a TLS package for our imported targets, do that now: set(MONGOC_TLS_BACKEND [[@TLS_BACKEND@]]) From ae672d92ed004911bffd39ee33fc814c5d5721fd Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Fri, 28 Mar 2025 11:51:40 -0600 Subject: [PATCH 07/26] Remove fragile installed-files tests, revise some for new filenames --- .../scripts/check-installed-files-bson.bat | 77 ---------------- .evergreen/scripts/check-installed-files.bat | 67 -------------- .../install-uninstall-check-windows.cmd | 47 +++------- .evergreen/scripts/install-uninstall-check.sh | 51 +++++------ .../scripts/link-sample-program-bson.sh | 82 ----------------- .../link-sample-program-mingw-bson.cmd | 16 ---- .../scripts/link-sample-program-mingw.cmd | 16 ---- .../scripts/link-sample-program-msvc-bson.cmd | 5 -- .../scripts/link-sample-program-msvc.cmd | 23 ----- .evergreen/scripts/link-sample-program.sh | 87 ------------------- 10 files changed, 39 insertions(+), 432 deletions(-) delete mode 100644 .evergreen/scripts/check-installed-files-bson.bat delete mode 100644 .evergreen/scripts/check-installed-files.bat diff --git a/.evergreen/scripts/check-installed-files-bson.bat b/.evergreen/scripts/check-installed-files-bson.bat deleted file mode 100644 index 4f4c2b0916..0000000000 --- a/.evergreen/scripts/check-installed-files-bson.bat +++ /dev/null @@ -1,77 +0,0 @@ -rem Validations shared by link-sample-program-msvc-bson.bat and -rem link-sample-program-mingw-bson.bat - -echo off - -rem Notice that the dll goes in "bin". -set DLL=%INSTALL_DIR%\bin\bson-1.0.dll -set major=1 -set LIB_DLL=%INSTALL_DIR%\bin\libbson%major%.dll -set LIB_LIB=%INSTALL_DIR%\lib\libbson%major%.lib -if "%MINGW%"=="1" ( - if not exist %LIB_DLL% ( - echo %LIB_DLL% is missing! - exit /B 1 - ) else ( - echo %LIB_DLL% check ok - ) - if exist %DLL% ( - echo %DLL% is present and should not be! - exit /B 1 - ) -) else ( - if not exist %DLL% ( - echo %DLL% is missing! - exit /B 1 - ) else ( - echo %DLL% check ok - ) - if exist %LIB_LIB% ( - echo %LIB_LIB% is present and should not be! - exit /B 1 - ) else ( - echo %LIB_LIB% check ok - ) -) -if not exist %INSTALL_DIR%\lib\pkgconfig\bson%major%.pc ( - echo bson%major%.pc missing! - exit /B 1 -) else ( - echo bson%major%.pc check ok -) -if not exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-1.0-config.cmake ( - echo bson-1.0-config.cmake missing! - exit /B 1 -) else ( - echo bson-1.0-config.cmake check ok -) -if not exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-1.0-config-version.cmake ( - echo bson-1.0-config-version.cmake missing! - exit /B 1 -) else ( - echo bson-1.0-config-version.cmake check ok -) -if not exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-targets.cmake ( - echo bson-targets.cmake missing! - exit /B 1 -) else ( - echo bson-targets.cmake check ok -) - -if "%LINK_STATIC%"=="1" ( - if not exist %INSTALL_DIR%\lib\pkgconfig\bson%major%-static.pc ( - echo bson%major%-static.pc missing! - exit /B 1 - ) else ( - echo bson%major%-static.pc check ok - ) -) else ( - if exist %INSTALL_DIR%\lib\pkgconfig\bson%major%-static.pc ( - echo bson%major%-static.pc should not have been installed! - exit /B 1 - ) else ( - echo bson%major%-static.pc missing, as expected - ) -) - -echo on diff --git a/.evergreen/scripts/check-installed-files.bat b/.evergreen/scripts/check-installed-files.bat deleted file mode 100644 index 02e0db0c64..0000000000 --- a/.evergreen/scripts/check-installed-files.bat +++ /dev/null @@ -1,67 +0,0 @@ -rem Validations shared by link-sample-program-msvc.bat and -rem link-sample-program-mingw.bat - -echo off - -rem Notice that the dll goes in "bin". -set DLL=%INSTALL_DIR%\bin\mongoc-1.0.dll -set LIB_DLL=%INSTALL_DIR%\bin\libmongoc-1.0.dll -set LIB_LIB=%INSTALL_DIR%\lib\libmongoc-1.0.lib -set major=1 -if "%MINGW%"=="1" ( - if not exist %LIB_DLL% ( - echo %LIB_DLL% is missing! - exit /B 1 - ) else ( - echo libmongoc-1.0.dll check ok - ) - if exist %DLL% ( - echo %DLL% is present and should not be! - exit /B 1 - ) -) else ( - if not exist %DLL% ( - echo %DLL% is missing! - exit /B 1 - ) else ( - echo mongoc-1.0.dll check ok - ) - if exist %LIB_LIB% ( - echo %LIB_LIB% is present and should not be! - exit /B 1 - ) else ( - echo libmongoc-1.0.lib check ok - ) -) -if not exist %INSTALL_DIR%\lib\pkgconfig\mongoc%major%.pc ( - echo mongoc%major%.pc missing! - exit /B 1 -) else ( - echo mongoc%major%.pc check ok -) -if not exist %INSTALL_DIR%\lib\cmake\mongoc-1.0\mongoc-1.0-config.cmake ( - echo mongoc-1.0-config.cmake missing! - exit /B 1 -) else ( - echo mongoc-1.0-config.cmake check ok -) -if not exist %INSTALL_DIR%\lib\cmake\mongoc-1.0\mongoc-1.0-config-version.cmake ( - echo mongoc-1.0-config-version.cmake missing! - exit /B 1 -) else ( - echo mongoc-1.0-config-version.cmake check ok -) -if not exist %INSTALL_DIR%\lib\cmake\mongoc-1.0\mongoc-targets.cmake ( - echo mongoc-targets.cmake missing! - exit /B 1 -) else ( - echo mongoc-targets.cmake check ok -) -if not exist %INSTALL_DIR%\lib\pkgconfig\mongoc%major%-static.pc ( - echo mongoc%major%-static.pc missing! - exit /B 1 -) else ( - echo mongoc%major%-static.pc check ok -) - -echo on diff --git a/.evergreen/scripts/install-uninstall-check-windows.cmd b/.evergreen/scripts/install-uninstall-check-windows.cmd index 332e072f95..6687a2d017 100644 --- a/.evergreen/scripts/install-uninstall-check-windows.cmd +++ b/.evergreen/scripts/install-uninstall-check-windows.cmd @@ -15,6 +15,9 @@ set CMAKE_MAKE_PROGRAM=C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bi rem Ensure Cygwin executables like sh.exe are not in PATH set PATH=C:\cygwin\bin;C:\Windows\system32;C:\Windows;C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bin;C:\mongoc;src\libbson;src\libmongoc +set version=1.31.0 +set major=1 + if "%BSON_ONLY%"=="1" ( set BUILD_DIR=%CD%\build-dir-bson set INSTALL_DIR=%CD%\install-dir-bson @@ -120,29 +123,11 @@ echo.%CC%| findstr /I "gcc">Nul && ( ) ) -if exist %INSTALL_DIR%\lib\pkgconfig\libbson-1.0.pc ( - echo libbson-1.0.pc found! - exit /B 1 -) else ( - echo libbson-1.0.pc check ok -) -if exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-1.0-config.cmake ( - echo bson-1.0-config.cmake found! - exit /B 1 -) else ( - echo bson-1.0-config.cmake check ok -) -if exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-1.0-config-version.cmake ( - echo bson-1.0-config-version.cmake found! +if exist %INSTALL_DIR%\lib\pkgconfig\bson%major%.pc ( + echo bson%major%.pc found! exit /B 1 ) else ( - echo bson-1.0-config-version.cmake check ok -) -if exist %INSTALL_DIR%\lib\cmake\bson-1.0\bson-targets.cmake ( - echo bson-targets.cmake found! - exit /B 1 -) else ( - echo bson-targets.cmake check ok + echo bson%major%.pc check ok ) if not exist %INSTALL_DIR%\lib\canary.txt ( echo canary.txt not found! @@ -157,11 +142,11 @@ if not exist %INSTALL_DIR%\lib ( echo %INSTALL_DIR%\lib check ok ) if "%BSON_ONLY%" NEQ "1" ( - if exist %INSTALL_DIR%\lib\pkgconfig\libmongoc-1.0.pc ( - echo libmongoc-1.0.pc found! + if exist %INSTALL_DIR%\lib\pkgconfig\mongoc%major%.pc ( + echo mongoc%major%.pc found! exit /B 1 ) else ( - echo libmongoc-1.0.pc check ok + echo mongoc%major%.pc check ok ) if exist %INSTALL_DIR%\lib\cmake\mongoc-1.0\mongoc-1.0-config.cmake ( echo mongoc-1.0-config.cmake found! @@ -182,23 +167,17 @@ if "%BSON_ONLY%" NEQ "1" ( echo mongoc-targets.cmake check ok ) ) -if exist %INSTALL_DIR%\include\libbson-1.0\bson\bson.h ( +if exist %INSTALL_DIR%\include\bson-%version%\bson\bson.h ( echo bson\bson.h found! exit /B 1 ) else ( echo bson\bson.h check ok ) -if exist %INSTALL_DIR%\include\libbson-1.0\bson.h ( - echo bson.h found! - exit /B 1 -) else ( - echo bson.h check ok -) -if exist %INSTALL_DIR%\include\libbson-1.0 ( - echo $INSTALL_DIR\include\libbson-1.0 found! +if exist %INSTALL_DIR%\include\bson-%version% ( + echo $INSTALL_DIR\include\bson-%version% found! exit /B 1 ) else ( - echo $INSTALL_DIR\include\libbson-1.0 check ok + echo $INSTALL_DIR\include\bson-%version% check ok ) if "%BSON_ONLY%" NEQ "1" ( if exist %INSTALL_DIR%\include\libmongoc-1.0\mongoc\mongoc.h ( diff --git a/.evergreen/scripts/install-uninstall-check.sh b/.evergreen/scripts/install-uninstall-check.sh index 5240c1c67e..6128c17e68 100755 --- a/.evergreen/scripts/install-uninstall-check.sh +++ b/.evergreen/scripts/install-uninstall-check.sh @@ -13,6 +13,13 @@ CMAKE=$(find_cmake_latest) . $DIR/check-symlink.sh SRCROOT=$(pwd) +# The major version of the project. Appears in certain install filenames. +_full_version=$(cat "$DIR/../../VERSION_CURRENT") +version="${_full_version%-*}" # 1.2.3-dev → 1.2.3 +major="${version%%.*}" # 1.2.3 → 1 +echo "major version: $version" +echo " full version: $major" + # Use ccache if able. . $DIR/find-ccache.sh find_ccache_and_export_vars "$(pwd)" || true @@ -20,7 +27,7 @@ find_ccache_and_export_vars "$(pwd)" || true SCRATCH_DIR=$(pwd)/.scratch rm -rf "$SCRATCH_DIR" mkdir -p "$SCRATCH_DIR" -cp -vr -- "$SRCROOT"/* "$SCRATCH_DIR" +cp -r -- "$SRCROOT"/* "$SCRATCH_DIR" if [ "$BSON_ONLY" ]; then BUILD_DIR=$SCRATCH_DIR/build-dir-bson @@ -58,8 +65,8 @@ if [[ -f $DIR/find-ccache.sh ]]; then find_ccache_and_export_vars "$SCRATCH_DIR" || true fi -$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $BSON_ONLY_OPTION "$SCRATCH_DIR" -$CMAKE --build . +$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DBUILD_TESTING=OFF -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $BSON_ONLY_OPTION "$SCRATCH_DIR" +$CMAKE --build . --parallel if [ "$DESTDIR" ]; then DESTDIR=$DESTDIR $CMAKE --build . --target install else @@ -93,29 +100,23 @@ $CMAKE --build . --target uninstall set +o xtrace -if test -f $INSTALL_DIR/lib/pkgconfig/libbson-1.0.pc; then - echo "libbson-1.0.pc found!" - exit 1 -else - echo "libbson-1.0.pc check ok" -fi -if test -f $INSTALL_DIR/lib/cmake/bson-1.0/bson-1.0-config.cmake; then - echo "bson-1.0-config.cmake found!" +if test -f $INSTALL_DIR/lib/pkgconfig/bson$major.pc; then + echo "bson$major.pc found!" exit 1 else - echo "bson-1.0-config.cmake check ok" + echo "bson$major.pc check ok" fi -if test -f $INSTALL_DIR/lib/cmake/bson-1.0/bson-1.0-config-version.cmake; then - echo "bson-1.0-config-version.cmake found!" +if test -f $INSTALL_DIR/lib/cmake/bson-$version/bsonConfig.cmake; then + echo "bsonConfig.cmake found!" exit 1 else - echo "bson-1.0-config-version.cmake check ok" + echo "bsonConfig.cmake check ok" fi -if test -f $INSTALL_DIR/lib/cmake/bson-1.0/bson-targets.cmake; then - echo "bson-targets.cmake found!" +if test -f $INSTALL_DIR/lib/cmake/bson-$version/bsonConfigVersion.cmake; then + echo "bsonConfigVersion.cmake found!" exit 1 else - echo "bson-targets.cmake check ok" + echo "bsonConfigVersion.cmake check ok" fi if test ! -f $INSTALL_DIR/lib/canary.txt; then echo "canary.txt not found!" @@ -130,11 +131,11 @@ else echo "$INSTALL_DIR/lib check ok" fi if [ -z "$BSON_ONLY" ]; then - if test -f $INSTALL_DIR/lib/pkgconfig/libmongoc-1.0.pc; then - echo "libmongoc-1.0.pc found!" + if test -f $INSTALL_DIR/lib/pkgconfig/mongoc$major.pc; then + echo "mongoc$major.pc found!" exit 1 else - echo "libmongoc-1.0.pc check ok" + echo "mongoc$major.pc check ok" fi if test -f $INSTALL_DIR/lib/cmake/mongoc-1.0/mongoc-1.0-config.cmake; then echo "mongoc-1.0-config.cmake found!" @@ -155,17 +156,17 @@ if [ -z "$BSON_ONLY" ]; then echo "mongoc-targets.cmake check ok" fi fi -if test -f $INSTALL_DIR/include/libbson-1.0/bson/bson.h; then +if test -f $INSTALL_DIR/include/bson-$version/bson/bson.h; then echo "bson/bson.h found!" exit 1 else echo "bson/bson.h check ok" fi -if test -d $INSTALL_DIR/include/libbson-1.0; then - echo "$INSTALL_DIR/include/libbson-1.0 found!" +if test -d $INSTALL_DIR/include/bson-$version; then + echo "$INSTALL_DIR/include/bson-$version found!" exit 1 else - echo "$INSTALL_DIR/include/libbson-1.0 check ok" + echo "$INSTALL_DIR/include/bson-$version check ok" fi if [ -z "$BSON_ONLY" ]; then if test -f $INSTALL_DIR/include/libmongoc-1.0/mongoc/mongoc.h; then diff --git a/.evergreen/scripts/link-sample-program-bson.sh b/.evergreen/scripts/link-sample-program-bson.sh index 384229f49e..fb62f5a927 100755 --- a/.evergreen/scripts/link-sample-program-bson.sh +++ b/.evergreen/scripts/link-sample-program-bson.sh @@ -25,12 +25,8 @@ OS=$(uname -s | tr '[:upper:]' '[:lower:]') echo "OS: $OS" if [ "$OS" = "darwin" ]; then - SO=dylib - LIB_SO=libbson$major.$version.dylib LDD="otool -L" else - SO=so - LIB_SO=libbson$major.so.$version LDD=ldd fi @@ -65,22 +61,6 @@ else $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_TESTING=OFF -DENABLE_TESTS=OFF -DENABLE_MONGOC=OFF -DENABLE_STATIC=OFF "$SCRATCH_DIR" $CMAKE --build . --parallel $CMAKE --build . --parallel --target install - - set +o xtrace - - if test -f $INSTALL_DIR/lib/libbson-static-1.0.a; then - echo "libbson-static-1.0.a shouldn't have been installed" - exit 1 - fi - if test -f $INSTALL_DIR/lib/libbson-1.0.a; then - echo "libbson-1.0.a shouldn't have been installed" - exit 1 - fi - if test -f $INSTALL_DIR/lib/pkgconfig/libbson-static-1.0.pc; then - echo "libbson-static-1.0.pc shouldn't have been installed" - exit 1 - fi - fi # Revert ccache options, they no longer apply. @@ -88,68 +68,6 @@ unset CCACHE_BASEDIR CCACHE_NOHASHDIR ls -l $INSTALL_DIR/lib -set +o xtrace - -# Check on Linux that libbson is installed into lib/ like: -# libbson-1.0.so -> libbson-1.0.so.0 -# libbson-1.0.so.0 -> libbson-1.0.so.0.0.0 -# libbson-1.0.so.0.0.0 -if [ "$OS" != "darwin" ]; then - # From check-symlink.sh - check_symlink libbson$major.so libbson$major.so.$major - check_symlink libbson$major.so.$major libbson$major.so.$version - SONAME=$(objdump -p $INSTALL_DIR/lib/$LIB_SO|grep SONAME|awk '{print $2}') - EXPECTED_SONAME="libbson$major.so.$major" - if [ "$SONAME" != "$EXPECTED_SONAME" ]; then - echo "SONAME should be $EXPECTED_SONAME, not $SONAME" - exit 1 - else - echo "library name check ok, SONAME=$SONAME" - fi -else - # Just test that the shared lib was installed. - if test ! -f $INSTALL_DIR/lib/$LIB_SO; then - echo "$LIB_SO missing!" - exit 1 - else - echo "$LIB_SO check ok" - fi -fi - -if test ! -f $INSTALL_DIR/lib/pkgconfig/bson$major.pc; then - echo "bson$major.pc missing!" - exit 1 -else - echo "bson$major.pc check ok" -fi -if test ! -f $INSTALL_DIR/lib/cmake/bson-$version/bsonConfig.cmake; then - echo "bsonConfig.cmake missing!" - exit 1 -else - echo "bsonConfig.cmake check ok" -fi -if test ! -f $INSTALL_DIR/lib/cmake/bson-$version/bsonConfig.cmake; then - echo "bsonConfig.cmake missing!" - exit 1 -else - echo "bsonConfig.cmake check ok" -fi - -if [ "$LINK_STATIC" ]; then - if test ! -f $INSTALL_DIR/lib/libbson$major.a; then - echo "libbson$major.a missing!" - exit 1 - else - echo "libbson$major.a check ok" - fi - if test ! -f $INSTALL_DIR/lib/pkgconfig/bson$major-static.pc; then - echo "bson$major-static.pc missing!" - exit 1 - else - echo "bson$major-static.pc check ok" - fi -fi - cd $SRCROOT if [ "$BUILD_SAMPLE_WITH_CMAKE" ]; then diff --git a/.evergreen/scripts/link-sample-program-mingw-bson.cmd b/.evergreen/scripts/link-sample-program-mingw-bson.cmd index 14c69263f0..d8a6926889 100644 --- a/.evergreen/scripts/link-sample-program-mingw-bson.cmd +++ b/.evergreen/scripts/link-sample-program-mingw-bson.cmd @@ -37,22 +37,6 @@ if errorlevel 1 ( exit /B 1 ) -set MINGW=1 -call ..\.evergreen\scripts\check-installed-files-bson.bat -if errorlevel 1 ( - exit /B 1 -) -set MINGW= - -if not exist %INSTALL_DIR%\lib\libbson%major%.a ( - echo libbson%major%.a missing! - exit /B 1 -) else ( - echo libbson%major%.a check ok -) - -cd %SRCROOT% - rem Test our pkg-config file set EXAMPLE_DIR=%SRCROOT%\src\libbson\examples\ cd %EXAMPLE_DIR% diff --git a/.evergreen/scripts/link-sample-program-mingw.cmd b/.evergreen/scripts/link-sample-program-mingw.cmd index ff9bf8417f..96031ea7d8 100644 --- a/.evergreen/scripts/link-sample-program-mingw.cmd +++ b/.evergreen/scripts/link-sample-program-mingw.cmd @@ -37,22 +37,6 @@ if errorlevel 1 ( exit /B 1 ) -set MINGW=1 -call ..\.evergreen\scripts\check-installed-files.bat -if errorlevel 1 ( - exit /B 1 -) -set MINGW= - -if not exist %INSTALL_DIR%\lib\libmongoc-static-1.0.a ( - echo libmongoc-static-1.0.a missing! - exit /B 1 -) else ( - echo libmongoc-static-1.0.a check ok -) - -cd %SRCROOT% - rem Test our pkg-config file set EXAMPLE_DIR=%SRCROOT%\src\libmongoc\examples\ cd %EXAMPLE_DIR% diff --git a/.evergreen/scripts/link-sample-program-msvc-bson.cmd b/.evergreen/scripts/link-sample-program-msvc-bson.cmd index 857a29d6e0..6ecbc2883d 100644 --- a/.evergreen/scripts/link-sample-program-msvc-bson.cmd +++ b/.evergreen/scripts/link-sample-program-msvc-bson.cmd @@ -34,11 +34,6 @@ if "%LINK_STATIC%"=="1" ( %CMAKE% --build . --target ALL_BUILD --config "Debug" -- /m %CMAKE% --build . --target INSTALL --config "Debug" -- /m -call ..\.evergreen\scripts\check-installed-files-bson.bat -if errorlevel 1 ( - exit /B %errorlevel% -) - rem Test our CMake package config file with CMake's find_package command. set EXAMPLE_DIR=%SRCROOT%\src\libbson\examples\cmake\find_package diff --git a/.evergreen/scripts/link-sample-program-msvc.cmd b/.evergreen/scripts/link-sample-program-msvc.cmd index 96dddff231..351649c5ca 100644 --- a/.evergreen/scripts/link-sample-program-msvc.cmd +++ b/.evergreen/scripts/link-sample-program-msvc.cmd @@ -52,29 +52,6 @@ if "%ENABLE_SSL%"=="1" ( %CMAKE% --build . --target ALL_BUILD --config "Debug" -- /m %CMAKE% --build . --target INSTALL --config "Debug" -- /m -call ..\.evergreen\scripts\check-installed-files.bat -if errorlevel 1 ( - exit /B %errorlevel% -) - -rem Shim library around the DLL. -set SHIM=%INSTALL_DIR%\lib\mongoc-1.0.lib -if not exist %SHIM% ( - echo %SHIM% is missing! - exit /B 1 -) else ( - echo %SHIM% check ok -) - -if not exist %INSTALL_DIR%\lib\mongoc-static-1.0.lib ( - echo mongoc-static-1.0.lib missing! - exit /B 1 -) else ( - echo mongoc-static-1.0.lib check ok -) - -cd %SRCROOT% - rem Test our CMake package config file with CMake's find_package command. set EXAMPLE_DIR=%SRCROOT%\src\libmongoc\examples\cmake\find_package diff --git a/.evergreen/scripts/link-sample-program.sh b/.evergreen/scripts/link-sample-program.sh index 987749645b..c41d01f5f8 100755 --- a/.evergreen/scripts/link-sample-program.sh +++ b/.evergreen/scripts/link-sample-program.sh @@ -28,12 +28,8 @@ OS=$(uname -s | tr '[:upper:]' '[:lower:]') echo "OS: $OS" if [ "$OS" = "darwin" ]; then - SO=dylib - LIB_SO=libmongoc-1.0.0.dylib LDD="otool -L" else - SO=so - LIB_SO=libmongoc-1.0.so.0 LDD=ldd fi @@ -97,89 +93,6 @@ unset CCACHE_BASEDIR CCACHE_NOHASHDIR ls -l $INSTALL_DIR/lib -set +o xtrace - -# Check on Linux that libmongoc is installed into lib/ like: -# libmongoc-1.0.so -> libmongoc-1.0.so.0 -# libmongoc-1.0.so.0 -> libmongoc-1.0.so.0.0.0 -# libmongoc-1.0.so.0.0.0 -if [ "$OS" != "darwin" ]; then - # From check-symlink.sh - check_symlink libmongoc-1.0.so libmongoc-1.0.so.0 - check_symlink libmongoc-1.0.so.0 libmongoc-1.0.so.0.0.0 - SONAME=$(objdump -p $INSTALL_DIR/lib/$LIB_SO|grep SONAME|awk '{print $2}') - EXPECTED_SONAME="libmongoc-1.0.so.0" - if [ "$SONAME" != "$EXPECTED_SONAME" ]; then - echo "SONAME should be $EXPECTED_SONAME, not $SONAME" - exit 1 - else - echo "library name check ok, SONAME=$SONAME" - fi -else - # Just test that the shared lib was installed. - if test ! -f $INSTALL_DIR/lib/$LIB_SO; then - echo "$LIB_SO missing!" - exit 1 - else - echo "$LIB_SO check ok" - fi -fi - - -if test ! -f $INSTALL_DIR/lib/pkgconfig/mongoc$major.pc; then - echo "mongoc$major.pc missing!" - exit 1 -else - echo "mongoc$major.pc check ok" -fi -if test ! -f $INSTALL_DIR/lib/cmake/mongoc-1.0/mongoc-1.0-config.cmake; then - echo "mongoc-1.0-config.cmake missing!" - exit 1 -else - echo "mongoc-1.0-config.cmake check ok" -fi -if test ! -f $INSTALL_DIR/lib/cmake/mongoc-1.0/mongoc-1.0-config-version.cmake; then - echo "mongoc-1.0-config-version.cmake missing!" - exit 1 -else - echo "mongoc-1.0-config-version.cmake check ok" -fi -if test ! -f $INSTALL_DIR/lib/cmake/mongoc-1.0/mongoc-targets.cmake; then - echo "mongoc-targets.cmake missing!" - exit 1 -else - echo "mongoc-targets.cmake check ok" -fi - - -if [ "$LINK_STATIC" ]; then - if test ! -f $INSTALL_DIR/lib/libmongoc-static-1.0.a; then - echo "libmongoc-static-1.0.a missing!" - exit 1 - else - echo "libmongoc-static-1.0.a check ok" - fi - if test ! -f $INSTALL_DIR/lib/pkgconfig/mongoc1-static.pc; then - echo "mongoc1-static.pc missing!" - exit 1 - else - echo "mongoc1-static.pc check ok" - fi -else - if test -f $INSTALL_DIR/lib/libmongoc-static-1.0.a; then - echo "libmongoc-static-1.0.a shouldn't have been installed" - exit 1 - fi - if test -f $INSTALL_DIR/lib/libmongoc-1.0.a; then - echo "libmongoc-1.0.a shouldn't have been installed" - exit 1 - fi - if test -f $INSTALL_DIR/lib/pkgconfig/mongoc1-static.pc; then - echo "mongoc1-static.pc shouldn't have been installed" - exit 1 - fi -fi - if [ "$OS" = "darwin" ] && [ "${HOSTTYPE:?}" != "arm64" ]; then if test -f $INSTALL_DIR/bin/mongoc-stat; then echo "mongoc-stat shouldn't have been installed" From 962edc2875531cdce45f37d5a8e3625acd2493e9 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Fri, 28 Mar 2025 19:28:23 -0600 Subject: [PATCH 08/26] Suppress DESTDIR when installing a project for testing --- build/cmake/TestProject.cmake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build/cmake/TestProject.cmake b/build/cmake/TestProject.cmake index 938dcc3947..a89532be1e 100644 --- a/build/cmake/TestProject.cmake +++ b/build/cmake/TestProject.cmake @@ -166,10 +166,14 @@ function(__do_test_project) cmake_path(ABSOLUTE_PATH tmp_install_prefix NORMALIZE) message(STATUS "Installing parent project into [${tmp_install_prefix}]") execute_process( - COMMAND ${CMAKE_COMMAND} - --install "${TEST_PROJECT_PARENT_BINARY_DIR}" - --prefix "${tmp_install_prefix}" - --config "${TEST_PROJECT_CONFIG}" + COMMAND + # Suppress DESTDIR + ${CMAKE_COMMAND} -E env --unset=DESTDIR + # Do the install: + ${CMAKE_COMMAND} + --install "${TEST_PROJECT_PARENT_BINARY_DIR}" + --prefix "${tmp_install_prefix}" + --config "${TEST_PROJECT_CONFIG}" COMMAND_ERROR_IS_FATAL LAST ) endif() From af0eba77646b0b4ab47f46c4d3ca990f3c4f9a3f Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Fri, 28 Mar 2025 19:54:38 -0600 Subject: [PATCH 09/26] Give DLL implibs a different file extension --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90f2813089..7222abca81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,6 +344,10 @@ set (CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) # Install libs with names like @rpath/libmongoc-1.0.0.dylib, not bare names. set (CMAKE_MACOSX_RPATH ON) +# Distinguish DLL import libs with a .dll.lib suffix. Also prevents filename collisions +# between static libraries and the import libraries +set (CMAKE_IMPORT_LIBRARY_SUFFIX .dll.lib) + # https://cmake.org/cmake/help/v3.11/policy/CMP0042.html # Enable a CMake 3.0+ policy that sets CMAKE_MACOSX_RPATH by default, and # silence a CMake 3.11 warning that the old behavior is deprecated. From 48ae32026934dc9d7e4e0becb22ec35b303a5b91 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Fri, 28 Mar 2025 19:57:52 -0600 Subject: [PATCH 10/26] Only set the implib suffix on Windows --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7222abca81..b4755c745b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -346,7 +346,9 @@ set (CMAKE_MACOSX_RPATH ON) # Distinguish DLL import libs with a .dll.lib suffix. Also prevents filename collisions # between static libraries and the import libraries -set (CMAKE_IMPORT_LIBRARY_SUFFIX .dll.lib) +if(WIN32) + set (CMAKE_IMPORT_LIBRARY_SUFFIX .dll.lib) +endif() # https://cmake.org/cmake/help/v3.11/policy/CMP0042.html # Enable a CMake 3.0+ policy that sets CMAKE_MACOSX_RPATH by default, and From 4b347453c91f3ae68f12783a01616d91b76edcfd Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 14:57:40 -0600 Subject: [PATCH 11/26] Tweak import tests to not assume the major version --- src/libmongoc/tests/import-tests.cmake | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libmongoc/tests/import-tests.cmake b/src/libmongoc/tests/import-tests.cmake index 46deb35e51..378d61f59f 100644 --- a/src/libmongoc/tests/import-tests.cmake +++ b/src/libmongoc/tests/import-tests.cmake @@ -1,5 +1,7 @@ include(TestProject) +math(EXPR next_major_version "${PROJECT_VERSION_MAJOR}+1") + # A bare find_package will succeed add_test_cmake_project( mongoc/CMake/bare-bson-import src/libmongoc/tests/cmake-import @@ -21,31 +23,31 @@ add_test_cmake_project( ) add_test_cmake_project( - mongoc/CMake/bson-import-1.0 src/libmongoc/tests/cmake-import + mongoc/CMake/bson-import-${PROJECT_VERSION_MAJOR}.0 src/libmongoc/tests/cmake-import INSTALL_PARENT SETTINGS FIND_BSON=1 - "FIND_BSON_ARGS=1.25;REQUIRED" + "FIND_BSON_ARGS=${PROJECT_VERSION_MAJOR}.0;REQUIRED" "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" ) -# Try to import a too-new version of 1.x that will never exist +# Try to import a too-new minor version that will never exist add_test_cmake_project( mongoc/CMake/bson-import-too-new-fails src/libmongoc/tests/cmake-import INSTALL_PARENT SETTINGS FIND_BSON=1 - "FIND_BSON_ARGS=1.9999.0" + "FIND_BSON_ARGS=${PROJECT_VERSION_MAJOR}.9999.0" EXPECT_FIND_BSON_FAILS=TRUE ) -# Try to import a 2.0 version, which is not installed in this test case +# Try to import the next major version, which is not installed in this test case add_test_cmake_project( - mongoc/CMake/bson-import-2.0-fails src/libmongoc/tests/cmake-import + mongoc/CMake/bson-import-${next_major_version}.0-fails src/libmongoc/tests/cmake-import INSTALL_PARENT SETTINGS FIND_BSON=1 - "FIND_BSON_ARGS=2.0" + "FIND_BSON_ARGS=${next_major_version}.0" EXPECT_FIND_BSON_FAILS=TRUE ) @@ -64,7 +66,7 @@ add_test_cmake_project( INSTALL_PARENT SETTINGS FIND_BSON=1 - "FIND_BSON_ARGS=${PROJECT_VERSION}...1.9999.0;REQUIRED" + "FIND_BSON_ARGS=${PROJECT_VERSION}...${PROJECT_VERSION_MAJOR}.9999.0;REQUIRED" "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" ) @@ -82,7 +84,7 @@ add_test_cmake_project( INSTALL_PARENT SETTINGS FIND_BSON=1 - "FIND_BSON_ARGS=1.0...2.0;REQUIRED" + "FIND_BSON_ARGS=${PROJECT_VERSION_MAJOR}.0...${next_major_version}.0;REQUIRED" "EXPECT_BSON_VERSION=${mongo-c-driver_VERSION_FULL}" ) @@ -91,7 +93,7 @@ add_test_cmake_project( INSTALL_PARENT SETTINGS FIND_BSON=1 - "FIND_BSON_ARGS=2.0...<3" + "FIND_BSON_ARGS=${next_major_version}.0...<${next_major_version}.9999" EXPECT_FIND_BSON_FAILS=TRUE ) From 6cbc3f2d4d9369074cca1d6fbf2a56dcc0ac61f8 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 15:04:29 -0600 Subject: [PATCH 12/26] Remove install code for Apple frameworks and modulemaps --- CMakeLists.txt | 4 +-- src/libbson/CMakeLists.txt | 29 ------------------- .../src/bson/modules/module.modulemap.in | 5 ---- src/libmongoc/CMakeLists.txt | 26 ----------------- .../src/mongoc/modules/module.modulemap.in | 5 ---- 5 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 src/libbson/src/bson/modules/module.modulemap.in delete mode 100644 src/libmongoc/src/mongoc/modules/module.modulemap.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b4755c745b..8bc44f5187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,8 +172,6 @@ mongo_setting(ENABLE_MONGODB_AWS_AUTH "Enable support for the MONGODB-AWS authen # Optional features that are DISABLED by default: mongo_bool_setting(ENABLE_RDTSCP "Enable fast performance counters using the Intel RDTSCP instruction" DEFAULT VALUE OFF) -mongo_bool_setting(ENABLE_APPLE_FRAMEWORK "Build libraries as Apple Frameworks on Darwin platforms" - DEFAULT VALUE OFF) mongo_bool_setting( ENABLE_CRYPTO_SYSTEM_PROFILE "Use system crypto profile" DEFAULT VALUE OFF @@ -341,7 +339,7 @@ set (CMAKE_BUILD_WITH_INSTALL_RPATH OFF) # Include any custom library paths in the final RPATH. set (CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) -# Install libs with names like @rpath/libmongoc-1.0.0.dylib, not bare names. +# Install libs with names like @rpath/libfoo.dylib, not bare names. set (CMAKE_MACOSX_RPATH ON) # Distinguish DLL import libs with a .dll.lib suffix. Also prevents filename collisions diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 7e1d260bf9..90e9740d15 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -129,13 +129,6 @@ configure_file ( "${PROJECT_BINARY_DIR}/src/bson/bson-version.h" ) -if (ENABLE_APPLE_FRAMEWORK) - configure_file ( - "${PROJECT_SOURCE_DIR}/src/bson/modules/module.modulemap.in" - "${PROJECT_BINARY_DIR}/src/bson/modules/module.modulemap" - ) -endif () - # 8888888b. .d888 d8b d8b 888 d8b # 888 "Y88b d88P" Y8P Y8P 888 Y8P # 888 888 888 888 @@ -236,18 +229,6 @@ set_target_properties(${bson_libs} PROPERTIES OUTPUT_NAME "${BSON_OUTPUT_BASENAME}${PROJECT_VERSION_MAJOR}" ) -if (ENABLE_APPLE_FRAMEWORK) - set_target_properties(bson_shared PROPERTIES - FRAMEWORK TRUE - MACOSX_FRAMEWORK_BUNDLE_VERSION ${MONGOC_VERSION} - MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MONGOC_VERSION} - MACOSX_FRAMEWORK_IDENTIFIER org.mongodb.bson - OUTPUT_NAME "${BSON_OUTPUT_BASENAME}" - PUBLIC_HEADER "${HEADERS}" - ) -endif () - - # 8888888888 888 # 888 888 # 888 888 @@ -328,7 +309,6 @@ function(install_export_target target) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" INCLUDES DESTINATION "${BSON_INSTALL_INCLUDEDIR}" - FRAMEWORK DESTINATION "${CMAKE_INSTALL_BINDIR}" ) # Install the unique export set into a file that is qualified by the name of # the target itself. The main config-file package will search for the @@ -362,19 +342,10 @@ install( FILES_MATCHING PATTERN "*.h" PATTERN "*-private.h" EXCLUDE - # Don't generate an empty "modules" directory - PATTERN "modules" EXCLUDE # Don't install jsonsl headers PATTERN "jsonsl" EXCLUDE ) -if (ENABLE_APPLE_FRAMEWORK) - install ( - FILES "${PROJECT_BINARY_DIR}/src/bson/modules/module.modulemap" - DESTINATION "${CMAKE_INSTALL_BINDIR}/bson.framework/Modules/" - ) -endif () - # Install the platform libraries from MongoPlatform.cmake. Search: PLATFORM-EXPORT-TARGET-INSTALL install(EXPORT mongo-platform-targets # The "00" prefix forces the file to sort to the top during globbing, because diff --git a/src/libbson/src/bson/modules/module.modulemap.in b/src/libbson/src/bson/modules/module.modulemap.in deleted file mode 100644 index 1a8a5ebe0c..0000000000 --- a/src/libbson/src/bson/modules/module.modulemap.in +++ /dev/null @@ -1,5 +0,0 @@ -framework module bson [system] { - umbrella header "bson/bson.h" - - export * -} \ No newline at end of file diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index a6b56d7b36..781386881f 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -752,13 +752,6 @@ configure_file ( "${PROJECT_BINARY_DIR}/src/mongoc/mongoc-version.h" ) -if (ENABLE_APPLE_FRAMEWORK) - configure_file ( - "${PROJECT_SOURCE_DIR}/src/mongoc/modules/module.modulemap.in" - "${PROJECT_BINARY_DIR}/src/mongoc/modules/module.modulemap" - ) -endif () - set (LIBRARIES ${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${LIBMONGOCRYPT_LIBRARY} ) @@ -902,17 +895,6 @@ if (ENABLE_SHARED) ) mongo_generate_pkg_config(mongoc_shared INSTALL RENAME mongoc${PROJECT_VERSION_MAJOR}.pc) - if (ENABLE_APPLE_FRAMEWORK) - set_target_properties (mongoc_shared PROPERTIES - FRAMEWORK TRUE - MACOSX_FRAMEWORK_BUNDLE_VERSION ${MONGOC_VERSION} - MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MONGOC_VERSION} - MACOSX_FRAMEWORK_IDENTIFIER org.mongodb.mongoc - OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}" - PUBLIC_HEADER "${HEADERS}" - ) - endif () # ENABLE_APPLE_FRAMEWORK - add_executable (mongoc-stat ${mongo-c-driver_SOURCE_DIR}/src/tools/mongoc-stat.c) target_compile_options (mongoc-stat PRIVATE ${mongoc-warning-options}) target_link_libraries (mongoc-stat mongoc_shared ${LIBRARIES}) @@ -1328,7 +1310,6 @@ install ( ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${MONGOC_HEADER_INSTALL_DIR} - FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} ) install ( @@ -1336,13 +1317,6 @@ install ( DESTINATION "${MONGOC_HEADER_INSTALL_DIR}/mongoc" ) -if (ENABLE_APPLE_FRAMEWORK) - install ( - FILES "${PROJECT_BINARY_DIR}/src/mongoc/modules/module.modulemap" - DESTINATION "${CMAKE_INSTALL_BINDIR}/mongoc.framework/Modules/" - ) -endif () - # Collect link items for the static library to be inserted into the pkg-config if(TARGET mongoc_static) set(link_options ${ZLIB_LIBRARIES} diff --git a/src/libmongoc/src/mongoc/modules/module.modulemap.in b/src/libmongoc/src/mongoc/modules/module.modulemap.in deleted file mode 100644 index fb2f5b619f..0000000000 --- a/src/libmongoc/src/mongoc/modules/module.modulemap.in +++ /dev/null @@ -1,5 +0,0 @@ -framework module mongoc { - umbrella header "mongoc/mongoc.h" - - export * -} \ No newline at end of file From bba33a7b1d98e259f2e7f280c1f5aa18a6531d16 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 15:08:35 -0600 Subject: [PATCH 13/26] Minor cleanup around docs targets --- src/libbson/CMakeLists.txt | 4 ++-- src/libmongoc/CMakeLists.txt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 90e9740d15..2ab11be11b 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -386,7 +386,7 @@ if (ENABLE_MAN_PAGES OR ENABLE_HTML_DOCS) add_custom_target (bson-doc ALL DEPENDS - $<$:bson-man> - $<$:bson-html> + $ + $ ) endif () diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 781386881f..c80c3a20eb 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -1388,13 +1388,13 @@ install( DESTINATION "${mongoc_cmake_prefix}" ) -if (ENABLE_MAN_PAGES STREQUAL ON OR ENABLE_HTML_DOCS STREQUAL ON) +if (ENABLE_MAN_PAGES OR ENABLE_HTML_DOCS) find_package (Sphinx REQUIRED) add_subdirectory (doc) add_custom_target (mongoc-doc ALL DEPENDS - $<$:mongoc-man> - $<$:mongoc-html> + $ + $ ) endif () From 14ddf56c41ca1126525e536454f5bfb906de8bc3 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 15:12:21 -0600 Subject: [PATCH 14/26] Minor wording tweaks --- src/libbson/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 2ab11be11b..cf3dfa954f 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -284,11 +284,11 @@ endif () # ENABLE_EXAMPLES # 888 888 888 X88 Y88b. 888 888 888 888 # 8888888 888 888 88888P' "Y888 "Y888888 888 888 -# Prefix directory for all libbson headers. +# Infix directory for all libbson headers. if(NOT DEFINED BSON_INSTALL_INCLUDEDIR) set(BSON_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/bson-${PROJECT_VERSION}") endif() -# Prefix directory for all libbson CMake package files +# Infix directory for all libbson CMake package files if(NOT DEFINED BSON_INSTALL_CMAKEDIR) set(BSON_INSTALL_CMAKEDIR "${MONGOC_INSTALL_CMAKEDIR}/bson-${PROJECT_VERSION}") endif() From ec82d99dfbc05ef31929d43b9659a06ba2f5dd61 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 15:47:43 -0600 Subject: [PATCH 15/26] libmongoc component renaming --- CMakeLists.txt | 6 +- src/CMakeLists.txt | 12 +-- src/libbson/CMakeLists.txt | 2 +- src/libmongoc/CMakeLists.txt | 65 +++++++------- src/libmongoc/etc/mongocConfig.cmake | 67 -------------- src/libmongoc/etc/mongocConfig.cmake.in | 112 ++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 108 deletions(-) delete mode 100644 src/libmongoc/etc/mongocConfig.cmake create mode 100644 src/libmongoc/etc/mongocConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc44f5187..fdec2969a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,12 +252,12 @@ include (CMakeDependentOption) include (GNUInstallDirs) # The directory where CMake config packages will be installed, based on the libdir from GNUInstallDirs mongo_setting( - MONGOC_INSTALL_CMAKEDIR "The directory in which CMake package files will be installed" + MONGO_C_DRIVER_INSTALL_CMAKEDIR "The directory in which CMake package files will be installed" TYPE STRING DEFAULT VALUE "${CMAKE_INSTALL_LIBDIR}/cmake" VALIDATE CODE [[ - if(IS_ABSOLUTE "${MONGOC_INSTALL_CMAKEDIR}") - message(SEND_ERROR "The CMake installation directory must be a relative path (Got “${MONGOC_INSTALL_CMAKEDIR}”)") + if(IS_ABSOLUTE "${MONGO_C_DRIVER_INSTALL_CMAKEDIR}") + message(SEND_ERROR "The CMake installation directory must be a relative path (Got “${MONGO_C_DRIVER_INSTALL_CMAKEDIR}”)") endif() ]] ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7b37749a90..c491fc29b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,20 +13,20 @@ if (CMAKE_CXX_COMPILER) # Add a C++ source file that will #include the main C headers. This "library" # does nothing other than validate that the C headers are valid C++ headers. add_library (mongoc-cxx-check OBJECT cpp-check.cpp) - if (TARGET mongoc_static) - target_link_libraries (mongoc-cxx-check PRIVATE mongoc_static) + if (TARGET mongoc::static) + target_link_libraries (mongoc-cxx-check PRIVATE mongoc::static) else () - target_link_libraries (mongoc-cxx-check PRIVATE mongoc_shared) + target_link_libraries (mongoc-cxx-check PRIVATE mongoc::shared) endif () endif () # public-header-warnings add_executable(public-header-warnings EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/c-check.c) -if (TARGET mongoc_static) - target_link_libraries(public-header-warnings PRIVATE mongoc_static) +if (TARGET mongoc::static) + target_link_libraries(public-header-warnings PRIVATE mongoc::static) else () - target_link_libraries(public-header-warnings PRIVATE mongoc_shared) + target_link_libraries(public-header-warnings PRIVATE mongoc::shared) endif () target_compile_options(public-header-warnings PRIVATE diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index cf3dfa954f..d1785b4e91 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -290,7 +290,7 @@ if(NOT DEFINED BSON_INSTALL_INCLUDEDIR) endif() # Infix directory for all libbson CMake package files if(NOT DEFINED BSON_INSTALL_CMAKEDIR) - set(BSON_INSTALL_CMAKEDIR "${MONGOC_INSTALL_CMAKEDIR}/bson-${PROJECT_VERSION}") + set(BSON_INSTALL_CMAKEDIR "${MONGO_C_DRIVER_INSTALL_CMAKEDIR}/bson-${PROJECT_VERSION}") endif() # pkg-config properties: diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index c80c3a20eb..056e14f40c 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -32,6 +32,13 @@ set (MONGOC_ENABLE_COMPRESSION_SNAPPY 0) set (MONGOC_ENABLE_COMPRESSION_ZLIB 0) set (MONGOC_ENABLE_COMPRESSION_ZSTD 0) +if(NOT DEFINED MONGOC_INSTALL_INCLUDEDIR) + set(MONGOC_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/mongoc-${PROJECT_VERSION}") +endif() +if(NOT DEFINED MONGOC_INSTALL_CMAKEDIR) + set(MONGOC_INSTALL_CMAKEDIR "${MONGO_C_DRIVER_INSTALL_CMAKEDIR}/mongoc-${PROJECT_VERSION}") +endif() + # Definition for mongoc-config.h: mongo_pick(MONGOC_ENABLE_SRV 1 0 ENABLE_SRV) @@ -341,7 +348,7 @@ function(_use_sasl libname) elseif(libname STREQUAL "CYRUS") find_package(SASL2 2.0 REQUIRED) target_link_libraries(_mongoc-sasl_backend INTERFACE SASL2::SASL2) - install(FILES "${mongo-c-driver_SOURCE_DIR}/build/cmake/FindSASL2.cmake" DESTINATION "${MONGOC_TARGETS_INSTALL_DIR}/3rdParty") + install(FILES "${mongo-c-driver_SOURCE_DIR}/build/cmake/FindSASL2.cmake" DESTINATION "${MONGOC_INSTALL_CMAKEDIR}/3rdParty") set(backend "Cyrus") else() message(FATAL_ERROR "Unknown SASL backend “${libname}”") @@ -844,6 +851,8 @@ set ( if (ENABLE_SHARED) add_library (mongoc_shared SHARED ${SOURCES} ${HEADERS}) + add_library(mongoc::shared ALIAS mongoc_shared) + set_property(TARGET mongoc_shared PROPERTY EXPORT_NAME mongoc::shared) if(WIN32) # Add resource-definition script for Windows shared library (.dll). configure_file(libmongoc.rc.in libmongoc.rc) @@ -888,9 +897,9 @@ if (ENABLE_SHARED) ) set_target_properties (mongoc_shared PROPERTIES - OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-${MONGOC_API_VERSION}" - VERSION 0.0.0 - SOVERSION 0 + OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}${PROJECT_VERSION_MAJOR}" + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" pkg_config_REQUIRES "bson${PROJECT_VERSION_MAJOR}" ) mongo_generate_pkg_config(mongoc_shared INSTALL RENAME mongoc${PROJECT_VERSION_MAJOR}.pc) @@ -910,6 +919,8 @@ endif () # ENABLE_SHARED if (MONGOC_ENABLE_STATIC_BUILD) add_library (mongoc_static STATIC ${SOURCES} ${HEADERS}) + add_library(mongoc::static ALIAS mongoc_static) + set_property(TARGET mongoc_static PROPERTY EXPORT_NAME mongoc::static) target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} bson::static mongo::detail::c_dependencies) if (NOT WIN32 AND ENABLE_PIC) target_compile_options (mongoc_static PUBLIC -fPIC) @@ -954,8 +965,8 @@ if (MONGOC_ENABLE_STATIC_BUILD) $ ) set_target_properties (mongoc_static PROPERTIES - VERSION 0.0.0 - OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-static-${MONGOC_API_VERSION}" + VERSION "${PROJECT_VERSION}" + OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}${PROJECT_VERSION_MAJOR}" pkg_config_REQUIRES "bson${PROJECT_VERSION_MAJOR}-static" ) if(MONGOC_ENABLE_STATIC_INSTALL) @@ -1132,7 +1143,7 @@ if (ENABLE_TESTS) # Remove once support for VS 2013 is dropped. target_compile_options(test-libmongoc-lib PRIVATE /wd4756) endif () - target_link_libraries (test-libmongoc-lib PUBLIC mongoc_static) + target_link_libraries (test-libmongoc-lib PUBLIC mongoc::static) # We have tests that test our deprecated api. target_compile_options (test-libmongoc-lib PRIVATE $<$>:-Wno-deprecated-declarations> @@ -1205,9 +1216,9 @@ if (ENABLE_EXAMPLES AND ENABLE_SHARED) # Enable unconditional warnings-as-errors for our source code. target_compile_options (${example} PRIVATE ${mongoc-warning-options}) - target_link_libraries (${example} mongoc_shared ${LIBRARIES}) + target_link_libraries (${example} PRIVATE mongoc::shared ${LIBRARIES}) if (WIN32) - target_link_libraries (${example} shlwapi) + target_link_libraries (${example} PRIVATE shlwapi) endif () endfunction () @@ -1281,7 +1292,7 @@ if (ENABLE_TESTS AND ENABLE_SHARED AND MONGOC_ENABLE_SSL AND NOT WIN32) # Benchmarks require SSL, and do not build on Windows. add_executable (benchmark-tls-pooled ${PROJECT_SOURCE_DIR}/tests/benchmark-tls-pooled.c) target_compile_options (benchmark-tls-pooled PRIVATE ${mongoc-warning-options}) - target_link_libraries (benchmark-tls-pooled mongoc_shared ${LIBRARIES}) + target_link_libraries (benchmark-tls-pooled PRIVATE mongoc::shared ${LIBRARIES}) endif () file (COPY ${PROJECT_SOURCE_DIR}/tests/binary DESTINATION ${PROJECT_BINARY_DIR}/tests) @@ -1299,9 +1310,7 @@ if (ENABLE_SHARED) list (APPEND TARGETS_TO_INSTALL mongoc_shared) endif () -set (MONGOC_HEADER_INSTALL_DIR - "${CMAKE_INSTALL_INCLUDEDIR}/libmongoc-${MONGOC_API_VERSION}" -) + install ( TARGETS ${TARGETS_TO_INSTALL} @@ -1309,12 +1318,12 @@ install ( LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - INCLUDES DESTINATION ${MONGOC_HEADER_INSTALL_DIR} + INCLUDES DESTINATION ${MONGOC_INSTALL_INCLUDEDIR} ) install ( FILES ${HEADERS} - DESTINATION "${MONGOC_HEADER_INSTALL_DIR}/mongoc" + DESTINATION "${MONGOC_INSTALL_INCLUDEDIR}/mongoc" ) # Collect link items for the static library to be inserted into the pkg-config @@ -1334,7 +1343,7 @@ if(TARGET mongoc_static) endif() # Relative include-path will be given the install prefix: -set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${MONGOC_HEADER_INSTALL_DIR}") +set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${MONGOC_INSTALL_INCLUDEDIR}") # Deprecated alias for libmongoc-1.0.pc, see CDRIVER-2086. if (MONGOC_ENABLE_SSL) @@ -1362,30 +1371,24 @@ configure_file (src/mongoc-config.cmake ) install (EXPORT mongoc-targets - NAMESPACE mongo:: FILE mongoc-targets.cmake - DESTINATION ${MONGOC_TARGETS_INSTALL_DIR} + DESTINATION "${MONGOC_INSTALL_CMAKEDIR}" ) -install ( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/mongoc/mongoc-${MONGOC_API_VERSION}-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/mongoc/mongoc-${MONGOC_API_VERSION}-config-version.cmake" - DESTINATION - ${MONGOC_TARGETS_INSTALL_DIR} - COMPONENT - Devel -) - -set(mongoc_cmake_prefix "${MONGOC_INSTALL_CMAKEDIR}/mongoc-${PROJECT_VERSION}") configure_file( ${mongo-c-driver_SOURCE_DIR}/build/cmake/packageConfigVersion.cmake.in mongocConfigVersion.cmake @ONLY ) +configure_file( + etc/mongocConfig.cmake.in + mongocConfig.cmake + @ONLY +) install( - FILES etc/mongocConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/mongocConfigVersion.cmake" - DESTINATION "${mongoc_cmake_prefix}" + FILES "${CMAKE_CURRENT_BINARY_DIR}/mongocConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/mongocConfigVersion.cmake" + DESTINATION "${MONGOC_INSTALL_CMAKEDIR}" ) if (ENABLE_MAN_PAGES OR ENABLE_HTML_DOCS) diff --git a/src/libmongoc/etc/mongocConfig.cmake b/src/libmongoc/etc/mongocConfig.cmake deleted file mode 100644 index e3ebf1b422..0000000000 --- a/src/libmongoc/etc/mongocConfig.cmake +++ /dev/null @@ -1,67 +0,0 @@ -#[[ - This is a transitional CMake package config file to allow compatibility - between libmongoc 1.x and libmongoc 2.x CMake packages. - - When distributed with libmongoc 1.x, this file is mostly just a shim for - the `mongoc-1.0` CMake packages. - - This file imports "mongoc-1.0" and generates alias targets for it: - - • `mongoc::shared` → `mongo::mongoc_shared` - • `mongoc::static` → `mongo::mongoc_static` - • `mongoc::mongoc` → Points to either `mongoc::shared` or `mongoc::static`, - controlled by `MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE` -]] - -# Check for missing components before proceeding. We don't provide any, so we -# should generate an error if the caller requests any *required* components. -set(missing_required_components) -foreach(comp IN LISTS mongoc_FIND_COMPONENTS) - if(mongoc_FIND_REQUIRED_${comp}) - list(APPEND missing_required_components "${comp}") - endif() -endforeach() - -if(missing_required_components) - list(JOIN missing_required_components ", " components) - set(mongoc_FOUND FALSE) - set(mongoc_NOT_FOUND_MESSAGE "The package version is compatible, but is missing required components: ${components}") - # Stop now. Don't generate any imported targets - return() -endif() - -include(CMakeFindDependencyMacro) - -# We are installed alongside the `mongoc-1.0` packages. Forcibly prevent find_package -# from considering any other `mongoc-1.0` package that might live elsewhere on the system -# by setting HINTS and NO_DEFAULT_PATH -get_filename_component(parent_dir "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) -find_dependency(mongoc-1.0 HINTS ${parent_dir} NO_DEFAULT_PATH) -# Also import the `bson` package, to ensure its targets are also available -find_dependency(bson ${mongoc_FIND_VERSION} HINTS ${parent_dir} NO_DEFAULT_PATH) - -# The library type that is linked with `mongoc::mongoc` -set(_default_lib_type) -# Add compat targets for the mongoc-1.0 package targets -if(TARGET mongo::mongoc_shared AND NOT TARGET mongoc::shared) - add_library(mongoc::shared IMPORTED INTERFACE) - set_property(TARGET mongoc::shared APPEND PROPERTY INTERFACE_LINK_LIBRARIES mongo::mongoc_shared) - set(_default_lib_type SHARED) -endif() -if(TARGET mongo::mongoc_static AND NOT TARGET mongoc::static) - add_library(mongoc::static IMPORTED INTERFACE) - set_property(TARGET mongoc::static APPEND PROPERTY INTERFACE_LINK_LIBRARIES mongo::mongoc_static) - # If static is available, set it as the default library type - set(_default_lib_type STATIC) -endif() - -# Allow the user to tweak what library type is linked for `mongoc::mongoc` -set(MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE "${_default_lib_type}" - CACHE STRING "The default library type that is used when linking against 'mongoc::mongoc' (either SHARED or STATIC, requires that the package was built with the appropriate library type)") -set_property(CACHE MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE PROPERTY STRINGS SHARED STATIC) - -if(NOT TARGET mongoc::mongoc) # Don't redefine the target if we were already included - string(TOLOWER "${MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE}" _type) - add_library(mongoc::mongoc IMPORTED INTERFACE) - set_property(TARGET mongoc::mongoc APPEND PROPERTY INTERFACE_LINK_LIBRARIES mongoc::${_type}) -endif() diff --git a/src/libmongoc/etc/mongocConfig.cmake.in b/src/libmongoc/etc/mongocConfig.cmake.in new file mode 100644 index 0000000000..10e743f64f --- /dev/null +++ b/src/libmongoc/etc/mongocConfig.cmake.in @@ -0,0 +1,112 @@ +#[[ + CMake package file for the mongoc library. + + This file globs and includes all "*-targets.cmake" files in the containing + directory, and intends that those files define the actual mongoc targets. + + This file also defines a `mongoc::mongoc` target, which redirects to either + `mongoc::static` or `mongoc::shared` depending on what type of library is + available and can be controlled with an import-time CMake setting. + + If the installation has a static library, it is named `mongoc::static`. If + the installation has a shared (dynamic) library, it is named `mongoc::shared`. +]] + +# The version of the mongoc package (comes from the project() call in the orginal project) +set(__mongoc_package_version [[@PROJECT_VERSION@]]) +set(__mongoc_sasl_backend [[@SASL_BACKEND@]]) +set(__mongoc_tls_package [[@TLS_IMPORT_PACKAGE@]]) +set(__mongoc_uses_bundled_utf8proc "@USE_BUNDLED_UTF8PROC@") +# Announce this one as a public var: +set(MONGOC_TLS_BACKEND [[@TLS_BACKEND@]]) + +# Check for missing components before proceeding. We don't provide any, so we +# should generate an error if the caller requests any *required* components. +set(missing_required_components) +foreach(comp IN LISTS mongoc_FIND_COMPONENTS) + if(mongoc_FIND_REQUIRED_${comp}) + list(APPEND missing_required_components "${comp}") + endif() +endforeach() + +if(missing_required_components) + list(JOIN missing_required_components ", " components) + set(mongoc_FOUND FALSE) + set(mongoc_NOT_FOUND_MESSAGE "The package version is compatible, but is missing required components: ${components}") + # Stop now. Don't generate any imported targets + return() +endif() + +# d8888b. d88888b d8888b. d88888b d8b db d8888b. d88888b d8b db .o88b. d888888b d88888b .d8888. +# 88 `8D 88' 88 `8D 88' 888o 88 88 `8D 88' 888o 88 d8P Y8 `88' 88' 88' YP +# 88 88 88ooooo 88oodD' 88ooooo 88V8o 88 88 88 88ooooo 88V8o 88 8P 88 88ooooo `8bo. +# 88 88 88~~~~~ 88~~~ 88~~~~~ 88 V8o88 88 88 88~~~~~ 88 V8o88 8b 88 88~~~~~ `Y8b. +# 88 .8D 88. 88 88. 88 V888 88 .8D 88. 88 V888 Y8b d8 .88. 88. db 8D +# Y8888D' Y88888P 88 Y88888P VP V8P Y8888D' Y88888P VP V8P `Y88P' Y888888P Y88888P `8888Y' +# Import dependencies +include(CMakeFindDependencyMacro) +get_filename_component(__parent_dir "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) +# Also import the `bson` package, to ensure its targets are also available +find_dependency(bson "${__mongoc_package_version}" HINTS ${__parent_dir}) + +# QUIET arg for finding dependencies: +unset(__quiet) +if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + set(__quiet QUIET) +endif() + +# Find libutf8proc (if we linked to an external library) +if(NOT __mongoc_uses_bundled_utf8proc AND NOT TARGET PkgConfig::PC_UTF8PROC) + # libmongoc was compiled against an external utf8proc and links against a + # FindPkgConfig-generated IMPORTED target. Find that package and generate that + # imported target here: + find_dependency(PkgConfig) + pkg_check_modules(PC_UTF8PROC ${__quiet} libutf8proc IMPORTED_TARGET GLOBAL) + if(NOT PC_UTF8PROC_FOUND) + # Handle if it wasn't found (find_dependency would usually do this for us, + # but pkg_check_modules() does not) + set(mongoc_FOUND FALSE) + set(mongoc_NOT_FOUND_MESSAGE "We were unable to find the required libutf8proc package with pkg-config") + return() + endif() +endif() + +# If we need to import a TLS package for our imported targets, do that now: +if(__mongoc_tls_package) + find_dependency("${__mongoc_tls_package}") +endif() + +# Find dependencies for SASL +if(__mongoc_sasl_backend STREQUAL "Cyrus") + # We need libsasl2. The find-module should be installed within this package. + # temporarily place it on the module search path: + set(__prev_path "${CMAKE_MODULE_PATH}") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/3rdParty") + find_dependency(SASL2 2.0) + set(CMAKE_MODULE_PATH "${__prev_path}") +endif() + +# Import the target files that will be install alongside this file. Only the +# targets of libraries that were actually installed alongside this file will be imported +file(GLOB __targets_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") +foreach(__file IN LISTS __targets_files) + include("${__file}") +endforeach() + +# The library type that is linked with `mongoc::mongoc` +set(__default_lib_type SHARED) +if(TARGET mongoc::static) + # If static is available, set it as the default library type + set(__default_lib_type STATIC) +endif() + +# Allow the user to tweak what library type is linked for `mongoc::mongoc` +set(MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE "${__default_lib_type}" + CACHE STRING "The default library type that is used when linking against 'mongoc::mongoc' (either SHARED or STATIC, requires that the package was built with the appropriate library type)") +set_property(CACHE MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE PROPERTY STRINGS SHARED STATIC) + +if(NOT TARGET mongoc::mongoc) # Don't redefine the target if we were already included + string(TOLOWER "${MONGOC_DEFAULT_IMPORTED_LIBRARY_TYPE}" __type) + add_library(mongoc::mongoc IMPORTED INTERFACE) + set_property(TARGET mongoc::mongoc APPEND PROPERTY INTERFACE_LINK_LIBRARIES mongoc::${__type}) +endif() From b5af35c3a70ebd32ebe5f47e2d42d8f7b26de669 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 16:19:25 -0600 Subject: [PATCH 16/26] Remove more X_API_VERSION --- src/libbson/libbson.rc.in | 5 ++-- src/libmongoc/CMakeLists.txt | 18 ------------ src/libmongoc/libmongoc.rc.in | 5 ++-- src/libmongoc/src/mongoc-config.cmake | 40 --------------------------- 4 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 src/libmongoc/src/mongoc-config.cmake diff --git a/src/libbson/libbson.rc.in b/src/libbson/libbson.rc.in index 47afe6f140..9015243d19 100644 --- a/src/libbson/libbson.rc.in +++ b/src/libbson/libbson.rc.in @@ -5,7 +5,6 @@ #include // Defines BSON_MAJOR_VERSION and other version macros. #define BSON_OUTPUT_BASENAME "@BSON_OUTPUT_BASENAME@" -#define BSON_API_VERSION "@BSON_API_VERSION@" VS_VERSION_INFO VERSIONINFO FILEVERSION BSON_MAJOR_VERSION,BSON_MINOR_VERSION,BSON_MICRO_VERSION,0 @@ -30,8 +29,8 @@ BEGIN VALUE "CompanyName", "MongoDB, Inc" VALUE "FileDescription", "A BSON Library for C" VALUE "FileVersion", BSON_VERSION_S - VALUE "InternalName", BSON_OUTPUT_BASENAME "-" BSON_API_VERSION - VALUE "OriginalFilename", BSON_OUTPUT_BASENAME "-" BSON_API_VERSION ".dll" + VALUE "InternalName", BSON_OUTPUT_BASENAME "@PROJECT_VERSION_MAJOR@" + VALUE "OriginalFilename", BSON_OUTPUT_BASENAME "@PROJECT_VERSION_MAJOR@.dll" VALUE "ProductName", "MongoDB C Driver" VALUE "ProductVersion", BSON_VERSION_S VALUE "LegalCopyright", "Copyright 2009-present MongoDB, Inc." diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 056e14f40c..05115e0946 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -12,8 +12,6 @@ project (libmongoc set(libmongoc_VERSION_PRERELEASE ${mongo-c-driver_VERSION_PRERELEASE}) set(libmongoc_VERSION_FULL ${mongo-c-driver_VERSION_FULL}) -set (MONGOC_API_VERSION 1.0) - include (CheckSchedGetCPU) include (CheckStructHasMember) include (CheckSymbolExists) @@ -23,9 +21,6 @@ include (InstallRequiredSystemLibraries) message (STATUS "libmongoc version (from VERSION_CURRENT file): ${MONGOC_VERSION}") -set (MONGOC_API_VERSION 1.0) -set (MONGOC_TARGETS_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/mongoc-${MONGOC_API_VERSION}") - # Defaults. set (MONGOC_ENABLE_COMPRESSION 0) set (MONGOC_ENABLE_COMPRESSION_SNAPPY 0) @@ -1357,19 +1352,6 @@ if (MONGOC_ENABLE_SSL) ) endif () -include (CMakePackageConfigHelpers) - -write_basic_package_version_file ( - "${CMAKE_CURRENT_BINARY_DIR}/mongoc/mongoc-${MONGOC_API_VERSION}-config-version.cmake" - VERSION ${MONGOC_VERSION} - COMPATIBILITY AnyNewerVersion -) - -configure_file (src/mongoc-config.cmake - "${CMAKE_CURRENT_BINARY_DIR}/mongoc/mongoc-${MONGOC_API_VERSION}-config.cmake" - @ONLY -) - install (EXPORT mongoc-targets FILE mongoc-targets.cmake DESTINATION "${MONGOC_INSTALL_CMAKEDIR}" diff --git a/src/libmongoc/libmongoc.rc.in b/src/libmongoc/libmongoc.rc.in index 6b9f3ea887..eff9817b17 100644 --- a/src/libmongoc/libmongoc.rc.in +++ b/src/libmongoc/libmongoc.rc.in @@ -5,7 +5,6 @@ #include // Defines MONGOC_MAJOR_VERSION and other version macros. #define MONGOC_OUTPUT_BASENAME "@MONGOC_OUTPUT_BASENAME@" -#define MONGOC_API_VERSION "@MONGOC_API_VERSION@" VS_VERSION_INFO VERSIONINFO FILEVERSION MONGOC_MAJOR_VERSION,MONGOC_MINOR_VERSION,MONGOC_MICRO_VERSION,0 @@ -30,8 +29,8 @@ BEGIN VALUE "CompanyName", "MongoDB, Inc" VALUE "FileDescription", "MongoDB Client Library for C" VALUE "FileVersion", MONGOC_VERSION_S - VALUE "InternalName", MONGOC_OUTPUT_BASENAME "-" MONGOC_API_VERSION - VALUE "OriginalFilename", MONGOC_OUTPUT_BASENAME "-" MONGOC_API_VERSION ".dll" + VALUE "InternalName", MONGOC_OUTPUT_BASENAME "@PROJECT_VERSION_MAJOR@" + VALUE "OriginalFilename", MONGOC_OUTPUT_BASENAME "@PROJECT_VERSION_MAJOR@.dll" VALUE "ProductName", "MongoDB C Driver" VALUE "ProductVersion", MONGOC_VERSION_S VALUE "LegalCopyright", "Copyright 2009-present MongoDB, Inc." diff --git a/src/libmongoc/src/mongoc-config.cmake b/src/libmongoc/src/mongoc-config.cmake deleted file mode 100644 index b836b874ad..0000000000 --- a/src/libmongoc/src/mongoc-config.cmake +++ /dev/null @@ -1,40 +0,0 @@ -include(CMakeFindDependencyMacro) -find_dependency(bson "@libmongoc_VERSION@") - -# If we need to import a TLS package for our imported targets, do that now: -set(MONGOC_TLS_BACKEND [[@TLS_BACKEND@]]) -set(_tls_package [[@TLS_IMPORT_PACKAGE@]]) -if(_tls_package) - find_dependency("${_tls_package}") -endif() - -include("${CMAKE_CURRENT_LIST_DIR}/mongoc-targets.cmake") - -unset(_required) -unset(_quiet) -if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - set(_required REQUIRED) -endif() -if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) - set(_quiet QUIET) -endif() - -set(_mongoc_built_with_bundled_utf8proc "@USE_BUNDLED_UTF8PROC@") -if(NOT _mongoc_built_with_bundled_utf8proc AND NOT TARGET PkgConfig::PC_UTF8PROC) - # libmongoc was compiled against an external utf8proc and links against a - # FindPkgConfig-generated IMPORTED target. Find that package and generate that - # imported target here: - find_dependency(PkgConfig) - pkg_check_modules(PC_UTF8PROC ${_required} ${_quiet} libutf8proc IMPORTED_TARGET GLOBAL) -endif() - -# Find dependencies for SASL -set(_sasl_backend [[@SASL_BACKEND@]]) -if(_sasl_backend STREQUAL "Cyrus") - # We need libsasl2. The find-module should be installed within this package. - # temporarily place it on the module search path: - set(_prev_path "${CMAKE_MODULE_PATH}") - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/3rdParty") - find_dependency(SASL2 2.0) - set(CMAKE_MODULE_PATH "${_prev_path}") -endif() From f8d484599f9379202eeb1ae3864acd227c4dd01c Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Sun, 30 Mar 2025 16:20:47 -0600 Subject: [PATCH 17/26] Remove libmongoc-ssl .pc files --- src/libmongoc/CMakeLists.txt | 12 ------------ src/libmongoc/src/libmongoc-ssl-1.0.pc.in | 11 ----------- 2 files changed, 23 deletions(-) delete mode 100644 src/libmongoc/src/libmongoc-ssl-1.0.pc.in diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 05115e0946..3b35a452e5 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -1340,18 +1340,6 @@ endif() # Relative include-path will be given the install prefix: set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${MONGOC_INSTALL_INCLUDEDIR}") -# Deprecated alias for libmongoc-1.0.pc, see CDRIVER-2086. -if (MONGOC_ENABLE_SSL) - configure_file ( - ${CMAKE_CURRENT_SOURCE_DIR}/src/libmongoc-ssl-1.0.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-ssl-1.0.pc - @ONLY) - install ( - FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-ssl-1.0.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig - ) -endif () - install (EXPORT mongoc-targets FILE mongoc-targets.cmake DESTINATION "${MONGOC_INSTALL_CMAKEDIR}" diff --git a/src/libmongoc/src/libmongoc-ssl-1.0.pc.in b/src/libmongoc/src/libmongoc-ssl-1.0.pc.in deleted file mode 100644 index d29b11014e..0000000000 --- a/src/libmongoc/src/libmongoc-ssl-1.0.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=${prefix} -libdir=@libdir@ -includedir=${exec_prefix}/include - -Name: libmongoc-@MONGOC_API_VERSION@ -Description: SSL support for the libmongoc-@MONGOC_API_VERSION@ library. -Version: @MONGOC_VERSION@ -Requires: libmongoc-1.0 -Libs: -Cflags: From c7bdbdaf75488b375fd40d2a29acb073bb6b1bbb Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 31 Mar 2025 10:36:01 -0600 Subject: [PATCH 18/26] Spelling --- src/libbson/etc/bsonConfig.cmake | 2 +- src/libmongoc/etc/mongocConfig.cmake.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libbson/etc/bsonConfig.cmake b/src/libbson/etc/bsonConfig.cmake index 3233ef6c84..2655fee94e 100644 --- a/src/libbson/etc/bsonConfig.cmake +++ b/src/libbson/etc/bsonConfig.cmake @@ -32,7 +32,7 @@ endif() include(CMakeFindDependencyMacro) find_dependency(Threads) # Required for Threads::Threads -# Import the target files that will be install alongside this file. Only the +# Import the target files that will be installed alongside this file. Only the # targets of libraries that were actually installed alongside this file will be imported file(GLOB __targets_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") foreach(__file IN LISTS __targets_files) diff --git a/src/libmongoc/etc/mongocConfig.cmake.in b/src/libmongoc/etc/mongocConfig.cmake.in index 10e743f64f..14d7e4c7ed 100644 --- a/src/libmongoc/etc/mongocConfig.cmake.in +++ b/src/libmongoc/etc/mongocConfig.cmake.in @@ -86,7 +86,7 @@ if(__mongoc_sasl_backend STREQUAL "Cyrus") set(CMAKE_MODULE_PATH "${__prev_path}") endif() -# Import the target files that will be install alongside this file. Only the +# Import the target files that will be installed alongside this file. Only the # targets of libraries that were actually installed alongside this file will be imported file(GLOB __targets_files "${CMAKE_CURRENT_LIST_DIR}/*-targets.cmake") foreach(__file IN LISTS __targets_files) From 8f42b2f89b4002b9340f10d728d994fe37c4427f Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 31 Mar 2025 14:35:26 -0600 Subject: [PATCH 19/26] Fix transposed version variables --- .evergreen/scripts/install-uninstall-check.sh | 4 ++-- .evergreen/scripts/link-sample-program-bson.sh | 4 ++-- .evergreen/scripts/link-sample-program.sh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.evergreen/scripts/install-uninstall-check.sh b/.evergreen/scripts/install-uninstall-check.sh index 6128c17e68..c07680e416 100755 --- a/.evergreen/scripts/install-uninstall-check.sh +++ b/.evergreen/scripts/install-uninstall-check.sh @@ -17,8 +17,8 @@ SRCROOT=$(pwd) _full_version=$(cat "$DIR/../../VERSION_CURRENT") version="${_full_version%-*}" # 1.2.3-dev → 1.2.3 major="${version%%.*}" # 1.2.3 → 1 -echo "major version: $version" -echo " full version: $major" +echo "major version: $major" +echo " full version: $version" # Use ccache if able. . $DIR/find-ccache.sh diff --git a/.evergreen/scripts/link-sample-program-bson.sh b/.evergreen/scripts/link-sample-program-bson.sh index fb62f5a927..c17230c9b8 100755 --- a/.evergreen/scripts/link-sample-program-bson.sh +++ b/.evergreen/scripts/link-sample-program-bson.sh @@ -17,8 +17,8 @@ CMAKE=$(find_cmake_latest) _full_version=$(cat "$DIR/../../VERSION_CURRENT") version="${_full_version%-*}" # 1.2.3-dev → 1.2.3 major="${version%%.*}" # 1.2.3 → 1 -echo "major version: $version" -echo " full version: $major" +echo "major version: $major" +echo " full version: $version" # Get the kernel name, lowercased OS=$(uname -s | tr '[:upper:]' '[:lower:]') diff --git a/.evergreen/scripts/link-sample-program.sh b/.evergreen/scripts/link-sample-program.sh index c41d01f5f8..c52656fae7 100755 --- a/.evergreen/scripts/link-sample-program.sh +++ b/.evergreen/scripts/link-sample-program.sh @@ -20,8 +20,8 @@ CMAKE=$(find_cmake_latest) _full_version=$(cat "$DIR/../../VERSION_CURRENT") version="${_full_version%-*}" # 1.2.3-dev → 1.2.3 major="${version%%.*}" # 1.2.3 → 1 -echo "major version: $version" -echo " full version: $major" +echo "major version: $major" +echo " full version: $version" # Get the kernel name, lowercased OS=$(uname -s | tr '[:upper:]' '[:lower:]') From 5d5be9e23df4ac911b9fd54ff9bcc3dd41e02b2f Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 31 Mar 2025 14:36:03 -0600 Subject: [PATCH 20/26] Wrong pkg-config filenames --- src/libmongoc/tests/import-tests.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libmongoc/tests/import-tests.cmake b/src/libmongoc/tests/import-tests.cmake index 378d61f59f..c46cf34bd0 100644 --- a/src/libmongoc/tests/import-tests.cmake +++ b/src/libmongoc/tests/import-tests.cmake @@ -136,7 +136,7 @@ add_test_cmake_project( mongoc/pkg-config/mongoc-import-shared src/libmongoc/tests/pkg-config-import INSTALL_PARENT SETTINGS - PKG_CONFIG_SEARCH=mongoc1 + PKG_CONFIG_SEARCH=mongoc${PROJECT_VERSION_MAJOR} "EXPECT_MONGOC_VERSION=${mongo-c-driver_VERSION_FULL}" ) @@ -144,7 +144,7 @@ add_test_cmake_project( mongoc/pkg-config/mongoc-import-static src/libmongoc/tests/pkg-config-import INSTALL_PARENT SETTINGS - PKG_CONFIG_SEARCH=mongoc1-static + PKG_CONFIG_SEARCH=mongoc${PROJECT_VERSION_MAJOR}-static "EXPECT_MONGOC_VERSION=${mongo-c-driver_VERSION_FULL}" EXPECT_BSON_STATIC=1 EXPECT_MONGOC_STATIC=1 From 018dca404f6719d096995afe68a4e8d3b673d38e Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 31 Mar 2025 14:44:15 -0600 Subject: [PATCH 21/26] Add NEWS entries regarding package renames --- NEWS | 25 +++++++++++++++++++++++++ src/libbson/NEWS | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/NEWS b/NEWS index 2a97df534a..a4d9d6ae53 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,26 @@ Unreleased (2.0.0) * New behavior: `authMechanismProperties=A:B,C:D:E,F:G` is parsed as `{'A': 'B': 'C': 'D:E', 'F': 'G'}`. * Calling `mongoc_bulk_operation_execute` on the same `mongoc_bulk_operation_t` repeatedly is an error. Previously this was only discouraged in documentation. + +### CMake Packages and Imported Targets + +The `mongoc-1.0` (and `bson-1.0`) CMake packages have been removed. Instead, use +`mongoc` or `bson`, and specify a version or version range to be imported: + +```cmake +find_package(mongoc 1.30...2.0) +``` + +The new packages import different target names: + +- `mongo::mongoc_static` → `mongoc::static` +- `mongo::mongoc_shared` → `mongoc::shared` +- The target `mongoc::mongoc` is a shim target that points to either the shared + library or the static library. + +The BSON library has had similar name changes. + + ## Removals * The `bson_md5_t` struct and associated API is removed. @@ -78,6 +98,11 @@ Unreleased (2.0.0) * `mongoc_index_opt_t`, `mongoc_index_opt_geo_t` `mongoc_index_opt_wt_t` are removed. Pass options using `bson_t` to `mongoc_collection_create_indexes_with_opts` instead. * `mongoc_collection_find_indexes` is removed. Use `mongoc_collection_find_indexes_with_opts` instead. * See [MongoDB documentation](https://www.mongodb.com/docs/languages/c/c-driver/current/indexes/) for working with indexes. +* The `libmongoc-ssl-1.0` pkg-config file has been removed. +* The pkg-config files `libmongoc-1.0`, `libmongoc-static-1.0`, `libbson-1.0`, + and `libbson-static-1.0` have been renamed to `mongoc2`, `mongoc2-static`, + `bson2`, and `bson2-static`, respectively. + ### Forwarding headers (`#include ` and `#include `) diff --git a/src/libbson/NEWS b/src/libbson/NEWS index 66c9249007..3972514d5a 100644 --- a/src/libbson/NEWS +++ b/src/libbson/NEWS @@ -24,6 +24,25 @@ libbson 2.0.0 (Unreleased) * `BSON_ERROR_BUFFER_SIZE` is reduced from `504` to `503` to reserve the final byte for internal use. * The data layout of `bson_error_t` remains otherwise unchanged: the size is still 512 bytes and the offset of the `.code`, `.domain`, and `.message` data members remain unchanged. +* The `libbson-1.0` and `libbson-static-1.0` pkg-config modules are now named + `bson1` and `bson1-static`, respectively. + +### CMake Packages and Imported Targets + +The `bson-1.0` CMake package have been removed. Instead, use or `bson`, and +specify a version or version range to be imported: + +```cmake +find_package(bson 1.30...2.0) +``` + +The new package imports different target names: + +- `mongo::bson_static` → `bson::static` +- `mongo::bson_shared` → `bson::shared` +- The target `bson::bson` is a shim target that points to either the shared + library or the static library. + ## Removals From 51d7f83ade02091e0387ad6022e273eb35e32a39 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 31 Mar 2025 14:46:03 -0600 Subject: [PATCH 22/26] Qualify installation of docs and licenses --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdec2969a2..b2f926510e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -465,7 +465,7 @@ if (ENABLE_MONGOC) endif () install (FILES COPYING NEWS README.rst THIRD_PARTY_NOTICES - DESTINATION ${CMAKE_INSTALL_DATADIR}/mongo-c-driver + DESTINATION ${CMAKE_INSTALL_DATADIR}/mongo-c-driver/${PROJECT_VERSION} ) if (ENABLE_UNINSTALL) @@ -477,7 +477,7 @@ if (ENABLE_UNINSTALL) # Generate a different script name for uninstalling libbson only: set (UNINSTALL_SCRIPT_NAME "uninstall-bson") endif () - set (UNINSTALL_PROG_DIR "${CMAKE_INSTALL_DATADIR}/mongo-c-driver") + set (UNINSTALL_PROG_DIR "${CMAKE_INSTALL_DATADIR}/mongo-c-driver/${PROJECT_VERSION}") include (GenerateUninstaller) endif () From 497721c480d7ff85c52befafaa9bf8b1e632570e Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 31 Mar 2025 14:47:55 -0600 Subject: [PATCH 23/26] Major-version qualify the `mongoc-stat` tool --- src/libmongoc/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 3b35a452e5..e10a4038a4 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -902,6 +902,7 @@ if (ENABLE_SHARED) add_executable (mongoc-stat ${mongo-c-driver_SOURCE_DIR}/src/tools/mongoc-stat.c) target_compile_options (mongoc-stat PRIVATE ${mongoc-warning-options}) target_link_libraries (mongoc-stat mongoc_shared ${LIBRARIES}) + set_property (TARGET mongoc-stat PROPERTY OUTPUT_NAME mongoc${PROJECT_VERSION_MAJOR}-stat) # mongoc-stat works if shared memory performance counters are enabled. if (ENABLE_SHM_COUNTERS) From dd654c218a631fa5bbb60ea98cc2785818a7c643 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 1 Apr 2025 08:06:53 -0400 Subject: [PATCH 24/26] use version 2 to refer to new libbson pkg-config files --- src/libbson/NEWS | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libbson/NEWS b/src/libbson/NEWS index 3972514d5a..f974b10834 100644 --- a/src/libbson/NEWS +++ b/src/libbson/NEWS @@ -24,8 +24,7 @@ libbson 2.0.0 (Unreleased) * `BSON_ERROR_BUFFER_SIZE` is reduced from `504` to `503` to reserve the final byte for internal use. * The data layout of `bson_error_t` remains otherwise unchanged: the size is still 512 bytes and the offset of the `.code`, `.domain`, and `.message` data members remain unchanged. -* The `libbson-1.0` and `libbson-static-1.0` pkg-config modules are now named - `bson1` and `bson1-static`, respectively. +* The pkg-config files `libbson-1.0`, have been renamed to `bson2`, and `bson2-static`, respectively. ### CMake Packages and Imported Targets From b005203661d4f24f02e14e3a481ab1cfc13c12fc Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 1 Apr 2025 08:07:12 -0400 Subject: [PATCH 25/26] relocate NEWS for libmongoc pkg-config file rename to "Changes" --- NEWS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index a4d9d6ae53..77439eace9 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,9 @@ Unreleased (2.0.0) * Old behavior: `authMechanismProperties=A:B,C:D:E,F:G` is parsed as `{'A': 'B', 'C': 'D:E,F:G'}`. * New behavior: `authMechanismProperties=A:B,C:D:E,F:G` is parsed as `{'A': 'B': 'C': 'D:E', 'F': 'G'}`. * Calling `mongoc_bulk_operation_execute` on the same `mongoc_bulk_operation_t` repeatedly is an error. Previously this was only discouraged in documentation. +* The pkg-config files `libmongoc-1.0`, `libmongoc-static-1.0`, `libbson-1.0`, + and `libbson-static-1.0` have been renamed to `mongoc2`, `mongoc2-static`, + `bson2`, and `bson2-static`, respectively. ### CMake Packages and Imported Targets @@ -99,9 +102,6 @@ The BSON library has had similar name changes. * `mongoc_collection_find_indexes` is removed. Use `mongoc_collection_find_indexes_with_opts` instead. * See [MongoDB documentation](https://www.mongodb.com/docs/languages/c/c-driver/current/indexes/) for working with indexes. * The `libmongoc-ssl-1.0` pkg-config file has been removed. -* The pkg-config files `libmongoc-1.0`, `libmongoc-static-1.0`, `libbson-1.0`, - and `libbson-static-1.0` have been renamed to `mongoc2`, `mongoc2-static`, - `bson2`, and `bson2-static`, respectively. ### Forwarding headers (`#include ` and `#include `) From 4d202bb627787de21a0131d4dbe47b10bd11bba5 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 1 Apr 2025 08:10:44 -0400 Subject: [PATCH 26/26] fix references to mongoc-stat --- .evergreen/scripts/link-sample-program.sh | 10 +++++----- src/libmongoc/.gitignore | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.evergreen/scripts/link-sample-program.sh b/.evergreen/scripts/link-sample-program.sh index c52656fae7..52d4c0f1e6 100755 --- a/.evergreen/scripts/link-sample-program.sh +++ b/.evergreen/scripts/link-sample-program.sh @@ -94,16 +94,16 @@ unset CCACHE_BASEDIR CCACHE_NOHASHDIR ls -l $INSTALL_DIR/lib if [ "$OS" = "darwin" ] && [ "${HOSTTYPE:?}" != "arm64" ]; then - if test -f $INSTALL_DIR/bin/mongoc-stat; then - echo "mongoc-stat shouldn't have been installed" + if test -f $INSTALL_DIR/bin/mongoc$major-stat; then + echo "mongoc$major-stat shouldn't have been installed" exit 1 fi else - if test ! -f $INSTALL_DIR/bin/mongoc-stat; then - echo "mongoc-stat missing!" + if test ! -f $INSTALL_DIR/bin/mongoc$major-stat; then + echo "mongoc$major-stat missing!" exit 1 else - echo "mongoc-stat check ok" + echo "mongoc$major-stat check ok" fi fi diff --git a/src/libmongoc/.gitignore b/src/libmongoc/.gitignore index 8bf24d3d51..4e6886c8f3 100644 --- a/src/libmongoc/.gitignore +++ b/src/libmongoc/.gitignore @@ -33,7 +33,7 @@ find-and-modify hello_mongoc mongoc-dump mongoc-ping -mongoc-stat +mongoc2-stat mongoc-tail # Test binaries