Repository navigation
Conversation
| set(CMAKE_CXX_STANDARD 14) | ||
|
|
||
| option(RUY_ENABLE_TESTS "Enable ruy's tests" ON) | ||
| if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) |
There was a problem hiding this comment.
This appears to be the canonical way to do this: https://cliutils.gitlab.io/modern-cmake/chapters/testing.html
Maybe better?
There was a problem hiding this comment.
Thanks for bringing this up! I took a look, then I realized that I wanted something different for ruy:
- The switch that I really want is not just "whether to build tests", it's "whether to build anything more than just the ruy public libraries", so it's not just about tests, it's also about the examples and in the future about docs.
- What this page offers is not a drop-in replacement, because it results in having to replicate the
CMAKE_PROJECT_NAME STREQUAL PROJECT_NAMEcondition everywhere theBUILD_TESTINGvariable is checked. Indeed, in CTest.cmake,BUILD_TESTINGis defined to have default valueONunconditionally. That in turns require another variable to override when people really want to enable tests in a dependency, so they end up suggesting that I write this:
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(tests)
endif()
I prefer the way it's done in the commit that I just pushed, are you OK? (i've tested it locally).
There was a problem hiding this comment.
I think not building things is mostly covered by EXCLUDE_FROM_ALL when included by a dependency. It won't get built unless someone specifically requests that target. The ifs are only necessary to avoid configuring things at all. Tests work a bit differently, for some reason in that they get added to the default ctest target even if they come from a subdirectory that is EXCLUDE_FROM_ALL, which is why they need the special handling. This seems fine though. I agree that having to check the project name everywhere would be a pain.
|
|
||
| if (NOT RUY_MINIMAL_BUILD) | ||
| add_subdirectory("example") | ||
| endif() No newline at end of file |
There was a problem hiding this comment.
Nit: newline at end of file
| endif() | ||
|
|
||
| if (NOT TARGET gtest) | ||
| if (NOT RUY_MINIMAL_BUILD AND NOT TARGET gtest) |
There was a problem hiding this comment.
I mentioned this on another PR, post-commit, but another thing I thought of that works particularly well for submodules is to check for the existence of a CMakeLists.txt in the directory. If someone hasn't initialized the ruy submodules, then the directory will be empty, so it will not exist. This works gracefully with a project using ruy as a submodule and not using recursive submodules without having to worry about the order in which things are defined.
| set(CMAKE_CXX_STANDARD 14) | ||
|
|
||
| option(RUY_ENABLE_TESTS "Enable ruy's tests" ON) | ||
| if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) |
There was a problem hiding this comment.
I think not building things is mostly covered by EXCLUDE_FROM_ALL when included by a dependency. It won't get built unless someone specifically requests that target. The ifs are only necessary to avoid configuring things at all. Tests work a bit differently, for some reason in that they get added to the default ctest target even if they come from a subdirectory that is EXCLUDE_FROM_ALL, which is why they need the special handling. This seems fine though. I agree that having to check the project name everywhere would be a pain.
Closes google/ruy#249 COPYBARA_INTEGRATE_REVIEW=google/ruy#249 from bjacob:tests-disabled-when-submodule 3a33bb081acadca3520edeae2c226827e9fe0f89 PiperOrigin-RevId: 353298619
Closes google/ruy#249 COPYBARA_INTEGRATE_REVIEW=google/ruy#249 from bjacob:tests-disabled-when-submodule 3a33bb081acadca3520edeae2c226827e9fe0f89 PiperOrigin-RevId: 353298619
No description provided.