Closed sgaisser closed 2 years ago
Great find. Please feel free to issue a PR changing that variable-name.
Which is not a bad thing though. Actually the standard name is BUILD_TESTING
, which is made available automatically when using include(CTest) -> This also sets enable_testing().
So this should be rather used.
Using the standard names is a good thing, because then people don't have to relearn options for each lib. It's the same with BUILD_SHARED_LIBS
. Most libraries use this variable for determining if the library should be static or shared. In fact it's kinda baked into cmake, if you specify just add_library() without STATIC / SHARED.
If you have name clashes with say Fetch_Content then use scopes. For instance:
# This is a new file dependencies/the_lib_I_use
set(BUILD_TESTING OFF)
FetchContent_MakeAvailable(lib_i_use)
This will just set the variable in this scope, so in this file. Also works with functions.
So I would recommend:
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
)I'm totally agreeing with you.
I someone would make a pull-request, I gladly integrate it.
Hi @pboettch, I think this could be closed.
During testing I found a Problem with a non-prefixed cmake option "BUILD_TESTS". This is a very common name which might collide with user options. Other libraries usually use something with the library name e.g. nlohmann/json uses JSON_BuildTests.