From 5f6a21d56404ad34aa01deca48ff41aae50d4613 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Wed, 21 Jul 2021 15:24:11 +0100 Subject: ecm_add_test: add -DQT_FORCE_ASSERTS to compile flags by default While debugging a failing test (KProcessTest in KCoreAddons), I noticed that the Q_ASSERT() statements inside that test weren't being executed because RelWithDebInfo builds default to passing -DQT_NO_DEBUG. With this change the test I was debugging now asserts early instead of failing a QCOMPARE later on. --- modules/ECMAddTests.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index de965f06..58c78d05 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -34,6 +34,9 @@ of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). Be aware that this changes the executable entry point on Windows (although some frameworks, such as Qt, abstract this difference away). +The tests will be build with -DQT_FORCE_ASSERTS to enable assertions in the +test executable even for release builds. + The TARGET_NAMES_VAR and TEST_NAMES_VAR arguments, if given, should specify a variable name to receive the list of generated target and test names, respectively. This makes it convenient to apply properties to them as a @@ -92,6 +95,7 @@ function(ecm_add_test) endif() add_test(NAME ${_testname} COMMAND ${_targetname}) target_link_libraries(${_targetname} ${ARG_LINK_LIBRARIES}) + target_compile_definitions(${_targetname} PRIVATE -DQT_FORCE_ASSERTS) ecm_mark_as_test(${_targetname}) if (CMAKE_LIBRARY_OUTPUT_DIRECTORY) if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") -- cgit v1.2.1