Skip to content

Commit

Permalink
CDRIVER-5635 Exclude tests and examples from ALL target (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
eramongodb authored Jul 19, 2024
1 parent 5735f0e commit ef17740
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 40 deletions.
12 changes: 10 additions & 2 deletions .evergreen/scripts/compile-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ if [[ "${OSTYPE}" == darwin* ]]; then
sysctl -n hw.logicalcpu
}
fi
export CMAKE_BUILD_PARALLEL_LEVEL
CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"

declare -a extra_configure_flags
IFS=' ' read -ra extra_configure_flags <<<"${EXTRA_CONFIGURE_FLAGS:-}"
Expand Down Expand Up @@ -208,5 +210,11 @@ CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1

"${cmake_binary}" "${configure_flags[@]}" ${extra_configure_flags[@]+"${extra_configure_flags[@]}"} .
"${cmake_binary}" --build . -- -j "$(nproc)"
"${cmake_binary}" --build . --target install
"${cmake_binary}" --build .
"${cmake_binary}" --install .

# For use by test tasks, which directly use the binary directory contents.
"${cmake_binary}" --build . --target mongo_c_driver_tests

# Also validate examples.
"${cmake_binary}" --build . --target mongo_c_driver_examples
42 changes: 28 additions & 14 deletions .evergreen/scripts/compile-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,38 @@ fi

"${cmake_binary:?}" --version

export CMAKE_BUILD_PARALLEL_LEVEL
CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"

if [[ "${CC}" =~ mingw ]]; then
# MinGW has trouble compiling src/cpp-check.cpp without some assistance.
configure_flags_append "-DCMAKE_CXX_STANDARD=11"
cmake_binary=$(native-path "$cmake_binary")

cmake_binary=$(native-path "$cmake_binary")
build_dir=$(native-path "$mongoc_dir")
prefix_path=$(native-path "$install_dir/lib/cmake")

env \
"CC=gcc" \
"CXX=g++" \
"$cmake_binary" \
-G "MinGW Makefiles" \
-D CMAKE_PREFIX_PATH="$(native-path "$install_dir/lib/cmake")" \
"${configure_flags[@]}" \
"${extra_configure_flags[@]}" \
-B "$build_dir" \
-S "$(native-path "$mongoc_dir")"

env "$cmake_binary" --build "$build_dir" --parallel "$(nproc)"
-G "MinGW Makefiles" \
-D CMAKE_PREFIX_PATH="$prefix_path" \
"${configure_flags[@]}" \
"${extra_configure_flags[@]}" \
-B "$build_dir" \
-S "$(native-path "$mongoc_dir")"

env "$cmake_binary" --build "$build_dir"
env "$cmake_binary" --build "$build_dir" --target mongo_c_driver_tests
env "$cmake_binary" --build "$build_dir" --target mongo_c_driver_examples
exit 0
fi

declare compile_flags=(
"/m" # Number of concurrent processes. No value=# of cpus
)
# MSBuild needs additional assistance.
# https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/
export UseMultiToolTask=1
export EnforceProcessCountAcrossBuilds=1

if [ "${COMPILE_LIBMONGOCRYPT}" = "ON" ]; then
echo "Installing libmongocrypt..."
Expand All @@ -136,5 +144,11 @@ if [ "${COMPILE_LIBMONGOCRYPT}" = "ON" ]; then
fi

"${cmake_binary}" -G "$CC" "${configure_flags[@]}" "${extra_configure_flags[@]}"
"${cmake_binary}" --build . --target ALL_BUILD --config "${build_config}" -- "${compile_flags[@]}"
"${cmake_binary}" --build . --target INSTALL --config "${build_config}" -- "${compile_flags[@]}"
"${cmake_binary}" --build . --config "${build_config}"
"${cmake_binary}" --install . --config "${build_config}"

# For use by test tasks, which directly use the binary directory contents.
"${cmake_binary}" --build . --config "${build_config}" --target mongo_c_driver_tests

# Also validate examples.
"${cmake_binary}" --build . --config "${build_config}" --target mongo_c_driver_examples
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ mongo_bool_setting(ENABLE_DEBUG_ASSERTIONS "Build library with runtime debug ass
include(Sanitizers)

# Toggle optional components:
mongo_bool_setting(ENABLE_TESTS "Build MongoDB C Driver tests")
mongo_bool_setting(ENABLE_EXAMPLES "Build MongoDB C Driver examples")
mongo_bool_setting(ENABLE_MAN_PAGES "Build the manual pages" DEFAULT VALUE OFF)
mongo_bool_setting(ENABLE_HTML_DOCS "Build the HTML documentation" DEFAULT VALUE OFF)
mongo_bool_setting(ENABLE_TESTS "Enable building MongoDB C Driver tests")
mongo_bool_setting(ENABLE_EXAMPLES "Enable building MongoDB C Driver examples")
mongo_bool_setting(ENABLE_MAN_PAGES "Enable building the manual pages" DEFAULT VALUE OFF)
mongo_bool_setting(ENABLE_HTML_DOCS "Enable building the HTML documentation" DEFAULT VALUE OFF)
mongo_bool_setting(ENABLE_UNINSTALL "Generate an 'uninstall' script and an 'uninstall' build target")
mongo_bool_setting(ENABLE_SRV "Enable support for mongodb+srv URIs.")

Expand Down Expand Up @@ -424,6 +424,10 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_DARWIN_C_SOURCE)
endif ()

# Convenience targets to build all tests or all examples.
add_custom_target(mongo_c_driver_tests)
add_custom_target(mongo_c_driver_examples)

add_subdirectory (src/common)

if (NOT USING_SYSTEM_BSON)
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Notes:

* Bump minimum wire protocol version from 6 (MongoDB 3.6) to 7 (MongoDB 4.0).

Changed:

* Test and example targets are excluded from the `ALL` target.
* All test targets can be built using the `mongo_c_driver_tests` target.
* All example targets can be built using the `mongo_c_driver_examples` target.

Deprecated:

* Use of `*_hint` functions is deprecated in favor of more aptly named `*_server_id` functions:
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ configure_file (
if (CMAKE_CXX_COMPILER)
# Add a C++ source file that will #include the main C headers. This "library"
# does nothing other than validate that the C headers are valid C++ headers.
add_library (mongoc-cxx-check STATIC cpp-check.cpp)
add_library (mongoc-cxx-check OBJECT cpp-check.cpp)
if (TARGET mongoc_static)
target_link_libraries (mongoc-cxx-check PRIVATE mongoc_static)
else ()
Expand Down
28 changes: 14 additions & 14 deletions src/libbson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,21 @@ endif ()
# 888
# 888

function (add_example bin src)
set (BSON_EXAMPLE_SOURCES ${PROJECT_SOURCE_DIR}/${src})
add_executable (${bin} ${BSON_EXAMPLE_SOURCES})

# Link against the shared lib like normal apps
if(TARGET bson_shared)
target_link_libraries (${bin} bson_shared)
elseif(TARGET bson_static)
target_link_libraries (${bin} bson_static)
else()
return()
endif()
endfunction ()

if (ENABLE_EXAMPLES)
function (add_example bin src)
add_executable (${bin} EXCLUDE_FROM_ALL ${src})
add_dependencies (mongo_c_driver_examples ${bin})

# Link against the shared lib like normal apps
if(TARGET bson_shared)
target_link_libraries (${bin} bson_shared)
elseif(TARGET bson_static)
target_link_libraries (${bin} bson_static)
else()
return()
endif()
endfunction ()

add_example (bcon-col-view examples/bcon-col-view.c)
add_example (bcon-speed examples/bcon-speed.c)
add_example (bson-metrics examples/bson-metrics.c)
Expand Down
13 changes: 8 additions & 5 deletions src/libmongoc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ if (MONGOC_ENABLE_SASL_CYRUS)
endif ()

if (ENABLE_TESTS)
add_library (test-libmongoc-lib STATIC ${test-libmongoc-sources})
add_library (test-libmongoc-lib STATIC EXCLUDE_FROM_ALL ${test-libmongoc-sources})
if (MSVC AND MSVC_VERSION VERSION_LESS 1900)
message (STATUS "Disabling warning C4756 for VS 2013 and older")
# Macro constant INFINITY triggers constant arithmetic overflow warnings in
Expand All @@ -1151,7 +1151,9 @@ if (ENABLE_TESTS)
)

function (mongoc_add_test test)
add_executable (${test} ${ARGN})
add_executable (${test} EXCLUDE_FROM_ALL ${ARGN})
add_dependencies (mongo_c_driver_tests ${test})

target_link_libraries (${test}
PUBLIC
$<$<C_COMPILER_ID:MSVC>:DbgHelp.dll>
Expand Down Expand Up @@ -1195,12 +1197,13 @@ endif ()

if (ENABLE_EXAMPLES AND ENABLE_SHARED)
function (mongoc_add_example example)
add_executable (${example} ${ARGN})
add_executable (${example} EXCLUDE_FROM_ALL ${ARGN})
add_dependencies (mongo_c_driver_examples ${example})

target_link_libraries (${example} mongoc_shared ${LIBRARIES})
if (WIN32)
target_link_libraries (${example} shlwapi)
endif ()
set (EXAMPLES ${EXAMPLES} ${example})
endfunction ()

# examples/
Expand Down Expand Up @@ -1286,7 +1289,7 @@ set (MONGOC_HEADER_INSTALL_DIR
)

install (
TARGETS ${TARGETS_TO_INSTALL} ${EXAMPLES}
TARGETS ${TARGETS_TO_INSTALL}
EXPORT mongoc-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down

0 comments on commit ef17740

Please sign in to comment.