--- CMakeLists.txt
+++ CMakeLists.txt	2026-04-26 20:03:33.020211169 +0000
@@ -1,50 +1,83 @@
 cmake_minimum_required(VERSION 3.8)
 project(uterm LANGUAGES CXX)
 
-set(OpenGL_GL_PREFERENCE GLVND)
+option(USE_SYSTEM_DEPS "Use system-installed dependencies" ON)
 
-if (NOT ${CMAKE_GENERATOR} STREQUAL Ninja)
-  message(FATAL_ERROR "Ninja must be used as the build generator.")
-endif ()
-
-if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-  message(WARNING "Clang is recommended for best performance")
+# Allow other generators besides Ninja
+if (NOT USE_SYSTEM_DEPS AND NOT ${CMAKE_GENERATOR} STREQUAL Ninja)
+  message(FATAL_ERROR "Ninja must be used as the build generator when building bundled deps.")
 endif()
 
-# Needed for GN
-find_package(Python COMPONENTS Interpreter REQUIRED)
-
 find_package(PkgConfig REQUIRED)
+
+# Core dependencies
 pkg_check_modules(GLFW3 REQUIRED glfw3)
-pkg_check_modules(EGL REQUIRED egl)
 pkg_check_modules(EPOXY REQUIRED epoxy)
 pkg_check_modules(LIBCONFUSE REQUIRED libconfuse)
 
-if (UNIX AND NOT APPLE)
+# Platform-specific GL handling
+if (APPLE)
+  find_library(OPENGL_FRAMEWORK OpenGL REQUIRED)
+  find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
+  set(GL_LIBRARIES ${OPENGL_FRAMEWORK} ${COCOA_FRAMEWORK} ${EPOXY_LIBRARIES})
+  set(GL_INCLUDE_DIRS ${EPOXY_INCLUDE_DIRS})
+else()
+  pkg_check_modules(EGL REQUIRED egl)
+  set(GL_LIBRARIES ${EGL_LIBRARIES} ${EPOXY_LIBRARIES})
+  set(GL_INCLUDE_DIRS ${EGL_INCLUDE_DIRS} ${EPOXY_INCLUDE_DIRS})
+endif()
+
+# Font handling
+if (NOT APPLE)
   pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
   pkg_check_modules(FREETYPE REQUIRED freetype2)
-  set(UNIX_FONT_STACK TRUE)
-endif ()
-
-add_compile_options(-fdiagnostics-color -Wno-everything -Wno-fatal-errors)
+  set(FONT_LIBRARIES ${FONTCONFIG_LIBRARIES} ${FREETYPE_LIBRARIES})
+endif()
 
+# Optional performance library
 find_library(TCMALLOC NAMES tcmalloc)
-if (NOT TCMALLOC)
-  message(WARNING "tcmalloc is recommended for best performance.")
-endif ()
-
-set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
-set(UTF8_TESTS OFF CACHE BOOL "")
-set(UTF8_SAMPLES OFF CACHE BOOL "")
-
-add_subdirectory(deps/abseil)
-add_subdirectory(deps/fmt)
-add_subdirectory(deps/libtsm)
-add_subdirectory(deps/utfcpp)
 
-include(cmake/BuildPhmap.cmake)
-include(cmake/BuildSkia.cmake)
+# System dependencies
+if (USE_SYSTEM_DEPS)
+  # Abseil
+  find_package(absl REQUIRED)
+
+  # fmt
+  find_package(fmt REQUIRED)
+
+  # Skia
+  pkg_check_modules(SKIA REQUIRED skia)
+
+  # libtsm
+  pkg_check_modules(LIBTSM REQUIRED libtsm)
+
+  # utfcpp (header-only)
+  find_path(UTFCPP_INCLUDE_DIR utf8.h PATH_SUFFIXES utf8cpp utf8)
+  if (NOT UTFCPP_INCLUDE_DIR)
+    message(FATAL_ERROR "utfcpp not found")
+  endif()
+
+  # Use bundled parallel-hashmap (system version API incompatible)
+  include(cmake/BuildPhmap.cmake)
+else()
+  # Use bundled dependencies
+  set(OpenGL_GL_PREFERENCE GLVND)
+  find_package(Python COMPONENTS Interpreter REQUIRED)
+
+  set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
+  set(UTF8_TESTS OFF CACHE BOOL "")
+  set(UTF8_SAMPLES OFF CACHE BOOL "")
+
+  add_subdirectory(deps/abseil)
+  add_subdirectory(deps/fmt)
+  add_subdirectory(deps/libtsm)
+  add_subdirectory(deps/utfcpp)
+
+  include(cmake/BuildPhmap.cmake)
+  include(cmake/BuildSkia.cmake)
+endif()
 
+# Build uterm
 add_executable(uterm
   src/config.cc
   src/display.cc
@@ -57,32 +90,60 @@
   src/text.cc
   src/uterm.cc
   src/window.cc)
+
 target_compile_features(uterm PUBLIC cxx_std_14)
+
 target_include_directories(uterm PUBLIC
   ${GLFW3_INCLUDE_DIRS}
-  ${EGL_INCLUDE_DIRS}
-  ${EPOXY_INCLUDE_DIRS}
-  ${LIBCONFUSE_INCLUDE_DIRS})
-target_link_libraries(uterm
-  absl::base
-  absl::failure_signal_handler
-  absl::hash
-  absl::stacktrace
-  absl::strings
-  absl::symbolize
-  fmt::fmt
-  phmap
-  skia
-  libtsm::tsm
-  utf8::cpp
-  ${GLFW3_LIBRARIES}
-  ${EGL_LIBRARIES}
-  ${EPOXY_LIBRARIES}
-  ${LIBCONFUSE_LIBRARIES}
-  ${TCMALLOC})
+  ${LIBCONFUSE_INCLUDE_DIRS}
+  ${GL_INCLUDE_DIRS}
+  ${SKIA_INCLUDE_DIRS}
+  ${LIBTSM_INCLUDE_DIRS}
+  ${UTFCPP_INCLUDE_DIR})
+
+if (USE_SYSTEM_DEPS)
+  target_link_libraries(uterm
+    absl::base
+    absl::failure_signal_handler
+    absl::hash
+    absl::stacktrace
+    absl::strings
+    absl::symbolize
+    fmt::fmt
+    phmap
+    ${SKIA_LIBRARIES}
+    ${LIBTSM_LIBRARIES}
+    ${GLFW3_LIBRARIES}
+    ${GL_LIBRARIES}
+    ${LIBCONFUSE_LIBRARIES}
+    ${FONT_LIBRARIES}
+    ${TCMALLOC})
+else()
+  target_link_libraries(uterm
+    absl::base
+    absl::failure_signal_handler
+    absl::hash
+    absl::stacktrace
+    absl::strings
+    absl::symbolize
+    fmt::fmt
+    phmap
+    skia
+    libtsm::tsm
+    utf8::cpp
+    ${GLFW3_LIBRARIES}
+    ${GL_LIBRARIES}
+    ${LIBCONFUSE_LIBRARIES}
+    ${FONT_LIBRARIES}
+    ${TCMALLOC})
+endif()
 
-if (UNIX_FONT_STACK)
+# macOS-specific frameworks
+if (APPLE)
   target_link_libraries(uterm
-    ${FONTCONFIG_LIBRARIES}
-    ${FREETYPE_LIBRARIES})
-endif ()
+    "-framework CoreFoundation"
+    "-framework ApplicationServices")
+endif()
+
+# Installation
+install(TARGETS uterm RUNTIME DESTINATION bin)
