CMake cleanup. - #384
Merged
Merged
CMake cleanup.#384
Conversation
Modernise and tidy the CMake a bit: - Use generator expressions for a lot of conditionals so that things are more reliable with multi-config generators (and less verbose). - Remove C as a needed language. None of the code was C but we were using C to test if headers worked. This was fragile because a build with `CMAKE_CXX_COMPILER` set might have checked things compiled with the system C compiler and then failed when the specified C++ compiler used different headers. - Rename the `BACKTRACE_HEADER` macro to `SNMALLOC_BACKTRACE_HEADER`. This is exposed into code that consumes snmalloc and so should be 'namespaced' (to the degree that's possible with C macros). - Use functions instead of macros for better variable scoping. - Factor out some duplicated bits into functions. - Update to the latest way of telling CMake to use C++17 or C++20. - Migrate everything that's setting global properties to setting only per-target properties. - Link with -nostdlib++ if it's available. If it isn't, fall back to enabling the C language and linking with the C compiler. - Make the per-test log messages verbose outputs. These kept scrolling important messages off the top of the screen for me. - Make building as a header-only library a public option. - Add install targets that install all of the headers and provide a config option. This works with the header-only configuration for integration with things like vcpkg. - Fix a missing `#endif` in the `malloc_useable_size` check. This was failing co compile on all platforms because of the missing `#endif`. - Bump the minimum version to 3.14 so that we have access to target_link_options. This is necessary to use generator expressions for linker flags. With these changes, it's now possible to install snmalloc and then, in another project, do something like this: ```cmake find_package(snmalloc CONFIG REQUIRED) target_link_libraries(t1 snmalloc::snmalloc) target_link_libraries(t2 snmalloc::snmallocshim-static) ``` In this example, `t1` gets all of the compile flags necessary to include snmalloc headers for its build configuration. `t2` is additionally linked to the snmalloc static shim library.
David Chisnall (davidchisnall)
requested review from
Matthew Parkinson (mjp41) and
Nathaniel Wesley Filardo (nwf)
September 1, 2021 13:43
These are on old-Ubuntu because we depend on an old clang-format.
Options that affect tests or shims should not appear when configuring as a header-only library.
Also add a linker warning that all symbols are defined and fix the error that it found.
These add a load of things on Windows that generate huge numbers of spurious warnings.
Matthew Parkinson (mjp41)
approved these changes
Sep 3, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Modernise and tidy the CMake a bit:
are more reliable with multi-config generators (and less verbose).
using C to test if headers worked. This was fragile because a build
with
CMAKE_CXX_COMPILERset might have checked things compiled withthe system C compiler and then failed when the specified C++ compiler
used different headers.
BACKTRACE_HEADERmacro toSNMALLOC_BACKTRACE_HEADER.This is exposed into code that consumes snmalloc and so should be
'namespaced' (to the degree that's possible with C macros).
per-target properties.
enabling the C language and linking with the C compiler.
important messages off the top of the screen for me.
config option. This works with the header-only configuration for
integration with things like vcpkg.
#endifin themalloc_useable_sizecheck. This wasfailing co compile on all platforms because of the missing
#endif.target_link_options. This is necessary to use generator expressions
for linker flags.
With these changes, it's now possible to install snmalloc and then, in
another project, do something like this:
In this example,
t1gets all of the compile flags necessary to includesnmalloc headers for its build configuration.
t2is additionallylinked to the snmalloc static shim library.