CMake: prevent leaking of CXX_STANDARD and allow linking as regular library from add_subdirectory #241
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.
Currently, the CMake script sets the
CMAKE_CXX_STANDARD
variable to11
. This leaks into parent projects when adding backward-cpp withadd_subdirectory()
. I have therefore modified the CMake script to explicitly set this property on each target of backward (I am not sure what is the difference betweenbackward-object
andbackward
, so I did it for both).Furthermore, the documentation recommends using the
add_backward()
macro to use backward when adding it as a sub-directory. As far as I know, CMake best practices are that you should be able to link to a library in a unique and consistent way, regardless of where it came from (imported, or added as a sub-directory). I have therefore made modifications to thebackward
andbackward-object
targets to include the necessary library dependencies, and defined the alias targetBackward::Backward
to allow linking as with thefind_package()
way, without having to add backward.cpp to the current target:This PR also updates the README accordingly.