Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use nested vcpkg manifests in submodules/sub-projects? #15279

Closed
mikepricedev opened this issue Dec 24, 2020 · 8 comments
Closed

How do I use nested vcpkg manifests in submodules/sub-projects? #15279

mikepricedev opened this issue Dec 24, 2020 · 8 comments
Assignees
Labels
category:question This issue is a question info:manifests This PR or Issue pertains to the Manifests feature

Comments

@mikepricedev
Copy link

├── CMakeLists.txt
├── vcpkg.json
├── vcpkg_installed
├── extern
│   ├── CMakeLists.txt
│   ├── sub_project
│   │   ├── CMakeLists.txt
│   │   ├── vcpkg.json
│   │   ├── vcpkg_installed

In the above folder structure the "sub_project" submodule uses vcpkg and a vcpkg.json manifest to manage its deps. The root project also uses vcpkg and a vcpkg.json manifest to manage deps.

However, when the project is configured the sub_project's CMakeLists.txt vcpkg wiring no longer finds packages installed in sub_project/vcpkg_installed dir.
Steps taken:

  1. vcpkg install ran in sub_project dir. vcpkg_installed dir was created as expected.
  2. PATHS option added to find_package in submodule cmake. (in my case using the frozen lib)
find_package(frozen REQUIRED
  PATHS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}"
)
  1. Step 2 finds the library (frozen), but when compiling generates: 'frozen/map.h' file not found #include <frozen/map.h> not an issue in sub_project standalone.
  2. The following correctly prints the include dirs.
get_target_property(frozeninc frozen::frozen INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "frozen INTERFACE_INCLUDE_DIRECTORIES: ${frozeninc}")

Note: using vcpkg as a submodule technique in both i.e.

set(
  CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/scripts/buildsystems/vcpkg.cmake"
  CACHE STRING "Vcpkg toolchain file")
@NancyLi1013 NancyLi1013 added the category:question This issue is a question label Dec 24, 2020
@NancyLi1013
Copy link
Contributor

Hi @mikepricedev

Thanks for posting this issue.

You might forget to add target_link_libraries(main PRIVATE frozen::frozen frozen::frozen-headers) in your CMakeLists.txt.

Could you please refer to the usage of frozen to rebuild your project?

 find_package(frozen CONFIG REQUIRED)
 target_link_libraries(main PRIVATE frozen::frozen frozen::frozen-headers)

@NancyLi1013
Copy link
Contributor

@mikepricedev

Please let me know if the above suggestion can work for you.

@mikepricedev
Copy link
Author

mikepricedev commented Dec 30, 2020

@NancyLi1013
Thank you so much for taking a look. Before I go further I realized I am making an assumption that I haven't found any specific documentation. Does vcpkg support project's using vcpkg.json that have submodules that also use vcpkg.json? I'm using the following technique to add my submodules to my root project's CMakeLists.txt.

add_subdirectory(extern/sub_project)

In my case, Frozen is a dep of the sub_project managed in the sub_project by a vcpkg.json manifest. When I build the sub_project project independently (not as a submodule) the #include <frozen/map.h> is not an issue.

It is only when the sub_project is built as a submodule of another project using vcpkg. Both projects have vcpkg.json mainfest files. If I hoist the dependencies from the sub_project and paste them into the root project's vcpkg.json dependencies . There is no issue.

I also noticed something else particular. The sub_project also has a dep to "boost-smart-ptr". When I build the sub_project independenly boost is found in the vcpkg_installed dir. When built as a submodule the dep is found from my system's copy of "boost". I do not have a system copy of "frozen".

@PhoebeHui PhoebeHui added the info:manifests This PR or Issue pertains to the Manifests feature label Mar 5, 2021
@PhoebeHui
Copy link
Contributor

PhoebeHui commented Mar 5, 2021

@mikepricedev, does this still be a question for you?

From manifests.md, when invoked from any subdirectory of the directory containing vcpkg.json, vcpkg install with no package arguments will install all manifest dependencies into /vcpkg_installed/.

@cyraid
Copy link

cyraid commented Apr 5, 2021

I'm running into this problem too.. But I'm relying on visual studio 2019 cmake support to use vcpkg. It seems to be ignoring the sub directory/sub directory.

Is there support for add_subdirectory and sub directories with their own vcpkg.json? (And just using the main project without opening separate visual studio 2019 instances with their own cmakelists.txt).

@strega-nil
Copy link
Contributor

@cyraid there is currently no support for having multiple top level manifests. We have considered some ways to solve this, but none of them very good. If you're interested in solving this issue, please open a discussion topic about it. Otherwise, writing a top-level vcpkg.json that contains all of the dependencies your subdirectories need, or alternatively using vcpkg to manage these dependencies as well, are the two solutions we see right now.

@cyraid
Copy link

cyraid commented Apr 7, 2021

Hi @strega-nil ! Thank you for the reply! Where would you guys like to discuss this? I mean, I don't have much time to talk about it but my quick input would be to add a ADD_TARGET_VCPKG in the sub directory inside that CMakeLists.txt. So, ADD_LIBRARY(MyPlugin), and then ADD_TARGET_VCPKG(MyPlugin). This way you could add the appropriate includes and properties etc. for that target. This would of course also call vcpkg in that directory too, but perhaps with the same cache directory and out from CMakeSettings.json?

@strega-nil
Copy link
Contributor

@cyraid https://github.com/microsoft/vcpkg/discussions

@microsoft microsoft locked and limited conversation to collaborators May 26, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
category:question This issue is a question info:manifests This PR or Issue pertains to the Manifests feature
Projects
None yet
Development

No branches or pull requests

5 participants