Skip to content

Commit dc12688

Browse files
authored
Improve CMake slightly (#620)
* Prefix build testing flag with SNMALLOC * Only add clangformat target is testing enabled.
1 parent 95bad42 commit dc12688

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
dependencies: "sudo apt install ninja-build"
6565
build-type: Release
6666
self-host: true
67-
extra-cmake-flags: "-DSNMALLOC_BENCHMARK_INDIVIDUAL_MITIGATIONS=On -DBUILD_TESTING=Off"
67+
extra-cmake-flags: "-DSNMALLOC_BENCHMARK_INDIVIDUAL_MITIGATIONS=On -DSNMALLOC_BUILD_TESTING=Off"
6868
# Check that we can build specifically with libstdc++
6969
- os: "ubuntu-latest"
7070
variant: "libstdc++ (Build only)"

CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include(CheckIPOSupported)
1313
include(CMakeDependentOption)
1414

1515
# Name chosen for compatibility with CTest.
16-
option(BUILD_TESTING "Build test programs as well as shims" ON)
16+
option(SNMALLOC_BUILD_TESTING "Build test programs as well as shims" ON)
1717

1818
option(SNMALLOC_HEADER_ONLY_LIBRARY "Use snmalloc has a header-only library" OFF)
1919
# Options that apply globally
@@ -288,7 +288,7 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
288288

289289
set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/test)
290290

291-
if(BUILD_TESTING)
291+
if(SNMALLOC_BUILD_TESTING)
292292
enable_testing()
293293
subdirlist(TEST_CATEGORIES ${TESTDIR})
294294
else()
@@ -448,7 +448,7 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
448448
target_compile_definitions(snmallocshim-checks-rust PRIVATE SNMALLOC_CHECK_CLIENT)
449449
endif()
450450

451-
if (BUILD_TESTING)
451+
if (SNMALLOC_BUILD_TESTING)
452452
if (WIN32
453453
OR (CMAKE_SYSTEM_NAME STREQUAL NetBSD)
454454
OR (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
@@ -496,7 +496,7 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
496496
set(DEFINES "SNMALLOC_CHECK_CLIENT_MITIGATIONS=${MITIGATION}")
497497
add_shim(snmallocshim-${MITIGATION} SHARED ${SHIM_FILES})
498498
target_compile_definitions(snmallocshim-${MITIGATION} PRIVATE ${DEFINES})
499-
if (BUILD_TESTING)
499+
if (SNMALLOC_BUILD_TESTING)
500500
make_tests(${MITIGATION} ${DEFINES})
501501
endif()
502502
endforeach()
@@ -511,13 +511,15 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
511511
set(DEFINES "-DSNMALLOC_CHECK_CLIENT_MITIGATIONS=${MITIGATIONSET}")
512512
add_shim(snmallocshim-${MITIGATIONNAME} SHARED ${SHIM_FILES})
513513
target_compile_definitions(snmallocshim-${MITIGATIONNAME} PRIVATE ${DEFINES})
514-
if (BUILD_TESTING)
514+
if (SNMALLOC_BUILD_TESTING)
515515
make_tests(${MITIGATIONNAME} ${DEFINES})
516516
endif()
517517
endforeach()
518518
endif()
519519

520-
clangformat_targets()
520+
if (SNMALLOC_BUILD_TESTING)
521+
clangformat_targets()
522+
endif ()
521523
endif()
522524

523525
install(TARGETS snmalloc EXPORT snmallocConfig)

0 commit comments

Comments
 (0)