|
2 | 2 |
|
3 | 3 | include(FetchContent)
|
4 | 4 |
|
5 |
| -message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... begin") |
6 |
| - |
7 |
| -set(fetch_args "") |
8 |
| -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0") |
9 |
| - set(fetch_args "SYSTEM") |
10 |
| -endif() |
11 |
| - |
12 |
| -# Declare mongo-c-driver as a dependency |
13 |
| -FetchContent_Declare( |
14 |
| - mongo-c-driver |
15 |
| - GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git |
16 |
| - GIT_TAG ${LIBMONGOC_DOWNLOAD_VERSION} |
17 |
| - |
18 |
| - ${fetch_args} |
19 |
| -) |
20 |
| - |
21 |
| -FetchContent_GetProperties(mongo-c-driver) |
22 |
| - |
23 |
| -if(NOT mongo-c-driver_POPULATED) |
24 |
| - set(OLD_ENABLE_TESTS ${ENABLE_TESTS}) |
25 |
| - set(OLD_BUILD_TESTING ${BUILD_TESTING}) |
26 |
| - set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) |
27 |
| - set(OLD_CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) |
28 |
| - |
29 |
| - # Set ENABLE_TESTS to OFF to disable the test-libmongoc target in the C driver. |
30 |
| - # This prevents the LoadTests.cmake script from attempting to execute test-libmongoc. |
31 |
| - # test-libmongoc is not built with the "all" target. |
32 |
| - # Attempting to execute test-libmongoc results in an error: "Unable to find executable: NOT_FOUND" |
33 |
| - set(ENABLE_TESTS OFF) |
34 |
| - set(BUILD_TESTING OFF) |
35 |
| - string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
36 |
| - string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
37 |
| - FetchContent_MakeAvailable(mongo-c-driver) |
38 |
| - set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) |
39 |
| - set(CMAKE_C_FLAGS ${OLD_CMAKE_C_FLAGS}) |
40 |
| - set(ENABLE_TESTS ${OLD_ENABLE_TESTS}) |
41 |
| - set(BUILD_TESTING ${OLD_BUILD_TESTING}) |
42 |
| -endif() |
43 |
| - |
44 |
| -message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... end") |
| 5 | +function(fetch_mongoc) |
| 6 | + message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... begin") |
| 7 | + |
| 8 | + set(fetch_args "") |
| 9 | + if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0") |
| 10 | + list(APPEND fetch_args "SYSTEM") |
| 11 | + endif() |
| 12 | + |
| 13 | + # Declare mongo-c-driver as a dependency |
| 14 | + FetchContent_Declare( |
| 15 | + mongo-c-driver |
| 16 | + GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git |
| 17 | + GIT_TAG ${LIBMONGOC_DOWNLOAD_VERSION} |
| 18 | + |
| 19 | + ${fetch_args} |
| 20 | + ) |
| 21 | + |
| 22 | + FetchContent_GetProperties(mongo-c-driver) |
| 23 | + |
| 24 | + if(NOT mongo-c-driver_POPULATED) |
| 25 | + # Must ensure BUILD_VERSION is not inherited either as a normal variable or as a cache variable. |
| 26 | + unset(BUILD_VERSION) |
| 27 | + unset(OLD_CACHE_BUILD_VERSION) |
| 28 | + if(DEFINED CACHE{BUILD_VERSION}) |
| 29 | + set(OLD_CACHE_BUILD_VERSION $CACHE{BUILD_VERSION}) |
| 30 | + unset(BUILD_VERSION CACHE) |
| 31 | + endif() |
| 32 | + |
| 33 | + # Disable unnecessary targets and potential conflicts with C++ Driver options. |
| 34 | + set(ENABLE_TESTS OFF) |
| 35 | + set(BUILD_TESTING OFF) |
| 36 | + string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 37 | + string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 38 | + |
| 39 | + FetchContent_MakeAvailable(mongo-c-driver) |
| 40 | + |
| 41 | + # Restore prior value of BUILD_VERSION cache variable only if was previously set. |
| 42 | + if(DEFINED OLD_CACHE_BUILD_VERSION) |
| 43 | + set(BUILD_VERSION ${OLD_CACHE_BUILD_VERSION} CACHE STRING "Library version (for both bsoncxx and mongocxx)") |
| 44 | + endif() |
| 45 | + endif() |
| 46 | + |
| 47 | + message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... end") |
| 48 | +endfunction() |
| 49 | + |
| 50 | +fetch_mongoc() |
0 commit comments