Skip to content

CMake: use system include dirs if used as sub-project#85

Closed
stertingen wants to merge 1 commit into
bfgroup:developfrom
stertingen:cmake-system-includes
Closed

CMake: use system include dirs if used as sub-project#85
stertingen wants to merge 1 commit into
bfgroup:developfrom
stertingen:cmake-system-includes

Conversation

@stertingen

Copy link
Copy Markdown
Contributor

The code should not emit warnings if used as sub-project.
This PR adds CMake logic to detect if Lyra was added using add_subdirectory and declares the include directories as SYSTEM includes.

@jayeshbadwaik

jayeshbadwaik commented Feb 28, 2025

Copy link
Copy Markdown

@stertingen Are you using CMake > 3.25, because since CMake 3.25, add_subdirectory provides an option to add SYSTEM which seems a much more robust way of doing things:

  1. It will annotate all usages with SYSTEM therefore preventing bugs where maintainer forgets to annotate something.
  2. It allows user to decide if they want the add_subdirectory as SYSTEM or not and does not force the decision.

If that solution is working for you, then we don't need this in lyra.

@grafikrobot grafikrobot moved this to 🆕 New in BFG Tasks Apr 15, 2026
@grafikrobot

Copy link
Copy Markdown
Member

Would this issue be resolved if we used #include ".." instead of #include <..> ?

@grafikrobot grafikrobot moved this from 🆕 New to 🏗 In progress in BFG Tasks May 11, 2026
@stertingen

stertingen commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@stertingen Are you using CMake > 3.25, because since CMake 3.25, add_subdirectory provides an option to add SYSTEM which seems a much more robust way of doing things:

1. It will annotate all usages with `SYSTEM` therefore preventing bugs where maintainer forgets to annotate something.

2. It allows user to decide if they want the `add_subdirectory` as SYSTEM or not and does not force the decision.

If that solution is working for you, then we don't need this in lyra.

As you said, that works for new CMake versions.
I am currently supporting CMake down to 3.12.

The necessity of this PR depends on the user experience this project wants to provide to downstream projects.
Usually, users of library do not want to be bothered with warnings coming from depending libraries, so if this code works just fine, it should not emit warnings.
We can manually disable every warning we want to ignore in the C++ code, but that would be more work. (Other libraries such as asio do this AFAIK)

As a workaround, I'm currently not using this library's CMake support, but set up the include directories manually to not get warnings from 3rd-party code:

if(NOT TARGET bfg::lyra)
    add_library(${PROJECT_NAME}_lyra INTERFACE)
    target_include_directories(${PROJECT_NAME}_lyra SYSTEM INTERFACE libs/Lyra/include)
    add_library(bfg::lyra ALIAS ${PROJECT_NAME}_lyra)
endif()

Would this issue be resolved if we used #include ".." instead of #include <..> ?

No. Compiler warnings are generated independently of how a header is included.

@grafikrobot

Copy link
Copy Markdown
Member

Okay, I totally misunderstood the root issue. The problem is warnings in the code itself. And using the SYSTEM tag works around it because compilers treat system labeled headers to silence warnings. So.. We definitely want to address the warnings. I recently made changes to remove all warnings generated when using these args -Wall -Wextra -pedantic -Werror -Wnon-virtual-dtor -Woverloaded-virtual -Wshadow -Wsign-compare -Wsign-conversion -Wsign-promo -Wundef -Wzero-as-null-pointer-constant. What warnings are you running into? And what warning compile args are you using?

Obviously new issues for the warnings would be good. And of course PRs welcomed.

@grafikrobot

Copy link
Copy Markdown
Member

Closing in favor of addressing the code warnings directly as needed.

@github-project-automation github-project-automation Bot moved this from 🏗 In progress to ✅ Done in BFG Tasks May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants