ref: 5b996b345952a582cd151d395774d896fff9a663
parent: a093ebd0187410943a19fbbe222b00451e2957ab
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Apr 2 21:34:47 EDT 2020
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.
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -526,7 +526,8 @@
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})
--- a/DoConfig/CMakeLists.txt
+++ b/DoConfig/CMakeLists.txt
@@ -9,9 +9,6 @@
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"
@@ -70,6 +67,16 @@
################
# 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)
--- /dev/null
+++ b/external/glad/CMakeLists.txt
@@ -1,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")
--- a/external/glad/include/glad/glad.h
+++ b/external/glad/include/glad/glad.h
@@ -86,7 +86,7 @@
GLAPI int gladLoadGLLoader(GLADloadproc);
-#include "../KHR/khrplatform.h"
+#include <KHR/khrplatform.h>
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
--- a/external/glad/src/glad.c
+++ b/external/glad/src/glad.c
@@ -22,7 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "../include/glad/glad.h"
+#include <glad/glad.h>
static void* get_proc(const char *namez);
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -10,7 +10,7 @@
#ifdef USE_OPENGLES2
#include <GLES2/gl2.h>
#else
-#include "../../../external/glad/include/glad/glad.h"
+#include <glad/glad.h>
#endif
#define SPRITEBATCH_IMPLEMENTATION