# Shared build options and warning policy for the plot project. # # Included by the top-level CMakeLists.txt; every subdirectory target is # expected to run plot_apply_warnings() so the core stays warning-clean # under -Wall -Wextra -Wpedantic -Wconversion -Wshadow. if(CMAKE_VERSION VERSION_LESS 3.24) message(FATAL_ERROR "plot requires CMake 3.24 or newer (found ${CMAKE_VERSION})") endif() # Adapters and examples pull in third-party SDKs, so they default to OFF; the # core library and its tests build on a bare toolchain. option(PLOT_BUILD_TESTS "Build the plot test suite" ON) option(PLOT_BUILD_EXAMPLES "Build the example programs" OFF) option(PLOT_BUILD_GLFW "Build the GLFW adapter and demo" OFF) option(PLOT_BUILD_IMGUI "Build the Dear ImGui adapter and demo" OFF) option(PLOT_BUILD_QT6 "Build the Qt6 adapter and demo" OFF) option(PLOT_BUILD_GTK4 "Build the GTK4 adapter and demo" OFF) # Apply the project warning set to a first-party target. Warnings are never # suppressed per file. function(plot_apply_warnings target) if(MSVC) target_compile_options(${target} PRIVATE /W4 /permissive-) else() target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Wconversion -Wshadow) endif() endfunction() # Resolves GLFW once for every target that needs it -- the GLFW host adapter and # the Dear ImGui backend both do. Discovery follows the design spec's order: # find_package first, pkg-config next, FetchContent only when neither can supply # GLFW (the last resort, because it needs the network). The result is cached in # PLOT_GLFW_DEP, so a build with several adapters enabled discovers -- and at # worst fetches -- exactly one copy. Sets to the target to link. function(plot_find_glfw out_var) if(NOT DEFINED PLOT_GLFW_DEP) set(plot_glfw_dep "") find_package(glfw3 3.3 QUIET) if(TARGET glfw) set(plot_glfw_dep glfw) elseif(TARGET glfw3::glfw3) set(plot_glfw_dep glfw3::glfw3) endif() if(NOT plot_glfw_dep) find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(GLFW_PC QUIET IMPORTED_TARGET glfw3) if(TARGET PkgConfig::GLFW_PC) set(plot_glfw_dep PkgConfig::GLFW_PC) endif() endif() endif() if(NOT plot_glfw_dep) message(STATUS "plot: glfw3 not found via find_package or pkg-config; fetching it") include(FetchContent) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.4 GIT_SHALLOW TRUE) FetchContent_MakeAvailable(glfw) set(plot_glfw_dep glfw) endif() set(PLOT_GLFW_DEP "${plot_glfw_dep}" CACHE INTERNAL "GLFW target the plot adapters link against") message(STATUS "plot: GLFW adapter dependency: ${plot_glfw_dep}") endif() set(${out_var} "${PLOT_GLFW_DEP}" PARENT_SCOPE) endfunction()