From 2ccb454345fcb653fbd1b567a7bd002640efe77f Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 26 Sep 2025 15:48:02 +0200 Subject: [PATCH] Add validate-backend-options.cmake script (#3828) Co-authored-by: Frank Elsinga --- CMakeLists.txt | 9 +----- cmake/validate-backend-options.cmake | 28 +++++++++++++++++++ .../MapLibreAndroidTestApp/build.gradle.kts | 10 +++++++ 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 cmake/validate-backend-options.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 064f8a785..eb43e3640 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,14 +21,7 @@ option(MLN_TEXT_SHAPING_HARFBUZZ "Use haffbuzz to shape complex text" ON) option(MLN_CORE_INCLUDE_DEPS "Include depdendencies in static build of core" OFF) option(MLN_CREATE_AUTORELEASEPOOL "Create autoreleasepool in render loop" OFF) -if (MLN_LEGACY_RENDERER) - message(FATAL "The legacy renderer is no longer supported") -endif() - -if (MLN_DRAWABLE_RENDERER) - message(FATAL "Do not pass MLN_DRAWABLE_RENDERER, the drawable renderer is now the default") -endif() - +include(cmake/validate-backend-options.cmake) include(cmake/clang-tidy.cmake) if (MLN_WITH_QT AND NOT CMAKE_OSX_DEPLOYMENT_TARGET) diff --git a/cmake/validate-backend-options.cmake b/cmake/validate-backend-options.cmake new file mode 100644 index 000000000..a7bfcf075 --- /dev/null +++ b/cmake/validate-backend-options.cmake @@ -0,0 +1,28 @@ +if (MLN_LEGACY_RENDERER) + message(FATAL "The legacy renderer is no longer supported") +endif() + +if (MLN_DRAWABLE_RENDERER) + message(FATAL "Do not pass MLN_DRAWABLE_RENDERER, the drawable renderer is now the default") +endif() + +set(backend_count 0) +if (MLN_WITH_OPENGL) + math(EXPR backend_count "${backend_count} + 1") +endif() +if (MLN_WITH_METAL) + math(EXPR backend_count "${backend_count} + 1") +endif() +if (MLN_WITH_VULKAN) + math(EXPR backend_count "${backend_count} + 1") +endif() + +if (backend_count EQUAL 0) + message(FATAL_ERROR + "You need to set a rendering backend. " + "Set exactly one of: MLN_WITH_OPENGL, MLN_WITH_METAL, or MLN_WITH_VULKAN.") +elseif (backend_count GREATER 1) + message(FATAL_ERROR + "Multiple rendering backends selected. " + "Please enable only one of: MLN_WITH_OPENGL, MLN_WITH_METAL, or MLN_WITH_VULKAN.") +endif() diff --git a/platform/android/MapLibreAndroidTestApp/build.gradle.kts b/platform/android/MapLibreAndroidTestApp/build.gradle.kts index bbe1ac04d..abdcaf5f3 100644 --- a/platform/android/MapLibreAndroidTestApp/build.gradle.kts +++ b/platform/android/MapLibreAndroidTestApp/build.gradle.kts @@ -79,9 +79,19 @@ android { productFlavors { create("opengl") { dimension = "renderer" + externalNativeBuild { + cmake { + arguments("-DMLN_WITH_OPENGL=ON", "-DMLN_WITH_VULKAN=OFF") + } + } } create("vulkan") { dimension = "renderer" + externalNativeBuild { + cmake { + arguments("-DMLN_WITH_OPENGL=OFF", "-DMLN_WITH_VULKAN=ON") + } + } } }