google / fruit

Fruit, a dependency injection framework for C++
https://github.com/google/fruit/wiki
Apache License 2.0
1.81k stars 199 forks source link

FindFruit from Cmake after installing via vcpkg.json #163

Open frederick-brier opened 1 week ago

frederick-brier commented 1 week ago

After installing Fruit via vcpkg.json, FindFruit() was not in the path. It was in the ./vcpkg/buildtrees/fruit/src/v3.7.1-b712e99c79.clean/cmake-modules/FindFruit.cmake. A file(GLOB_RECURSE...) found the file's path and I was able to add it to the CMAKE_MODULE_PATH and then call FindFruit(), but it would be nice FindFruit.cmake was automagically added to the path. Also the vcpkg include and libpath was not updated and had to be set manually. Is this a vcpkg port issue? Or something in Fruit's CMake support?

poletti-marco commented 1 week ago

Hi, I suspect this is due to the vcpkg configuration, from my understanding it was written more as a way to use Fruit as a dependency of another project that uses vcpkg as opposed to a general way to install Fruit and then use it in various build systems (unless your project uses both cmake and vcpkg?).

https://github.com/google/fruit/wiki/install has other options to install Fruit that (unlike vcpkg) are officially supported. If you do want to use vcpkg, the configuration lives in a separate repo with different maintainers, see https://github.com/google/fruit/wiki/install#with-vcpkg-on-windows-not-officially-supported.

If the other (non-vcpkg) options don't work well for you, can you explain your use case more in detail? From the path you mention, it seems like this is on Linux, is this correct?

tt4g commented 1 week ago

I think it is because vcpkg is customizing the CMake configuration when installing fruit.

If you look at ports/fruit/portfile.cmake, you will see that fruit is installed using a custom command provided by vcpkg.

From my little research, it seems that the vcpkg_cmake_configure() command replaces CMAKE_INSTALL_PREFIX with CURRENT_PACKAGES_DIR: https://github.com/microsoft/vcpkg/blob/7adc2e4d49e8d0efc07a369079faa6bc3dbb90f3/ports/vcpkg-cmake/vcpkg_cmake_configure.cmake#L236 If CURRENT_PACKAGES_DIR is different from the standard CMake path, then FindFruit.cmake will not find it.

frederick-brier commented 1 week ago

For this product and its build environment, it is actually Windows. Since I do a lot of Linux development and PowerShell handles forward slashes, when acceptable, we use forward slashes. We are using vcpkg.json to pull in several Boost libraries, OpenCL, and several other libraries across 60+ repositories being built with GitHub Actions. I am introducing DI using Fruit and it seemed the easiest way to add it. Plus we are building arm64 in addition to x64. vcpkg triplets constructed with the processor as a variable is convenient. tt4g, you have pointed out the issue being the portfile.cmake. I will create a story in our backlog and see if I can fix it at some point. Thank you.

tt4g commented 1 week ago

It seems that at least CMAKE_TOOLCHAIN_FILE needs to be set for CMake and vcpkg integration: https://learn.microsoft.com/en-us/vcpkg/users/buildsystems/cmake-integration#cmake_toolchain_file

frederick-brier commented 1 week ago

We have a VcpkgSupport.cmake file (in a git submodule ) that sets the CMAKE_TOOLCHAINFILE value along with a number of other VCPKG* variables that is included prior to the project() command. Please feel free to pelt me with any other suggestions. It is always possible I overlooked something :). Thank you for your help.