cpp-best-practices / gui_starter_template

A template CMake project to get you started with C++ and tooling
The Unlicense
2.5k stars 447 forks source link

PROJECT_IS_TOP_LEVEL in test/CMakeLists.txt is not set prior to CMake 3.21 #220

Open bgd54 opened 2 years ago

bgd54 commented 2 years ago

Hi! Thanks for this project! When I use CMake 3.18 on the top level CMakeLists.txt I get the error:

[gui_starter_template]$ mkdir build [gui_starter_template]$ cd build [build]$ cmake .. //... CMake Warning (dev) at CMakeLists.txt:139 (message): Building Tests. Be sure to check out test/constexpr_tests.cpp for constexpr testing This warning is for project developers. Use -Wno-dev to suppress it.

CMake Error at test/CMakeLists.txt:10 (find_package): Could not find a package configuration file provided by "myproject" with any of the following names:

myprojectConfig.cmake
myproject-config.cmake

Add the installation prefix of "myproject" to CMAKE_PREFIX_PATH or set "myproject_DIR" to a directory containing one of the above files. If "myproject" provides a separate development package or SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred!

The variable is previously set by the top level CMakeLists.txt or the last project() call (CMake 3.21+). My understanding is that with CMake 3.21+ in test/CMakeLists.txt the project() call will set PROJECT_IS_TOP_LEVEL to OFF, while with older CMake versions the variable keeps its original value(1) from: https://github.com/cpp-best-practices/gui_starter_template/blob/849f985489e34992ab01d475043f54bc076416a2/CMakeLists.txt#L42