Subject: [PATCH 1/6] gnu: Add arrayfire-glad.

From: Adam Faiz <[email-masked]>
Date: Sun, 27 Aug 2023 02:50:37 +0800

>From 668b7978a7dd2e6daece5209621601575eaad900 Mon Sep 17 00:00:00 2001
Message-ID: <6[email-masked]>
In-Reply-To: <[email-masked]>
References: <[email-masked]>
From: AwesomeAdam54321 <[email-masked]>
Date: Sun, 27 Aug 2023 01:59:48 +0800
Subject: [PATCH 1/6] gnu: Add arrayfire-glad.

* gnu/packages/patches/arrayfire-glad-add-packaging-support.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it here.
* gnu/packages/gl.scm (arrayfire-glad): New variable.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/gl.scm                           |  42 +++++
 ...arrayfire-glad-add-packaging-support.patch | 145 ++++++++++++++++++
 3 files changed, 188 insertions(+)
 create mode 100644 gnu/packages/patches/arrayfire-glad-add-packaging-support.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index adda02d410..3c1f7665ff 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -902,6 +902,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/akonadi-not-relocatable.patch		\
   %D%/packages/patches/akonadi-timestamps.patch		\
   %D%/packages/patches/allegro-mesa-18.2.5-and-later.patch	\
+  %D%/packages/patches/arrayfire-glad-add-packaging-support.patch		\
   %D%/packages/patches/ibus-anthy-fix-tests.patch		\
   %D%/packages/patches/ibus-table-paths.patch			\
   %D%/packages/patches/anki-mpv-args.patch			\
diff --git a/gnu/packages/gl.scm b/gnu/packages/gl.scm
index b53b42a9ba..7476aba06f 100644
--- a/gnu/packages/gl.scm
+++ b/gnu/packages/gl.scm
@@ -108,6 +108,48 @@ (define-public glu
 as ASCII text.")
     (license (license:x11-style "http://directory.fsf.org/wiki/License:SGIFreeBv2"))))
 
+(define-public arrayfire-glad
+  (let ((commit "ef8c5508e72456b714820c98e034d9a55b970650")
+        (revision "0"))
+    (package
+      (name "arrayfire-glad")
+      (version (git-version "0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/arrayfire/glad.git")
+               (commit commit)))
+         (sha256
+          (base32 "0yln2mrymhb6ni6gb1vc0vrzbrkzmsxk7wyvbgqlv16bnmrmxmdv"))
+         (patches (search-patches "arrayfire-glad-add-packaging-support.patch"))
+         (modules '((guix build utils)))
+         (snippet
+          #~(begin
+              (substitute* "CMakeLists.txt"
+                (("OBJECT") "SHARED")
+                (("af_glad_obj_lib") "glad")
+                (("target_include_directories.*)\n" all)
+                 (string-append all "\n\n"
+                                "configure_file(glad.pc.in glad.pc @ONLY)\n"
+                                "install(DIRECTORY include/\n"
+                                "DESTINATION include/)\n"
+                                "\n\n"
+                                "install(TARGETS glad\n"
+                                "DESTINATION lib/)\n"
+                                "install(FILES ${CMAKE_CURRENT_BINARY_DIR}/glad.pc\n"
+                                "DESTINATION lib/pkgconfig/)\n"
+                                "install(FILES gladConfig.cmake\n"
+                                "DESTINATION lib/cmake/glad/)\n")))))
+         (file-name (git-file-name name version))))
+      (build-system cmake-build-system)
+      (arguments
+       (list #:tests? #f)) ; no tests
+      (home-page "https://github.com/arrayfire/glad")
+      (synopsis "OpenGL(3.3) Loader Library")
+      (description "OpenGL(3.3) Loader Library, a dependency of ArrayFire.")
+      (license license:bsd-3))))
+
 (define-public freeglut
   (package
     (name "freeglut")
diff --git a/gnu/packages/patches/arrayfire-glad-add-packaging-support.patch b/gnu/packages/patches/arrayfire-glad-add-packaging-support.patch
new file mode 100644
index 0000000000..a7591eee7b
--- /dev/null
+++ b/gnu/packages/patches/arrayfire-glad-add-packaging-support.patch
@@ -0,0 +1,145 @@
+From ceaa23fd1834ad56fe5f74d544b650be9a55360b Mon Sep 17 00:00:00 2001
+From: AwesomeAdam54321 <[email-masked]>
+Date: Sat, 26 Aug 2023 16:38:13 +0800
+Subject: [PATCH] glad: Add package configuration files.
+
+* glad.pc.in: Add pkg-config file.
+* gladConfig.cmake: Add CMake package file for detection by external packages.
+---
+ glad.pc.in          |  11 +++++
+ gladConfig.cmake | 104 +++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 115 insertions(+)
+ create mode 100644 glad.pc
+ create mode 100644 gladConfig.cmake
+
+diff --git a/glad.pc.in b/glad.pc.in
+new file mode 100644
+index 0000000..5c29fcd
+--- /dev/null
++++ b/glad.pc.in
+@@ -0,0 +1,11 @@
++prefix=@CMAKE_INSTALL_PREFIX@   # this defines a variable
++exec_prefix=${prefix}      # defining another variable with a substitution
++libdir=${exec_prefix}/lib
++includedir=${prefix}/include
++
++Name: glad
++Description: OpenGL(3.3) Loader Library
++Version: 0
++URL: https://github.com/arrayfire/glad
++Libs: -L${libdir} -lglad
++Cflags: -I${includedir}/glad
+\ No newline at end of file
+diff --git a/gladConfig.cmake b/gladConfig.cmake
+new file mode 100644
+index 0000000..1213d3e
+--- /dev/null
++++ b/gladConfig.cmake
+@@ -0,0 +1,104 @@
++# Finds the glad libraries
++#
++# Sets the following variables:
++#          glad_FOUND
++#          glad_INCLUDE_DIR
++#          glad_DYNAMIC_LIBRARY
++#          glad_STATIC_LIBRARY
++#
++# Usage:
++# find_package(glad)
++# if (glad_FOUND)
++#    target_link_libraries(mylib PRIVATE glad::glad)
++# endif (glad_FOUND)
++#
++# OR if you want to link against the static library:
++#
++# find_package(glad)
++# if (glad_FOUND)
++#    target_link_libraries(mylib PRIVATE glad::glad_STATIC)
++# endif (glad_FOUND)
++#
++# NOTE: You do not need to include the glad include directories since they
++# will be included as part of the target_link_libraries command
++
++set(PX ${CMAKE_STATIC_LIBRARY_PREFIX})
++set(SX ${CMAKE_STATIC_LIBRARY_SUFFIX})
++
++# use pkg-config to get the directories and then use these values
++# in the find_path() and find_library() calls
++if (NOT WIN32)
++    find_package(PkgConfig)
++    pkg_check_modules(gladPkg REQUIRED glad)
++endif (NOT WIN32)
++
++find_path(glad_INCLUDE_DIR
++    NAMES glad.h
++    PATHS
++        /usr/include
++        /usr/local/include
++        /sw/include
++        /opt/local/include
++    HINTS
++        ${gladPkg_INCLUDE_DIRS} # Generated by pkg-config
++    )
++
++find_library(glad_DYNAMIC_LIBRARY
++    NAMES glad fontconfig ${gladPkg_LIBRARY}
++    PATHS
++        /usr/local
++        /usr/X11
++        /usr
++        /sw
++        /opt/local
++        /usr/lib/x86_64-linux-gnu
++    HINTS
++        ${gladPkg_LIBRARY_DIRS} # Generated by pkg-config
++    PATH_SUFFIXES
++        lib64
++        lib
++    )
++
++find_library(glad_STATIC_LIBRARY
++    NAMES ${PX}fontconfig${SX} ${PX}glad${SX} ${PX}${gladPkg_LIBRARY}${SX}
++    PATHS
++        /usr/local
++        /usr/X11
++        /usr
++        /sw
++        /opt/local
++        /usr/lib/x86_64-linux-gnu
++    HINTS
++        ${gladPkg_LIBRARY_DIRS} # Generated by pkg-config
++    PATH_SUFFIXES
++        lib64
++        lib
++    )
++
++mark_as_advanced(
++    glad_INCLUDE_DIR
++    glad_DYNAMIC_LIBRARY
++    glad_STATIC_LIBRARY
++    )
++
++include(FindPackageHandleStandardArgs)
++
++find_package_handle_standard_args(glad
++    REQUIRED_VARS glad_DYNAMIC_LIBRARY glad_INCLUDE_DIR
++    )
++
++if (glad_FOUND AND NOT TARGET glad::glad)
++    add_library(glad::glad UNKNOWN IMPORTED)
++    set_target_properties(glad::glad PROPERTIES
++        IMPORTED_LINK_INTERFACE_LANGUAGE "C"
++        IMPORTED_LOCATION ${glad_DYNAMIC_LIBRARY}
++        INTERFACE_INCLUDE_DIRECTORIES ${glad_INCLUDE_DIR})
++
++    if (glad_STATIC_LIBRARY)
++        add_library(glad::glad_STATIC UNKNOWN IMPORTED)
++        set_target_properties(glad::glad_STATIC PROPERTIES
++            IMPORTED_LINK_INTERFACE_LANGUAGE "C"
++            IMPORTED_LOCATION "${glad_STATIC_LIBRARY}"
++            INTERFACE_INCLUDE_DIRECTORIES "${glad_INCLUDE_DIR}")
++    endif (glad_STATIC_LIBRARY)
++endif ()
+-- 
+2.41.0
+
-- 
2.41.0