Skip to content

mongo-c-driver: fix problems with newer CMake versions - #30788

Open
Dahlgren wants to merge 3 commits into
conan-io:masterfrom
Dahlgren:package/mongo-c-driver-cmake
Open

mongo-c-driver: fix problems with newer CMake versions#30788
Dahlgren wants to merge 3 commits into
conan-io:masterfrom
Dahlgren:package/mongo-c-driver-cmake

Conversation

@Dahlgren

@Dahlgren Dahlgren commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Changes to recipe: mongo-c-driver

Motivation

It's not possible to compile mongo-c-driver recipe when newer versions of CMake are on system path, the recipe doesn't declare any CMake range

Details


  • Read the contributing guidelines
  • Checked that this PR is not a duplicate: list of PRs by recipe
  • If this is a bug fix, please link related issue or provide bug details
  • Tested locally with at least one configuration using a recent version of Conan

Add a 👍 reaction to pull requests you find important to help the team prioritize, thanks!

- <2.4.0 has broken TRY_COMPILE in src/libmongoc/CMakeLists.txt, failing in CMake 4.4+
  - mongodb/mongo-c-driver@ea1b547
- <1.30.3/<2.1.0 has CMP0042 OLD in src/libbson/CMakeLists.txt, removed in CMake 4+
  - mongodb/mongo-c-driver@2344038
  - mongodb/mongo-c-driver@c60f45f
- <1.25 has cmake_minimum_required (VERSION 3.1) in src/libbson/CMakeLists.txt, rejected in CMake 4+
  - mongodb/mongo-c-driver@3c7951b#diff-71a4c7cf57df62b3b3d8bb547bcf79c5fafb5accb4a6608d696ccdf43e17ad6a
@jcar87

jcar87 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Does defining CMAKE_POLICY_VERSION_MINIMUM (to 3.5 as minimum) as suggested in #26878 not work?

Clipping the version range of CMake to <4 would prevent usage with Visual Studio 2026. I'd say we would only do this if the build script truly does not work with CMake <4 even with the policy workaround.

@Dahlgren

Dahlgren commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Does defining CMAKE_POLICY_VERSION_MINIMUM (to 3.5 as minimum) as suggested in #26878 not work?

It only fixes the last issue with cmake_minimum_required (VERSION 3.1), if we drop older versions we can go up to <4.4

@jcar87

jcar87 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

I'm a bit confused. What version of mongo-c-driver are you attempting to build from source, and what error are you getting if you attempt to build that with CMake 4.0? thanks!

@Dahlgren

Dahlgren commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

With self.tool_requires("cmake/4.0.3") (and CMAKE_POLICY_VERSION_MINIMUM=3.5 for 1.24.3),

Version Builds
2.2.1
2.2.0
1.30.6
1.29.2
1.29.1
1.29.0
1.28.1
1.27.6
1.26.2
1.24.3
CMake Error at src/libbson/CMakeLists.txt:37 (cmake_policy):
  Policy CMP0042 may not be set to OLD behavior because this version of CMake
  no longer supports it.  The policy was introduced in CMake version 3.0.0,
  and use of NEW behavior is now required.

  Please either update your CMakeLists.txt files to conform to the new
  behavior or use an older version of CMake that still supports the old
  behavior.  Run cmake --help-policy CMP0042 for more information.

Either we can drop these older <1.30.3 versions or we can add this patch,

if Version(self.version) < "1.30.3":
    replace_in_file(self, os.path.join(self.source_folder, "src", "libbson", "CMakeLists.txt"),
                          "cmake_policy (SET CMP0042 OLD)", "")

By also adding this we can support CMake 4.4,

if Version(self.version) < "2.4.0":
            replace_in_file(self, os.path.join(self.source_folder, "src", "libmongoc", "CMakeLists.txt"),
                                  "\"-Werror -DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'\"",
                                  "\"-DCOMPILE_DEFINITIONS=-Werror\" \"-DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'\"")

I've added both fixes as separate commits, let me know which combination you prefer

@Dahlgren Dahlgren changed the title mongo-c-driver: declare valid CMake range mongo-c-driver: fix problems with newer CMake versions Aug 18, 2026
@jcar87

jcar87 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Hi @Dahlgren thanks so much for the table and for the work working out which versions build and don't.

However, based on what you are saying I think we may just leave this as is - if all versions greater than 1.30.6 work with CMake 4, then users should use those instead. If this is because of mongo-cxx-driver, we can just update the dependency there.

We will generally not backport fixes to "older" versions if newer versions are already published and working and can be trivially updated to.

@Dahlgren

Dahlgren commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

How about dropping versions older than 1.30.6 and just adding the CMake 4.4 fix then? My issue is the CMake 4.4 incompatibility with mongo-c-driver/1.30.6.

@jcar87

jcar87 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

How about dropping versions older than 1.30.6 and just adding the CMake 4.4 fix then? My issue is the CMake 4.4 incompatibility with mongo-c-driver/1.30.6.

1.30.6 should theoretically be compatible with 4.0: https://github.com/mongodb/mongo-c-driver/blob/1.30.6/CMakeLists.txt#L1

What is the error when CMake 4.4. is used - if it worked with 4.0-4.3.x, it could very well be a CMake regression too.

@Dahlgren

Copy link
Copy Markdown
Contributor Author

1.30.6 should theoretically be compatible with 4.0: https://github.com/mongodb/mongo-c-driver/blob/1.30.6/CMakeLists.txt#L1

Yes, mongo-c-driver/1.30.6 works fine with cmake/[>=3.15 <4.4]

What is the error when CMake 4.4. is used - if it worked with 4.0-4.3.x, it could very well be a CMake regression too.

CMake Error: The warning category "error -DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'" is not known.
CMake Error at src/libmongoc/CMakeLists.txt:453 (TRY_COMPILE):
  Failed to configure test project build system.
Call Stack (most recent call first):
  src/libmongoc/CMakeLists.txt:477 (mongoc_get_accept_args)

It's an incorrect CMAKE_FLAGS argument in TRY_COMPILE, https://github.com/mongodb/mongo-c-driver/blob/1.30.6/src/libmongoc/CMakeLists.txt#L453-L455

TRY_COMPILE (RES ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/accept_test${VAR}.c CMAKE_FLAGS
"-Werror -DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'" OUTPUT_VARIABLE LOG2)

According to the CMake docs the CMAKE_FLAGS should use -DVAR:TYPE=VALUE format and even has explicit matching example CMAKE_FLAGS -DCOMPILE_DEFINITIONS=-Werror, https://cmake.org/cmake/help/v4.0/command/try_compile.html#options

It's only fixed in latest 2.4.0 release, mongodb/mongo-c-driver@ea1b547

Version Builds
2.2.1
2.2.0
1.30.6

Applying this patch would fix the build for the existing versions,

if Version(self.version) < "2.4.0":
            replace_in_file(self, os.path.join(self.source_folder, "src", "libmongoc", "CMakeLists.txt"),
                                  "\"-Werror -DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'\"",
                                  "\"-DCOMPILE_DEFINITIONS=-Werror\" \"-DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'\"")

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