Skip to content

Commit

Permalink
(#20905) freeglut: Add support for Wayland
Browse files Browse the repository at this point in the history
* freeglut: Add support for Wayland

* Add patch for 3.2.2

* Use VirtualBuildEnv

* Ensure that the GLES libraries are linked in from the libglvnd Conan package

* Revert "Use VirtualBuildEnv"

This reverts commit b32ddc8.

* Drop v1 test packages

* Bump CMake minimum required to 3.11 to enable policy CMP0072

* Bump the minimum required CMake version

* Add a patch to include a missing function definition

* Update patches to match the fixes merged upstream

* Add patch to pick up the correct GLES libraries

* Only allow the gles option on Linux and FreeBSD

* Set default for get_safe

* Default GLES as the upstream project does
  • Loading branch information
jwillikers authored Feb 26, 2024
1 parent 584c8d8 commit c87d051
Show file tree
Hide file tree
Showing 15 changed files with 636 additions and 73 deletions.
36 changes: 36 additions & 0 deletions recipes/freeglut/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,39 @@ 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"
- patch_file: "patches/3.4.0-0002-Use-find_library-to-locate-GL-libraries-not-provided.patch"
patch_description: "Use find_library to locate GL libraries"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/148"
patch_type: "portability"
"3.2.2":
- patch_file: "patches/3.2.1-0002-fixed-android-undefined-reference-to-glutCreateMenuU.patch"
patch_description: "Add a missing function definition"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/122"
patch_type: "portability"
- patch_file: "patches/3.2.2-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"
- patch_file: "patches/3.2.2-0002-Use-find_library-to-locate-GL-libraries-not-provided.patch"
patch_description: "Use find_library to locate GL libraries"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/148"
patch_type: "portability"
"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"
- patch_file: "patches/3.2.1-0002-fixed-android-undefined-reference-to-glutCreateMenuU.patch"
patch_description: "Add a missing function definition"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/122"
patch_type: "portability"
- patch_file: "patches/3.2.1-0003-Use-find_library-to-locate-GL-libraries-not-provided.patch"
patch_description: "Use find_library to locate GL libraries"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/148"
patch_type: "portability"
101 changes: 90 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,6 +25,8 @@ 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,
Expand All @@ -32,25 +35,71 @@ class freeglutConan(ConanFile):
"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 not in ["Android", "FreeBSD", "Linux"]:
self.options.rm_safe("gles")
else:
self.options.gles = self.settings.os == "Android"
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 +113,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 @@ -73,22 +133,28 @@ def generate(self):
tc.variables["FREEGLUT_BUILD_DEMOS"] = False
tc.variables["FREEGLUT_BUILD_STATIC_LIBS"] = not self.options.shared
tc.variables["FREEGLUT_BUILD_SHARED_LIBS"] = self.options.shared
tc.variables["FREEGLUT_GLES"] = self.options.gles
tc.variables["FREEGLUT_GLES"] = self.options.get_safe("gles", False)
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", False)
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 +173,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 +190,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,94 @@
From 4c573afc0453f3572c494d22b4f3bad9a9ce4073 Mon Sep 17 00:00:00 2001
From: Jordan Williams <jordan@jwillikers.com>
Date: Tue, 7 Nov 2023 07:38:42 -0600
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.
CMake 3.11 and later enable CMake policy CMP0072.
This prefers the GLVND libraries when available.

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f403afa..a2a95c02 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,9 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)
-PROJECT(freeglut)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR)
+PROJECT(freeglut LANGUAGES C)
+
+if (POLICY CMP0072)
+ cmake_policy(SET CMP0072 NEW)
+endif()

# for multiarch LIBDIR support (requires cmake>=2.8.8)
INCLUDE(GNUInstallDirs)
@@ -257,17 +261,52 @@ 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)
+ if(NOT CMAKE_VERSION VERSION_LESS "3.27")
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL GLES2 OpenGL)
+ LIST(APPEND LIBS GLESv1_CM OpenGL::EGL OpenGL::GLES2 OpenGL::OpenGL)
+ elseif(NOT CMAKE_VERSION VERSION_LESS "3.10")
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL OpenGL)
+ LIST(APPEND LIBS GLESv2 GLESv1_CM OpenGL::EGL OpenGL::OpenGL)
+ else()
+ FIND_PACKAGE(OpenGL REQUIRED)
+ LIST(APPEND LIBS EGL GLESv2 GLESv1_CM)
+ endif()
ELSE()
- FIND_PACKAGE(OpenGL REQUIRED)
- LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
- INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
+ if(NOT CMAKE_VERSION VERSION_LESS "3.10")
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS OpenGL)
+ LIST(APPEND LIBS OpenGL::GL)
+ else()
+ FIND_PACKAGE(OpenGL REQUIRED)
+ LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
+ INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
+ endif()
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)
+ INCLUDE(FindPkgConfig)
+ if(NOT CMAKE_VERSION VERSION_LESS "3.10")
+ FIND_PACKAGE(OpenGL REQUIRED COMPONENTS EGL OpenGL)
+ LIST(APPEND LIBS OpenGL::EGL OpenGL::OpenGL)
+ else()
+ FIND_PACKAGE(OpenGL REQUIRED)
+ LIST(APPEND LIBS EGL)
+ endif()
+ if(NOT CMAKE_VERSION VERSION_LESS "3.6")
+ 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 PkgConfig::wayland-client PkgConfig::wayland-cursor PkgConfig::wayland-egl PkgConfig::xkbcommon)
+ else()
+ PKG_CHECK_MODULES(wayland-client REQUIRED)
+ PKG_CHECK_MODULES(wayland-cursor REQUIRED)
+ PKG_CHECK_MODULES(wayland-egl REQUIRED)
+ PKG_CHECK_MODULES(xkbcommon REQUIRED)
+ LIST(APPEND LIBS ${wayland-client_LINK_LIBRARIES} ${wayland-cursor_LINK_LIBRARIES} ${wayland-egl_LINK_LIBRARIES} ${xkbcommon_LINK_LIBRARIES})
+ INCLUDE_DIRECTORIES(${wayland-client_INCLUDE_DIRS} ${wayland-cursor_INCLUDE_DIRS} ${wayland-egl_INCLUDE_DIRS} ${xkbcommon_INCLUDE_DIRS})
+ endif()
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,25 @@
From 782e63b2eacd47155864d0d1d9b70615418e3083 Mon Sep 17 00:00:00 2001
From: Jonatha Gabriel <jonathagabrielns@gmail.com>
Date: Sun, 4 Sep 2022 23:25:23 -0300
Subject: [PATCH] fixed android undefined reference to glutCreateMenuUcall

---
src/gles_stubs.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/gles_stubs.c b/src/gles_stubs.c
index bc87c0d8..63a19209 100644
--- a/src/gles_stubs.c
+++ b/src/gles_stubs.c
@@ -18,6 +18,8 @@ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
return GL_FALSE;
}

+int FGAPIENTRY glutCreateMenuUcall( FGCBMenuUC callback, FGCBUserData userData ) { return 0; }
+
int glutCreateMenu( void (* callback)( int menu ) ) { return 0; }
void glutDestroyMenu( int menu ) {}
int glutGetMenu( void ) { return 0; }
--
2.41.0

Loading

0 comments on commit c87d051

Please sign in to comment.