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.
The information in this file does not constitute documentation. If still relevant, an issue can be created.
The contents of the file are pasted below for future reference.
The build system
We are currently migrating from
autotools
toCMake
as a build-system. This documentcurrently describes how we intend to perform this migration, and will be updated after
the migration to explain how the new
CMake
configuration works.Stages during the build
netdata-installer.sh
, take in arguments and environment settings to control thebuild.
autoreconf -ivf ; ./configure
passing arguments into the configurescript. This becomes
generation-time
in CMake. This includes package / system detectionand configuration resulting in the
config.h
in the source root.make install
to handle all the install steps put intothe Makefiles by the configure step (puts binaries / libraries / config into target
tree structure).
system-level configuration (privilege setting, user / groups, fetch/build/install
go.d
plugins, telemetry, installing service for startup, uninstaller, auto-updates.
The ideal migration result is to replace all of this with the following steps:
The
-D...
indicates where the command-line arguments for configuration are passed intoCMake
.CMake generation time
At generation time we need to solve the following issues:
Feature flags
Every command-line switch on the installer and the configure script needs to becomes an
argument to the CMake generation, we can do this with variables in the CMake cache:
CMakeLists.txt:
Command-line interface
Dependency detection
We have a mixture of soft- and hard-dependencies on libraries. For most of these we expect
pkg-config
information, for some we manually probe for libraries and include files. Weshould treat all of the external dependencies consistently:
pkg-config
(e.g. the standardjemalloc
drops a.pc
into the system but we do not check for it.
.pc
is found perform a manual search for libraries under known names, andcheck for accessible symbols inside them.
-DWITH_JEMALLOC=/...
).indicate it is not present in the
config.h
.Before doing any dependency detection we need to determine which search paths are
really in use for the current compiler, after the
project
declaration we can use:The output format for this switch works on both
Clang
andgcc
, it also includesthe include search path, which can be extracted in a similar way. Standard advice here
is to list the
ldconfig
cache or use the-V
flag to check, but this does not workconsistently across platforms - in particular
gcc
will reconfigureld
when it iscalled to gcc's internal view of search paths. During experiments each of these
alternative missed / added unused paths. Dumping the compiler's own estimate of the
search paths seems to work consistently across clang/gcc/linux/freebsd configurations.
The default behaviour in CMake is to search across predefined paths (e.g.
CMAKE_LIBRARY_PATH
)that are based on heuristics about the current platform. Most projects using CMake seem
to overwrite this with their own estimates.
We can use the extracted paths as a base, add our own heuristics based on OS and then
set(CMAKE_LIBRARY_PATH ${OUR_OWN_LIB_SEARCH})
to get the best results. Roughly we dothe following for each external dependency:
For checking the include path we have two options, if we overwrite the
CMAKE_
... variablesto change the internal search path we can use:
Or we can build a custom search path and then use:
Note: we may have cases where there is no
.pc
but we have access to a.cmake
(e.g. AWS SDK, mongodb,cmocka) - these need to be checked / pulled inside the repo while building a prototype.Compiler compatibility checks
In CMakeLists.txt:
In cmake/config.in:
If we want to check explicitly if something compiles (e.g. the accept4 check, or the
strerror_r
typing issue) then we set theCMAKE_
... paths and then use:This produces a bool that we can use inside CMake or propagate into the
config.h
.We can handle the atomic checks with:
For the specific problem of getting the correct type signature in log.c for the
strerror_r
calls we can replicate what we have now, or we can delete this code completely and use a
better solution that is documented here.
To replicate what we have now:
Note: I did not find an explicit way to select compiler when both
clang
andgcc
arepresent. We might have an implicit way (like redirecting
cc
) but we should put one in.Debugging problems in test compilations
Test compilations attempt to feed a test-input into the targeted compiler and result
in a yes/no decision, this is similar to
AC_LANG_SOURCE(.... if test $ac_...
in .m4
.We have two techniques to use in CMake:
The
check_c_source_compiles
is light-weight:CMakeFiles/CMakeErrors.log
But we cannot alter the include-paths / library-paths / compiler-flags specifically for
the test without overwriting the current CMake settings. The alternative approach is
slightly more heavy-weight:
try_compile
- it requires a.c
file in the tree.This implies that we can do this to diagnose problems / develop test-programs, but we
have to make them bullet-proof as we cannot expose this to end-users. This means that
the results of the compilation must be crisp - exactly yes/no if the feature we are
testing is supported.
System configuration checks
For any system configuration checks that fall outside of the above scope (includes, libraries,
packages, test-compilation checks) we have a fall-back that we can use to glue any holes
that we need, e.g. to pull out the packaging strings, inside the
CMakeLists.h
:and this in the
config.h.in
:CMake build time
We have a working definition of the targets that is in use with CLion and works on modern
CMake (3.15). It breaks on older CMake version (e.g. 3.7) with an error message (issue#7091).
No PoC yet to fix this, but it looks like changing the target properties should do it (in the
worst case we can drop the separate object completely and merge the sources directly into
the final target).
Steps needed for building a prototype:
CMAKE_
variables in the cacheaccording to the feature options and dependencies.
access the dashboard).
config.h
generated by autotools against the CMake versionand document / fix any deviations.
CMake install target
I've only looked at this superficially as we do not have a prototype yet, but each of the
first-stage install steps (in
make install
) and the second-stage (innetdata-installer.sh
)look feasible.
General issues
We need to choose a minimum CMake version that is an available package across all of our
supported environments. There is currently a build issue CMake build doesn't work on Ubuntu 18.04 #7091 that documents a problem
in the compilation phase (we cannot link in libnetdata as an object on old CMake versions
and need to find a different way to express this).
The default variable-expansion / comparisons in CMake are awkward, we need this to make it
sane:
Default paths for libs / includes are not comprehensive on most environments, we still need
some heuristics for common locations, e.g.
/usr/local
on FreeBSD.Recommendations
We should follow these steps:
the team uses.
offer to support it.
build-system).
Some smaller miscellaneous suggestions:
_Generic
/strerror_r
config to make the system simpler (use the techniqueon the blog post to make the standard version re-entrant so that it is thread-safe).
Background