cmake_minimum_required(VERSION 3.14) cmake_policy(SET CMP0046 NEW) cmake_policy(SET CMP0063 NEW) cmake_policy(SET CMP0071 NEW) project(spingle C) include(CheckCSourceCompiles) find_package(OpenGL REQUIRED) find_package(SDL2 REQUIRED) find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_check_modules(FLAC IMPORTED_TARGET flac>=1.3.3) pkg_check_modules(Vorbis IMPORTED_TARGET vorbis>=1.3.6 vorbisfile>=1.3.6 ogg>=1.3.4) pkg_check_modules(Opus IMPORTED_TARGET opus>=1.3.1 opusfile>=0.11 ogg>=1.3.4) pkg_check_modules(MikMod IMPORTED_TARGET libmikmod>=3.3.11) endif() check_c_source_compiles( "int main(int argc, char *argv[]) { static void *const ar[] = {&&c0, &&c1, &&c2, &&c3}; goto *ar[argc]; c0: return 1; c1: return 2; c2: return 3; c3: return 4; return 0; }" HAVE_COMPUTED_GOTO) set(srcs source/anorm_dots.h source/anorms.h source/arch_def.c source/arch_def.h source/bgmusic.c source/bgmusic.h source/bspfile.h source/cdaudio.h source/cfgfile.c source/cfgfile.h source/chase.c source/cl_demo.c source/cl_input.c source/cl_main.c source/cl_parse.c source/cl_tent.c source/client.h source/cmd.c source/cmd.h source/common.c source/common.h source/console.c source/console.h source/crc.c source/crc.h source/cvar.c source/cvar.h source/draw.h source/filenames.h source/gl_draw.c source/gl_fog.c source/gl_mesh.c source/gl_model.c source/gl_model.h source/gl_refrag.c source/gl_rlight.c source/gl_rmain.c source/gl_rmisc.c source/gl_screen.c source/gl_sky.c source/gl_texmgr.c source/gl_texmgr.h source/gl_warp.c source/gl_warp_sin.h source/glquake.h source/host.c source/host_cmd.c source/image.c source/image.h source/input.h source/keys.c source/keys.h source/lib/lodepng.h source/lib/stb_image_write.h source/mathlib.c source/mathlib.h source/menu.c source/menu.h source/modelgen.h source/net.h source/net_defs.h source/net_dgrm.c source/net_dgrm.h source/net_loop.c source/net_loop.h source/net_main.c source/net_sys.h source/platform.h source/pr_cmds.c source/pr_defs.h source/pr_edict.c source/pr_edict.h source/pr_exec.c source/pr_global.h source/pr_load.c source/pr_ops.h source/pr_string.c source/progs.h source/protocol.h source/q_ctype.h source/q_defs.h source/q_sound.h source/q_stdinc.h source/r_alias.c source/r_brush.c source/r_part.c source/r_sprite.c source/r_world.c source/render.h source/sbar.c source/sbar.h source/screen.h source/server.h source/snd_codec.c source/snd_codec.h source/snd_codeci.h source/snd_dma.c source/snd_flac.c source/snd_mem.c source/snd_mix.c source/snd_mod.c source/snd_opus.c source/snd_umx.c source/snd_vorbis.c source/spritegn.h source/strl_fn.c source/sv_main.c source/sv_move.c source/sv_phys.c source/sv_user.c source/sys.h source/vid.h source/view.c source/view.h source/wad.c source/wad.h source/world.c source/world.h source/zone.c source/zone.h) set(srcs_linux source/linux/pl_linux.c source/linux/qs_bmp.h) set(srcs_osx source/osx/pl_osx.c) set(srcs_unix source/unix/net_bsd.c source/unix/net_udp.c source/unix/net_udp.h source/unix/sys_sdl_unix.c) set(srcs_windows source/windows/net_win.c source/windows/net_wins.c source/windows/net_wins.h source/windows/net_wipx.c source/windows/net_wipx.h source/windows/pl_win.c source/windows/spingle.rc source/windows/sys_sdl_win.c source/windows/wsaerror.h) set(srcs_sdl source/sdl/cd_sdl.c source/sdl/endian_sdl.h source/sdl/gl_vidsdl.c source/sdl/in_sdl.c source/sdl/main_sdl.c source/sdl/snd_sdl.c) set(libs m OpenGL::GL ${SDL2_LIBRARIES}) set(defs "") list(APPEND srcs ${srcs_sdl}) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(USE_WINSOCK_2 TRUE CACHE BOOL "Use WinSock2 for networking") list(APPEND srcs ${srcs_windows}) list(APPEND libs winmm) if(USE_WINSOCK_2) list(APPEND libs ws2_32) list(APPEND defs _USE_WINSOCK2) else() list(APPEND libs wsock32) endif() elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") list(APPEND srcs ${srcs_unix} ${srcs_linux}) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") list(APPEND srcs ${srcs_unix} ${srcs_osx}) else() message(FATAL_ERROR "platform not supported") endif() if(HAVE_COMPUTED_GOTO) list(APPEND defs HAVE_COMPUTED_GOTO=1) endif() macro(agw_checked_library define library) if(${library}_FOUND) list(APPEND defs ${define}=1) list(APPEND libs PkgConfig::${library}) endif() endmacro() agw_checked_library(USE_CODEC_FLAC FLAC) agw_checked_library(USE_CODEC_VORBIS Vorbis) agw_checked_library(USE_CODEC_OPUS Opus) agw_checked_library(USE_CODEC_MOD MikMod) add_executable(quake WIN32 ${srcs}) target_compile_options(quake PUBLIC $<$: -Wall -Wextra -Werror -Wno-missing-field-initializers> # why are these even warnings? $<$: -Wno-array-bounds -Wno-stringop-truncation> $<$: /W4>) target_include_directories(quake SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS}) target_include_directories(quake PUBLIC source) target_compile_definitions(quake PUBLIC ${defs}) target_link_libraries(quake ${libs})