vcpkg icon indicating copy to clipboard operation
vcpkg copied to clipboard

Using vcpkg repo with cmake not adding include paths

Open yamcenutzer opened this issue 9 years ago • 5 comments

According to docs, it should be enough to specify the toolchain file (vcpkg.cmake) on config command for cmake. However, that does not add the vcpkg/installed//include to the generated compile instructions.

If I explicitely add the vcpkg/installed//include to the CMakeLists.txts file, then it works (Or just add Boost_INCLUDE_DIR, since points to all the includes...)

I don't know if that is a bug of cmake 3.8.rc2 or, vcpkg.cmake, or if i'm doing something wrong. I'm using the cmake-usage sample from the (old) wiki, except instead of sqlite, I'm including boost/asio.hpp. Everything else is the same (hello worlr type main.cpp, cmakelists finding boost system, instead of sqlite).

Coinfiguring works, but build doesn't, complaining can't find boost/asio.hpp.... same with others. e.g. rapidxml

IIRC it used to work earlier, but not sure. Using version 0.0.76-d46563d862228241124bfa345c6b0d80b0efac7b

yamcenutzer avatar Mar 14 '17 13:03 yamcenutzer

We don't add the include path by default anymore because we have no way to ensure we add the path to the end of your compiler line. If your sources happen to share a header with one that is installed inside Vcpkg, we don't want to override your header.

The fix, fortunately, is quite easy: just pick any header that you're expecting to get out of Vcpkg, then do

find_path(SYSTEM_INCLUDE_DIR zlib.h)
include_directories(${SYSTEM_INCLUDE_DIR})

This lets you control exactly where in your compiler line it gets added. You will usually want it added at the end.

ras0219-msft avatar Mar 16 '17 23:03 ras0219-msft

Ok, so the workaround I'm using (as described in the OP) is also what you would suggest. It might be better to just define a generic 'vcpkg_Include_dir' to use, otherwise one would have to add documentation to the Cmakelists fiel why only one of the include dirs are being used

Thx.

yamcenutzer avatar Mar 17 '17 00:03 yamcenutzer

I highly recommend we add this to the documentation about CMake immediately. I just ran into the exact same issue and was awfully confused until I found this issue.

cmazakas avatar Mar 31 '17 05:03 cmazakas

Thanks for showing how important this is! I've extended the documentation with a6957eb, please take a look and make sure it would have helped you :)

ras0219-msft avatar Mar 31 '17 05:03 ras0219-msft

It's awesome! Thank you so much!

cmazakas avatar Apr 01 '17 18:04 cmazakas