Skip to content

Commit 51c4708

Browse files
authored
CXX-2749 Use FetchContent and find_package() to obtain mnmlstc/core (#1019)
* Print name of example project being tested on failure * Use FetchContent and find_package() to obtain mnmlstc/core * Update documentation to remove special handling of mnmlstc/core * Remove obsoleted special handling of mnmlstc/core * Bump minimum CMake version to 3.15
1 parent 60a3e7c commit 51c4708

25 files changed

+125
-131
lines changed

Diff for: .evergreen/build_example_projects.sh

+3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ for project in bsoncxx mongocxx; do
1515
cd $project
1616

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

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

2729
if [[ ! ( "$OSTYPE" =~ cygwin ) ]]; then
2830
if ! ( cd pkg-config/$DIR && ./build.sh >|output.txt 2>&1); then
31+
echo "Example $project/pkg-config/$DIR failed" 1>&2
2932
cat pkg-config/$DIR/output.txt 1>&2
3033
exit 1
3134
fi

Diff for: .ycm_extra_conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
'-x', 'c++',
4646
'-Isrc',
4747
'-Ibuild/src',
48-
'-Ibuild/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core/include',
4948
'-Isrc/third_party/catch/include',
5049
'-I/usr/local/include/libmongoc-1.0',
5150
'-I/usr/local/include/libbson-1.0',

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

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

2024
### Fixed
2125
- Explicitly document that throwing an exception from an APM callback is undefined behavior.
26+
- Do not prematurely install mnmlstc/core headers during the CMake build step.

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
15+
cmake_minimum_required(VERSION 3.15)
1616

1717
if(POLICY CMP0025)
1818
cmake_policy(SET CMP0025 NEW)

Diff for: cmake/BsoncxxUtil.cmake

+3-9
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,15 @@ function(bsoncxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
2929
endif()
3030

3131
if(BSONCXX_POLY_USE_MNMLSTC AND NOT BSONCXX_POLY_USE_SYSTEM_MNMLSTC)
32-
add_dependencies(${TARGET} EP_mnmlstc_core)
33-
ExternalProject_Get_Property(EP_mnmlstc_core source_dir)
3432
target_include_directories(
3533
${TARGET}
3634
PUBLIC
37-
$<BUILD_INTERFACE:${source_dir}/include>
38-
$<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/${BSONCXX_HEADER_INSTALL_DIR}>
35+
$<BUILD_INTERFACE:${CORE_INCLUDE_DIR}>
36+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc>
3937
)
4038
elseif(BSONCXX_POLY_USE_BOOST)
4139
find_package(Boost 1.56.0 REQUIRED)
42-
if(CMAKE_VERSION VERSION_LESS 3.15.0)
43-
target_include_directories(${TARGET} PUBLIC ${Boost_INCLUDE_DIRS})
44-
else()
45-
target_link_libraries(${TARGET} PUBLIC Boost::boost)
46-
endif()
40+
target_link_libraries(${TARGET} PUBLIC Boost::boost)
4741
endif()
4842

4943
target_link_libraries(${TARGET} PRIVATE ${libbson_target})

Diff for: cmake/make_dist/MakeDist.cmake

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ include (MakeDistFiles)
1717
function (MAKE_DIST PACKAGE_PREFIX MONGOCXX_SOURCE_DIR BUILD_SOURCE_DIR)
1818

1919
set (CMAKE_COMMAND_TMP "")
20-
if (${CMAKE_VERSION} VERSION_GREATER 3.1)
21-
set (CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env)
22-
endif ()
20+
set (CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env)
2321

2422
# -- Remove any existing packaging directory.
2523

Diff for: cmake/make_dist/MakeDistCheck.cmake

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ function (RUN_DIST_CHECK PACKAGE_PREFIX EXT)
1717
endif ()
1818

1919
set (MY_CMAKE_COMMAND "")
20-
if (${CMAKE_VERSION} VERSION_GREATER 3.1)
21-
set (MY_CMAKE_COMMAND ${CMAKE_COMMAND} -E env)
22-
endif ()
20+
set (MY_CMAKE_COMMAND ${CMAKE_COMMAND} -E env)
2321

2422
find_program (MAKE_COMMAND NAMES make gmake)
2523
if (${MAKE_COMMAND} STREQUAL "MAKE_COMMAND-NOTFOUND")

Diff for: cmake/make_dist/MakeDistFiles.cmake

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
if (${CMAKE_VERSION} VERSION_LESS 3.3)
3-
include (CMakeParseArguments)
4-
endif ()
5-
61
function (SET_LOCAL_DIST output)
72
set (dist_files "")
83
foreach (file ${ARGN})

Diff for: debian/patches/0002_skip_mnmlstc_extra_step.patch

-21
This file was deleted.

Diff for: debian/patches/series

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
0001_remove_embedded_js.patch
2-
0002_skip_mnmlstc_extra_step.patch

Diff for: debian/rules

-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,10 @@ ifneq (,$(filter pkg.mongo-cxx-driver.mnmlstc,$(DEB_BUILD_PROFILES)))
5050
mv $(CURDIR)/debian/tmp-mnmlstc/usr/include/bsoncxx/v_noabi/bsoncxx/third_party \
5151
$(CURDIR)/debian/tmp/usr/include/bsoncxx/v_noabi/bsoncxx/
5252
rm -rf $(CURDIR)/debian/tmp-mnmlstc
53-
# Fix MNMLSTC headers; handle the CMake external project step patched out
54-
# by debian/patches/0002_skip_mnmlstc_extra_step.patch
55-
( cd $(CURDIR)/debian/tmp/usr/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc; \
56-
find . -type f | xargs perl -pi -e "s|#include <core|#include <bsoncxx/third_party/mnmlstc/core|g" )
5753
endif
5854

5955
override_dh_auto_test:
6056
# do nothing
6157

6258
override_dh_missing:
6359
dh_missing --fail-missing
64-

Diff for: docs/content/mongocxx-v3/installation/linux.md

+1-12
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,7 @@ cmake .. \
8585

8686
### Step 4: Build and install the driver
8787

88-
If you are using the default MNMLSTC polyfill and are installing to a
89-
directory requiring root permissions, you should install the polyfill with
90-
`sudo` before building the rest of mongocxx so you don't have to run
91-
the entire build with `sudo`:
92-
93-
```sh
94-
# Only for MNMLSTC polyfill
95-
sudo cmake --build . --target EP_mnmlstc_core
96-
```
97-
98-
Once MNMLSTC is installed, or if you are using a different polyfill,
99-
build and install the driver:
88+
Build and install the driver:
10089

10190
```sh
10291
cmake --build .

Diff for: docs/content/mongocxx-v3/installation/macos.md

+1-12
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,7 @@ cmake .. \
8585

8686
### Step 4: Build and install the driver
8787

88-
If you are using the default MNMLSTC polyfill and are installing to a
89-
directory requiring root permissions, you should install the polyfill with
90-
`sudo` before building the rest of mongocxx so you don't have to run
91-
the entire build with `sudo`:
92-
93-
```sh
94-
# Only for MNMLSTC polyfill
95-
sudo cmake --build . --target EP_mnmlstc_core
96-
```
97-
98-
Once MNMLSTC is installed, or if you are using a different polyfill,
99-
build and install the driver:
88+
Build and install the driver:
10089

10190
```sh
10291
cmake --build .

Diff for: examples/add_subdirectory/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ add_executable(hello_mongocxx hello_mongocxx.cpp)
4040
# Visual Studio pre 2017 requires boost polyfill.
4141
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_STANDARD LESS 17)
4242
find_package(Boost 1.56.0 REQUIRED)
43-
if (CMAKE_VERSION VERSION_LESS 3.15.0)
44-
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
45-
else()
46-
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
47-
endif()
43+
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
4844
endif()
4945

5046
target_link_libraries(hello_mongocxx

Diff for: examples/projects/bsoncxx/cmake/shared/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)
4444
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4545
if (CMAKE_CXX_STANDARD LESS 17)
4646
find_package(Boost 1.56.0 REQUIRED)
47-
if (CMAKE_VERSION VERSION_LESS 3.15.0)
48-
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})
49-
else()
50-
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
51-
endif()
47+
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
5248
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
5349
endif ()
5450
endif()

Diff for: examples/projects/bsoncxx/cmake/static/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)
4444
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4545
if (CMAKE_CXX_STANDARD LESS 17)
4646
find_package(Boost 1.56.0 REQUIRED)
47-
if (CMAKE_VERSION VERSION_LESS 3.15.0)
48-
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})
49-
else()
50-
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
51-
endif()
47+
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
5248
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
5349
endif ()
5450
endif()

Diff for: examples/projects/mongocxx/cmake/shared/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)
4444
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4545
if (CMAKE_CXX_STANDARD LESS 17)
4646
find_package(Boost 1.56.0 REQUIRED)
47-
if (CMAKE_VERSION VERSION_LESS 3.15.0)
48-
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
49-
else()
50-
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
51-
endif()
47+
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
5248
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
5349
endif ()
5450
endif()

Diff for: examples/projects/mongocxx/cmake/static/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)
5050
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5151
if (CMAKE_CXX_STANDARD LESS 17)
5252
find_package(Boost 1.56.0 REQUIRED)
53-
if (CMAKE_VERSION VERSION_LESS 3.15.0)
54-
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
55-
else()
56-
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
57-
endif()
53+
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
5854
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
5955
endif ()
6056
endif()

Diff for: generate_uninstall/CMakeLists.txt

-16
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ if (WIN32)
1919
"${CMAKE_INSTALL_PREFIX}"
2020
)
2121
install (CODE "
22-
if (EXISTS \${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt)
23-
file (
24-
STRINGS
25-
\${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt
26-
ADDL_MANIFEST_FILES
27-
)
28-
list (APPEND CMAKE_INSTALL_MANIFEST_FILES \${ADDL_MANIFEST_FILES})
29-
endif ()
3022
string(REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
3123
\"\${CMAKE_INSTALL_MANIFEST_FILES}\")
3224
string(REPLACE \"/\" \"\\\\\" MONGOCXX_INSTALL_MANIFEST_CONTENT_WIN32
@@ -59,14 +51,6 @@ if (WIN32)
5951
)
6052
else ()
6153
install (CODE "
62-
if (EXISTS \${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt)
63-
file (
64-
STRINGS
65-
\${CMAKE_BINARY_DIR}/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-build/install_manifest.txt
66-
ADDL_MANIFEST_FILES
67-
)
68-
list (APPEND CMAKE_INSTALL_MANIFEST_FILES \${ADDL_MANIFEST_FILES})
69-
endif ()
7054
string(REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
7155
\"\${CMAKE_INSTALL_MANIFEST_FILES}\")
7256
file(WRITE \"mongocxx_install_manifest.txt\"

Diff for: src/bsoncxx/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ message ("bsoncxx version: ${BSONCXX_VERSION}")
7373
set(BSONCXX_INLINE_NAMESPACE "v${BSONCXX_ABI_VERSION}")
7474
set(BSONCXX_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/${BSONCXX_INLINE_NAMESPACE}" CACHE INTERNAL "")
7575

76+
if (BSONCXX_POLY_USE_MNMLSTC AND NOT BSONCXX_POLY_USE_SYSTEM_MNMLSTC)
77+
# For deprecated CMake package config files.
78+
set(BSONCXX_POLY_MNMLSTC_DEPRECATED_INCLUDE_DIRS
79+
[[list(PREPEND LIBBSONCXX_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc")]]
80+
)
81+
set(BSONCXX_POLY_MNMLSTC_DEPRECATED_STATIC_INCLUDE_DIRS
82+
[[list(PREPEND LIBBSONCXX_STATIC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc")]]
83+
)
84+
85+
# For pkg-config files. Trailing space to separate cflags.
86+
set(BSONCXX_POLY_MNMLSTC_PKGCONFIG_INCLUDE_DIRS
87+
[[-I${includedir}/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc ]]
88+
)
89+
set(BSONCXX_POLY_MNMLSTC_PKGCONFIG_STATIC_INCLUDE_DIRS
90+
[[-I${includedir}/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc ]]
91+
)
92+
endif ()
93+
7694
set(LIBBSON_REQUIRED_VERSION 1.24.0)
7795
set(LIBBSON_REQUIRED_ABI_VERSION 1.0)
7896

Diff for: src/bsoncxx/cmake/libbsoncxx-config.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(LIBBSONCXX_PACKAGE_VERSION @BSONCXX_VERSION@)
2222
@PACKAGE_INIT@
2323

2424
set_and_check(LIBBSONCXX_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@PACKAGE_INCLUDE_INSTALL_DIRS@")
25+
@BSONCXX_POLY_MNMLSTC_DEPRECATED_INCLUDE_DIRS@
2526

2627
# We want to provide an absolute path to the library and we know the
2728
# directory and the base name, but not the suffix, so we use CMake's

Diff for: src/bsoncxx/cmake/libbsoncxx-static-config.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ find_package(libbson-static-@LIBBSON_REQUIRED_ABI_VERSION@ @LIBBSON_REQUIRED_VER
2828
@PACKAGE_INIT@
2929

3030
set_and_check(LIBBSONCXX_STATIC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@PACKAGE_INCLUDE_INSTALL_DIRS@")
31+
@BSONCXX_POLY_MNMLSTC_DEPRECATED_STATIC_INCLUDE_DIRS@
3132

3233
# We want to provide an absolute path to the library and we know the directory and the base name,
3334
# but not the suffix, so we use CMake's find_library() to pick that up.

Diff for: src/bsoncxx/config/libbsoncxx-static.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ Description: The MongoDB C++11 BSON Library
2121
URL: http://github.com/mongodb/mongo-cxx-driver
2222
Version: @BSONCXX_VERSION@
2323
Requires: libbson-static-@LIBBSON_REQUIRED_ABI_VERSION@ >= @LIBBSON_REQUIRED_VERSION@
24-
Cflags: -I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@ -DBSONCXX_STATIC
24+
Cflags: @BSONCXX_POLY_MNMLSTC_PKGCONFIG_STATIC_INCLUDE_DIRS@-I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@ -DBSONCXX_STATIC
2525
Libs: -L${libdir} -lbsoncxx-static

Diff for: src/bsoncxx/config/libbsoncxx.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Name: libbsoncxx
2020
Description: The MongoDB C++11 BSON Library
2121
URL: http://github.com/mongodb/mongo-cxx-driver
2222
Version: @BSONCXX_VERSION@
23-
Cflags: -I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@
23+
Cflags: @BSONCXX_POLY_MNMLSTC_PKGCONFIG_INCLUDE_DIRS@-I${includedir}/bsoncxx/@BSONCXX_INLINE_NAMESPACE@
2424
Libs: -L${libdir} -lbsoncxx

0 commit comments

Comments
 (0)