cmake: fail configuring when no X11 or wayland could be found (#11310)

It's still possible to build SDL by configuring with -DSDL_NO_UNIX_DESKTOP_SANITY_CHECK=ON
This commit is contained in:
Anonymous Maarten 2024-10-23 22:19:40 +02:00 committed by GitHub
parent 540db0d164
commit e8b69b03fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 5 deletions

View file

@ -608,7 +608,7 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
job.cmake_arguments.extend(( job.cmake_arguments.extend((
f"-DCMAKE_C_COMPILER={job.cc}", f"-DCMAKE_C_COMPILER={job.cc}",
f"-DCMAKE_CXX_COMPILER={job.cxx}", f"-DCMAKE_CXX_COMPILER={job.cxx}",
"-DCMAKE_SYSTEM_NAME=Haiku", "-DSDL_UNIX_CONSOLE_BUILD=ON",
)) ))
job.shared_lib = SharedLibType.SO_0 job.shared_lib = SharedLibType.SO_0
job.static_lib = StaticLibType.A job.static_lib = StaticLibType.A
@ -621,6 +621,9 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
job.apt_packages = [] job.apt_packages = []
job.shared_lib = SharedLibType.SO_0 job.shared_lib = SharedLibType.SO_0
job.static_lib = StaticLibType.A job.static_lib = StaticLibType.A
job.cmake_arguments.extend((
"-DSDL_UNIX_CONSOLE_BUILD=ON",
))
case SdlPlatform.LoongArch64: case SdlPlatform.LoongArch64:
job.run_tests = False job.run_tests = False
job.cc = "${LOONGARCH64_CC}" job.cc = "${LOONGARCH64_CC}"
@ -628,6 +631,7 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
job.cmake_arguments.extend(( job.cmake_arguments.extend((
f"-DCMAKE_C_COMPILER={job.cc}", f"-DCMAKE_C_COMPILER={job.cc}",
f"-DCMAKE_CXX_COMPILER={job.cxx}", f"-DCMAKE_CXX_COMPILER={job.cxx}",
"-DSDL_UNIX_CONSOLE_BUILD=ON",
"-DCMAKE_SYSTEM_NAME=Linux", "-DCMAKE_SYSTEM_NAME=Linux",
)) ))
job.shared_lib = SharedLibType.SO_0 job.shared_lib = SharedLibType.SO_0

View file

@ -394,11 +394,21 @@ function(SDL_PrintSummary)
message(STATUS "") message(STATUS "")
endif() endif()
if(UNIX AND NOT (ANDROID OR APPLE OR EMSCRIPTEN)) if(UNIX AND NOT (ANDROID OR APPLE OR EMSCRIPTEN OR HAIKU OR RISCOS))
if(NOT (HAVE_X11 OR HAVE_WAYLAND)) if(NOT (HAVE_X11 OR HAVE_WAYLAND))
message(STATUS "SDL is being built without a X11 or wayland video driver.") if(NOT SDL_UNIX_CONSOLE_BUILD)
message(STATUS "The library will not be able to create windows on most unix environments.") message(FATAL_ERROR
message(STATUS "") "SDL could not find X11 or Wayland development libraries on your system. "
"This means SDL will not be able to create windows on a typical unix operating system. "
"Most likely, this is not wanted."
"\n"
"On Linux, install the packages listed at "
"https://github.com/libsdl-org/SDL/blob/main/docs/README-linux.md#build-dependencies "
"\n"
"If you really don't need desktop windows, the documentation tells you how to skip this check. "
"https://github.com/libsdl-org/SDL/blob/main/docs/README-cmake.md#cmake-fails-to-build-without-x11-or-wayland-support\n"
)
endif()
endif() endif()
endif() endif()
endfunction() endfunction()

View file

@ -306,6 +306,14 @@ Configure your project with `-DSDL_LIBC=ON` to make use of sanitizers.
## CMake FAQ ## CMake FAQ
### CMake fails to build without X11 or Wayland support
Install the required system packages prior to running CMake.
See [README-linux][README-linux.md#build-dependencies] for the list of dependencies on Linux.
Other unix operationg systems should provide similar packages.
If you **really** don't need to show windows, add `-DSDL_UNIX_CONSOLE_BUILD=ON` to the CMake configure command.
### How do I copy a SDL3 dynamic library to another location? ### How do I copy a SDL3 dynamic library to another location?
Use [CMake generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#target-dependent-expressions). Use [CMake generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#target-dependent-expressions).