Skip to content

Commit 2d30996

Browse files
authored
CXX-3087 Replace single-argument FetchContent_Populate with FetchContent_MakeAvailable (#1186)
1 parent 4836b7e commit 2d30996

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
99

1010
## 3.11.0 [Unreleased]
1111

12-
<!-- Will contain entries for the next minor release -->
12+
### Changed
13+
14+
- `FetchContent_MakeAvailable()` is used to populate dependencies instead of `FetchContent_Populate()` for the Mongo C Driver (when not provided by `CMAKE_PREFIX_PATH`) and mnmlstc/core (when automatically selected or `BSONCXX_POLY_USE_MNMLSTC=ON`).
15+
- Note: `FetchContent_Populate()` is still used for mnmlstc/core for CMake versions prior to 3.18 to avoid `add_subdirectory()` behavior.
1316

1417
### Deprecated
1518

@@ -71,6 +74,7 @@ accordance with [MongoDB Software Lifecycle Schedules](https://www.mongodb.com/l
7174
- Add VERSIONINFO resource to bsoncxx.dll and mongocxx.dll.
7275

7376
### Changed
77+
7478
- Do not build tests as part of `all` target. Configure with `BUILD_TESTING=ON` to build tests.
7579
- Bump minimum required CMake version to 3.15 to support the FetchContent module and for consistency with the C Driver.
7680
- Improve handling of downloaded (non-system) mnmlstc/core as the polyfill library.
@@ -79,11 +83,13 @@ accordance with [MongoDB Software Lifecycle Schedules](https://www.mongodb.com/l
7983
- Bump minimum C Driver version to [1.25.0](https://github.com/mongodb/mongo-c-driver/releases/tag/1.25.0).
8084

8185
### Fixed
86+
8287
- Explicitly document that throwing an exception from an APM callback is undefined behavior.
8388
- Do not prematurely install mnmlstc/core headers during the CMake build step.
8489
- Require a C Driver CMake package is found via `find_dependency()` for all installed CXX Driver package configurations.
8590

8691
### Removed
92+
8793
- Remove support for exported targets from the CMake project build tree.
8894
- Drop support for the following operating systems:
8995
- macOS 10.14 and 10.15

cmake/FetchMnmlstcCore.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ FetchContent_Declare(
1212
EP_mnmlstc_core
1313

1414
SOURCE_DIR "${core-src}"
15+
SOURCE_SUBDIR "" # Disable `add_subdirectory()` in `FetchContent_MakeAvailable()`.
1516
SUBBUILD_DIR "${core-subbuild}"
1617
BINARY_DIR "${core-build}"
1718
INSTALL_DIR "${core-install}"
@@ -32,7 +33,12 @@ if(core_FOUND AND "$CACHE{INTERNAL_MONGOC_MNMLSTC_CORE_FOUND}")
3233
else()
3334
if(NOT ep_mnmlstc_core_POPULATED)
3435
message(STATUS "Downloading mnmlstc/core...")
35-
FetchContent_Populate(EP_mnmlstc_core)
36+
if("${CMAKE_VERSION}" VERSION_LESS "3.18.0")
37+
# SOURCE_SUBDIR is not yet supported.
38+
FetchContent_Populate(EP_mnmlstc_core)
39+
else()
40+
FetchContent_MakeAvailable(EP_mnmlstc_core)
41+
endif()
3642
message(STATUS "Downloading mnmlstc/core... done.")
3743
endif()
3844

cmake/FetchMongoC.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ if(NOT mongo-c-driver_POPULATED)
2121

2222
set(ENABLE_EXTRA_ALIGNMENT OFF)
2323

24-
FetchContent_Populate(mongo-c-driver)
25-
2624
# Set ENABLE_TESTS to OFF to disable the test-libmongoc target in the C driver.
2725
# This prevents the LoadTests.cmake script from attempting to execute test-libmongoc.
2826
# test-libmongoc is not built with the "all" target.
@@ -31,7 +29,7 @@ if(NOT mongo-c-driver_POPULATED)
3129
set(BUILD_TESTING OFF)
3230
string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
3331
string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
34-
add_subdirectory(${mongo-c-driver_SOURCE_DIR} ${mongo-c-driver_BINARY_DIR})
32+
FetchContent_MakeAvailable(mongo-c-driver)
3533
set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS})
3634
set(CMAKE_C_FLAGS ${OLD_CMAKE_C_FLAGS})
3735
set(ENABLE_TESTS ${OLD_ENABLE_TESTS})

0 commit comments

Comments
 (0)