From f48844235708c5b93ce4879e1d50bb9a4abca997 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Mon, 25 Jul 2022 23:17:59 +0100
Subject: [PATCH] make header-only glad an export target

---
 CMakeLists.txt                    | 74 ++++++++++++++-----------------
 fggl/gfx/CMakeLists.txt           |  2 +-
 vendor/header_only/CMakeLists.txt | 13 ++++--
 3 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cac5dd4..e508f6a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,63 +8,63 @@ option(FGGL_EXAMPLES "Should we build examples or just the library" ON)
 option(FGGL_TESTS "Should we enable the testing suite?" ON)
 option(FGGL_DOCS "Should we build documentation?" ON)
 
+##
+# Windows
+# When on windows, integrate vcpkg
+##
 if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
   set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
       CACHE STRING "")
 endif()
+##
+# /windows
+##
 
 # Define the project
 project(fggl
 	VERSION 0.1
-	DESCRIPTION ""
-	HOMEPAGE_URL ""
+	DESCRIPTION "FOSS Galaxy Game Library, for use in Education, and Games"
+	HOMEPAGE_URL "https://git.fossgalaxy.com/gamedev/fggl"
 	LANGUAGES C CXX)
 
-include(GNUInstallDirs)
-
-if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
-	# testing support
-	include(CTest)
-
-	# Documentation support
-	if (FGGL_DOCS)
-		find_package(Doxygen)
-		if (Doxygen_FOUND)
-			add_subdirectory( docs )
-		else()
-			message(STATUS "Doxygen not found, not building docs")
-		endif()
-	endif()
-
-endif()
-
+# export compile commands for vim/neovim users
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
-
-##
-# end windows support
-##
-
 # vendor dependencies
 add_subdirectory( vendor/imgui )
+add_subdirectory( vendor/header_only )
 
-# engine
+# engine headers
+file(GLOB_RECURSE public_headers
+	${PROJECT_SOURCE_DIR}/include/fggl/*.hpp
+)
+
+# engine sources, enable strict compiler warnings
 add_subdirectory( fggl )
-add_subdirectory( vendor/header_only )
+target_compile_options( fggl PRIVATE -Wall -Wpedantic -Wextra -Wodr -fno-strict-aliasing -fno-strict-overflow )
+set_property(TARGET fggl PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
+
 
 # 3rd party integrations
 add_subdirectory( integrations/bullet )
 
-
-## G++ enable insane checks
-target_compile_options( ${PROJECT_NAME} PRIVATE -Wall -Wpedantic -Wextra -Wodr -fno-strict-aliasing -fno-strict-overflow )
-set_property(TARGET fggl PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
-
-# extras
+# Unit Tests
 if (FGGL_TESTS)
+	include(CTest)
 	add_subdirectory(tests)
 endif()
 
+# Documentation support
+if (FGGL_DOCS)
+	find_package(Doxygen)
+	if (Doxygen_FOUND)
+		add_subdirectory( docs )
+	else()
+		message(STATUS "Doxygen not found, not building docs")
+	endif()
+endif()
+
+# Demo project
 if (FGGL_EXAMPLES)
   add_subdirectory(demo)
   target_compile_options( demo PRIVATE -Wall -Wextra -Wodr -Wdouble-promotion -fno-strict-aliasing -fno-strict-overflow )
@@ -75,13 +75,7 @@ endif()
 # INSTALL PHASE
 # see https://decovar.dev/blog/2021/03/08/cmake-cpp-library/
 ##
-
-file(GLOB_RECURSE public_headers
-	${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.hpp
-	${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h
-)
-
-#include(CMakePrintHelpers)
+include(GNUInstallDirs)
 
 # Structure preserving header macro
 foreach(header ${public_headers})
diff --git a/fggl/gfx/CMakeLists.txt b/fggl/gfx/CMakeLists.txt
index 52c770f..cfc7512 100644
--- a/fggl/gfx/CMakeLists.txt
+++ b/fggl/gfx/CMakeLists.txt
@@ -5,7 +5,7 @@ find_package( glfw3 REQUIRED )
 include(CMakePrintHelpers)
 cmake_print_variables(GLFW_TARGETS)
 
-target_link_libraries(fggl PUBLIC glfw )
+target_link_libraries(fggl PUBLIC glfw fggl-glad)
 
 target_sources(fggl
     PRIVATE
diff --git a/vendor/header_only/CMakeLists.txt b/vendor/header_only/CMakeLists.txt
index f92d1f1..d663884 100644
--- a/vendor/header_only/CMakeLists.txt
+++ b/vendor/header_only/CMakeLists.txt
@@ -1,5 +1,7 @@
-target_include_directories( fggl
-    PUBLIC
+add_library(fggl-glad INTERFACE)
+
+target_include_directories( fggl-glad
+    INTERFACE
         $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/public>
         $<INSTALL_INTERFACE:include/fggl>
 )
@@ -11,10 +13,15 @@ install(
     DESTINATION
         ${CMAKE_INSTALL_INCLUDEDIR}/fggl/glad
 )
-
 install(
         FILES
             public/KHR/khrplatform.h
         DESTINATION
             ${CMAKE_INSTALL_INCLUDEDIR}/fggl/KHR
 )
+
+install(TARGETS fggl-glad
+    EXPORT fgglTargets
+    DESTINATION
+        ${CMAKE_INSTALL_LIBDIR}/fggl/glad
+)
\ No newline at end of file
-- 
GitLab