glfw / glfw.github.io

Jekyll sources for GLFW website
https://www.glfw.org/
Other
28 stars 17 forks source link

Building With CMake and installed GLFW binaries #45

Open thomastjeffery opened 6 years ago

thomastjeffery commented 6 years ago

This page says that you can add the line

find_package(glfw3 3.2 REQUIRED)

to your CMakeLists.txt, and be able to build the project using CMake.

It does nothing to explain where to put the glfw3 binaries, and does not provide a Findglfw3.cmake, glfw3Config.cmake, or a glfw3-config.cmake file, which CMake needs to evaluate the find_package macro. The precompiled binaries from here do not provide them either.

Simply adding the above find_package line to a simple CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(Test)
add_executable(test main.cc)

find_package(glfw3 3.2 REQUIRED)

yields this error:

CMake Error at CMakeLists.txt:6 (find_package):
  By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "glfw3", but
  CMake did not find one.

  Could not find a package configuration file provided by "glfw3" (requested
  version 3.2) with any of the following names:

    glfw3Config.cmake
    glfw3-config.cmake

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

Is there an example Findglfw3.cmake, glfw3Config.cmake, or glfw3-config.cmake file somewhere?

siavashserver commented 6 years ago

@thomastjeffery related glfw/glfw#634

thomastjeffery commented 6 years ago

As far as I can tell, the binary release contains no .cmake files whatsoever.

It really isn't trivial to find a FindGLFW3.cmake file that you can be certain (as a new user) is compatible. If the main docs continue to recommend using CMake, they should really provide this file in releases.

yuqli commented 5 years ago

I have this exact same problem. Thanks for raising the issue up!

varungoel1988 commented 5 years ago

same issue.. anyone can help??

jollescott commented 4 years ago

Ran into this issue today, solved by installing the libglfw3-dev package instead of libglfw3 on Ubuntu 18.04 LTS. Not sure if it is an optimal solution though.

mholzel commented 4 years ago

For reference, I have seen two cases where this happens (these don't seem to be the case for the original user, but will hopefully help others):

  1. The case that @jollescott mentions
  2. People putting the find_package call before a project declaration
onoriofelipe commented 4 years ago

Stumbled upon this via google, adding a "redirect" link.

(...) Is there an example Findglfw3.cmake, glfw3Config.cmake, or glfw3-config.cmake file somewhere?

As explained in https://github.com/glfw/glfw/issues/483#issue-65229070 , when you build and install GLFW then the file glfw3Config.cmake can be found in <install_dir>/lib/cmake/glfw/ .

The file is not available in the precompiled Windows binary release.

TJ-Perez commented 3 years ago

Still having this issue using the latest precompiled Windows binaries, can't find any information about where to find these files/where they need to be

bartholmberg commented 3 years ago

Updates on Findglfw3.cmake /glfw3Config.cmake [?] So glfw3 lib binaries, /include but no cmake files for dependent builds. Like Ospay_studio...snipped below....

:\catkin_ws>cd c:\repo\ospray_studio

c:\repo\ospray_studio>cmake . -- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042. -- C:/repo/ospray_studio/glfw3libs -- This build is for C++14 CMake Error at CMakeLists.txt:46 (find_package): By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "glfw3", but CMake did not find one.

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

glfw3Config.cmake
glfw3-config.cmake
sparshpriyadarshi commented 2 years ago

image

weisterki commented 1 year ago

glfw3-config.cmake

I installed libigl[glfw], and find the glfw3Config.cmake at C:\src\vcpkg\installed\x86-windows\share\glfw3; but there is no glfw3-config.cmake in any folder.

Areshkew commented 1 year ago

Same issue, there is a solution?

Areshkew commented 1 year ago

Same issue, there is a solution?

I found a Solution, you should follow this steps:

  1. Download GLFW Source.

  2. Execute the following cmake commands: cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build cmake --build build cmake --install build --prefix install

  3. Then a "install" folder will be created, there will be the lib, cmake, and include folders, copy them into your project folder. I copied them in "project_root/dependencies/GLFW".

  4. Finally in your cmakelist.txt add the following. list(APPEND CMAKE_PREFIX_PATH "dependencies/GLFW/lib/cmake") find_package(glfw3 REQUIRED) target_link_libraries(Chess glfw)

Now you can build your project :D

FSSRepo commented 4 months ago

@Areshkew I'm getting this on windows:

  wave.c
  wave.vcxproj -> C:\Users\stewa\Downloads\VkGalaxy-main\glfw-master\build\examples\Debug\wave.exe
  1>Building Custom Rule C:/Users/stewa/Downloads/VkGalaxy-main/glfw-master/tests/CMakeLists.txt
  window.c
  window.vcxproj -> C:\Users\stewa\Downloads\VkGalaxy-main\glfw-master\build\tests\Debug\window.exe
  1>Building Custom Rule C:/Users/stewa/Downloads/VkGalaxy-main/glfw-master/examples/CMakeLists.txt
  windows.c
  windows.vcxproj -> C:\Users\stewa\Downloads\VkGalaxy-main\glfw-master\build\examples\Debug\windows.exe
  1>Building Custom Rule C:/Users/stewa/Downloads/VkGalaxy-main/glfw-master/CMakeLists.txt

C:\Users\stewa\Downloads\VkGalaxy-main\glfw-master\build>cmake --install .
-- Install configuration: "Release"
CMake Error at src/cmake_install.cmake:39 (file):
  file INSTALL cannot find
  "C:/Users/stewa/Downloads/VkGalaxy-main/glfw-master/build/src/Release/glfw3.lib":
  File exists.
Call Stack (most recent call first):
  cmake_install.cmake:37 (include)

C:\Users\stewa\Downloads\VkGalaxy-main\glfw-master\build>cmake --install . --prefix install
-- Install configuration: "Release"
CMake Error at src/cmake_install.cmake:39 (file):
  file INSTALL cannot find
  "C:/Users/stewa/Downloads/VkGalaxy-main/glfw-master/build/src/Release/glfw3.lib":
  File exists.
Call Stack (most recent call first):
  cmake_install.cmake:37 (include)

C:\Users\stewa\Downloads\VkGalaxy-main\glfw-master\build>
RiwajMainali commented 4 months ago

@FSSRepo For windows, you gotta make the build files, where you will find the cmake-gui to be easiest way. I recommend this tutorial till you have glfw-build folder, just make sure to run the cmd as admin. after you have glfw-build, just add it to your project lib folder

Also, make sure to use glfw3 as package name not just glfw, this is because the cmake in glfw-build is named glfw3Config.cmake

As an example, here is mine,

set(glfw3_DIR  "${CMAKE_SOURCE_DIR}/Lib/glfw-build/src")
find_package(glfw3 3.4 REQUIRED)
include_directories(${glfw3_DIR})
FSSRepo commented 4 months ago

@FSSRepo For windows, you gotta make the build files, where you will find the cmake-gui to be easiest way.

I realized that I had to build it in Release mode, that's why it didn't allow me to use the cmake --install build --prefix install command.