Skip to content

CXX-2745 Add advanced CMake options to toggle root namespace redeclarations #1324

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

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/BsoncxxUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ function(bsoncxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
DEFINE_SYMBOL BSONCXX_EXPORT
)

if(BSONCXX_API_OVERRIDE_DEFAULT_ABI)
target_compile_definitions(${TARGET} PUBLIC BSONCXX_API_OVERRIDE_DEFAULT_ABI)
endif()

if(ENABLE_ABI_TAG_IN_LIBRARY_FILENAMES)
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}${abi_tag})
else()
Expand Down
4 changes: 4 additions & 0 deletions cmake/MongocxxUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ function(mongocxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
DEFINE_SYMBOL MONGOCXX_EXPORTS
)

if(MONGOCXX_API_OVERRIDE_DEFAULT_ABI)
target_compile_definitions(${TARGET} PUBLIC MONGOCXX_API_OVERRIDE_DEFAULT_ABI)
endif()

if(ENABLE_ABI_TAG_IN_LIBRARY_FILENAMES)
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}${abi_tag})
else()
Expand Down
6 changes: 6 additions & 0 deletions src/bsoncxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ message(STATUS "bsoncxx version: ${BSONCXX_VERSION}")
option(BSONCXX_POLY_USE_IMPLS "Use bsoncxx implementations for stdx polyfills" OFF)
option(BSONCXX_POLY_USE_STD "Use C++17 std library for stdx polyfills" OFF)

option(BSONCXX_API_OVERRIDE_DEFAULT_ABI "The default ABI namespace to use for root namespace redeclarations" OFF)
mark_as_advanced(BSONCXX_API_OVERRIDE_DEFAULT_ABI)
if(BSONCXX_API_OVERRIDE_DEFAULT_ABI)
message(WARNING "BSONCXX_API_OVERRIDE_DEFAULT_ABI is an experimental feature")
endif()

set(BSONCXX_OUTPUT_BASENAME "bsoncxx" CACHE STRING "Output bsoncxx library base name")

# Count how many polyfill options are true-ish
Expand Down
13 changes: 13 additions & 0 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/stdx/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ using v1::stdx::optional;
namespace bsoncxx {
namespace stdx {

#if defined(BSONCXX_API_OVERRIDE_DEFAULT_ABI)

using v1::stdx::in_place;
using v1::stdx::in_place_t;
using v1::stdx::make_optional;
using v1::stdx::nullopt;
using v1::stdx::nullopt_t;
using v1::stdx::optional;

#else

using v_noabi::stdx::in_place;
using v_noabi::stdx::in_place_t;
using v_noabi::stdx::make_optional;
using v_noabi::stdx::nullopt;
using v_noabi::stdx::nullopt_t;
using v_noabi::stdx::optional;

#endif // defined(BSONCXX_API_OVERRIDE_DEFAULT_ABI)

} // namespace stdx
} // namespace bsoncxx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ using v1::stdx::string_view;
namespace bsoncxx {
namespace stdx {

#if defined(BSONCXX_API_OVERRIDE_DEFAULT_ABI)

using v1::stdx::basic_string_view;
using v1::stdx::string_view;

#else

using v_noabi::stdx::basic_string_view;
using v_noabi::stdx::string_view;

#endif // defined(BSONCXX_API_OVERRIDE_DEFAULT_ABI)

} // namespace stdx
} // namespace bsoncxx

Expand Down
6 changes: 6 additions & 0 deletions src/mongocxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ message(STATUS "mongocxx version: ${MONGOCXX_VERSION}")
option(MONGOCXX_ENABLE_SSL "Enable SSL - if the underlying C driver offers it" ON)
option(MONGOCXX_ENABLE_SLOW_TESTS "Run slow tests when invoking the the test target" OFF)

option(MONGOCXX_API_OVERRIDE_DEFAULT_ABI "The default ABI namespace to use for root namespace redeclarations" OFF)
mark_as_advanced(MONGOCXX_API_OVERRIDE_DEFAULT_ABI)
if(MONGOCXX_API_OVERRIDE_DEFAULT_ABI)
message(WARNING "MONGOCXX_API_OVERRIDE_DEFAULT_ABI is an experimental feature")
endif ()

set(MONGOCXX_OUTPUT_BASENAME "mongocxx" CACHE STRING "Output mongocxx library base name")

set(MONGOCXX_PKG_DEP "") # Required by mongocxx-config.cmake.in.
Expand Down