Skip to content

CMake modernization: add Backward::Interface and Backward::Object targets#310

Merged
bombela merged 3 commits intobombela:masterfrom
lahwaacz:master
Nov 23, 2023
Merged

CMake modernization: add Backward::Interface and Backward::Object targets#310
bombela merged 3 commits intobombela:masterfrom
lahwaacz:master

Conversation

@lahwaacz
Copy link
Copy Markdown
Contributor

@lahwaacz lahwaacz commented Sep 2, 2023

This PR should make it easier to use the backward.cpp file in downstream projects. As documented in the README, with this PR there are now three targets:

  • Backward::Interface is an interface target that brings compiler definition
    flags, include directory, and external libraries. This is all you need to use
    the backward.hpp header library.
  • Backward::Object brings Backward::Interface and backward.cpp as an
    OBJECT CMake library. This target cannot be exported, so it is not
    available when Backward is used via find_package.
  • Backward::Backward brings Backward::Interface and backward.cpp as
    either STATIC or SHARED library (depending on the BACKWARD_SHARED
    option). This target is exported and always available, however note that the
    linker will not include unused objects from a static library, unless the
    -Wl,--whole-archive option (or similar) is used.

This PR marks the add_backward target as deprecated and removes the ${BACKWARD_ENABLE} variable.

Before this PR, using the Backward::Backward target was not easy and consistent:

  • the BackwardConfig.cmake defined the target such that its interface had only the things needed to use backward.hpp (i.e. BACKWARD_INCLUDE_DIRS, BACKWARD_DEFINITIONS, BACKWARD_LIBRARIES)
  • the main CMakeLists.txt file defined the target such that it contained even backward.cpp as either STATIC or SHARED library
  • linking to a static library libbackward.a does not have the desired effect, unless the
    -Wl,--whole-archive option (or similar) is used (the linker discards unused objects from a static library)

The BACKWARD_TESTS option does not make sense when Backward is used via
find_package() so it does not belong to the BackwardConfig.cmake file.
@bombela
Copy link
Copy Markdown
Owner

bombela commented Nov 23, 2023

Thank you for the fine work.

@bombela bombela merged commit fdc176a into bombela:master Nov 23, 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.

2 participants