[waffle] [PATCHv2 04/10] cmake: add autodetection for waffle_has_egl, glx...

Emil Velikov emil.l.velikov at gmail.com
Fri Jun 6 06:18:37 PDT 2014


Silence the pkg_check_modules and check set the default
options depending on the packages found.

Error out if the user has selected an option and it's
requirements are not met.

v2:
 - Do not silence pkg_check_modules.
 - Explicitly list the failing requirements.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---

The patch turned out a bit longer that I would like to,
although I cannot see any sane way of splitting it up :'(

At least it nicely prints which dependency is missing, so that
there should be little-to-no head-bashing from people building
waffle.

-Emil


 CMakeLists.txt                             |  2 +-
 Options.cmake                              | 32 ++++++++++++--
 cmake/Modules/WaffleFindDependencies.cmake | 30 ++++++-------
 cmake/Modules/WaffleValidateOptions.cmake  | 70 ++++++++++++++++++++++++++++++
 4 files changed, 113 insertions(+), 21 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b32b3d1..cf19929 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,12 +30,12 @@ cmake_minimum_required(VERSION 2.8)
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
 
 include(WaffleDefineOS)
+include(WaffleFindDependencies)
 include(Options.cmake)
 include(WaffleDefineInternalOptions)
 include(WaffleValidateOptions)
 include(WaffleDefineVersion)
 include(WaffleDefineCompilerFlags)
-include(WaffleFindDependencies)
 include(GNUInstallDirs)
 
 if(waffle_build_tests)
diff --git a/Options.cmake b/Options.cmake
index 7f694e3..c316070 100644
--- a/Options.cmake
+++ b/Options.cmake
@@ -1,9 +1,33 @@
 if(waffle_on_linux)
+    if(gl_FOUND AND x11-xcb_FOUND)
+        set(glx_default ON)
+    else()
+        set(glx_default OFF)
+    endif()
+
+    if(wayland-client_FOUND AND wayland-egl_FOUND AND egl_FOUND)
+        set(wayland_default ON)
+    else()
+        set(wayland_default OFF)
+    endif()
+
+    if(x11-xcb_FOUND AND egl_FOUND)
+        set(x11_egl_default ON)
+    else()
+        set(x11_egl_default OFF)
+    endif()
+
+    if(gbm_FOUND AND libudev_FOUND AND egl_FOUND)
+        set(gbm_default ON)
+    else()
+        set(gbm_default OFF)
+    endif()
+
     # On Linux, you must enable at least one of the below options.
-    option(waffle_has_glx "Build support for GLX" OFF)
-    option(waffle_has_wayland "Build support for Wayland" OFF)
-    option(waffle_has_x11_egl "Build support for X11/EGL" OFF)
-    option(waffle_has_gbm "Build support for GBM" OFF)
+    option(waffle_has_glx "Build support for GLX" ${glx_default})
+    option(waffle_has_wayland "Build support for Wayland" ${wayland_default})
+    option(waffle_has_x11_egl "Build support for X11/EGL" ${x11_egl_default})
+    option(waffle_has_gbm "Build support for GBM" ${gbm_default})
 endif()
 
 option(waffle_build_tests "Build tests" ON)
diff --git a/cmake/Modules/WaffleFindDependencies.cmake b/cmake/Modules/WaffleFindDependencies.cmake
index 527e01f..9245772 100644
--- a/cmake/Modules/WaffleFindDependencies.cmake
+++ b/cmake/Modules/WaffleFindDependencies.cmake
@@ -61,24 +61,22 @@ if(waffle_on_mac)
     find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation REQUIRED)
 endif()
 
-if(waffle_has_egl)
-    waffle_pkg_config(egl REQUIRED egl)
-endif()
 
-if(waffle_has_glx)
-    waffle_pkg_config(gl REQUIRED gl)
-endif()
+if(waffle_on_linux)
+    # waffle_has_egl
+    waffle_pkg_config(egl egl)
 
-if(waffle_has_wayland)
-    waffle_pkg_config(wayland-client REQUIRED wayland-client>=1)
-    waffle_pkg_config(wayland-egl REQUIRED wayland-egl>=9.1)
-endif()
+    # waffle_has_glx
+    waffle_pkg_config(gl gl)
 
-if(waffle_has_x11)
-    waffle_pkg_config(x11-xcb REQUIRED x11-xcb)
-endif()
+    # waffle_has_wayland
+    waffle_pkg_config(wayland-client wayland-client>=1)
+    waffle_pkg_config(wayland-egl wayland-egl>=9.1)
+
+    # waffle_has_x11
+    waffle_pkg_config(x11-xcb x11-xcb)
 
-if(waffle_has_gbm)
-    waffle_pkg_config(gbm REQUIRED gbm)
-    waffle_pkg_config(libudev REQUIRED libudev)
+    # waffle_has_gbm
+    waffle_pkg_config(gbm gbm)
+    waffle_pkg_config(libudev libudev)
 endif()
diff --git a/cmake/Modules/WaffleValidateOptions.cmake b/cmake/Modules/WaffleValidateOptions.cmake
index 03eb4ba..d9fc299 100644
--- a/cmake/Modules/WaffleValidateOptions.cmake
+++ b/cmake/Modules/WaffleValidateOptions.cmake
@@ -52,6 +52,76 @@ if(waffle_on_linux)
                 "waffle_has_glx, waffle_has_wayland, "
                 "waffle_has_x11_egl, waffle_has_gbm.")
     endif()
+    if(waffle_has_gbm)
+        if(NOT gbm_FOUND)
+            set(gbm_missing_deps
+                "${gbm_missing_deps} gbm"
+                )
+        endif()
+        if(NOT libudev_FOUND)
+            set(gbm_missing_deps
+                "${gbm_missing_deps} libudev"
+                )
+        endif()
+        if(NOT egl_FOUND)
+            set(gbm_missing_deps
+                "${gbm_missing_deps} egl"
+                )
+        endif()
+        if(gbm_missing_deps)
+            message(FATAL_ERROR "gbm dependency is missing: ${gbm_missing_deps}")
+        endif()
+    endif()
+    if(waffle_has_glx)
+        if(NOT gl_FOUND)
+            set(glx_missing_deps
+                "${glx_missing_deps} gl"
+                )
+        endif()
+        if(NOT x11-xcb_FOUND)
+            set(glx_missing_deps
+                "${glx_missing_deps} x11-xcb"
+                )
+        endif()
+        if(glx_missing_deps)
+            message(FATAL_ERROR "glx dependency is missing: ${glx_missing_deps}")
+        endif()
+    endif()
+    if(waffle_has_wayland)
+        if(NOT wayland-client_FOUND)
+            set(wayland_missing_deps
+                "${wayland_missing_deps} wayland-client>=1"
+                )
+        endif()
+        if(NOT wayland-egl_FOUND)
+            set(wayland_missing_deps
+                "${wayland_missing_deps} wayland-egl>=9.1"
+                )
+        endif()
+        if(NOT egl_FOUND)
+            set(wayland_missing_deps
+                "${wayland_missing_deps} egl"
+                )
+        endif()
+        if(wayland_missing_deps)
+            message(FATAL_ERROR "wayland dependency is missing: ${wayland_missing_deps}")
+        endif()
+    endif()
+    if(waffle_has_x11_egl)
+        if(NOT x11-xcb_FOUND)
+            set(x11_egl_missing_deps
+                "${x11_egl_missing_deps} x11-xcb"
+                )
+        endif()
+        if(NOT egl_FOUND)
+            set(x11_egl_missing_deps
+                "${x11_egl_missing_deps} egl"
+                )
+        endif()
+        if(x11_egl_missing_deps)
+            message(FATAL_ERROR "x11_egl dependency is missing: ${x11_egl_missing_deps}")
+        endif()
+    endif()
 elseif(waffle_on_mac)
     if(waffle_has_gbm)
         message(FATAL_ERROR "Option is not supported on Darwin: waffle_has_gbm.")
-- 
1.9.3



More information about the waffle mailing list