feat: compile on linux

This commit is contained in:
ktyl 2023-07-24 22:15:49 +01:00
parent 4c94e0f047
commit 4cbe93321d
2 changed files with 28 additions and 10 deletions

View File

@ -10,7 +10,11 @@ if(WIN32)
# OpenGL # OpenGL
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
elseif(UNIX OR APPLE) elseif(UNIX)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
find_package(OpenGL REQUIRED)
elseif(APPLE)
message(FATAL_ERROR "Linux and macOS platforms are not supported yet.") message(FATAL_ERROR "Linux and macOS platforms are not supported yet.")
endif() endif()
@ -19,4 +23,8 @@ add_executable(${PROJECT_NAME} hello.cpp)
if(WIN32) if(WIN32)
target_link_libraries(${PROJECT_NAME} glfw3) target_link_libraries(${PROJECT_NAME} glfw3)
target_link_libraries(${PROJECT_NAME} OpenGL::GL) target_link_libraries(${PROJECT_NAME} OpenGL::GL)
endif() elseif(UNIX)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${GLFW_LIBRARIES})
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
endif()

View File

@ -1,5 +1,11 @@
// To compile on Windows // To compile on Windows
// Install GLFW 3.3.8
// https://www.glfw.org/download.html
// On Windows:
// extract the downloaded .zip file to "C:/libs"; this is currently expected
// by our CMakeLists.txt.
// Install CMake // Install CMake
// https://cmake.org/download // https://cmake.org/download
// Add to PATH for all users // Add to PATH for all users
@ -11,17 +17,21 @@
// The last step compiles the executable - this can also be done from Visual // The last step compiles the executable - this can also be done from Visual
// Studio // Studio
// Install GLFW 3.3.8
// https://www.glfw.org/download.html
// On Windows:
// extract the downloaded .zip file to "C:/libs"; this is currently expected
// by our CMakeLists.txt.
// To run in VS // To run in VS
// Set startup project in Solution Explorer // Set startup project in Solution Explorer
// Press F5 to run
//
// To compile on Arch Linux
//
// Install dependencies
// sudo pacman -S glfw mesa
//
// Build
// cmake ..
// cmake --build .
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <gl/GL.h> #include <GL/gl.h>
int main() int main()
{ {
@ -49,4 +59,4 @@ int main()
glfwTerminate(); glfwTerminate();
return 0; return 0;
} }