quake-based game engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
5.2KB

  1. cmake_minimum_required(VERSION 3.14)
  2. cmake_policy(SET CMP0046 NEW)
  3. cmake_policy(SET CMP0063 NEW)
  4. cmake_policy(SET CMP0071 NEW)
  5. project(spingle C)
  6. include(CheckCSourceCompiles)
  7. find_package(OpenGL REQUIRED)
  8. find_package(SDL2 REQUIRED)
  9. find_package(PkgConfig)
  10. if(PKG_CONFIG_FOUND)
  11. pkg_check_modules(FLAC IMPORTED_TARGET flac>=1.3.3)
  12. pkg_check_modules(Vorbis IMPORTED_TARGET vorbis>=1.3.6
  13. vorbisfile>=1.3.6
  14. ogg>=1.3.4)
  15. pkg_check_modules(Opus IMPORTED_TARGET opus>=1.3.1
  16. opusfile>=0.11
  17. ogg>=1.3.4)
  18. pkg_check_modules(MikMod IMPORTED_TARGET libmikmod>=3.3.11)
  19. endif()
  20. check_c_source_compiles(
  21. "int main(int argc, char *argv[]) {
  22. static void *const ar[] = {&&c0, &&c1, &&c2, &&c3};
  23. goto *ar[argc];
  24. c0: return 1;
  25. c1: return 2;
  26. c2: return 3;
  27. c3: return 4;
  28. return 0;
  29. }"
  30. HAVE_COMPUTED_GOTO)
  31. set(srcs
  32. source/anorm_dots.h
  33. source/anorms.h
  34. source/arch_def.c
  35. source/arch_def.h
  36. source/bgmusic.c
  37. source/bgmusic.h
  38. source/bspfile.h
  39. source/cdaudio.h
  40. source/cfgfile.c
  41. source/cfgfile.h
  42. source/chase.c
  43. source/cl_demo.c
  44. source/cl_input.c
  45. source/cl_main.c
  46. source/cl_parse.c
  47. source/cl_tent.c
  48. source/client.h
  49. source/cmd.c
  50. source/cmd.h
  51. source/common.c
  52. source/common.h
  53. source/console.c
  54. source/console.h
  55. source/crc.c
  56. source/crc.h
  57. source/cvar.c
  58. source/cvar.h
  59. source/draw.h
  60. source/filenames.h
  61. source/gl_draw.c
  62. source/gl_fog.c
  63. source/gl_mesh.c
  64. source/gl_model.c
  65. source/gl_model.h
  66. source/gl_refrag.c
  67. source/gl_rlight.c
  68. source/gl_rmain.c
  69. source/gl_rmisc.c
  70. source/gl_screen.c
  71. source/gl_sky.c
  72. source/gl_texmgr.c
  73. source/gl_texmgr.h
  74. source/gl_warp.c
  75. source/gl_warp_sin.h
  76. source/glquake.h
  77. source/host.c
  78. source/host_cmd.c
  79. source/image.c
  80. source/image.h
  81. source/input.h
  82. source/keys.c
  83. source/keys.h
  84. source/lib/lodepng.h
  85. source/lib/stb_image_write.h
  86. source/mathlib.c
  87. source/mathlib.h
  88. source/menu.c
  89. source/menu.h
  90. source/modelgen.h
  91. source/net.h
  92. source/net_defs.h
  93. source/net_dgrm.c
  94. source/net_dgrm.h
  95. source/net_loop.c
  96. source/net_loop.h
  97. source/net_main.c
  98. source/net_sys.h
  99. source/platform.h
  100. source/pr_cmds.c
  101. source/pr_defs.h
  102. source/pr_edict.c
  103. source/pr_edict.h
  104. source/pr_exec.c
  105. source/pr_global.h
  106. source/pr_load.c
  107. source/pr_ops.h
  108. source/pr_string.c
  109. source/progs.h
  110. source/protocol.h
  111. source/q_ctype.h
  112. source/q_defs.h
  113. source/q_sound.h
  114. source/q_stdinc.h
  115. source/r_alias.c
  116. source/r_brush.c
  117. source/r_part.c
  118. source/r_sprite.c
  119. source/r_world.c
  120. source/render.h
  121. source/sbar.c
  122. source/sbar.h
  123. source/screen.h
  124. source/server.h
  125. source/snd_codec.c
  126. source/snd_codec.h
  127. source/snd_codeci.h
  128. source/snd_dma.c
  129. source/snd_flac.c
  130. source/snd_mem.c
  131. source/snd_mix.c
  132. source/snd_mod.c
  133. source/snd_opus.c
  134. source/snd_umx.c
  135. source/snd_vorbis.c
  136. source/spritegn.h
  137. source/strl_fn.c
  138. source/sv_main.c
  139. source/sv_move.c
  140. source/sv_phys.c
  141. source/sv_user.c
  142. source/sys.h
  143. source/vid.h
  144. source/view.c
  145. source/view.h
  146. source/wad.c
  147. source/wad.h
  148. source/world.c
  149. source/world.h
  150. source/zone.c
  151. source/zone.h)
  152. set(srcs_linux
  153. source/linux/pl_linux.c
  154. source/linux/qs_bmp.h)
  155. set(srcs_osx
  156. source/osx/pl_osx.c)
  157. set(srcs_unix
  158. source/unix/net_bsd.c
  159. source/unix/net_udp.c
  160. source/unix/net_udp.h
  161. source/unix/sys_sdl_unix.c)
  162. set(srcs_windows
  163. source/windows/net_win.c
  164. source/windows/net_wins.c
  165. source/windows/net_wins.h
  166. source/windows/net_wipx.c
  167. source/windows/net_wipx.h
  168. source/windows/pl_win.c
  169. source/windows/spingle.rc
  170. source/windows/sys_sdl_win.c
  171. source/windows/wsaerror.h)
  172. set(srcs_sdl
  173. source/sdl/cd_sdl.c
  174. source/sdl/endian_sdl.h
  175. source/sdl/gl_vidsdl.c
  176. source/sdl/in_sdl.c
  177. source/sdl/main_sdl.c
  178. source/sdl/snd_sdl.c)
  179. set(libs
  180. m
  181. OpenGL::GL
  182. ${SDL2_LIBRARIES})
  183. set(defs "")
  184. list(APPEND srcs ${srcs_sdl})
  185. if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  186. set(USE_WINSOCK_2 TRUE CACHE BOOL "Use WinSock2 for networking")
  187. list(APPEND srcs ${srcs_windows})
  188. list(APPEND libs winmm)
  189. if(USE_WINSOCK_2)
  190. list(APPEND libs ws2_32)
  191. list(APPEND defs _USE_WINSOCK2)
  192. else()
  193. list(APPEND libs wsock32)
  194. endif()
  195. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  196. list(APPEND srcs ${srcs_unix} ${srcs_linux})
  197. elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  198. list(APPEND srcs ${srcs_unix} ${srcs_osx})
  199. else()
  200. message(FATAL_ERROR "platform not supported")
  201. endif()
  202. if(HAVE_COMPUTED_GOTO)
  203. list(APPEND defs HAVE_COMPUTED_GOTO=1)
  204. endif()
  205. macro(agw_checked_library define library)
  206. if(${library}_FOUND)
  207. list(APPEND defs ${define}=1)
  208. list(APPEND libs PkgConfig::${library})
  209. endif()
  210. endmacro()
  211. agw_checked_library(USE_CODEC_FLAC FLAC)
  212. agw_checked_library(USE_CODEC_VORBIS Vorbis)
  213. agw_checked_library(USE_CODEC_OPUS Opus)
  214. agw_checked_library(USE_CODEC_MOD MikMod)
  215. add_executable(quake WIN32 ${srcs})
  216. target_compile_options(quake PUBLIC
  217. $<$<C_COMPILER_ID:AppleClang,Clang,GNU>:
  218. -Wall -Wextra -Werror -Wno-missing-field-initializers>
  219. # why are these even warnings?
  220. $<$<C_COMPILER_ID:GNU>: -Wno-array-bounds -Wno-stringop-truncation>
  221. $<$<C_COMPILER_ID:MSVC>: /W4>)
  222. target_include_directories(quake SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS})
  223. target_include_directories(quake PUBLIC source)
  224. target_compile_definitions(quake PUBLIC ${defs})
  225. target_link_libraries(quake ${libs})