CMake: add set_and_warn_incompatible macro, use for HEADLESS & GHOST_SDL

When WITH_GHOST_SDL or WITH_HEADLESS were used, the message didn't make
much sense, especially since the features warned about weren't
necessarily enabled or even supported by the platform.

Replace with a `set_and_warn_incompatible` macro which only reports
configuration changes based on incompatible features.
This commit is contained in:
Campbell Barton 2023-10-07 19:11:51 +11:00
parent 1bb098bf44
commit 833eddafa3
2 changed files with 23 additions and 11 deletions

View File

@ -1134,17 +1134,16 @@ if(WITH_INSTALL_PORTABLE)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
endif()
if(WITH_GHOST_SDL OR WITH_HEADLESS)
message(STATUS "Disabling Ghost Wayland, X11, Input IME, and OpenXR")
set(WITH_GHOST_WAYLAND OFF)
set(WITH_GHOST_X11 OFF)
set(WITH_X11_XINPUT OFF)
set(WITH_X11_XF86VMODE OFF)
set(WITH_X11_XFIXES OFF)
set(WITH_GHOST_XDND OFF)
set(WITH_INPUT_IME OFF)
set(WITH_XR_OPENXR OFF)
endif()
set_and_warn_incompatible(WITH_HEADLESS WITH_GHOST_WAYLAND OFF)
set_and_warn_incompatible(WITH_HEADLESS WITH_GHOST_SDL OFF)
set_and_warn_incompatible(WITH_HEADLESS WITH_GHOST_X11 OFF)
set_and_warn_incompatible(WITH_HEADLESS WITH_INPUT_IME OFF)
set_and_warn_incompatible(WITH_HEADLESS WITH_XR_OPENXR OFF)
set_and_warn_incompatible(WITH_GHOST_SDL WITH_GHOST_WAYLAND OFF)
set_and_warn_incompatible(WITH_GHOST_SDL WITH_GHOST_X11 OFF)
set_and_warn_incompatible(WITH_GHOST_SDL WITH_INPUT_IME OFF)
set_and_warn_incompatible(WITH_GHOST_SDL WITH_XR_OPENXR OFF)
if(WITH_BUILDINFO)
find_package(Git)

View File

@ -1455,6 +1455,19 @@ macro(set_and_warn_dependency
endif()
endmacro()
macro(set_and_warn_incompatible
_dependency _setting _val)
# when $_dependency is enabled, forces $_setting = $_val
if(${${_dependency}} AND ${${_setting}})
if(WITH_STRICT_BUILD_OPTIONS)
message(SEND_ERROR "${_dependency} enabled but incompatible with ${_setting}")
else()
message(STATUS "${_dependency} is enabled but incompatible, setting ${_setting}=${_val}")
endif()
set(${_setting} ${_val})
endif()
endmacro()
macro(set_and_warn_library_found
_library_name _library_found _setting)
if(((NOT ${_library_found}) OR (NOT ${${_library_found}})) AND ${${_setting}})