Skip to content

Commit

Permalink
(#22428) freeglut: Use the mesa-glu package when not on Apple or Windows
Browse files Browse the repository at this point in the history
The glu/system package installs the Mesa GLU system package on Linux and FreeBSD.
Now that the mesa-glu package is available in Conan, use that instead.
  • Loading branch information
jwillikers authored Feb 27, 2024
1 parent 3d3d57e commit 86284a9
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 2 deletions.
12 changes: 12 additions & 0 deletions recipes/freeglut/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ patches:
patch_description: "Use find_library to locate GL libraries"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/148"
patch_type: "portability"
- patch_file: "patches/3.4.0-0003-Incorporate-the-include-directory-for-glu.h-in-CMake.patch"
patch_description: "Incorporate the include directory for glu.h in CMake"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/154"
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"
Expand All @@ -31,6 +35,10 @@ patches:
patch_description: "Use find_library to locate GL libraries"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/148"
patch_type: "portability"
- patch_file: "patches/3.2.2-0003-Incorporate-the-include-directory-for-glu.h-in-CMake.patch"
patch_description: "Incorporate the include directory for glu.h in CMake"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/154"
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"
Expand All @@ -44,3 +52,7 @@ patches:
patch_description: "Use find_library to locate GL libraries"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/148"
patch_type: "portability"
- patch_file: "patches/3.2.1-0004-Incorporate-the-include-directory-for-glu.h-in-CMake.patch"
patch_description: "Incorporate the include directory for glu.h in CMake"
patch_source: "https://github.com/FreeGLUTProject/freeglut/pull/154"
patch_type: "portability"
12 changes: 10 additions & 2 deletions recipes/freeglut/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
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
Expand Down Expand Up @@ -91,7 +92,11 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("glu/system")
if is_apple_os(self) or self.settings.os == "Windows":
self.requires("glu/system")
else:
# FreeGLUT includes glu.h in freeglut_std.h.
self.requires("mesa-glu/9.0.3", transitive_headers=True)
if self._with_libglvnd:
self.requires("libglvnd/1.7.0")
else:
Expand Down Expand Up @@ -190,7 +195,6 @@ 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.append("glu::glu")
if self._requires_libglvnd_egl:
self.cpp_info.components["freeglut_"].requires.append("libglvnd::egl")
if self._requires_libglvnd_gles:
Expand All @@ -206,3 +210,7 @@ def package_info(self):
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"])
if is_apple_os(self) or self.settings.os == "Windows":
self.cpp_info.components["freeglut_"].requires.append("glu::glu")
else:
self.cpp_info.components["freeglut_"].requires.append("mesa-glu::mesa-glu")
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From c81e600ace29bf5f3ded5e2650859f3303aaac6e Mon Sep 17 00:00:00 2001
From: Jordan Williams <jordan@jwillikers.com>
Date: Wed, 7 Feb 2024 10:09:25 -0600
Subject: [PATCH] Incorporate the include directory for glu.h in CMake

FreeGLUT doesn't properly check for the glu.h header file when it is required.
The glu.h header is not necessary when FreeGLUT is built for GLES.
However, the demos require use libGLU and so require the include and the library.

CMake's FindOpenGL didn't properly search for the glu.h header file until very recently.
Refer to this PR: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9216.

This PR checks for the glu.h header and adds the corresponding include directory when it is required.
For versions of CMake prior to 3.29, the include directory for GLU is added even when linking against the OpenGL::GLU target.
Like the FindOpenGL module, GLU include directories are ignored on Windows.
---
CMakeLists.txt | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 772e73f3..162eec40 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -290,6 +290,17 @@ ELSE()
LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
endif()
+
+ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ # CMake 3.29 properly locates the include directory for glu.h in the OPENGL_GLU_INCLUDE_DIR variable for us.
+ if(CMAKE_VERSION VERSION_LESS "3.29")
+ FIND_PATH(OPENGL_GLU_INCLUDE_DIR NAMES GL/glu.h OpenGL/glu.h HINTS ${OPENGL_INCLUDE_DIR})
+ endif()
+ if(NOT OPENGL_GLU_INCLUDE_DIR)
+ message(FATAL_ERROR "Failed to find the glu.h header file.")
+ endif()
+ INCLUDE_DIRECTORIES(${OPENGL_GLU_INCLUDE_DIR})
+ endif()
ENDIF()

# For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
@@ -566,7 +577,15 @@ INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL COMPONENT Devel)
# Optionally build demos, on by default.
option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )

-SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
+set(DEMO_LIBS ${LIBS})
+if (FREEGLUT_BUILD_DEMOS)
+ if (OPENGL_GLU_FOUND)
+ list(APPEND DEMO_LIBS ${OPENGL_glu_LIBRARY})
+ else()
+ message(FATAL_ERROR "Failed to find the GLU library which is required to build the demos.")
+ endif()
+endif()
+
# lib m for math, not needed on windows
IF (NOT WIN32)
LIST(APPEND DEMO_LIBS m)
--
2.43.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 278ac11cf27c8112021735240dc0b34fe849045e Mon Sep 17 00:00:00 2001
From: Jordan Williams <jordan@jwillikers.com>
Date: Wed, 7 Feb 2024 10:09:25 -0600
Subject: [PATCH] Incorporate the include directory for glu.h in CMake

FreeGLUT doesn't properly check for the glu.h header file when it is required.
The glu.h header is not necessary when FreeGLUT is built for GLES.
However, the demos require use libGLU and so require the include and the library.

CMake's FindOpenGL didn't properly search for the glu.h header file until very recently.
Refer to this PR: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9216.

This PR checks for the glu.h header and adds the corresponding include directory when it is required.
For versions of CMake prior to 3.29, the include directory for GLU is added even when linking against the OpenGL::GLU target.
Like the FindOpenGL module, GLU include directories are ignored on Windows.
---
CMakeLists.txt | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c2549b1b..4ebc33af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -294,6 +294,17 @@ ELSE()
LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
endif()
+
+ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ # CMake 3.29 properly locates the include directory for glu.h in the OPENGL_GLU_INCLUDE_DIR variable for us.
+ if(CMAKE_VERSION VERSION_LESS "3.29")
+ FIND_PATH(OPENGL_GLU_INCLUDE_DIR NAMES GL/glu.h OpenGL/glu.h HINTS ${OPENGL_INCLUDE_DIR})
+ endif()
+ if(NOT OPENGL_GLU_INCLUDE_DIR)
+ message(FATAL_ERROR "Failed to find the glu.h header file.")
+ endif()
+ INCLUDE_DIRECTORIES(${OPENGL_GLU_INCLUDE_DIR})
+ endif()
ENDIF()

# For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
@@ -578,7 +589,15 @@ INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL COMPONENT Devel)
# Optionally build demos, on by default.
option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )

-SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
+set(DEMO_LIBS ${LIBS})
+if (FREEGLUT_BUILD_DEMOS)
+ if (OPENGL_GLU_FOUND)
+ list(APPEND DEMO_LIBS ${OPENGL_glu_LIBRARY})
+ else()
+ message(FATAL_ERROR "Failed to find the GLU library which is required to build the demos.")
+ endif()
+endif()
+
# lib m for math, not needed on windows
IF (NOT WIN32)
LIST(APPEND DEMO_LIBS m)
--
2.43.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
From 90f733b3adec8b3f97a24d4dd9dc47a595a17c2c Mon Sep 17 00:00:00 2001
From: Jordan Williams <jordan@jwillikers.com>
Date: Wed, 7 Feb 2024 10:09:25 -0600
Subject: [PATCH] Incorporate the include directory for glu.h in CMake

FreeGLUT doesn't properly check for the glu.h header file when it is required.
The glu.h header is not necessary when FreeGLUT is built for GLES.
However, the demos require use libGLU and so require the include and the library.

CMake's FindOpenGL didn't properly search for the glu.h header file until very recently.
Refer to this PR: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9216.

This PR checks for the glu.h header and adds the corresponding include directory when it is required.
For versions of CMake prior to 3.29, the include directory for GLU is added even when linking against the OpenGL::GLU target.
Like the FindOpenGL module, GLU include directories are ignored on Windows.
---
CMakeLists.txt | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index afb4d735..aaf854d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -324,6 +324,7 @@ ELSE()
get_filename_component(X11_LIB_PATH ${X11_Xi_LIB} DIRECTORY)

find_library(OPENGL_gl_LIBRARY NAME GL HINTS ${X11_LIB_PATH})
+ find_path(OPENGL_GLU_INCLUDE_DIR NAMES GL/glu.h OpenGL/glu.h HINTS ${X11_Xi_INCLUDE_PATH})
find_library(OPENGL_glu_LIBRARY NAME GLU HINTS ${X11_LIB_PATH})
endif()

@@ -335,6 +336,17 @@ ELSE()
LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
endif()
+
+ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ # CMake 3.29 properly locates the include directory for glu.h in the OPENGL_GLU_INCLUDE_DIR variable for us.
+ if(CMAKE_VERSION VERSION_LESS "3.29")
+ FIND_PATH(OPENGL_GLU_INCLUDE_DIR NAMES GL/glu.h OpenGL/glu.h HINTS ${OPENGL_INCLUDE_DIR})
+ endif()
+ if(NOT OPENGL_GLU_INCLUDE_DIR)
+ message(FATAL_ERROR "Failed to find the glu.h header file.")
+ endif()
+ INCLUDE_DIRECTORIES(${OPENGL_GLU_INCLUDE_DIR})
+ endif()
ENDIF()

# For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
@@ -599,7 +611,15 @@ INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL COMPONENT Devel)
# Optionally build demos, on by default.
option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )

-SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
+set(DEMO_LIBS ${LIBS})
+if (FREEGLUT_BUILD_DEMOS)
+ if (OPENGL_GLU_FOUND)
+ list(APPEND DEMO_LIBS ${OPENGL_glu_LIBRARY})
+ else()
+ message(FATAL_ERROR "Failed to find the GLU library which is required to build the demos.")
+ endif()
+endif()
+
# lib m for math, not needed on windows
IF (NOT WIN32)
LIST(APPEND DEMO_LIBS m)
--
2.43.2

0 comments on commit 86284a9

Please sign in to comment.