-
Notifications
You must be signed in to change notification settings - Fork 545
CXX-3266 avoid inheriting BUILD_VERSION by auto-downloaded C Driver #1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
12368f0
a3776d4
6ab102b
c4c9cb5
e8bd245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,43 +2,56 @@ | |||||||||||
|
||||||||||||
include(FetchContent) | ||||||||||||
|
||||||||||||
message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... begin") | ||||||||||||
|
||||||||||||
set(fetch_args "") | ||||||||||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0") | ||||||||||||
set(fetch_args "SYSTEM") | ||||||||||||
endif() | ||||||||||||
|
||||||||||||
# Declare mongo-c-driver as a dependency | ||||||||||||
FetchContent_Declare( | ||||||||||||
mongo-c-driver | ||||||||||||
GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git | ||||||||||||
GIT_TAG ${LIBMONGOC_DOWNLOAD_VERSION} | ||||||||||||
|
||||||||||||
${fetch_args} | ||||||||||||
) | ||||||||||||
|
||||||||||||
FetchContent_GetProperties(mongo-c-driver) | ||||||||||||
|
||||||||||||
if(NOT mongo-c-driver_POPULATED) | ||||||||||||
set(OLD_ENABLE_TESTS ${ENABLE_TESTS}) | ||||||||||||
set(OLD_BUILD_TESTING ${BUILD_TESTING}) | ||||||||||||
set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) | ||||||||||||
set(OLD_CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) | ||||||||||||
|
||||||||||||
# Set ENABLE_TESTS to OFF to disable the test-libmongoc target in the C driver. | ||||||||||||
# This prevents the LoadTests.cmake script from attempting to execute test-libmongoc. | ||||||||||||
# test-libmongoc is not built with the "all" target. | ||||||||||||
# Attempting to execute test-libmongoc results in an error: "Unable to find executable: NOT_FOUND" | ||||||||||||
set(ENABLE_TESTS OFF) | ||||||||||||
set(BUILD_TESTING OFF) | ||||||||||||
string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||||||||||||
string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") | ||||||||||||
FetchContent_MakeAvailable(mongo-c-driver) | ||||||||||||
set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) | ||||||||||||
set(CMAKE_C_FLAGS ${OLD_CMAKE_C_FLAGS}) | ||||||||||||
set(ENABLE_TESTS ${OLD_ENABLE_TESTS}) | ||||||||||||
set(BUILD_TESTING ${OLD_BUILD_TESTING}) | ||||||||||||
endif() | ||||||||||||
|
||||||||||||
message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... end") | ||||||||||||
function(fetch_mongoc) | ||||||||||||
message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... end") | ||||||||||||
|
||||||||||||
set(fetch_args "") | ||||||||||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0") | ||||||||||||
list(APPEND fetch_args "SYSTEM") | ||||||||||||
endif() | ||||||||||||
|
||||||||||||
# Declare mongo-c-driver as a dependency | ||||||||||||
FetchContent_Declare( | ||||||||||||
mongo-c-driver | ||||||||||||
GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git | ||||||||||||
GIT_TAG ${MONGOC_DOWNLOAD_VERSION} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This may fix failing tasks that seem to be using the auto-downloaded C driver. Example. |
||||||||||||
|
||||||||||||
${fetch_args} | ||||||||||||
) | ||||||||||||
|
||||||||||||
FetchContent_GetProperties(mongo-c-driver) | ||||||||||||
|
||||||||||||
if(NOT mongo-c-driver_POPULATED) | ||||||||||||
# Must ensure BUILD_VERSION is not inherited either as a normal variable or as a cache variable. | ||||||||||||
unset(OLD_BUILD_VERSION) | ||||||||||||
if(DEFINED BUILD_VERSION) | ||||||||||||
set(OLD_BUILD_VERSION ${BUILD_VERSION}) | ||||||||||||
unset(BUILD_VERSION) | ||||||||||||
endif() | ||||||||||||
unset(OLD_CACHE_BUILD_VERSION) | ||||||||||||
if(DEFINED CACHE{BUILD_VERSION}) | ||||||||||||
set(OLD_CACHE_BUILD_VERSION $CACHE{BUILD_VERSION}) | ||||||||||||
unset(BUILD_VERSION CACHE) | ||||||||||||
endif() | ||||||||||||
|
||||||||||||
# Disable unnecessary targets and potential conflicts with C++ Driver options. | ||||||||||||
set(ENABLE_TESTS OFF) | ||||||||||||
set(BUILD_TESTING OFF) | ||||||||||||
string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||||||||||||
string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") | ||||||||||||
|
||||||||||||
FetchContent_MakeAvailable(mongo-c-driver) | ||||||||||||
|
||||||||||||
# Restore prior value of BUILD_VERSION only when they were previously set. | ||||||||||||
if(DEFINED OLD_BUILD_VERSION) | ||||||||||||
set(BUILD_VERSION ${OLD_BUILD_VERSION}) | ||||||||||||
endif() | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
IIUC restoring the normal variable is not needed, since the |
||||||||||||
if(DEFINED OLD_CACHE_BUILD_VERSION) | ||||||||||||
set(BUILD_VERSION ${OLD_CACHE_BUILD_VERSION} CACHE STRING "Library version (for both bsoncxx and mongocxx)") | ||||||||||||
endif() | ||||||||||||
endif() | ||||||||||||
|
||||||||||||
message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... end") | ||||||||||||
endfunction() | ||||||||||||
|
||||||||||||
fetch_mongoc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.