RFC: Make ECMAddTests respect BUILD_TESTING
ClosedPublic

Authored by kfunk on Aug 7 2017, 1:53 PM.

Details

Summary

Use-case: Make building unit tests optional, by just following the CMake
BUILD_TESTING option.

The usual approach to conditionally build tests is to do:

if (BUILD_TESTING)
    add_executable(TestOne TestOne.cpp)
    target_link_libraries(TestOne my_library)
endif()

or:

if (BUILD_TESTING)
    add_subdirectory(tests)
endif()

This patch just turns all calls to ecm_add_test(...) into no-ops if
BUILD_TESTING=OFF.

See:

https://cmake.org/cmake/help/v3.6/module/CTest.html

Diff Detail

Repository
R240 Extra CMake Modules
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
kfunk created this revision.Aug 7 2017, 1:53 PM
Restricted Application added projects: Frameworks, Build System. · View Herald TranscriptAug 7 2017, 1:53 PM
Restricted Application added subscribers: Build System, Frameworks. · View Herald Transcript
kfunk updated this revision to Diff 17830.Aug 7 2017, 1:54 PM

Remove unrelated hunks

kfunk added a comment.Aug 7 2017, 1:55 PM

It's not possible to easily disable tests at the moment, is it? I might be missing something.

Anyhow, this patch tries to make it easy to build KDevelop without tests; trying to avoid hacky approaches like those being done in Gentoo:

https://bugs.gentoo.org/show_bug.cgi?id=627242
kfunk updated this revision to Diff 17835.Aug 7 2017, 2:19 PM

Fix typo. "no-top" is something else.

In ecm_mark_as_test (which is used in ecm_add_test) we already disable the target if BUILD_TESTING is false, why is that not enough?

kfunk added a comment.Aug 7 2017, 2:44 PM

In ecm_mark_as_test (which is used in ecm_add_test) we already disable the target if BUILD_TESTING is false, why is that not enough?

Good question. I didn't explain that in the commit message:

ecm_add_test also invokes target_link_libraries(...) which may pull in additionally dependencies if BUILD_TESTING=ON.

Example:

ecm_add_test(test_svnrecursiveadd.cpp LINK_LIBRARIES
    Qt5::Test Qt5::Gui
)
  • If BUILD_TESTING=OFF & without this patch: We still need Qt5::Test around.
  • If BUILD_TESTING=OFF & with this patch: We no longer need Qt5::Test at all.

This patch actually makes it pretty easy to get rid off the Qt5::Test dependency in a whole KDE project without touching lots of CMake code.

Oh, I see. +1 then!

In D7187#133331, @kfunk wrote:

Anyhow, this patch tries to make it easy to build KDevelop without tests; trying to avoid hacky approaches like those being done in Gentoo:

Much appreciated if we can drop those.

vkrause added a subscriber: vkrause.Aug 7 2017, 5:46 PM

Another +1, would also help the KDE Yocto recipes.

kfunk added a comment.Aug 7 2017, 6:09 PM

Guys... no one gave me an "Accepted' yet :)

kossebau added a subscriber: kossebau.EditedAug 7 2017, 6:21 PM

+1 as well. Please also add a note in the API dox what BUILD_TESTING will do on this macro, so this is not magic behaviour and people can plan with this (like making sure to not set target_link_libraries(... Qt5::Tests) separately, but only pass as args in the macro *cough*kdevelop*cough*)

kfunk added a comment.Aug 7 2017, 6:22 PM

+1 as well. Please also add a note in the API dox what BUILD_TESTING will do on this macro, so this is not magic behaviour and people can plan with this (like making sure to not set target_link_libraries(... Qt5::Tests) separately, but only pass as args in the macro *cough*kdevelop*cough*)

Will do.

vkrause accepted this revision.Aug 7 2017, 7:41 PM
This revision is now accepted and ready to land.Aug 7 2017, 7:41 PM
This revision was automatically updated to reflect the committed changes.