CMake cleanup. (#384)
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). - Clean up the options and use dependent options to hide options that are not always relevant. - 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. - Make the linker error if the shim libraries depend on symbols that are not defined in the explicitly-provided libraries. - Make the old-Ubuntu CI jobs use C++17 explicitly (previously CMake was silently ignoring the fact that the compiler didn't support C++20) - Fix errors found by the more aggressive linking mode. 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.
This commit is contained in:
9
.github/workflows/main.yml
vendored
9
.github/workflows/main.yml
vendored
@@ -18,12 +18,13 @@ jobs:
|
||||
# Build each combination of OS and release/debug variants
|
||||
os: [ "ubuntu-latest", "ubuntu-18.04", "macos-11", "macos-10.15", "freebsd-12.2", "freebsd-13.0" ]
|
||||
build-type: [ Release, Debug ]
|
||||
extra-cmake-flags: [ " " ]
|
||||
extra-cmake-flags: [ "" ]
|
||||
# Modify the complete matrix
|
||||
include:
|
||||
# Provide the dependency installation for each platform
|
||||
- os: "ubuntu-18.04"
|
||||
dependencies: "sudo apt install ninja-build"
|
||||
cmake-flags: "-DSNMALLOC_USE_CXX17=ON"
|
||||
- os: "ubuntu-latest"
|
||||
dependencies: "sudo apt install ninja-build"
|
||||
- os: "macos-11"
|
||||
@@ -68,7 +69,7 @@ jobs:
|
||||
- name: Install build dependencies
|
||||
run: ${{ matrix.dependencies }}
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -G Ninja ${{ matrix.extra-cmake-flags }}
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -G Ninja ${{ matrix.cmake-flags }} ${{ matrix.extra-cmake-flags }}
|
||||
# Build with a nice ninja status line
|
||||
- name: Build
|
||||
working-directory: ${{github.workspace}}/build
|
||||
@@ -201,7 +202,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build
|
||||
run: cmake -B ${{github.workspace}}/build -DSNMALLOC_USE_CXX17=ON
|
||||
- name: Install clang-tidy
|
||||
run: sudo apt install clang-tidy-9
|
||||
# Run the clang-format check and error if it generates a diff
|
||||
@@ -213,7 +214,7 @@ jobs:
|
||||
git diff --exit-code
|
||||
- name: Run clang-tidy
|
||||
run: |
|
||||
clang-tidy-9 src/override/malloc.cc -header-filter="`pwd`/*" -warnings-as-errors='*' -export-fixes=tidy.fail -- -std=c++17 -mcx16 -DSNMALLOC_PLATFORM_HAS_GETENTROPY=0
|
||||
clang-tidy-9 src/override/malloc.cc -header-filter="`pwd`/*" -warnings-as-errors='*' -export-fixes=tidy.fail -- -std=c++17 -mcx16 -DSNMALLOC_PLATFORM_HAS_GETENTROPY=0
|
||||
if [ -f tidy.fail ] ; then
|
||||
cat tidy.fail
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user