cpp-best-practices/cmake_template

Checking version doesn't work

1aam2am1 opened this issue · 0 comments

add_test(NAME cli.version_matches COMMAND intro --version)
set_tests_properties(cli.version_matches PROPERTIES PASS_REGULAR_EXPRESSION "${PROJECT_VERSION}")

Doesn't work as PROJECT_VERSION is version from

project(CmakeConfigPackageTests LANGUAGES CXX)

and not from root project.

We can use CMAKE_PROJECT_VERSION, but this will break tests when our project isn't top one.

But this should work as we return if

# Don't even look at tests if we're not top level
if(NOT PROJECT_IS_TOP_LEVEL)
  return()
endif()