Build libowfat tests with asserts enabled

This commit is contained in:
OpenAI
2026-06-03 11:34:51 +00:00
committed by Mario Fetka
parent 9c4faae381
commit dfac00bd51

View File

@@ -291,10 +291,23 @@ elseif(LIBOWFAT_BUILD_STATIC)
add_library(libowfat::libowfat ALIAS libowfat_static)
endif()
function(_libowfat_disable_ndebug target)
# A number of upstream unit tests use assert() for all checks and deliberately
# refuse to compile when NDEBUG is set by a Release build. Compile tests with
# asserts enabled and without optimisation even when the library itself is built
# as Release, matching the intent of the original test programs.
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${target} PRIVATE -UNDEBUG -O0)
elseif(MSVC)
target_compile_options(${target} PRIVATE /UNDEBUG)
endif()
endfunction()
if(LIBOWFAT_RUN_SELF_TESTS)
add_executable(libowfat_smoke_t "${CMAKE_CURRENT_SOURCE_DIR}/t.c")
target_link_libraries(libowfat_smoke_t PRIVATE libowfat::libowfat)
_libowfat_disable_ndebug(libowfat_smoke_t)
add_test(NAME libowfat_smoke_t COMMAND libowfat_smoke_t)
set_tests_properties(libowfat_smoke_t PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
@@ -306,6 +319,7 @@ if(LIBOWFAT_BUILD_TEST_PROGRAMS)
string(MAKE_C_IDENTIFIER "libowfat_test_${_test_name}" _test_target)
add_executable(${_test_target} "${_test_src}")
target_link_libraries(${_test_target} PRIVATE libowfat::libowfat)
_libowfat_disable_ndebug(${_test_target})
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${_test_target} PRIVATE
-Wno-error=implicit-int