Thanks for the replies! I will close this PR because as obnoxious as find_package(Threads REQUIRED) behavior is for producing misleading error and hiding useful debug information, the REQUIRED keyword actually does seem to be used in bitcoin core and leveldb, so maybe it is not as much as a problem for others as it has been for me. And there could be other ways of avoiding harms like #352, or maybe moving the find_package call later so more useful errors can be triggered earlier. When I first made this change a year ago as part of #209, I didn't know techniques for debugging find_package errors and found this very confusing, but now I won't have this problem anymore.
Sorry for pushing back earlier. I pushed back because review comments were arguing against removing REQUIRED without acknowledging the harms it caused or pointing to any benefits it offered. But thinking about it more, one real benefit that REQUIRED offers is more predictability and less variance between builds. For example with 45c7dca6a55c2892d2b1b177123a3dea71d15090, if libmultiprocess is built on two openbsd systems, and one has clang-scan-deps installed and one doesn't, find_package may succeed on one system and fail on the other causing the library to be built with slightly different threading flags even if both builds succeed and are usable.
I still think 45c7dca6a55c2892d2b1b177123a3dea71d15090 is a correct change, just that benefits may not outweigh this cost. It is correct because the cmake FindThreads module is not a hard dependency of libmultiprocess (unlike Cap'n Proto). FindThreads is just a convenience module provided with cmake to help with portability and it is perfectly possible to write multithreaded code without it, avoiding its warts and bugs.
re: purpleKarrot #354 (review)
The docs are wrong.
Is there something we can report upstream? Can you share the situation and output of the suppressed diagnostics?
I encountered these errors a year ago but you can see the error output in 45c7dca6a55c2892d2b1b177123a3dea71d15090 commit message and the CMAKE_CXX_SCAN_FOR_MODULES bug is reported upstream https://gitlab.kitware.com/cmake/cmake/-/work_items/27228. I described the bad CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES/ FindThreads interaction in #163 (comment) with steps to reproduce and you actually replied to that and seemed to think it was the same underlying bug.
re: maflcko #354 (comment)
Ok, what I wanted to say was that this doesn't practically happen in reality. Someone changing the policy isn't something a real end-user does, but more a dev-only thing.
I don't think this is true because these errors depend on individual platform configurations. The same policies can work on one platform and cause problems on other platforms and this is exactly what we seen with FindThreads where the bug isn't even really triggered by the platform, but just by what packages are currently installed. Better error output is better for everyone and is not just a temporary development need.
re: hebasto #354#pullrequestreview-5029651423
In the following example, the build fails during the linking stage because it doesn't configure the thread library properly:
That example seems to be artificial (setup is not described) unlike the real examples in the commit message, and even in that case cannot find -lpthread seems like a much better error than Could NOT find Threads (missing: Threads_FOUND) would be because it points to a clear cause.