Skip to content

CXX-2749 Use FetchContent and find_package() to obtain mnmlstc/core #1019

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 12 commits into from
Sep 14, 2023
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
3 changes: 3 additions & 0 deletions .evergreen/build_example_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ for project in bsoncxx mongocxx; do
cd $project

if ! ( cd cmake/$DIR && ./build.sh >|output.txt 2>&1); then
echo "Example $project/cmake/$DIR failed" 1>&2
cat cmake/$DIR/output.txt 1>&2
exit 1
fi

if ! ( cd cmake-deprecated/$DIR && ./build.sh >|output.txt 2>&1); then
echo "Example $project/cmake-deprecated/$DIR failed" 1>&2
cat cmake-deprecated/$DIR/output.txt 1>&2
exit 1
fi

if [[ ! ( "$OSTYPE" =~ cygwin ) ]]; then
if ! ( cd pkg-config/$DIR && ./build.sh >|output.txt 2>&1); then
echo "Example $project/pkg-config/$DIR failed" 1>&2
cat pkg-config/$DIR/output.txt 1>&2
exit 1
fi
Expand Down
1 change: 0 additions & 1 deletion .ycm_extra_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
'-x', 'c++',
'-Isrc',
'-Ibuild/src',
'-Ibuild/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core/include',
'-Isrc/third_party/catch/include',
'-I/usr/local/include/libmongoc-1.0',
'-I/usr/local/include/libbson-1.0',
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Do not build tests as part of `all` target. Configure with `BUILD_TESTING=ON` to build tests.
- Bump minimum required CMake version to 3.15 to support the FetchContent module and for consistency with the C Driver.
- Improve handling of downloaded (non-system) mnmlstc/core as the polyfill library.
- Use `FetchContent` instead of `ExternalProject` to download and build the library.
- Do not patch include directives in mnmlstc/core headers.

### Fixed
- Explicitly document that throwing an exception from an APM callback is undefined behavior.
- Do not prematurely install mnmlstc/core headers during the CMake build step.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15)

if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
Expand Down Expand Up @@ -458,4 +458,3 @@ endif ()
if (CMAKE_GENERATOR_TOOLSET)
message (STATUS "\tinstance: ${CMAKE_GENERATOR_TOOLSET}")
endif ()

12 changes: 3 additions & 9 deletions cmake/BsoncxxUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ function(bsoncxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
endif()

if(BSONCXX_POLY_USE_MNMLSTC AND NOT BSONCXX_POLY_USE_SYSTEM_MNMLSTC)
add_dependencies(${TARGET} EP_mnmlstc_core)
ExternalProject_Get_Property(EP_mnmlstc_core source_dir)
target_include_directories(
${TARGET}
PUBLIC
$<BUILD_INTERFACE:${source_dir}/include>
$<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/${BSONCXX_HEADER_INSTALL_DIR}>
$<BUILD_INTERFACE:${CORE_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc>
)
elseif(BSONCXX_POLY_USE_BOOST)
find_package(Boost 1.56.0 REQUIRED)
if(CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(${TARGET} PUBLIC ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(${TARGET} PUBLIC Boost::boost)
endif()
target_link_libraries(${TARGET} PUBLIC Boost::boost)
endif()

target_link_libraries(${TARGET} PRIVATE ${libbson_target})
Expand Down
4 changes: 1 addition & 3 deletions cmake/make_dist/MakeDist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ include (MakeDistFiles)
function (MAKE_DIST PACKAGE_PREFIX MONGOCXX_SOURCE_DIR BUILD_SOURCE_DIR)

set (CMAKE_COMMAND_TMP "")
if (${CMAKE_VERSION} VERSION_GREATER 3.1)
set (CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env)
endif ()
set (CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env)

# -- Remove any existing packaging directory.

Expand Down
4 changes: 1 addition & 3 deletions cmake/make_dist/MakeDistCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ function (RUN_DIST_CHECK PACKAGE_PREFIX EXT)
endif ()

set (MY_CMAKE_COMMAND "")
if (${CMAKE_VERSION} VERSION_GREATER 3.1)
set (MY_CMAKE_COMMAND ${CMAKE_COMMAND} -E env)
endif ()
set (MY_CMAKE_COMMAND ${CMAKE_COMMAND} -E env)

find_program (MAKE_COMMAND NAMES make gmake)
if (${MAKE_COMMAND} STREQUAL "MAKE_COMMAND-NOTFOUND")
Expand Down
5 changes: 0 additions & 5 deletions cmake/make_dist/MakeDistFiles.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

if (${CMAKE_VERSION} VERSION_LESS 3.3)
include (CMakeParseArguments)
endif ()

function (SET_LOCAL_DIST output)
set (dist_files "")
foreach (file ${ARGN})
Expand Down
21 changes: 0 additions & 21 deletions debian/patches/0002_skip_mnmlstc_extra_step.patch

This file was deleted.

1 change: 0 additions & 1 deletion debian/patches/series
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
0001_remove_embedded_js.patch
0002_skip_mnmlstc_extra_step.patch
5 changes: 0 additions & 5 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,10 @@ ifneq (,$(filter pkg.mongo-cxx-driver.mnmlstc,$(DEB_BUILD_PROFILES)))
mv $(CURDIR)/debian/tmp-mnmlstc/usr/include/bsoncxx/v_noabi/bsoncxx/third_party \
$(CURDIR)/debian/tmp/usr/include/bsoncxx/v_noabi/bsoncxx/
rm -rf $(CURDIR)/debian/tmp-mnmlstc
# Fix MNMLSTC headers; handle the CMake external project step patched out
# by debian/patches/0002_skip_mnmlstc_extra_step.patch
( cd $(CURDIR)/debian/tmp/usr/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc; \
find . -type f | xargs perl -pi -e "s|#include <core|#include <bsoncxx/third_party/mnmlstc/core|g" )
endif

override_dh_auto_test:
# do nothing

override_dh_missing:
dh_missing --fail-missing

13 changes: 1 addition & 12 deletions docs/content/mongocxx-v3/installation/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,7 @@ cmake .. \

### Step 4: Build and install the driver

If you are using the default MNMLSTC polyfill and are installing to a
directory requiring root permissions, you should install the polyfill with
`sudo` before building the rest of mongocxx so you don't have to run
the entire build with `sudo`:

```sh
# Only for MNMLSTC polyfill
sudo cmake --build . --target EP_mnmlstc_core
```

Once MNMLSTC is installed, or if you are using a different polyfill,
build and install the driver:
Build and install the driver:

```sh
cmake --build .
Expand Down
13 changes: 1 addition & 12 deletions docs/content/mongocxx-v3/installation/macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,7 @@ cmake .. \

### Step 4: Build and install the driver

If you are using the default MNMLSTC polyfill and are installing to a
directory requiring root permissions, you should install the polyfill with
`sudo` before building the rest of mongocxx so you don't have to run
the entire build with `sudo`:

```sh
# Only for MNMLSTC polyfill
sudo cmake --build . --target EP_mnmlstc_core
```

Once MNMLSTC is installed, or if you are using a different polyfill,
build and install the driver:
Build and install the driver:

```sh
cmake --build .
Expand Down
6 changes: 1 addition & 5 deletions examples/add_subdirectory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ add_executable(hello_mongocxx hello_mongocxx.cpp)
# Visual Studio pre 2017 requires boost polyfill.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
endif()
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
endif()

target_link_libraries(hello_mongocxx
Expand Down
6 changes: 1 addition & 5 deletions examples/projects/bsoncxx/cmake/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
endif()
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
endif ()
endif()
Expand Down
6 changes: 1 addition & 5 deletions examples/projects/bsoncxx/cmake/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
endif()
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
endif ()
endif()
Expand Down
6 changes: 1 addition & 5 deletions examples/projects/mongocxx/cmake/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
endif()
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
endif ()
endif()
Expand Down
6 changes: 1 addition & 5 deletions examples/projects/mongocxx/cmake/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
endif()
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
endif ()
endif()
Expand Down
16 changes: 0 additions & 16 deletions generate_uninstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ if (WIN32)
"${CMAKE_INSTALL_PREFIX}"
)
install (CODE "
if (EXISTS \${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt)
file (
STRINGS
\${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt
ADDL_MANIFEST_FILES
)
list (APPEND CMAKE_INSTALL_MANIFEST_FILES \${ADDL_MANIFEST_FILES})
endif ()
string(REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
\"\${CMAKE_INSTALL_MANIFEST_FILES}\")
string(REPLACE \"/\" \"\\\\\" MONGOCXX_INSTALL_MANIFEST_CONTENT_WIN32
Expand Down Expand Up @@ -59,14 +51,6 @@ if (WIN32)
)
else ()
install (CODE "
if (EXISTS \${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt)
file (
STRINGS
\${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt
ADDL_MANIFEST_FILES
)
list (APPEND CMAKE_INSTALL_MANIFEST_FILES \${ADDL_MANIFEST_FILES})
endif ()
string(REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
\"\${CMAKE_INSTALL_MANIFEST_FILES}\")
file(WRITE \"mongocxx_install_manifest.txt\"
Expand Down
18 changes: 18 additions & 0 deletions src/bsoncxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ message ("bsoncxx version: ${BSONCXX_VERSION}")
set(BSONCXX_INLINE_NAMESPACE "v${BSONCXX_ABI_VERSION}")
set(BSONCXX_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/${BSONCXX_INLINE_NAMESPACE}" CACHE INTERNAL "")

if (BSONCXX_POLY_USE_MNMLSTC AND NOT BSONCXX_POLY_USE_SYSTEM_MNMLSTC)
# For deprecated CMake package config files.
set(BSONCXX_POLY_MNMLSTC_DEPRECATED_INCLUDE_DIRS
[[list(PREPEND LIBBSONCXX_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc")]]
)
set(BSONCXX_POLY_MNMLSTC_DEPRECATED_STATIC_INCLUDE_DIRS
[[list(PREPEND LIBBSONCXX_STATIC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc")]]
)

# For pkg-config files. Trailing space to separate cflags.
set(BSONCXX_POLY_MNMLSTC_PKGCONFIG_INCLUDE_DIRS
[[-I${includedir}/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc ]]
)
set(BSONCXX_POLY_MNMLSTC_PKGCONFIG_STATIC_INCLUDE_DIRS
[[-I${includedir}/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc ]]
)
endif ()

set(LIBBSON_REQUIRED_VERSION 1.24.0)
set(LIBBSON_REQUIRED_ABI_VERSION 1.0)

Expand Down
1 change: 1 addition & 0 deletions src/bsoncxx/cmake/libbsoncxx-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(LIBBSONCXX_PACKAGE_VERSION @BSONCXX_VERSION@)
@PACKAGE_INIT@

set_and_check(LIBBSONCXX_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@PACKAGE_INCLUDE_INSTALL_DIRS@")
@BSONCXX_POLY_MNMLSTC_DEPRECATED_INCLUDE_DIRS@

# We want to provide an absolute path to the library and we know the
# directory and the base name, but not the suffix, so we use CMake's
Expand Down
1 change: 1 addition & 0 deletions src/bsoncxx/cmake/libbsoncxx-static-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ find_package(libbson-static-@LIBBSON_REQUIRED_ABI_VERSION@ @LIBBSON_REQUIRED_VER
@PACKAGE_INIT@

set_and_check(LIBBSONCXX_STATIC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@PACKAGE_INCLUDE_INSTALL_DIRS@")
@BSONCXX_POLY_MNMLSTC_DEPRECATED_STATIC_INCLUDE_DIRS@

# We want to provide an absolute path to the library and we know the directory and the base name,
# but not the suffix, so we use CMake's find_library() to pick that up.
Expand Down
2 changes: 1 addition & 1 deletion src/bsoncxx/config/libbsoncxx-static.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Description: The MongoDB C++11 BSON Library
URL: http://github.com/mongodb/mongo-cxx-driver
Version: @BSONCXX_VERSION@
Requires: libbson-static-@LIBBSON_REQUIRED_ABI_VERSION@ >= @LIBBSON_REQUIRED_VERSION@
Cflags: -I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@ -DBSONCXX_STATIC
Cflags: @BSONCXX_POLY_MNMLSTC_PKGCONFIG_STATIC_INCLUDE_DIRS@-I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@ -DBSONCXX_STATIC
Libs: -L${libdir} -lbsoncxx-static
2 changes: 1 addition & 1 deletion src/bsoncxx/config/libbsoncxx.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Name: libbsoncxx
Description: The MongoDB C++11 BSON Library
URL: http://github.com/mongodb/mongo-cxx-driver
Version: @BSONCXX_VERSION@
Cflags: -I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@
Cflags: @BSONCXX_POLY_MNMLSTC_PKGCONFIG_INCLUDE_DIRS@-I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@
Libs: -L${libdir} -lbsoncxx
Loading