CMake: update backend selection

The single DAWN_ENABLE_OPENGL flag in the root CMakeLists.txt did not define
DAWN_ENABLE_BACKEND_DESKTOP_GL or DAWN_ENABLE_BACKEND_OPENGLES, so examples
with `-b opengl` reported `Backend isn't present` and failed to start.

ENABLE_OPENGL flag in root CMakeLists.txt was replaced by ENABLE_DESKTOP_GL
and ENABLE_OPENGLES flags, repeating the logic of similar flags
in GN buildsystem as done in src/common/BUILD.gn
and scripts/dawn_features.gni.

Change-Id: I6302de7aa98436ddc0aa002d83dd6b3e7102e49c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/56283
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Sergey K <sergey.ext@gmail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1d481a0..4fefeb4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,7 +50,8 @@
 # Default values for the backend-enabling options
 set(ENABLE_D3D12 OFF)
 set(ENABLE_METAL OFF)
-set(ENABLE_OPENGL OFF)
+set(ENABLE_OPENGLES OFF)
+set(ENABLE_DESKTOP_GL OFF)
 set(ENABLE_VULKAN OFF)
 set(USE_X11 OFF)
 set(BUILD_EXAMPLE OFF)
@@ -64,7 +65,8 @@
 elseif(APPLE)
     set(ENABLE_METAL ON)
 elseif(UNIX)
-    set(ENABLE_OPENGL ON)
+    set(ENABLE_OPENGLES ON)
+    set(ENABLE_DESKTOP_GL ON)
     set(ENABLE_VULKAN ON)
     set(USE_X11 ON)
 endif()
@@ -82,7 +84,8 @@
 option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
 option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
 option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
-option(DAWN_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ${ENABLE_OPENGL})
+option(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
+option(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
 option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
 option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
 option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
@@ -99,6 +102,11 @@
 set(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" CACHE STRING "Directory in which to find SPIRV-Tools")
 set(DAWN_TINT_DIR "${DAWN_THIRD_PARTY_DIR}/tint" CACHE STRING "Directory in which to find Tint")
 
+# Much of the backend code is shared among desktop OpenGL and OpenGL ES
+if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
+    set(DAWN_ENABLE_OPENGL ON)
+endif()
+
 ################################################################################
 # Dawn's public and internal "configs"
 ################################################################################
@@ -131,6 +139,12 @@
 if (DAWN_ENABLE_NULL)
     target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
 endif()
+if (DAWN_ENABLE_DESKTOP_GL)
+    target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
+endif()
+if (DAWN_ENABLE_OPENGLES)
+    target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
+endif()
 if (DAWN_ENABLE_OPENGL)
     target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
 endif()