From 4cbe93321d86348f9021e735dea7500450a93ddf Mon Sep 17 00:00:00 2001 From: ktyl Date: Mon, 24 Jul 2023 22:15:49 +0100 Subject: [PATCH] feat: compile on linux --- CMakeLists.txt | 12 ++++++++++-- hello.cpp | 26 ++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 201cc05..bc9d7ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,11 @@ if(WIN32) # OpenGL 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.") endif() @@ -19,4 +23,8 @@ add_executable(${PROJECT_NAME} hello.cpp) if(WIN32) target_link_libraries(${PROJECT_NAME} glfw3) target_link_libraries(${PROJECT_NAME} OpenGL::GL) -endif() \ No newline at end of file +elseif(UNIX) + include_directories(${GLFW_INCLUDE_DIRS}) + target_link_libraries(${PROJECT_NAME} ${GLFW_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} OpenGL::GL) +endif() diff --git a/hello.cpp b/hello.cpp index ea8bb5f..047e8da 100644 --- a/hello.cpp +++ b/hello.cpp @@ -1,5 +1,11 @@ // 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 // https://cmake.org/download // Add to PATH for all users @@ -11,17 +17,21 @@ // The last step compiles the executable - this can also be done from Visual // 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 // 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 -#include +#include int main() { @@ -49,4 +59,4 @@ int main() glfwTerminate(); return 0; -} \ No newline at end of file +}