From 5b996b345952a582cd151d395774d896fff9a663 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 3 Apr 2020 01:34:47 +0100 Subject: [PATCH] Give glad a CMake file Today I learned that CMake will error if the project shares a dependency with a nested CMake file (which could be from an entirely-separate project that you have no control over). I'm starting to really hate CMake. --- CMakeLists.txt | 3 ++- DoConfig/CMakeLists.txt | 13 ++++++++++--- external/glad/CMakeLists.txt | 11 +++++++++++ external/glad/include/glad/glad.h | 2 +- external/glad/src/glad.c | 2 +- src/Backends/Rendering/OpenGL3.cpp | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 external/glad/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 609f8636..6e79bed7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -526,7 +526,8 @@ else() endif() if(BACKEND_RENDERER MATCHES "OpenGL3") - target_sources(CSE2 PRIVATE "external/glad/src/glad.c" "external/glad/include/glad/glad.h" "external/glad/include/KHR/khrplatform.h") + add_subdirectory("external/glad" EXCLUDE_FROM_ALL) + target_link_libraries(CSE2 PRIVATE glad) find_package(OpenGL REQUIRED) target_link_libraries(CSE2 PRIVATE OpenGL::GL ${CMAKE_DL_LIBS}) diff --git a/DoConfig/CMakeLists.txt b/DoConfig/CMakeLists.txt index 6df9ec78..3edd211f 100644 --- a/DoConfig/CMakeLists.txt +++ b/DoConfig/CMakeLists.txt @@ -9,9 +9,6 @@ project(DoConfig LANGUAGES C CXX) add_executable(DoConfig WIN32 "icon.rc" - "../external/glad/include/glad/glad.h" - "../external/glad/include/KHR/khrplatform.h" - "../external/glad/src/glad.c" "DoConfig.cpp" "imgui/imconfig.h" "imgui/imgui.cpp" @@ -71,6 +68,16 @@ endif() # Dependencies # ################ +# glad + +if(NOT TARGET glad) + add_subdirectory("../external/glad" "glad" EXCLUDE_FROM_ALL) +endif() + +target_link_libraries(DoConfig PRIVATE glad) + +# GLFW3 + if(NOT FORCE_LOCAL_LIBS) find_package(PkgConfig QUIET) endif() diff --git a/external/glad/CMakeLists.txt b/external/glad/CMakeLists.txt new file mode 100644 index 00000000..2b6298c1 --- /dev/null +++ b/external/glad/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.12) + +project(glad LANGUAGES C) + +add_library(glad + "include/glad/glad.h" + "include/KHR/khrplatform.h" + "src/glad.c" +) + +target_include_directories(glad PUBLIC "include") diff --git a/external/glad/include/glad/glad.h b/external/glad/include/glad/glad.h index 1b59b588..39d8722e 100644 --- a/external/glad/include/glad/glad.h +++ b/external/glad/include/glad/glad.h @@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void); GLAPI int gladLoadGLLoader(GLADloadproc); -#include "../KHR/khrplatform.h" +#include typedef unsigned int GLenum; typedef unsigned char GLboolean; typedef unsigned int GLbitfield; diff --git a/external/glad/src/glad.c b/external/glad/src/glad.c index dfeaf6fc..6e1f11d9 100644 --- a/external/glad/src/glad.c +++ b/external/glad/src/glad.c @@ -22,7 +22,7 @@ #include #include #include -#include "../include/glad/glad.h" +#include static void* get_proc(const char *namez); diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 65b1cd87..abd19e1f 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -10,7 +10,7 @@ #ifdef USE_OPENGLES2 #include #else -#include "../../../external/glad/include/glad/glad.h" +#include #endif #define SPRITEBATCH_IMPLEMENTATION