Skip to content

Commit 2fa3f3e

Browse files
committed
Prevent broken tests related statements when BUILD_TESTING is OFF
1 parent 37ae7ee commit 2fa3f3e

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎DataFormats/Detectors/Common/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ o2_add_test(CTFEntropyCoder
6060
COMPONENT_NAME DetectorsCommonDataFormats
6161
TARGETVARNAME TEST_CTF_ENTROPY_CODER
6262
LABELS detectorsbase)
63-
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
63+
if(BUILD_TESTING AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
6464
target_compile_options(${TEST_CTF_ENTROPY_CODER} PRIVATE -march=native)
6565
endif()

‎Utilities/rANS/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ if(${ENABLE_VTUNE_PROFILER})
5151
target_link_libraries(${LIBRANS} INTERFACE PkgConfig::Vtune)
5252
endif()
5353

54+
# o2_add_test() returns early when BUILD_TESTING is off, so TARGETVARNAME is
55+
# never set and the target_compile_options() below would see an empty target.
56+
if(BUILD_TESTING)
5457
o2_add_test(Utils
5558
NAME ransUtils
5659
SOURCES test/test_ransUtils.cxx
@@ -186,6 +189,7 @@ o2_add_test(Serialize
186189
TARGETVARNAME TEST_SERIALIZE
187190
LABELS utils)
188191
target_compile_options(${TEST_SERIALIZE} PRIVATE ${RANS_TEST_ARCH})
192+
endif()
189193

190194
if (TARGET benchmark::benchmark)
191195
o2_add_header_only_library(libransBenchmark

‎cmake/O2AddTest.cmake‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ include(O2AddExecutable)
6363

6464
function(o2_add_test)
6565

66-
if(NOT BUILD_TESTING)
67-
return()
68-
endif()
69-
7066
cmake_parse_arguments(
7167
PARSE_ARGV
7268
1
@@ -80,6 +76,16 @@ function(o2_add_test)
8076
message(FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
8177
endif()
8278

79+
# Parsed before this check so TARGETVARNAME can be defined (empty) even when
80+
# no target is made: `if(VAR)` at the call site is then reliable, and a value
81+
# left by an earlier call cannot leak into it.
82+
if(NOT BUILD_TESTING)
83+
if(A_TARGETVARNAME)
84+
set(${A_TARGETVARNAME} "" PARENT_SCOPE)
85+
endif()
86+
return()
87+
endif()
88+
8389
set(testName ${ARGV0})
8490

8591
set(linkLibraries ${A_PUBLIC_LINK_LIBRARIES})

0 commit comments

Comments
 (0)