Skip to content

Commit ce1226c

Browse files
CXX-2577 compile and test with c++20 (#968)
* use latest CMake * use correct output file path in case of failed example build * Fix CMake variable typo * CXX-2577 compile and test with c++20 * syntax update for c++20 conformance * CXX-2577 compile and test with c++20 (RHEL9 variants) * don't generate verbose makefiles Co-authored-by: Ezra Chung <[email protected]> * include_expansions_in_env to make the distro_id expansion available * more cleanly specify C++ standard for example build * comment to explain the usage of SKIP_LEGACY_SHELL * ignore maybe-uninitialized warning around a smaller section of code * use bash test syntax Co-authored-by: Ezra Chung <[email protected]> * remove unnecessary use of "$@" * handling of Boost dependency with newer CMake * expand tabs to spaces --------- Co-authored-by: Ezra Chung <[email protected]>
1 parent ed5a02f commit ce1226c

File tree

21 files changed

+160
-47
lines changed

21 files changed

+160
-47
lines changed

.evergreen/build_example_projects.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,25 @@ else
88
DIR=shared
99
fi
1010

11-
. .evergreen/find_cmake.sh
12-
export CMAKE="$CMAKE"
13-
1411
cd examples/projects
1512

1613
for project in bsoncxx mongocxx; do
1714
(
1815
cd $project
1916

2017
if ! ( cd cmake/$DIR && ./build.sh >|output.txt 2>&1); then
21-
cat output.txt 1>&2
18+
cat cmake/$DIR/output.txt 1>&2
2219
exit 1
2320
fi
2421

2522
if ! ( cd cmake-deprecated/$DIR && ./build.sh >|output.txt 2>&1); then
26-
cat output.txt 1>&2
23+
cat cmake-deprecated/$DIR/output.txt 1>&2
2724
exit 1
2825
fi
2926

30-
if [ "Windows_NT" != "$OS" ]; then
27+
if [[ ! ( "$OSTYPE" =~ cygwin ) ]]; then
3128
if ! ( cd pkg-config/$DIR && ./build.sh >|output.txt 2>&1); then
32-
cat output.txt 1>&2
29+
cat pkg-config/$DIR/output.txt 1>&2
3330
exit 1
3431
fi
3532
fi

.evergreen/compile.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ case "$OS" in
4949
;;
5050
esac
5151

52-
. .evergreen/find_cmake.sh
53-
5452
cd build
55-
"$CMAKE" -G "$GENERATOR" "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" -DMONGOCXX_ENABLE_SLOW_TESTS=ON -DENABLE_UNINSTALL=ON "$@" ..
56-
"$CMAKE" --build . --config $BUILD_TYPE -- $CMAKE_BUILD_OPTS
57-
"$CMAKE" --build . --config $BUILD_TYPE --target install -- $CMAKE_BUILD_OPTS
58-
"$CMAKE" --build . --config $BUILD_TYPE --target $CMAKE_EXAMPLES_TARGET -- $CMAKE_BUILD_OPTS
53+
"${cmake_binary}" -G "$GENERATOR" "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" -DMONGOCXX_ENABLE_SLOW_TESTS=ON -DENABLE_UNINSTALL=ON "$@" ..
54+
"${cmake_binary}" --build . --config $BUILD_TYPE -- $CMAKE_BUILD_OPTS
55+
"${cmake_binary}" --build . --config $BUILD_TYPE --target install -- $CMAKE_BUILD_OPTS
56+
"${cmake_binary}" --build . --config $BUILD_TYPE --target $CMAKE_EXAMPLES_TARGET -- $CMAKE_BUILD_OPTS
5957

6058
if [ "$_RUN_DISTCHECK" ]; then
61-
DISTCHECK_BUILD_OPTS="-j$CONCURRENCY" "$CMAKE" --build . --config $BUILD_TYPE --target distcheck
59+
DISTCHECK_BUILD_OPTS="-j$CONCURRENCY" "${cmake_binary}" --build . --config $BUILD_TYPE --target distcheck
6260
fi

.mci.yml

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ functions:
175175
git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git
176176
fi
177177
cd drivers-evergreen-tools
178+
# The legacy shell is only present in server 5.0 builds and earlier,
179+
# but there is no 5.0 build for RHEL9, so we have to avoid it
180+
if [[ "${build_variant}" =~ "rhel9" ]]; then
181+
export SKIP_LEGACY_SHELL=1
182+
fi
178183
export DRIVERS_TOOLS=$(pwd)
179184
if [ "Windows_NT" == "$OS" ]; then
180185
export DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
@@ -351,6 +356,7 @@ functions:
351356
params:
352357
shell: bash
353358
working_dir: "mongo-cxx-driver"
359+
include_expansions_in_env: ["distro_id"]
354360
script: |
355361
set -o errexit
356362
set -o pipefail
@@ -367,13 +373,20 @@ functions:
367373
ADDL_OPTS="$ADDL_OPTS -DENABLE_TESTS=OFF"
368374
fi
369375
376+
if [[ -n "${REQUIRED_CXX_STANDARD}" ]]; then
377+
ADDL_OPTS="$ADDL_OPTS -DCMAKE_CXX_STANDARD=${REQUIRED_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON"
378+
fi
379+
370380
MONGOC_PREFIX="$(pwd)/../mongoc"
371381
echo "MONGOC_PREFIX=$MONGOC_PREFIX"
372382
373-
if [ "Windows_NT" == "$OS" ]; then
383+
if [[ "$OSTYPE" =~ cygwin ]]; then
374384
MONGOC_PREFIX=$(cygpath -m "$MONGOC_PREFIX")
375385
fi
376-
export CMAKE=${cmake}
386+
. "$MONGOC_PREFIX/.evergreen/scripts/find-cmake-latest.sh"
387+
declare cmake_binary
388+
export cmake_binary="$(find_cmake_latest)"
389+
command -v "$cmake_binary"
377390
378391
if [ ! -d ../drivers-evergreen-tools ]; then
379392
git clone --depth 1 [email protected]:mongodb-labs/drivers-evergreen-tools.git ../drivers-evergreen-tools
@@ -398,14 +411,15 @@ functions:
398411
params:
399412
shell: bash
400413
working_dir: "mongo-cxx-driver"
414+
include_expansions_in_env: ["distro_id"]
401415
script: |
402416
set -o errexit
403417
set -o pipefail
404418
405419
# Grabs the mongocryptd path
406420
pushd ..
407421
export MONGOCRYPTD_PATH=$(pwd)/
408-
if [ "Windows_NT" == "$OS" ]; then
422+
if [[ "$OSTYPE" =~ cygwin ]]; then
409423
export MONGOCRYPTD_PATH=$(cygpath -m $MONGOCRYPTD_PATH)
410424
fi
411425
popd # ..
@@ -453,7 +467,7 @@ functions:
453467
454468
pushd ../../drivers-evergreen-tools
455469
export DRIVERS_TOOLS=$(pwd)
456-
if [ "Windows_NT" == "$OS" ]; then
470+
if [[ "$OSTYPE" =~ cygwin ]]; then
457471
export DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
458472
fi
459473
popd # ../../drivers-evergreen-tools
@@ -514,7 +528,7 @@ functions:
514528
register_ca_cert() {
515529
local OS=$(uname -s | tr '[:upper:]' '[:lower:]')
516530
echo "register_ca_cert: OS: $OS"
517-
case "$OS" in
531+
case "$OSTYPE" in
518532
cygwin*)
519533
certutil.exe -addstore "Root" "$DRIVERS_TOOLS\.evergreen\x509gen\ca.pem"
520534
;;
@@ -559,7 +573,7 @@ functions:
559573
echo "Waiting for mock KMS servers to start... done."
560574
fi
561575
562-
if [ "Windows_NT" == "$OS" ]; then
576+
if [[ "$OSTYPE" =~ cygwin ]]; then
563577
CTEST_OUTPUT_ON_FAILURE=1 MSBuild.exe /p:Configuration=${build_type} /verbosity:minimal RUN_TESTS.vcxproj
564578
# Only run examples if MONGODB_API_VERSION is unset. We do not append
565579
# API version to example clients, so examples will fail when requireApiVersion
@@ -660,8 +674,7 @@ functions:
660674
export CC="${example_projects_cc}"
661675
export CXX="${example_projects_cxx}"
662676
export CXX_STANDARD="${example_projects_cxx_standard}"
663-
export CMAKE=${cmake}
664-
if [ "Windows_NT" == "$OS" ]; then
677+
if [[ "$OSTYPE" =~ cygwin ]]; then
665678
export MSVC=1
666679
elif [ "$(uname -s | tr '[:upper:]' '[:lower:]')" == "darwin" ]; then
667680
export DYLD_LIBRARY_PATH="$(pwd)/build/install/lib:$DYLD_LIBRARY_PATH"
@@ -680,6 +693,10 @@ functions:
680693
# is true.
681694
if [[ -z "$MONGODB_API_VERSION" ]]; then
682695
echo "Building example projects..."
696+
. "$PREFIX/.evergreen/scripts/find-cmake-latest.sh"
697+
declare cmake_binary
698+
export cmake_binary="$(find_cmake_latest)"
699+
command -v "$cmake_binary"
683700
.evergreen/build_example_projects.sh
684701
echo "Building example projects... done."
685702
fi
@@ -839,6 +856,39 @@ tasks:
839856
- func: "run_kms_servers"
840857
- func: "test"
841858

859+
- name: compile_and_test_with_shared_libs_cxx20
860+
commands:
861+
- func: "setup"
862+
- func: "start_mongod"
863+
- func: "install_c_driver"
864+
- func: "compile"
865+
vars:
866+
RUN_DISTCHECK: 1
867+
REQUIRED_CXX_STANDARD: 20
868+
- func: "clone_drivers-evergreen-tools"
869+
- func: "run_kms_servers"
870+
- func: "test"
871+
vars:
872+
REQUIRED_CXX_STANDARD: 20
873+
example_projects_cxx_standard: 20
874+
875+
- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
876+
commands:
877+
- func: "setup"
878+
- func: "start_mongod"
879+
- func: "install_c_driver"
880+
vars:
881+
BSON_EXTRA_ALIGNMENT: 1
882+
- func: "compile"
883+
vars:
884+
REQUIRED_CXX_STANDARD: 20
885+
- func: "clone_drivers-evergreen-tools"
886+
- func: "run_kms_servers"
887+
- func: "test"
888+
vars:
889+
REQUIRED_CXX_STANDARD: 20
890+
example_projects_cxx_standard: 20
891+
842892
- name: compile_with_shared_libs
843893
commands:
844894
- func: "setup"
@@ -1171,6 +1221,52 @@ buildvariants:
11711221
#######################################
11721222
# Linux Buildvariants #
11731223
#######################################
1224+
- name: rhel9-release-latest
1225+
display_name: "RHEL 9 Release (MongoDB Latest)"
1226+
expansions:
1227+
build_type: "Release"
1228+
tar_options: *linux_tar_options
1229+
extra_path: *linux_extra_path
1230+
cmake_flags: *linux_cmake_flags
1231+
mongodb_version: *version_latest
1232+
lib_dir: "lib64"
1233+
run_on:
1234+
- rhel90-large
1235+
tasks:
1236+
- name: compile_and_test_with_shared_libs
1237+
- name: compile_and_test_with_shared_libs_extra_alignment
1238+
- name: compile_and_test_with_shared_libs_cxx20
1239+
- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
1240+
- name: compile_and_test_with_static_libs
1241+
- name: compile_and_test_with_static_libs_extra_alignment
1242+
- name: compile_and_test_with_shared_libs_replica_set
1243+
- name: build_example_with_add_subdirectory
1244+
distros:
1245+
- rhel90-large
1246+
1247+
- name: arm-rhel9-release-latest
1248+
display_name: "arm64 RHEL 9 Release (MongoDB Latest)"
1249+
expansions:
1250+
build_type: "Release"
1251+
tar_options: *linux_tar_options
1252+
extra_path: *linux_extra_path
1253+
cmake_flags: *linux_cmake_flags
1254+
mongodb_version: *version_latest
1255+
lib_dir: "lib64"
1256+
run_on:
1257+
- rhel90-arm64-large
1258+
tasks:
1259+
- name: compile_and_test_with_shared_libs
1260+
- name: compile_and_test_with_shared_libs_extra_alignment
1261+
- name: compile_and_test_with_shared_libs_cxx20
1262+
- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
1263+
- name: compile_and_test_with_static_libs
1264+
- name: compile_and_test_with_static_libs_extra_alignment
1265+
- name: compile_and_test_with_shared_libs_replica_set
1266+
- name: build_example_with_add_subdirectory
1267+
distros:
1268+
- rhel90-arm64-large
1269+
11741270
- name: debian11-release-latest
11751271
display_name: "Debian 11 Release (MongoDB Latest)"
11761272
expansions:
@@ -1184,6 +1280,8 @@ buildvariants:
11841280
tasks:
11851281
- name: compile_and_test_with_shared_libs
11861282
- name: compile_and_test_with_shared_libs_extra_alignment
1283+
- name: compile_and_test_with_shared_libs_cxx20
1284+
- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
11871285
- name: compile_and_test_with_static_libs
11881286
- name: compile_and_test_with_static_libs_extra_alignment
11891287
- name: compile_and_test_with_shared_libs_replica_set
@@ -1205,6 +1303,8 @@ buildvariants:
12051303
tasks:
12061304
- name: compile_and_test_with_shared_libs
12071305
- name: compile_and_test_with_shared_libs_extra_alignment
1306+
- name: compile_and_test_with_shared_libs_cxx20
1307+
- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
12081308
- name: compile_and_test_with_static_libs
12091309
- name: compile_and_test_with_static_libs_extra_alignment
12101310
- name: compile_and_test_with_shared_libs_replica_set

cmake/BsoncxxUtil.cmake

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ function(bsoncxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
3737
$<BUILD_INTERFACE:${source_dir}/include>
3838
$<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/${BSONCXX_HEADER_INSTALL_DIR}>
3939
)
40-
elseif(BSONCXX_POLY_USE_BOOST)
41-
if (CMAKE_VERSION VERSION_LESS 3.15.0)
42-
target_include_directories(${TARGET} PUBLIC ${Boost_INCLUDE_DIRS})
43-
else()
44-
target_link_libraries(${TARGET} PUBLIC Boost::boost)
45-
endif()
40+
elseif(BSONCXX_POLY_USE_BOOST)
41+
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()
4647
endif()
4748

4849
target_link_libraries(${TARGET} PRIVATE ${libbson_target})
@@ -66,7 +67,7 @@ endfunction(bsoncxx_add_library)
6667

6768
# Install the specified forms of the bsoncxx library (i.e., shared and/or static)
6869
# with associated CMake config files
69-
function(bsoncxx_install BSONCXX_TARGET_LIST BSONCXX_PKG_DEP)
70+
function(bsoncxx_install BSONCXX_TARGET_LIST BSONCXX_PKG_DEP BSONCXX_BOOST_PKG_DEP)
7071
install(TARGETS
7172
${BSONCXX_TARGET_LIST}
7273
EXPORT bsoncxx_targets

examples/projects/bsoncxx/cmake-deprecated/shared/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/bsoncxx/cmake-deprecated/static/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/bsoncxx/cmake/shared/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)
4242

4343
# Visual Studio pre 2017 requires boost polyfill.
4444
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
45-
if (CXX_STANDARD LESS 17)
45+
if (CMAKE_CXX_STANDARD LESS 17)
4646
find_package(Boost 1.56.0 REQUIRED)
4747
if (CMAKE_VERSION VERSION_LESS 3.15.0)
4848
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})

examples/projects/bsoncxx/cmake/shared/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/bsoncxx/cmake/static/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)
4242

4343
# Visual Studio pre 2017 requires boost polyfill.
4444
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
45-
if (CXX_STANDARD LESS 17)
45+
if (CMAKE_CXX_STANDARD LESS 17)
4646
find_package(Boost 1.56.0 REQUIRED)
4747
if (CMAKE_VERSION VERSION_LESS 3.15.0)
4848
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})

examples/projects/bsoncxx/cmake/static/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/mongocxx/cmake-deprecated/shared/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/mongocxx/cmake-deprecated/static/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/mongocxx/cmake/shared/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)
4242

4343
# Visual Studio pre 2017 requires boost polyfill.
4444
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
45-
if (CXX_STANDARD LESS 17)
45+
if (CMAKE_CXX_STANDARD LESS 17)
4646
find_package(Boost 1.56.0 REQUIRED)
4747
if (CMAKE_VERSION VERSION_LESS 3.15.0)
4848
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})

examples/projects/mongocxx/cmake/shared/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o pipefail
44

55
BUILD_TYPE=${BUILD_TYPE:-Release}
66
CXX_STANDARD=${CXX_STANDARD:-11}
7-
CMAKE=${CMAKE:-cmake}
7+
CMAKE=${cmake_binary:-cmake}
88

99
rm -rf build/*
1010
cd build

examples/projects/mongocxx/cmake/static/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)
4848

4949
# Visual Studio pre 2017 requires boost polyfill.
5050
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
51-
if (CXX_STANDARD LESS 17)
51+
if (CMAKE_CXX_STANDARD LESS 17)
5252
find_package(Boost 1.56.0 REQUIRED)
5353
if (CMAKE_VERSION VERSION_LESS 3.15.0)
5454
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})

0 commit comments

Comments
 (0)