Skip to content

Disable tests by default when ruy is a subproject. - #249

Closed
bjacob wants to merge 3 commits into
google:masterfrom
bjacob:tests-disabled-when-submodule
Closed

bjacob wants to merge 3 commits into
google:masterfrom
bjacob:tests-disabled-when-submodule

Conversation

@bjacob

@bjacob bjacob commented Jan 22, 2021

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread CMakeLists.txt
set(CMAKE_CXX_STANDARD 14)

option(RUY_ENABLE_TESTS "Enable ruy's tests" ON)
if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing this up! I took a look, then I realized that I wanted something different for ruy:

  1. 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.
  2. What this page offers is not a drop-in replacement, because it results in having to replicate the CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME condition everywhere the BUILD_TESTING variable is checked. Indeed, in CTest.cmake, BUILD_TESTING is defined to have default value ON unconditionally. 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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread CMakeLists.txt Outdated

if (NOT RUY_MINIMAL_BUILD)
add_subdirectory("example")
endif() No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread CMakeLists.txt Outdated
endif()

if (NOT TARGET gtest)
if (NOT RUY_MINIMAL_BUILD AND NOT TARGET gtest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, done!

Comment thread CMakeLists.txt
set(CMAKE_CXX_STANDARD 14)

option(RUY_ENABLE_TESTS "Enable ruy's tests" ON)
if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

liujinye-sys pushed a commit to open-vela/apps_math_ruy that referenced this pull request Jul 23, 2025
Closes google/ruy#249

COPYBARA_INTEGRATE_REVIEW=google/ruy#249 from bjacob:tests-disabled-when-submodule 3a33bb081acadca3520edeae2c226827e9fe0f89
PiperOrigin-RevId: 353298619
liujinye-sys pushed a commit to open-vela/apps_math_ruy that referenced this pull request Dec 16, 2025
Closes google/ruy#249

COPYBARA_INTEGRATE_REVIEW=google/ruy#249 from bjacob:tests-disabled-when-submodule 3a33bb081acadca3520edeae2c226827e9fe0f89
PiperOrigin-RevId: 353298619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants