Search code examples
vcpkg

vcpkg doesn't work if I try a different clang version?


I'm building a C++ program on macOS. I want to try clang from the clang website, rather than the default that comes with Xcode from Apple. I downloaded a binary build of clang+llvm, unpacked it and added this line to my root CMakeLists.txt:

set(CMAKE_CXX_COMPILER /MyStuff/clang+llvm-15.0.1-x86_64-apple-darwin/bin/clang++)

Now I get errors from CMake:

CMake Error at CMakeLists.txt:20 (find_package):
  Could not find a package configuration file provided by "range-v3" with any
  of the following names:

    range-v3Config.cmake
    range-v3-config.cmake

That range-v3 is a package for a C++ library that I had installed with vcpkg.

Do I need to somehow update vcpkg to use the newer clang? How?

Here's my cmake command line:

cmake -B build-debug -S . -DCMAKE_TOOLCHAIN_FILE=/Users/rob/Dev/vcpkg/scripts/buildsystems/vcpkg.cmake

Update

I started using manifest mode. Here is my vcpkg.json

{
  "name": "memogu",
  "version-string": "0.1.0",
  "dependencies": [
    "fmt",
    "range-v3",
    "stduuid",
    "date"
  ]
}

Solution

  • CMAKE_CXX_COMPILER needs to be set before project() or enable_language() since it runs compiler detection at that point. If it is set afterwards CMake will detect that change and try to reconfigure the project. If it is done without a cache variable you'll end up with an infinite reconfigure loop.
    CMAKE_CXX_COMPILER should either be set via the cmd line or via a cmake toolchain file.

    To provide a toolchain with vcpkg you can either use VCPKG_CHAINLOAD_TOOLCHAIN_FILE or provide your toolchain as CMAKE_TOOLCHAIN_FILE and just include(vcpkg.cmake) in your toolchain or in the CMakeLists.txt before project()