cmake find_package cannot locate glfw after build and install

柔情痞子 提交于 2021-02-18 19:01:25

问题


I'm trying to use cmake's find_package function to find the installation of glfw3 and I'm not quite sure I'm understanding the instructions. I've download glfw3 and followed the instructions for building.

downloaded the src, went to the root, and ran cmake ..

Then I open the main solution glfw.sln in visual studio. I built the solution and everything seemed to build fine. I can see where the lib was created and everything. In my own cmake project, when I use find_package(glfw3 REQUIRED) I receive this error:

By not providing "Findglfw.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "glfw", but
CMake did not find one.

Could not find a package configuration file provided by "glfw" with any of
the following names:

glfwConfig.cmake
glfw-config.cmake

Add the installation prefix of "glfw" to CMAKE_PREFIX_PATH or set
"glfw_DIR" to a directory containing one of the above files.  If "glfw"
provides a separate development package or SDK, be sure it has been
installed.

I was under the impression that once I ran and installed another cmake library that it was to be included in other projects like glfw3, it would install a glfw3config.cmake somewhere where any call to cmake can find it. Is there a reason why that is not happening? Where is this folder that contains the *config.cmake normally located?


回答1:


This is probably because you built gflw3 but didn't do the Windows/Visual Studio equivalent of make install so the artifacts are not deployed to a location which cmake knows to look for.

You should pass a suitable directory with -DCMAKE_INSTALL_PREFIX= when invoking cmake for glfw3 and then reference it in -DCMAKE_PREFIX_PATH= for your own project. Basically:

  1. Configure your gflw3 project where to install its output artifacts with -DCMAKE_INSTALL_PREFIX=C:/Users/me/gflw3 when running cmake for it.
  2. Build gflw3 & deploy/install it.
  3. Tell your own project to look for things in C:/Users/me/gflw3 with -DCMAKE_PREFIX_PATH=C:/Users/me/gflw3 when running cmake for it.


来源:https://stackoverflow.com/questions/40076082/cmake-find-package-cannot-locate-glfw-after-build-and-install

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!