Skip to content

Conversation

@cschreib
Copy link

Currently, the CMake script sets the CMAKE_CXX_STANDARD variable to 11. This leaks into parent projects when adding backward-cpp with add_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 between backward-object and backward, 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 the backward and backward-object targets to include the necessary library dependencies, and defined the alias target Backward::Backward to allow linking as with the find_package() way, without having to add backward.cpp to the current target:

target_link_libraries(my_app PRIVATE Backward::Backward)

This PR also updates the README accordingly.

@lahwaacz
Copy link
Contributor

lahwaacz commented Sep 2, 2023

Setting CMAKE_CXX_STANDARD in a subdirectory does not "leak" the value to a parent directory, see the explanation on variable scopes in https://cmake.org/cmake/help/latest/command/set.html

As for the add_backward() macro, see my recent CMake modernization PR: #310

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.

2 participants