From cb4fb07d2bb7f5d778ec89d7136acb22e3a3778a Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 5 Feb 2024 12:18:36 -0800 Subject: [PATCH] CMake: improved handling of OpenGL and X11 libraries on linux --- CMakeLists.txt | 19 ++++++++++++------- Graphics/Archiver/CMakeLists.txt | 3 ++- Graphics/GraphicsEngineOpenGL/CMakeLists.txt | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33b67f0f8..b36e33a3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -469,35 +469,40 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") endif() endif() -if(PLATFORM_MACOS) +if(PLATFORM_LINUX) + find_library(OPENGL_LIBRARY GL) + if (NOT OPENGL_LIBRARY) + message(FATAL_ERROR "Failed to find OpenGL library") + endif() +elseif(PLATFORM_MACOS) find_library(APP_KIT AppKit) if (NOT APP_KIT) - message(FATAL_ERROR "AppKit not found") + message(FATAL_ERROR "Failed to find AppKit framework") endif() elseif(PLATFORM_IOS) find_library(CORE_FOUNDATION CoreFoundation) if(NOT CORE_FOUNDATION) - message(FATAL_ERROR "Cannot find CoreFoundation framework") + message(FATAL_ERROR "Failed to find CoreFoundation framework") endif() find_library(FOUNDATION Foundation) if(NOT FOUNDATION) - message(FATAL_ERROR "Cannot find Foundation framework") + message(FATAL_ERROR "Failed to find Foundation framework") endif() find_library(OPENGLES OpenGLES) if(NOT OPENGLES) - message(FATAL_ERROR "Cannot find OpenGLES framework") + message(FATAL_ERROR "Failed to find OpenGLES framework") endif() elseif(PLATFORM_TVOS) find_library(CORE_FOUNDATION CoreFoundation) if(NOT CORE_FOUNDATION) - message(FATAL_ERROR "Cannot find CoreFoundation framework") + message(FATAL_ERROR "Failed to find CoreFoundation framework") endif() find_library(FOUNDATION Foundation) if(NOT FOUNDATION) - message(FATAL_ERROR "Cannot find Foundation framework") + message(FATAL_ERROR "Failed to find Foundation framework") endif() endif() diff --git a/Graphics/Archiver/CMakeLists.txt b/Graphics/Archiver/CMakeLists.txt index 6635d121c..50aab4481 100644 --- a/Graphics/Archiver/CMakeLists.txt +++ b/Graphics/Archiver/CMakeLists.txt @@ -132,7 +132,8 @@ if(GL_SUPPORTED OR GLES_SUPPORTED) if(PLATFORM_WIN32) target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew opengl32.lib) elseif(PLATFORM_LINUX) - target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew GL X11) + find_package(X11 REQUIRED) + target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew ${OPENGL_LIBRARY} X11::X11) elseif(PLATFORM_MACOS) find_package(OpenGL REQUIRED) target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew ${OPENGL_LIBRARY}) diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index cc1237490..92e8f4d17 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -198,7 +198,8 @@ if(PLATFORM_WIN32) elseif(PLATFORM_ANDROID) set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLESv3 EGL) elseif(PLATFORM_LINUX) - set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew GL X11) + find_package(X11 REQUIRED) + set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew ${OPENGL_LIBRARY} X11::X11) elseif(PLATFORM_MACOS) find_package(OpenGL REQUIRED) set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew ${OPENGL_LIBRARY})