Avoid including CTest in if this is not a top-level cmake project because as reported https://github.com/chaincodelabs/libmultiprocess/pull/145#issuecomment-2644563297 this adds a BUILD_TESTING option could be confused for Bitcoin core's BUILD_TESTS option.
cmake: Avoid including CTest if not top level project #161
pull ryanofsky wants to merge 1 commits into bitcoin-core:master from ryanofsky:pr/notest changing 1 files +1 −1-
ryanofsky commented at 5:23 AM on February 10, 2025: collaborator
-
a7f0669320
cmake: Avoid including CTest if not top level project
Reported https://github.com/chaincodelabs/libmultiprocess/pull/145#issuecomment-2644563297 this creates confusion in the bitoin core project because it adds a BUILD_TESTING variable which is confusing because bitcoin core uses a different BUILD_TESTS variable.
-
ryanofsky commented at 5:24 AM on February 10, 2025: collaborator
Marking as a draft for now because this change seems to result in
mptestnot being found by ctest in Bitcoin core project. I assume some other change is needed there to be compatible with this, but I'm not sure what that would be. -
hebasto commented at 9:13 AM on February 10, 2025: member
Marking as a draft for now because this change seems to result in
mptestnot being found by ctest in Bitcoin core project. I assume some other change is needed there to be compatible with this, but I'm not sure what that would be.Maybe
set(BUILD_TESTING ON)inbitcoin/src/ipc/CMakeLists.txtbefore callingadd_subdirectory(libmultiprocess)?This will satisfy the following condition: https://github.com/chaincodelabs/libmultiprocess/blob/26b9f3dda42110a8ffa5e81b0ea78ba1e30ae659/test/CMakeLists.txt#L22
-
ryanofsky commented at 1:31 PM on February 10, 2025: collaborator
Thanks will experiment, but do you think
set(BUILD_TESTING ${BUILD_TESTS})make sense? Or should BUILD_TESTS not be followed?In general I'm pretty confused about this situation. I don't understand why bitcoin is using a different variable name and not including ctest when both bitcoin and libmultiprocess cmake projects appear to be using ctest. Is bitcoin using ctest in a different way than libmultiprocess is using ctest?
-
hebasto commented at 1:45 PM on February 10, 2025: member
Thanks will experiment, but do you think
set(BUILD_TESTING ${BUILD_TESTS})make sense?Yes, it does. We do the same for the
secp256k1subtree.In general I'm pretty confused about this situation. I don't understand why bitcoin is using a different variable name and not including ctest when both bitcoin and libmultiprocess cmake projects appear to be using ctest. Is bitcoin using ctest in a different way than libmultiprocess is using ctest?
For Bitcoin Core's test suite, different executables and commands are used, including
test_bitcoin,test_bitcoin-qt,bench_bitcoinand a few of Python scripts. Using CTest'sBUILD_TESTINGvariable to control the configuration of these targets seems confusing. Additionally, theBUILD_TESTSandBUILD_BENCHvariables inherit the corresponding Autotools' options—namely,--disable-testsand--disable-bench. -
ryanofsky commented at 1:49 PM on February 10, 2025: collaborator
Using CTest's BUILD_TESTING variable to control the configuration of these targets seems confusing.
This is the part I don't understand. We are using ctest so why would it be confusing to use the ctest variable and less confusing to have our own similarly named variable?
-
hebasto commented at 2:17 PM on February 10, 2025: member
Using CTest's BUILD_TESTING variable to control the configuration of these targets seems confusing.
This is the part I don't understand. We are using ctest so why would it be confusing to use the ctest variable and less confusing to have our own similarly named variable?
Hmm, I was going to respond with the following example:
$ cmake -B build -DBUILD_TESTS=OFF -DBUILD_BENCH=ON $ cmake --build build -j $(nproc) $ ctest --test-dir build Internal ctest changing into directory: /home/hebasto/git/bitcoin/build Test project /home/hebasto/git/bitcoin/build Start 1: util_rpcauth_test 1/2 Test [#1](/bitcoin-core-multiprocess/1/): util_rpcauth_test .................. Passed 0.12 sec Start 2: bench_sanity_check_high_priority 2/2 Test [#2](/bitcoin-core-multiprocess/2/): bench_sanity_check_high_priority ... Passed 5.73 sec 100% tests passed, 0 tests failed out of 2 Total Test time (real) = 5.85 secHowever, due to the following (buggy?) code:
if(BUILD_TESTS) enable_testing() endif()my example is broken, and the semantics of
BUILD_TESTSare indistinguishable from those ofBUILD_TESTING.UPD. Bitcoin Core's code should have
enable_testing()unconditionally. -
ryanofsky commented at 2:39 PM on February 10, 2025: collaborator
I see, so the idea that you want BUILD_TESTS to specifically control whether or not test_bitcoin executable is built, and want BUILD_TESTING as an option for whether to require ctest to simply not exist and always be forced on? That seems reasonable and consistent.
I will say this is not the approach I would take if I were designing the cmake build. IMO, it makes more sense to have options to control whether dependencies are used, not whether targets are built. So having a BUILD_TESTING option to control whether ctest is used seems useful, and having a BUILD_TEST option to control whether test_bitcoin is built seems less useful. But your approach is consistent and I think it should work.
I think I will merge this PR, and then in https://github.com/bitcoin/bitcoin/pull/31741 I can decide what to do to support it. I could do
set(BUILD_TESTING ON)and add a comment about how bitcoin build always requires ctest so this option is forced on. I couldset(BUILD_TESTING ${BUILD_TESTS})and letBUILD_TESTScontrol whether unit tests are built in general. Or I could add a separate option to control whether libmultiprocess unit tests are built. - ryanofsky merged this on Feb 10, 2025
- ryanofsky closed this on Feb 10, 2025
- Sjors referenced this in commit 6aabfcb615 on Feb 10, 2025
- Sjors referenced this in commit 1746618e08 on Feb 13, 2025
- ryanofsky referenced this in commit 83e40d3b52 on Feb 24, 2025
- ryanofsky referenced this in commit 8619f03ec2 on Feb 24, 2025
- ryanofsky referenced this in commit cbb7b41c20 on Feb 24, 2025
- fanquake referenced this in commit 01f7715766 on Feb 25, 2025
- fanquake referenced this in commit ba0a4391ff on Feb 25, 2025
- janus referenced this in commit 86cb86b050 on Sep 1, 2025
- bitcoin-core locked this on Feb 10, 2026