Reputation: 87
I made a simple program using glfw in Linux. and I want to build it in windows now.
when I install glfw in Linux, I did the following steps.
Then in CMakeLists.txt file:
find_package( glfw3 3.3 REQUIRED )
add_executable(main main.cpp)
target_link_libraries(main glfw)
in source code:
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
//use glfw
So I want to do the same thing in windows visual studio.
I did the following steps.
As a result, I got C:\Program Files (x86)\GLFW folder. there is include, lib, config files.
And then I created a new CMake project.
CMake File:
cmake_minimum_required (VERSION 3.8)
set (CMAKE_PREFIX_PATH "C:\Program Files (x86)\GLFW\lib\cmake\glfw3")
find_package( glfw3 3.3 REQUIRED )
include_directories( "C:\Program Files (x86)\GLFW" )
project ("glfw_test")
add_executable (glfw_test "glfw_test.cpp" "glfw_test.h")
And error message saying:
CMake Error at C:\Users\home\source\repos\glfw_test\CMakeLists.txt:3 (set):
Syntax error in CMake code at
C:/Users/home/source/repos/glfw_test/CMakeLists.txt:3
when parsing string
C:\Program Files (x86)\GLFW\lib\cmake\glfw3
Invalid character escape '\P'. glfw_test C:\Users\home\source\repos\glfw_test\CMakeLists.txt 3
Questions.
Upvotes: 0
Views: 3692
Reputation: 6744
TL;DR answers:
CMAKE_INSTALL_PREFIX
to your GLFW CMake command, e.g.cmake -S <sourcedir> -B <builddir> -DCMAKE_INSTALL_PRFIX=<yourinstalldir>
cmake --build <builddir> --target install --config Release
If you do not specify an installation prefix to your cmake command on Windows it is set to C:\Program Files (x86)
for 32bit builds and to C:\Program Files
for 64bit builds.
Do not hardcode CMAKE_PREFIX_PATH
into your CMakeLists.txt
. Explicitly specify what generator and architecture you want to use for your build. Add it to your CMake command line as argument, e.g.
cmake -S <sourcedir> -B <builddir> -G "Visual Studio 16 2019" -A Win32 -DCMAKE_PREFIX_PATH=<yourglfwrootinstalldir>
And your CMakeLists.txt file should look as follows:
cmake_minimum_required (VERSION 3.8)
project ("glfw_test")
find_package( glfw3 3.3 REQUIRED )
add_executable (glfw_test glfw_test.cpp glfw_test.h)
target_link_libraries(glfw_test PRIVATE glfw)
Upvotes: 1