Skip to content

CMake cleanup. - #384

Merged
David Chisnall (davidchisnall) merged 14 commits into
snmalloc2from
cmake-cleanup
Sep 3, 2021
Merged

David Chisnall (davidchisnall) merged 14 commits into
snmalloc2from
cmake-cleanup

Conversation

@davidchisnall

Copy link
Copy Markdown
Collaborator

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:

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.

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.
Comment thread CMakeLists.txt
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt
Comment thread CMakeLists.txt
Comment thread CMakeLists.txt Outdated
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.
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.

3 participants