-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Cmake config improvements #1271
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
cdunn2001
merged 6 commits into
open-source-parsers:master
from
sergeyrachev:cmake-config-improvements
May 5, 2021
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0402378
- exported targets go to separate generated file and package config …
sergeyrachev 6a076e3
- declare namespaced export target to simplify the library usage
sergeyrachev cfb9120
- empty line at end of file
sergeyrachev 37ce902
- narrowed lines to be aligned with overall file line width
sergeyrachev 6f6613a
- workaround for CMake < 3.18 ALIAS target limitation to not point to…
sergeyrachev 816ef22
- isolated namespace targets into separate file
sergeyrachev 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cmake_policy(PUSH) | ||
cmake_policy(VERSION 3.0) | ||
|
||
@PACKAGE_INIT@ | ||
|
||
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-targets.cmake" ) | ||
|
||
if(TARGET jsoncpp_static) | ||
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED ) | ||
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static") | ||
elseif(TARGET jsoncpp_lib) | ||
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED ) | ||
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib") | ||
endif() | ||
|
||
check_required_components(JsonCpp) | ||
|
||
cmake_policy(POP) |
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.
I would put this logic in a file
jsoncpp-namespaced-targets.cmake
exported withinstall(EXPORT ...)
.Moreover, for consistency with
add_subdirectory()
,JsonCpp::JsonCpp
ALIAS target should be added in CMakeLists.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.
You mean such that lines 6-7 above read like this?
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.
That's it 😃
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.
Right. And about the ALIAS target, where would you do that?
Uh oh!
There was an error while loading. Please reload this page.
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.
In
/src/lib_json/CMakeLists.txt
close toadd_library()
calls. Unfortunately, it will probably requires some ugly branching because currentlyjsoncpp
can build both shared & static, or shared only, or static only.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.
I would be glad to add ALIAS to CMakeLists to use the namespaced target in build tree also.
What is the usecase of having both static and shared build at same time? CMake allows to specify the library type during generation with -DBUILD_SHARED_LIBS=Off/On although it relies on CMakeLists.txt to not specify types explicitly.
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.
@spacelm: Could we imagine fixing the
include
part of your comment in this PR, and leaving the ALIAS part for another PR? So that there could be a discussion about @sergeyrachev's point with which I agree: why not relying onBUILD_SHARED_LIBS
instead? That makes it simpler IMO, and if you want both, you can run the build twice 🤔.Uh oh!
There was an error while loading. Please reload this page.
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.
No problem for me to add ALIAS target in another PR, it would be an improvement.
Then, you can introduce a new breaking change in jsoncpp by removing again the ability to build both static & shared (AFAIK, it was removed for 1.9.0, then introduced again in 1.9.4...). Since I'm against build of both static & shared, I would be happy, but I'm not the maintainer.