Skip to content

Define a platform-support CMake target #1332

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 5 commits into from
Jul 3, 2023

Conversation

vector-of-bool
Copy link
Contributor

This changeset introduces a target mongo::detail::c_platform, which exposes usage requirements common to the platform on which we are being built. This consolidates some duplicated build setting handling between libbson and libmongoc, and introduces a central location for such settings.

This also replaces usage of add_compile_options for directory-level build settings. Such settings are now propagated properly on install results (including the generated pkg-config files).

mongo::detail::c_platform is intended to hold usage requirements common to all
libraries in the project. This will replace usage of directory-level
compile/link options, which do not propagate on the generated libraries when
they are installed.

This allows one to export/install libmongoc libraries that expose
additional usage requirements, such as linking instrumentation runtimes
(coverage, sanitizers, etc.)

Also: Sanitizers.cmake and ENABLE_COVERAGE now attach their options
to the platform-support library. This allows installed libmongoc with
sanitizers enabled to "just work," as downstream users will now receive
link options for coverage and sanitizers as usage requirements from the
libbson and libmongoc libraries.

Also: Enable threading on c_platform rather than linking. Fix the bson
and mongoc packages to pull Threads::Threads as a dependency

This also affects generated pkg-config files automatically.
Copy link
Contributor

@joshbsiegel joshbsiegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor feedback; otherwise, LGTM. 👏 for more target-based configuration.

@@ -47,7 +47,7 @@ function (mongoc_add_platform_compile_options)
endif()
set(opt "$<${expr}:${suffix}>")
else ()
message (SEND_ERROR "Unknown option prefix to mongoc_add_platform_compile_options(): “${prefix}” in “${opt}”")
message (SEND_ERROR "Unknown option prefix to mongoc_add_warning_options(): “${prefix}” in “${opt}”")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message (SEND_ERROR "Unknown option prefix to mongoc_add_warning_options(): “${prefix}” in “${opt}”")
message (SEND_ERROR "Unknown option prefix to ${CMAKE_CURRENT_FUNCTION}(): “${prefix}” in “${opt}”")

Comment on lines 69 to 72
# Enable multi-threading:
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
mongo_platform_use_target(Threads::Threads)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little out-of-place. Suggest moving into root CMakeLists.txt given it applies to both libbson and libmongoc.

add_library(_mongo-platform INTERFACE)
add_library(mongo::detail::c_platform ALIAS _mongo-platform)
set_property(TARGET _mongo-platform PROPERTY EXPORT_NAME detail::c_platform)
install(TARGETS _mongo-platform EXPORT bson-targets)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
install(TARGETS _mongo-platform EXPORT bson-targets)
install(TARGETS _mongo-platform EXPORT bson-targets)
install(TARGETS _mongo-platform EXPORT mongoc-targets)

Do we want to include the imported target in the mongoc-targets file as well? Or are we fine with obtaining it transitively via libbson?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little out-of-place. Consider moving the install() command into src/libbson/CMakeLists.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be exported only once, otherwise it will be defined twice and goofs will ensue. I chose the bson-targets export set only because it is pulled by both bson and mongoc. An "ideal" would be to define a third export set, but I think that has diminishing value when it can just ride along with the bson targets. I've also tucked it into the "detail" namespace so that we "reserve the right" to move/break/change/delete it in the future.

@vector-of-bool vector-of-bool merged commit 207785a into mongodb:master Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants