-
Notifications
You must be signed in to change notification settings - Fork 455
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45eb784
Define a mongo::detail::c_platform support library
vector-of-bool e03f6a4
Remove more usage of FindThreads
vector-of-bool 414b568
Comman naming tweaks
vector-of-bool b62e6a4
Merge branch 'master' into platform-target
vector-of-bool ffeb034
Tweaks from PR comments
vector-of-bool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#[[ | ||
|
||
Defines a target mongo::detail::c_platform (alias of _mongo-platform), which | ||
exposes system-level supporting compile and link usage requirements. All targets | ||
should link to this target with level PUBLIC. | ||
|
||
Use mongo_platform_compile_options and mongo_platform_link_options to add usage | ||
requirements to this library. | ||
|
||
The mongo::detail::c_platform library is installed and exported with the | ||
bson-targets export set as an implementation detail. It is installed with this | ||
export set so that it is available to both libbson and libmongoc (attempting to | ||
install this target in both bson-targets and mongoc-targets export sets would | ||
lead to duplicate definitions of mongo::detail::c_platform for downstream | ||
users). | ||
|
||
]] | ||
|
||
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) | ||
|
||
|
||
#[[ | ||
Define additional platform-support compile options | ||
|
||
These options are added to the mongo::detail::c_platform INTERFACE library. | ||
]] | ||
function (mongo_platform_compile_options) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION}) | ||
message(DEBUG "Add platform-support compilation options: ${ARGN}") | ||
target_compile_options(_mongo-platform INTERFACE ${ARGN}) | ||
endfunction () | ||
|
||
#[[ | ||
Define additional platform-support link options. | ||
|
||
These options are added to the mongo::detail::c_platform INTERFACE library. | ||
]] | ||
function(mongo_platform_link_options) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION}) | ||
message(DEBUG "Add platform-support runtime linking options: ${ARGN}") | ||
target_link_options(_mongo-platform INTERFACE ${ARGN}) | ||
endfunction() | ||
|
||
#[[ | ||
Add targets to the usage requirements for the current platform. | ||
|
||
All of the named items must be the names of existing targets. Note that these | ||
targets will also need to be available at import-time for consumers (unless | ||
wrapped in $<BUILD_INTERFACE:>). | ||
]] | ||
function(mongo_platform_use_target) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION}) | ||
message(DEBUG "Add platform-support usage of targets: ${ARGN}") | ||
foreach(item IN LISTS ARGN) | ||
if(item MATCHES "::") | ||
# CMake will enforce that this link names an existing target | ||
target_link_libraries(_mongo-platform INTERFACE "${item}") | ||
else() | ||
# Generate a configure-time-error if the named item is not the name of a target | ||
target_link_libraries(_mongo-platform INTERFACE | ||
$<IF:$<TARGET_EXISTS:${item}>,${item},NO_SUCH_TARGET::${item}>) | ||
endif() | ||
endforeach() | ||
endfunction() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
include(CMakeFindDependencyMacro) | ||
find_dependency(Threads) # Required for Threads::Threads | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/bson-targets.cmake") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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 intosrc/libbson/CMakeLists.txt
?There was a problem hiding this comment.
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.