6

I am testing vcpkg for my project and I came across a problem with cmake-gui

I have installed vcpkg, with the help of vcpkg Boost libraries were installed. When I compile via command line, everything works as it should. I use command

cmake .. -DCMAKE_TOOLCHAIN_FILE=D:/repos/vcpkg/scripts/buildsystems/vcpkg.cmake -G"Visual Studio 15 Win64"

But the problem is when I want to use cmake-gui to generate build files. It reports that Boost is not found.

I tried to add

set(CMAKE_TOOLCHAIN_FILE "D:/repos/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Path for vcpkg.cmake")

to the top of my Makefile, but it did not help. I also tried with add_definitions and add_compile_options, without success.

So what should I add to my cmake file to be able to use cmake-gui with vcpkg ?

JoeFromVienna
  • 71
  • 1
  • 3

2 Answers2

4

I know this question is a bit old but I recently ran into this issue myself.

One thing that worked for me is to add an entry using the "add entry" button at the top right of the GUI (see below).

enter image description here

I then added the following to my cmake lists:

if(CMAKE_TOOLCHAIN_FILE)
    include(${CMAKE_TOOLCHAIN_FILE})
endif(CMAKE_TOOLCHAIN_FILE)

Note that I did this after I had already configured the project (so the CMakeCache.txt had already been generated at this point.

Developer Paul
  • 1,502
  • 2
  • 13
  • 18
1

I had the same problem and solved it by modifying the CMakeLists.txt file
Enter vcpkg integrate install in the terminal to see your own path,for me ,it as follow:

Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake"
...

Add the following to the CMakeLists.txt file (Note, it must be placed before project)

SET(CMAKE_TOOLCHAIN_FILE "C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake")
Kargath
  • 450
  • 5
  • 15
  • local configuration should never be part of `CMakeLists.txt` since it is local setting which will impact other developers (for example working on Linux). So your answer is wrong. Anyway in comment there was duplicate proposal, which properly solve the problem (what OP confirms). So I've closed question as duplicate using linked SO question. – Marek R Nov 14 '22 at 10:08
  • @MarekR I noticed [someone mentioned the link](https://stackoverflow.com/questions/29982505/setting-a-cross-compiler-file-using-the-cmake-gui) in the comments of the question, But that question doesn't make it clear that CMAKE_TOOLCHAIN_FILE and DCMAKE_TOOLCHAIN_FILE are the same thing, I'm answering this question to illustrate that. – Kargath Nov 15 '22 at 16:12
  • I'm just nitpicking on `SET(CMAKE_TOOLCHAIN_FILE "C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake")`. Yes it will work (on single machine), but this is bad solution. You can't commit this into shared repository. – Marek R Nov 15 '22 at 16:37
  • @MarekR you're right – Kargath Nov 15 '22 at 16:47