Skip to content

Conversation

@eramongodb
Copy link
Contributor

Followup to #1052.

Addresses CMP0169, which has been emitting a warning since CMake 3.18, but is made an error since 3.30 when the policy is set to NEW (as is now the case following #1052):

CMake Error at FetchContent.cmake:1951 (message):
  Calling FetchContent_Populate(embedded_mcd) is deprecated, call
  FetchContent_MakeAvailable(embedded_mcd) instead.  Policy CMP0169 can be
  set to OLD to allow FetchContent_Populate(embedded_mcd) to be called
  directly for now, but the ability to call it with declared details will be
  removed completely in a future version.
Call Stack (most recent call first):
  cmake/FetchMongoC.cmake:35 (FetchContent_Populate)
  cmake/ImportBSON.cmake:105 (include)
  CMakeLists.txt:27 (include)

This is the same issue described in mongodb/mongo-cxx-driver#1186, and the solution is the same: using *_MakeAvailable() for CMake 3.18 and newer (which supports SOURCE_SUBDIR), and using *_Populate() for backward compatibility until the minimum required CMake version is raised to 3.18 or newer. This applies to IntelDFP (targets manually defined in IntelDFP.cmake) and libbson (manual call to add_subdirectory() in ImportBSON.cmake).

Interestingly, the initial attempt to apply this change produced the following error:

CMake Error at MongoPlatform.cmake:19 (add_library):
  add_library cannot create target "_mongo-platform" because another target
  with the same name already exists.  The existing target is an interface
  library created in source directory
  "_deps/embedded_mcd-src".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  _deps/embedded_mcd-src/CMakeLists.txt:29 (include)

This is due to the mongo-c-driver project being add_subdirectory()'d twice: once by *_MakeAvailable() and once again later in ImportBSON.cmake. Unlike in mongodb/mongo-cxx-driver#1186, it seems newer CMake versions do not accept SOURCE_SUBDIR "" as a workaround (possibly due to CMP0174?). Therefore, although a bit more awkward, SOURCE_SUBDIR is set to "/dev/null" instead of "". (It just needs to be a (non-existent) directory which does not contain a CMakeLists.txt file.)

@eramongodb eramongodb requested a review from kevinAlbs August 12, 2025 21:58
@eramongodb eramongodb self-assigned this Aug 12, 2025
@eramongodb eramongodb requested a review from a team as a code owner August 12, 2025 21:58
@eramongodb
Copy link
Contributor Author

eramongodb commented Aug 13, 2025

After further testing, SOURCE_SUBDIR "/dev/null" is rejected by CMake 3.15:

CMake Error at ExternalProject.cmake:1668 (message):
  External project embedded_mcd-populate has non-relative SOURCE_SUBDIR!

Replaced /dev/null with a reserved NO_ADD_SUBDIRECTORY "directory" (none of the FetchContent projects we import should have a directory with this name or a CMakeLists.txt file within it).

@eramongodb eramongodb merged commit 6d8de05 into mongodb:master Aug 15, 2025
52 of 56 checks passed
@eramongodb eramongodb deleted the crypt-cmake-compat branch August 15, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants