Skip to content

Conversation

@traversaro
Copy link
Contributor

@traversaro traversaro commented Apr 7, 2025

We had a failure in a project that included serial_cpp via FetchContent, as it started to enable BUILD_TESTING, and we experience the failure:

CMake Error at /home/runner/micromamba/envs/internalprojectenv/share/cmake-4.0/Modules/FindPackageHandleStandardArgs.cmake:227 (message):
  Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
  GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
  /home/runner/micromamba/envs/internalprojectenv/share/cmake-4.0/Modules/FindPackageHandleStandardArgs.cmake:591 (_FPHSA_FAILURE_MESSAGE)
  /home/runner/micromamba/envs/internalprojectenv/share/cmake-4.0/Modules/FindGTest.cmake:273 (find_package_handle_standard_args)
  build/_deps/serial_cpp-src/tests/CMakeLists.txt:2 (find_package)

The additional dependency on GTest if one enable BUILD_TESTING definitely breaks POLA.

A more user-friend behavior is to disable tests if PROJECT_IS_TOP_LEVEL is OFF, unless someone really needs them enabled, in that case the new advanced option serial_cpp_FORCE_RESPECT_BUILD_TESTING can be used to force them to be enabled even if PROJECT_IS_TOP_LEVEL is OFF.

@traversaro traversaro changed the title Do not add tests if PROJECT_IS_TOP_LEVEL is OFF Do not add tests if project is included via add_subdirectory/FetchContent Apr 7, 2025
Copy link

@dariosortino dariosortino left a comment

Choose a reason for hiding this comment

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

Honestly way out of my knowledge but approving to ack the modification

@traversaro traversaro merged commit ff106b6 into main Apr 7, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants