CMake Cache Issue

Hi everybody. I have a problem with CMake cache and FindBoost module. I use CMake 4.0; however, I have experienced this in the past with other versions as well.

My subdirectory (src) CMakeFiles.txt includes this for finding Boost:

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost 1.87.0 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

Presets configure part looks like this:

 "configurePresets": [
   {
     "name": "windows-base",
     "description": "Target Windows with the Visual Studio development environment.",
     "hidden": true,
     "generator": "Ninja",
     "binaryDir": "${sourceDir}/out/build/${presetName}",
     "installDir": "${sourceDir}/out/install/${presetName}",
     "cacheVariables": {
       "CMAKE_C_COMPILER": "cl.exe",
       "CMAKE_CXX_COMPILER": "cl.exe"
     },
     "condition": {
       "type": "equals",
       "lhs": "${hostSystemName}",
       "rhs": "Windows"
     }
   },
   {
     "name": "x64-debug",
     "displayName": "x64 Debug",
     "description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)",
     "hidden": true, // temporary
     "inherits": "windows-base",
     "architecture": {
       "value": "x64",
       "strategy": "external"
     },
     "cacheVariables": {
       "CMAKE_BUILD_TYPE": "Debug",
       "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
     }
   }
 ],

Even though there is a vcpkg tool chain specified, I have Boost installed manually.

In the UserPresets file I also have a hint variable:

  "configurePresets": [
    {
      "name": "x64-debug-user",
      "displayName": "x64 Debug User",
      "description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug) (User)",
      "inherits": "x64-debug",
      "cacheVariables": {
        "Boost_DIR": "C:\\Boost\\lib\\cmake\\Boost-1.87.0"
      }
    }
  ],

The problem I experience is with the error below:

1> [CMake] CMake Error at src/CMakeLists.txt:7 (find_package):
1> [CMake]   By not providing "FindBoost.cmake" in CMAKE_MODULE_PATH this project has
1> [CMake]   asked CMake to find a package configuration file provided by "Boost", but
1> [CMake]   CMake did not find one.
1> [CMake] 
1> [CMake]   Could not find a package configuration file provided by "Boost" (requested
1> [CMake]   version 1.87.0) with any of the following names:
1> [CMake] 
1> [CMake]     BoostConfig.cmake
1> [CMake]     boost-config.cmake
1> [CMake] 
1> [CMake]   Add the installation prefix of "Boost" to CMAKE_PREFIX_PATH or set
1> [CMake]   "Boost_DIR" to a directory containing one of the above files.  If "Boost"
1> [CMake]   provides a separate development package or SDK, be sure it has been
1> [CMake]   installed.
1> [CMake] 
1> [CMake] 
1> [CMake] -- Configuring incomplete, errors occurred!

I found a way to fix it by deleting CMakeFiles directory, after than I reconfigure, and the error goes away. “Project → Delete cache and Reconfigure” in Visual Studio won’t work though.

Everything works when the error goes away, but it returns eventually, usually when I reopen the project.

So, in summary, my question is how to fix the issue with boost search and the need to delete CMakeFiles to fix it.

Thank you.

The FindBoost module is deprecated as of 3.30; did you know that?

See https://cmake.org/cmake/help/latest/module/FindBoost.html

Only the old part of it is, isn’t it? My project is searching for BoostConfig.cmake, which is the modern way and not deprecated.

Well, the error message is explicitly telling you that it couldn’t find any of those, so I suggest you enable more verbose/debug output to understand exactly what is going on.

Probably you didn’t read my message fully. I don’t have the problem with it finding it, this problem goes away after I delete CMakeFiles folder and regenerate - project works fine and Boost is successfully detected.