# ============================================================================== # Find earcut # ============================================================================== # This module fetches the earcut.hpp polygon triangulation library. # # Targets provided: # earcut::earcut - The earcut library target # # Variables set: # earcut_FOUND - TRUE if earcut is available # earcut_LIBRARIES - The earcut library target (earcut::earcut) # earcut_INCLUDE_DIR - Include directories for earcut # earcut_VERSION - Version of earcut (if available) # ============================================================================== if (DEFINED _FINDEARCUT_INCLUDED) return() endif() set(_FINDEARCUT_INCLUDED TRUE) # Use the version passed to find_package(), or default to v2.2.4 if (DEFINED earcut_FIND_VERSION AND NOT earcut_FIND_VERSION STREQUAL "") set(EARCUT_VERSION "${earcut_FIND_VERSION}") else() set(EARCUT_VERSION "2.2.4") endif() message(STATUS "Fetching earcut ${EARCUT_VERSION}") include(FetchContent) find_program(GIT_EXECUTABLE git) if (NOT GIT_EXECUTABLE) message(FATAL_ERROR "Fetch with zip not supported.") endif() FetchContent_Declare( earcut GIT_REPOSITORY https://github.com/mapbox/earcut.hpp.git GIT_TAG v${EARCUT_VERSION} SOURCE_SUBDIR _unused # no CMakeLists.txt here; skips add_subdirectory ) # SOURCE_SUBDIR points to a non-existent directory so FetchContent_MakeAvailable # skips add_subdirectory; we only need the headers under include/. FetchContent_MakeAvailable(earcut) add_library(earcut INTERFACE) target_include_directories(earcut SYSTEM INTERFACE "${earcut_SOURCE_DIR}/include") add_library(earcut::earcut ALIAS earcut) set(earcut_FOUND TRUE) set(earcut_LIBRARIES earcut::earcut) set(earcut_VERSION "${EARCUT_VERSION}") set(earcut_INCLUDE_DIR "${earcut_SOURCE_DIR}/include") set(EARCUT_LICENSE_FILE "${earcut_SOURCE_DIR}/LICENSE" CACHE FILEPATH "Path to earcut license file")