Skip to content

Commit

Permalink
freeglut: Add support for Wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillikers committed Nov 2, 2023
1 parent 86a9581 commit 8d11723
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 12 deletions.
16 changes: 16 additions & 0 deletions recipes/freeglut/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ sources:
"3.2.1":
sha256: "d4000e02102acaf259998c870e25214739d1f16f67f99cb35e4f46841399da68"
url: "https://github.com/FreeGLUTProject/freeglut/releases/download/v3.2.1/freeglut-3.2.1.tar.gz"
patches:
"3.4.0":
- patch_file: "patches/3.4.0-0001-Use-find_package-and-pkg_check_modules-to-find-more.patch"
patch_description: "Use find_package and pkg_check_modules to find dependencies"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/147"
patch_type: "conan"
"3.2.2":
- patch_file: "patches/3.2.1-0001-Use-find_package-and-pkg_check_modules-to-find-more.patch"
patch_description: "Use find_package and pkg_check_modules to find dependencies"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/147"
patch_type: "conan"
"3.2.1":
- patch_file: "patches/3.2.1-0001-Use-find_package-and-pkg_check_modules-to-find-more.patch"
patch_description: "Use find_package and pkg_check_modules to find dependencies"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/147"
patch_type: "conan"
97 changes: 86 additions & 11 deletions recipes/freeglut/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import collect_libs, copy, get, rmdir
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.scm import Version
import os

Expand All @@ -11,7 +12,7 @@
class freeglutConan(ConanFile):
name = "freeglut"
description = "Open-source alternative to the OpenGL Utility Toolkit (GLUT) library"
topics = ("opengl", "gl", "glut", "utility", "toolkit", "graphics")
topics = ("gl", "glut", "graphics," "opengl", "toolkit", "utility")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://freeglut.sourceforge.net"
license = "X11"
Expand All @@ -24,33 +25,77 @@ class freeglutConan(ConanFile):
"print_errors_at_runtime": [True, False],
"print_warnings_at_runtime": [True, False],
"replace_glut": [True, False],
"with_wayland": [True, False],

}
default_options = {
"shared": False,
"fPIC": True,
"gles": False,
"gles": True,
"print_errors_at_runtime": True,
"print_warnings_at_runtime": True,
"replace_glut": True,
"with_wayland": True,
}

@property
def _requires_libglvnd_egl(self):
return self._requires_libglvnd_gles or self.options.get_safe("with_wayland")

@property
def _requires_libglvnd_gles(self):
return self._with_libglvnd and self.options.get_safe("gles")

@property
def _requires_libglvnd_glx(self):
return self._with_libglvnd and not self.options.get_safe("gles")

@property
def _with_libglvnd(self):
return self.settings.os in ["FreeBSD", "Linux"]

@property
def _with_x11(self):
return self.settings.os in ["FreeBSD", "Linux"] and not self.options.get_safe("with_wayland")

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
self.options.rm_safe("fPIC")
if self.settings.os != "Linux":
self.options.rm_safe("with_wayland")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

if self._requires_libglvnd_egl:
self.options["libglvnd"].egl = True
if self._requires_libglvnd_gles:
self.options["libglvnd"].gles1 = True
self.options["libglvnd"].gles2 = True
if self._requires_libglvnd_glx:
self.options["libglvnd"].glx = True
if self.options.get_safe("with_wayland"):
self.options["xkbcommon"].with_wayland = True

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("opengl/system")
self.requires("glu/system")
if self.settings.os == "Linux":
if self._with_libglvnd:
self.requires("libglvnd/1.7.0")
else:
self.requires("opengl/system")
if self.options.get_safe("with_wayland"):
self.requires("wayland/1.22.0")
self.requires("xkbcommon/1.6.0")
if self._with_x11:
self.requires("xorg/system")

def validate(self):
Expand All @@ -64,6 +109,17 @@ def validate(self):
(self.settings.compiler == "clang" and Version(self.settings.compiler.version) >= "11.0"):
# see https://github.com/dcnieho/FreeGLUT/issues/86
raise ConanInvalidConfiguration(f"{self.ref} does not support gcc >= 10 and clang >= 11")
if self._requires_libglvnd_egl and not self.dependencies["libglvnd"].options.egl:
raise ConanInvalidConfiguration(f"{self.ref} requires the egl option of libglvnd to be enabled when either the gles option or with_wayland option is enabled")
if self._requires_libglvnd_gles and not self.dependencies["libglvnd"].options.gles1:
raise ConanInvalidConfiguration(f"{self.ref} requires the gles1 option of libglvnd to be enabled when the gles option is enabled")
if self._requires_libglvnd_gles and not self.dependencies["libglvnd"].options.gles2:
raise ConanInvalidConfiguration(f"{self.ref} requires the gles2 option of libglvnd to be enabled when the gles option is enabled")
if self._requires_libglvnd_glx and not self.dependencies["libglvnd"].options.glx:
raise ConanInvalidConfiguration(f"{self.ref} requires the glx option of libglvnd to be enabled when the gles option is disabled")
if self.options.get_safe("with_wayland") and not self.dependencies["xkbcommon"].options.with_wayland:
raise ConanInvalidConfiguration(f"{self.ref} requires the with_wayland option of xkbcommon to be enabled when the with_wayland option is enabled")


def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand All @@ -76,19 +132,25 @@ def generate(self):
tc.variables["FREEGLUT_GLES"] = self.options.gles
tc.variables["FREEGLUT_PRINT_ERRORS"] = self.options.print_errors_at_runtime
tc.variables["FREEGLUT_PRINT_WARNINGS"] = self.options.print_warnings_at_runtime
tc.variables["FREEGLUT_WAYLAND"] = self.options.get_safe("with_wayland")
tc.variables["FREEGLUT_INSTALL_PDB"] = False
tc.variables["INSTALL_PDB"] = False
tc.variables["FREEGLUT_REPLACE_GLUT"] = self.options.replace_glut
tc.preprocessor_definitions["FREEGLUT_LIB_PRAGMAS"] = "0"
tc.generate()
cmake_deps = CMakeDeps(self)
cmake_deps.generate()
pkg_config_deps = PkgConfigDeps(self)
pkg_config_deps.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
Expand All @@ -107,7 +169,7 @@ def package_info(self):

# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
self.cpp_info.components["freeglut_"].libs = collect_libs(self)
if self.settings.os == "Linux":
if self.settings.os in ["FreeBSD", "Linux"]:
self.cpp_info.components["freeglut_"].system_libs.extend(["pthread", "m", "dl", "rt"])
elif self.settings.os == "Windows":
if not self.options.shared:
Expand All @@ -124,6 +186,19 @@ def package_info(self):
self.cpp_info.components["freeglut_"].names["cmake_find_package_multi"] = config_target
self.cpp_info.components["freeglut_"].set_property("cmake_target_name", f"FreeGLUT::{config_target}")
self.cpp_info.components["freeglut_"].set_property("pkg_config_name", pkg_config)
self.cpp_info.components["freeglut_"].requires.extend(["opengl::opengl", "glu::glu"])
if self.settings.os == "Linux":
self.cpp_info.components["freeglut_"].requires.append("glu::glu")
if self._requires_libglvnd_egl:
self.cpp_info.components["freeglut_"].requires.append("libglvnd::egl")
if self._requires_libglvnd_gles:
self.cpp_info.components["freeglut_"].requires.append("libglvnd::gles1")
self.cpp_info.components["freeglut_"].requires.append("libglvnd::gles2")
if self._requires_libglvnd_glx:
self.cpp_info.components["freeglut_"].requires.append("libglvnd::gl")
if self._with_libglvnd:
self.cpp_info.components["freeglut_"].requires.append("libglvnd::opengl")
else:
self.cpp_info.components["freeglut_"].requires.append("opengl::opengl")
if self._with_x11:
self.cpp_info.components["freeglut_"].requires.append("xorg::xorg")
if self.options.get_safe("with_wayland"):
self.cpp_info.components["freeglut_"].requires.extend(["wayland::wayland-client", "wayland::wayland-cursor", "wayland::wayland-egl", "xkbcommon::xkbcommon"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From df112bd86e895f4e545e65d71682d417e9b054e2 Mon Sep 17 00:00:00 2001
From: Jordan Williams <jordan@jwillikers.com>
Date: Thu, 2 Nov 2023 15:27:49 -0500
Subject: [PATCH] Use find_package and pkg_check_modules to find more
dependencies

This commit enhances the use of the FindOpenGL CMake module.
This requires CMake version 3.10 for the OpenGL::EGL imported target.

Finds the Wayland and xkbcommon dependencies with pkg_check_modules.
This works with the pkg-config files provided by the upstream projects.
---
CMakeLists.txt | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f403afa..43e36113 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)
-PROJECT(freeglut)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
+PROJECT(freeglut LANGUAGES C)

# for multiarch LIBDIR support (requires cmake>=2.8.8)
INCLUDE(GNUInstallDirs)
@@ -257,17 +257,24 @@ ENDIF()
# GLES1 and GLES2 libraries are compatible and can be co-linked.
IF(FREEGLUT_GLES)
LIST(APPEND PUBLIC_DEFINITIONS -DFREEGLUT_GLES)
- LIST(APPEND LIBS GLESv2 GLESv1_CM EGL)
+ # todo Use the OpenGL GLES2 component from CMake 3.27 when available.
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL)
+ LIST(APPEND LIBS GLESv2 GLESv1_CM OpenGL::EGL)
ELSE()
- FIND_PACKAGE(OpenGL REQUIRED)
- LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
- INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS OpenGL)
+ LIST(APPEND LIBS OpenGL::GL)
ENDIF()

# For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
IF(FREEGLUT_WAYLAND)
ADD_DEFINITIONS(-DFREEGLUT_WAYLAND)
- LIST(APPEND LIBS wayland-client wayland-cursor wayland-egl EGL xkbcommon)
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL)
+ INCLUDE(FindPkgConfig)
+ PKG_CHECK_MODULES(wayland-client REQUIRED IMPORTED_TARGET wayland-client)
+ PKG_CHECK_MODULES(wayland-cursor REQUIRED IMPORTED_TARGET wayland-cursor)
+ PKG_CHECK_MODULES(wayland-egl REQUIRED IMPORTED_TARGET wayland-egl)
+ PKG_CHECK_MODULES(xkbcommon REQUIRED IMPORTED_TARGET xkbcommon)
+ LIST(APPEND LIBS OpenGL::EGL PkgConfig::wayland-client PkgConfig::wayland-cursor PkgConfig::wayland-egl PkgConfig::xkbcommon)
ENDIF()

# lib m for math, not needed on windows
--
2.41.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From d8ce1f40a725742f85c6f5286ca4623307fe6f59 Mon Sep 17 00:00:00 2001
From: Jordan Williams <jordan@jwillikers.com>
Date: Thu, 2 Nov 2023 15:27:49 -0500
Subject: [PATCH] Use find_package and pkg_check_modules to find more
dependencies

This commit enhances the use of the FindOpenGL CMake module.
This requires CMake version 3.10 for the OpenGL::EGL imported target.

Finds the Wayland and xkbcommon dependencies with pkg_check_modules.
This works with the pkg-config files provided by the upstream projects.
---
CMakeLists.txt | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 832d8672..83cf2927 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)
-PROJECT(freeglut C)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
+PROJECT(freeglut LANGUAGES C)

# for multiarch LIBDIR support (requires cmake>=2.8.8)
INCLUDE(GNUInstallDirs)
@@ -292,7 +292,9 @@ ENDIF()
# GLES1 and GLES2 libraries are compatible and can be co-linked.
IF(FREEGLUT_GLES)
LIST(APPEND PUBLIC_DEFINITIONS -DFREEGLUT_GLES)
- LIST(APPEND LIBS GLESv2 GLESv1_CM EGL)
+ # todo Use the OpenGL GLES2 component from CMake 3.27 when available.
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL)
+ LIST(APPEND LIBS GLESv2 GLESv1_CM OpenGL::EGL)
ELSE()
# On OS X, we need to link against the X11 OpenGL libraries, NOT the Cocoa OpenGL libraries.
# To do that, you need to manually find two of the libraries before calling FindOpenGL
@@ -304,15 +306,20 @@ ELSE()
find_library(OPENGL_glu_LIBRARY NAME GLU HINTS ${X11_LIB_PATH})
endif()

- FIND_PACKAGE(OpenGL REQUIRED)
- LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
- INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS OpenGL)
+ LIST(APPEND LIBS OpenGL::GL)
ENDIF()

# For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
IF(FREEGLUT_WAYLAND)
ADD_DEFINITIONS(-DFREEGLUT_WAYLAND)
- LIST(APPEND LIBS wayland-client wayland-cursor wayland-egl EGL xkbcommon)
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL)
+ INCLUDE(FindPkgConfig)
+ PKG_CHECK_MODULES(wayland-client REQUIRED IMPORTED_TARGET wayland-client)
+ PKG_CHECK_MODULES(wayland-cursor REQUIRED IMPORTED_TARGET wayland-cursor)
+ PKG_CHECK_MODULES(wayland-egl REQUIRED IMPORTED_TARGET wayland-egl)
+ PKG_CHECK_MODULES(xkbcommon REQUIRED IMPORTED_TARGET xkbcommon)
+ LIST(APPEND LIBS OpenGL::EGL PkgConfig::wayland-client PkgConfig::wayland-cursor PkgConfig::wayland-egl PkgConfig::xkbcommon)
ENDIF()

# lib m for math, not needed on windows
--
2.41.0

1 change: 0 additions & 1 deletion recipes/libglvnd/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def package(self):

save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), textwrap.dedent('''\
Copyright (c) 2013, NVIDIA CORPORATION.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
Expand Down

0 comments on commit 8d11723

Please sign in to comment.