build: Enable system library semantics for nall
in other targets
#1839
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.
Description
When other targets (
ares
,ruby
,hiro
, etc.) are compiled, they will now treat the 'include directory' for nall (the directory from which nall include paths are resolved, i.e.#include <nall/nall.hpp>
) as a "system" directory, using theSYSTEM
CMake property.Principally, the directory having this property means that compiling non-
nall
targets will not emit compiler diagnostic flags from code contained innall
headers. The exact behavior will depend on the compiler's interpretation of the "system" property.This is more idiomatic behavior for
nall
being treated as a "standard library", and moreover a "header-only" standard library, where including headers includes the definitions of all relevant functions (other than certain system-conflicting headers previously separated into separate implementations in #898 and #1064).Also adds the
headers.cpp
file tonall
, which includes allnall
headers that are included in different parts of ares.The addition of
headers.cpp
means that compilingnall
itself will also compile these headers (once), and thus we can define diagnostic flags fornall
separately and make use of diagnostic information effectively on a per-target basis; we may still receive compiler diagnostic information for our standard library.To enable this behavior, the entirety of
nall
is moved down one level in the source tree into anall
parent directory. Since CMake defines theSYSTEM
property on a directory basis (or at least, this is how it must be defined for our usage ofnall
as a mostly header-centric library), andnall
paths must be resolved such that#include <nall/nall.hpp>
is a valid path, this change is necessary so that other targets are not also treated as libraries withSYSTEM
semantics when their headers or implementations are#include
d relative to the top-level repository directory.This behavior is switched by the CMake cache variable
ARES_TREAT_NALL_AS_SYSTEM
.Motivation and Context
As part of ares upkeep and build system modernization, we may wish to increase compiler strictness in ares and build the project with more diagnostic flags enabled, to catch bugs in new and old code, keep up with evolving C/C++ standards, and generally improve code quality and readability where appropriate.
Under our existing build system code, defining diagnostic flags on a per-target basis did not work effectively. For example:
Semantically, this would indicate we want to raise the
-Wcomma
diagnostic flag inruby
code andruby
code only. But under our current patterns, this flag would necessarily not only be raised inruby
code, but in allnall
headers thatruby
code directly#include
s. And sincenall
is our standard library, and the vast majority ofnall
function definitions are present in these headers by virtue of nall being largely a 'header-only' library, each inclusion would raise the flag for most of, if not the entirenall
standard library.This situation would be further compounded in targets with many translation units (such as
ares
), which could include the omnibusnall/nall.hpp
header dozens of times. For a warning like-Wshorten-64-to-32
, this could generate tens of thousands of identical compiler warnings in the same source files, with the potential to overwhelm available memory and slow build times to a crawl.With these headers in "system" directories, we can apply flags per-target and successfully receive warnings for only code that is semantically part of those targets.