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.

A quite weird problem. Here I run the same command two times without changing anything. Everything works fine in the first run and breaks in the second.

> cmake --preset x64-debug-user
-- The C compiler identification is MSVC 19.43.34809.0
-- The CXX compiler identification is MSVC 19.43.34809.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx86/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.8s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_TOOLCHAIN_FILE


-- Build files have been written to: D:/Dev/Edu/Server/out/build/x64-debug-user
> cmake --preset x64-debug-user
-- Configuring done (0.1s)
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= cl.exe
CMAKE_CXX_COMPILER= cl.exe

-- The C compiler identification is MSVC 19.43.34809.0
-- The CXX compiler identification is MSVC 19.43.34809.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx86/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at src/CMakeLists.txt:7 (find_package):
  By not providing "FindBoost.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Boost", but
  CMake did not find one.

  Could not find a package configuration file provided by "Boost" (requested
  version 1.87.0) with any of the following names:

    BoostConfig.cmake
    boost-config.cmake

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


-- Configuring incomplete, errors occurred!

Solution: vcpkg conflicted with manual finding process. In the Microsoft documentation it stated that find_package first finds manually and then executes vcpkg, but that’s doesn’t appear to be so. I now have two user-presets, one of them with vcpkg toolchain.