scripts: cosmetix
[k8vavoom.git] / CMakeLists.txt
bloba555247af065d2afbf3a89f31a7af1fd6a416cd5
1 cmake_minimum_required(VERSION 3.0)
2 if(COMMAND cmake_policy)
3   cmake_policy(SET CMP0003 NEW)
4   cmake_policy(SET CMP0026 NEW)
5 endif(COMMAND cmake_policy)
8 project(k8vavoom)
9 include(CheckIncludeFile)
12 option(WITH_SDL2       "Use SDL2 library" ON)
13 option(WITH_OPENGL     "Use OpenGL library" ON)
14 option(WITH_MIMALLOC   "Use mi-malloc memory allocator" ON)
15 option(WITH_MOJOAL     "Enable MojoAL OpenAL impletentation over SDL Mixer" OFF)
16 option(WITH_SYS_OPUS   "Enable Opus support via system libopus and libopusfile (if off, internal libraries will be used)" OFF)
17 option(WITH_SYS_VORBIS "Enable Vorbis support via libvorbis (if off, stb_vorbis will be used)" OFF)
18 option(WITH_LIBMAD     "Enable MP3 support via libmad (if off, dr_mp3 will be used)" OFF)
19 option(WITH_SYS_FLAC   "Enable FLAC support via libflac (if off, dr_flac will be used)" OFF)
20 option(WITH_FLUID      "Enable FluidSynth support" ON)
21 option(WITH_LIBJIT     "Enable LibJIT support in VavoomC compiler (don't use!)" OFF)
22 option(WITH_XRANDR     "Enable XRandR support for DPI detection (don't use!)" OFF)
23 option(WITH_WNT64      "Enable 64-bit build" OFF)
24 if(WIN32)
25 option(WITH_SYS_FLUID  "Use system FluidSynth library" OFF)
26 else(WIN32)
27 option(WITH_SYS_FLUID  "Use system FluidSynth library" ON)
28 endif(WIN32)
30 if(WITH_OPENGL)
31   option(WITH_GLES "Use hacks for GL4ES (experimental)" OFF)
32   option(WITH_GL4ES "Use GL4ES directly (experimental)" OFF)
33   if(WITH_GL4ES)
34     if(WITH_GLES)
35       set(WITH_GL4ES ON)
36     endif()
37     if(GL4ES_LIBRARY_DIR STREQUAL "")
38       message(FATAL_ERROR "GL4ES_LIBRARY_DIR not setted")
39     endif()
40     if(GL4ES_INCLUDE_DIR STREQUAL "")
41       message(FATAL_ERROR "GL4ES_INCLUDE_DIR not setted")
42     endif()
43   endif()
44 endif()
46 option(WITH_STB_JPEG   "Use stb_image to load jpegs" ON)
47 option(WITH_SYS_LIBJPG "Use system libjpg (if stb_image is off)" ON)
49 option(WITH_OLD_CPU "Use pIV CPU instruction set" OFF)
51 #option(WITH_RPATH "Use -rpath" OFF)
52 set(RPATH_VALUE "" CACHE STRING "-rpath linker option value")
54 # default is SSE2
55 option(WITH_SSE3 "Use SSE3 instruction set (may not compile)" OFF)
56 option(WITH_SSE4 "Use SSE4 instruction set (may not compile)" OFF)
57 option(WITH_SSE41 "Use SSE4.1 instruction set (may not compile)" OFF)
58 option(WITH_SSE42 "Use SSE4.2 instruction set (may not compile)" OFF)
59 option(NO_SSE "Disable all SSE instructions" OFF)
60 option(INSANE_AVX "Use AVX2 instruction set (don't do this, it won't give you any noticeable speedup and may be broken)" OFF)
62 # do not tempt poor things
63 if("$ENV{USER}" STREQUAL "ketmar")
64   option(WITH_GCC_ANAL "Turn on gcc10 static analyzer" OFF)
65   option(WITH_GCC_IDIOCITY "Turn on gcc idiotic pseudo-warnings (don't care, won't fix)" OFF)
66 else()
67   set(WITH_GCC_ANAL OFF)
68   set(WITH_GCC_IDIOCITY OFF)
69 endif()
71 option(WITH_GLAD "Use supplied GLAD for GL bindings" OFF)
72 option(NO_PTHREAD "Disable pthreads, use C11 threads instead" OFF)
73 option(NO_MEMRCHR "Disable usage of memrchr()" OFF)
74 option(NO_RAWTTY "Disable raw TTY control" OFF)
76 option(WITH_STRTODEX "Use internal strtod implementation to parse floats" ON)
78 # do not tempt poor things
79 if("$ENV{USER}" STREQUAL "ketmar")
80   option(DEBUG_FPU_CHECKS "Use FPU and turn on some checks (GNU/Linux only)" OFF)
81   option(UNSTABLE_OPTIMISATIONS "Use -O3 (WARNING! DON'T DO THAT! NEVER!)" OFF)
82 else()
83   set(DEBUG_FPU_CHECKS OFF)
84   set(UNSTABLE_OPTIMISATIONS OFF)
85 endif()
87 if(CMAKE_CROSSCOMPILING AND WIN32)
88   option(SDL2_OVERRIDE "Some specific changes for custom-built SDL2 (do not turn on if you don't know what it is)" ON)
89 else(CMAKE_CROSSCOMPILING AND WIN32)
90   option(SDL2_OVERRIDE "Some specific changes for custom-built SDL2 (do not turn on if you don't know what it is)" OFF)
91 endif(CMAKE_CROSSCOMPILING AND WIN32)
93 if(CMAKE_CROSSCOMPILING AND WIN32)
94   #if(MINGW)
95   option(WITH_WINE "Use wine to run built executables" ON)
96   option(WITH_STATIC_OPENAL "Use special flags to link with static OpenAL" ON)
97   #endif(MINGW)
98   set(WITH_STRTODEX ON)
99 endif(CMAKE_CROSSCOMPILING AND WIN32)
101 if(NSWITCH)
102   option(WITH_NXLINK "Redirect standard output to NXLink" OFF)
103   set(NO_SSE ON) # set it right away for proper logging and cflags
104   set(WITH_MIMALLOC OFF)
105 endif(NSWITCH)
107 option(FOSSIL_REPO_PATH "Local path to k8vavoom Fossil repository (leave empty if unsure)" OFF)
111 if(CYGWIN)
112   set(WITH_MIMALLOC OFF)
113 endif()
115 # perform some platform and compiler checks
116 set(VV_STACK_REALIGN OFF)
117 if(CMAKE_CROSSCOMPILING AND WIN32)
118   # cross-compiling to shitdoze
119   message(STATUS "Cross-compiling to shitdoze...")
120 elseif(CMAKE_CROSSCOMPILING)
121   # cross-compiling to something else, let's play safe
122   message(STATUS "Turning off SSE and mi-malloc")
123   set(NO_SSE ON)
124   set(WITH_MIMALLOC OFF)
125 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)")
126   # compiling to x86
127   #if(CMAKE_SIZEOF_VOID_P EQUAL 8)
128   #  set(OPUS_CPU_X64 1)
129   #else()
130   #  set(OPUS_CPU_X86 1)
131   #endif()
132   set(VV_STACK_REALIGN ON)
133 #elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
134 #  set(OPUS_CPU_ARM 1)
135 else()
136   # compiling to something else, let's play safe
137   add_definitions(-DVV_NOT_X86)
138   message(STATUS "Turning off SSE and mi-malloc")
139   set(NO_SSE ON)
140   set(WITH_MIMALLOC OFF)
141 endif()
143 set( RES_FLAGS -Fpe-i386 )
145 if (WITH_WNT64)
146     message(STATUS "*** 64-bit builds are UNSUPPORTED ***")
147     add_definitions(-DSTK_TIMET_FIX)
148     set( RES_FLAGS -Fpe-x86-64 )
149 endif ()
151 set(K8_UNFUCK_AS_GCC ON)
152 set(K8_UNFUCK_AS_SHITLANG OFF)
153 if(NOT CMAKE_COMPILER_IS_GNUCC)
154   if (APPLE OR CMAKE_HOST_APPLE OR XCODE_VERSION)
155     message(FATAL_ERROR "Apple platform is not supported.")
156     return()
157   endif(APPLE OR CMAKE_HOST_APPLE OR XCODE_VERSION)
159   if (MSVC OR MSVC80 OR MSVC_IDE)
160     message(FATAL_ERROR "m$ compilers aren't supported. GTFO.")
161     return()
162   endif(MSVC OR MSVC80 OR MSVC_IDE)
164   message(WARNING "Only GNU C/C++ compilers are supported to build k8vavoom and tools!")
165   message(WARNING "Your compiler is not GNU, please, don't report bugs.")
166   set(K8_UNFUCK_AS_GCC OFF)
168   if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
169     message(WARNING "And, by the way. clang sux.")
170     set(K8_UNFUCK_AS_SHITLANG ON)
171   endif()
172 endif(NOT CMAKE_COMPILER_IS_GNUCC)
174 option(ENABLE_CLIENT      "Build client executable" ON)
175 option(ENABLE_SERVER      "Build dedicated server executable (don't do that!)" OFF)
176 option(ENABLE_MASTER      "Build master server (no reason to build it)" OFF)
177 option(ENABLE_QUERY_DEMO  "Build query demo (can be used to send rcon commands)" OFF)
178 option(ENABLE_VCCRUN      "Build vccrun executable" OFF)
179 option(ENABLE_MD2FIXER    "Build fixmd2 executable (you don't need it)" OFF)
181 option(ENABLE_VCCRUN_ONLY "Build ONLY vccrun" OFF)
182 option(ENABLE_UTILS_ONLY "Build ONLY utils" OFF)
184 if(UNIX)
185   option(ENABLE_WRAPPERS "Enable creation of wrapper scripts" ON)
186 endif(UNIX)
189 #  COMMAND git rev-parse --verify -q --short=16 HEAD
191 execute_process(
192   COMMAND git rev-parse --verify -q HEAD
193   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
194   OUTPUT_VARIABLE GIT_COMMIT_HASH
195   ERROR_VARIABLE GIT_ERROR
196   RESULT_VARIABLE GET_EXEC_RESULT
197   OUTPUT_STRIP_TRAILING_WHITESPACE
200 if(NOT ${GET_EXEC_RESULT} EQUAL 0)
201   set(GIT_COMMIT_HASH "UNKNOWN")
202 else()
203   if(NOT ${GIT_ERROR} STREQUAL "")
204     set(GIT_COMMIT_HASH "UNKNOWN")
205   endif()
207   if(${GIT_COMMIT_HASH} STREQUAL "")
208     set(GIT_COMMIT_HASH "UNKNOWN")
209   endif()
210 endif()
212 #message(STATUS "hash=" ${GIT_COMMIT_HASH})
213 #message(STATUS "error=" ${GIT_ERROR})
215 #add_definitions("-DVV_GIT_COMMIT_HASH=${GIT_COMMIT_HASH}")
218 if(ENABLE_UTILS_ONLY)
219   set(ENABLE_CLIENT OFF)
220   set(ENABLE_SERVER OFF)
221   set(ENABLE_VCCRUN OFF)
222   set(ENABLE_VCCRUN_ONLY OFF)
223   set(WITH_LIBJIT OFF)
224 elseif(ENABLE_VCCRUN_ONLY)
225   #set(WITH_SYS_VORBIS OFF)
226   #set(WITH_LIBMAD OFF)
227   #set(WITH_SYS_FLAC OFF)
228   #set(WITH_SYS_LIBJPG OFF)
229   #set(WITH_SYS_ZLIB OFF)
230   set(ENABLE_CLIENT OFF)
231   set(ENABLE_SERVER OFF)
232   set(ENABLE_MASTER OFF)
233   set(ENABLE_QUERY_DEMO OFF)
234   set(ENABLE_VCCRUN ON)
235   set(ENABLE_MD2FIXER OFF)
237   if (NOT WITH_SYS_VORBIS OR NOT WITH_SYS_FLAC)
238     message(SEND_ERROR "OpenAL, Vorbis and Flac are required")
239     return()
240   endif()
241 else()
242   if(NOT ENABLE_CLIENT)
243     if(NOT ENABLE_SERVER)
244       message(STATUS "Neither client, nor server was requested")
245     else(NOT ENABLE_SERVER)
246       message(STATUS "Server-only build, turning off SDL2, OpenGL and OpenAL")
247     endif(NOT ENABLE_SERVER)
248     set(WITH_SDL2 OFF)
249     set(WITH_OPENGL OFF)
250     set(WITH_GL4ES OFF)
251     set(WITH_SYS_VORBIS OFF)
252     set(WITH_SYS_OPUS OFF)
253     set(WITH_LIBMAD OFF)
254     set(WITH_SYS_FLAC OFF)
255   endif(NOT ENABLE_CLIENT)
256 endif()
258 if(NOT CMAKE_BUILD_TYPE)
259   set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
260 endif()
262 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
264 if(NOT SDL2_OVERRIDE)
265   check_include_file(SDL2/SDL.h HAVE_SDL2_SUBDIR)
266   if(HAVE_SDL2_SUBDIR)
267     #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lSDL2main -lSDL2")
268     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lSDL2")
269     add_definitions(-DVAVOOM_ARCH_LINUX_SPECIAL_SDL=1)
270   endif(HAVE_SDL2_SUBDIR)
271 endif(NOT SDL2_OVERRIDE)
273 if(WITH_WNT64)
274   add_definitions(-DSDL_MAIN_HANDLED)
275 endif(WITH_WNT64)
278 set(UNFUCK_GCC_FLAGS "")
279 set(UNFUCK_GXX_FLAGS "")
281 if(K8_UNFUCK_AS_SHITLANG)
282  set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-ignored-optimization-argument")
283  set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-unused-command-line-argument")
284  set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-unknown-warning-option")
285 endif(K8_UNFUCK_AS_SHITLANG)
287 if(K8_UNFUCK_AS_GCC)
288   #set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Werror=format-security")
289   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-aggressive-loop-optimizations")
290   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fcommon") # fuck you, shitcc10
291   if(WITH_GCC_ANAL)
292     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fanalyzer")
293   endif(WITH_GCC_ANAL)
294 endif(K8_UNFUCK_AS_GCC)
296 # WARNING! do not touch anything here even if you think you know what you're doing.
297 #          any change may and WILL break the code.
298 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-delete-null-pointer-checks")
299 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-strict-aliasing")
300 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-strict-overflow")
301 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fwrapv")
302 if(K8_UNFUCK_AS_GCC)
303   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-diagnostics-show-caret")
304 endif(K8_UNFUCK_AS_GCC)
305 if(K8_UNFUCK_AS_GCC AND UNIX AND NOT CMAKE_CROSSCOMPILING)
306   # i refuse to upgrade, lol
307   if("$ENV{USER}" STREQUAL "ketmar")
308     set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wabi=10")
309     set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -fabi-version=10")
310   endif()
311 endif(K8_UNFUCK_AS_GCC AND UNIX AND NOT CMAKE_CROSSCOMPILING)
313 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fsigned-char")
314 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -fexceptions")
315 if(NSWITCH)
316   set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -frtti")
317 endif(NSWITCH)
319 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wall")
320 #set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-frame-address")
322 if(NOT WITH_GCC_IDIOCITY)
323   if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
324     # k8: fuck you, gcc. i have my own style, gtfo.
325     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-misleading-indentation")
326     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-ignored-attributes")
327   endif()
328 endif(NOT WITH_GCC_IDIOCITY)
330 if(VV_STACK_REALIGN)
331   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mstackrealign")
332   message(STATUS "enabled stack realign")
333 endif(VV_STACK_REALIGN)
335 if(WITH_STRTODEX)
336   add_definitions(-DVCORE_ALLOW_STRTODEX=1)
337 endif(WITH_STRTODEX)
340 ##############
341 ## warnings ##
342 ##############
344 if(RPATH_VALUE)
345   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,${RPATH_VALUE}")
346 endif(RPATH_VALUE)
348 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Werror=format-security")
349 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wparentheses")
351 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)
352   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-diagnostics-show-line-numbers")
353   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-diagnostics-show-labels")
354 endif()
356 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.9)
357   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wimplicit-fallthrough")
358   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wshadow=local")
359   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Walloc-zero")
360 endif()
362 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.7)
363   #set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wno-class-memaccess")
364   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wmultistatement-macros")
365   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wmissing-attributes")
366   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wcast-function-type")
367   set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wsuggest-override")
368 endif()
370 if(WITH_GCC_IDIOCITY)
371   # don't use!
372   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wextra")
373   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-ignored-attributes")
374   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-unused-parameter")
375   set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-misleading-indentation")
376   if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)
377     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-address-of-packed-member")
378   endif()
379   # for mi-malloc
380   if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
381     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-invalid-memory-model")
382   endif()
383 else(WITH_GCC_IDIOCITY)
384   # for mi-malloc
385   if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
386     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-invalid-memory-model")
387   endif()
389   if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)
390     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-misleading-indentation")
391   endif()
392   if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)
393     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-address-of-packed-member")
394   endif()
395 endif(WITH_GCC_IDIOCITY)
397 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wno-old-style-cast")
398 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Woverloaded-virtual")
399 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wsign-promo")
400 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wmultiple-inheritance")
401 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -Wvirtual-inheritance")
403 # this protects some shitpp classes from MT code; we don't need this
404 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -fno-threadsafe-statics")
405 # who cares, i don't use std
406 set(UNFUCK_GXX_FLAGS "${UNFUCK_GXX_FLAGS} -fno-use-cxa-get-exception-ptr")
409 ###########################
410 ## some math/FPU options ##
411 ###########################
413 if(NOT DEBUG_FPU_CHECKS AND NOT NSWITCH)
414   # use -ffast-math, 'cause why not?
415   # k8: nope, i command my former self to not do this
416   #set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -ffast-math")
417   if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
418     # on gcc 5.x leads to internal compiler errors
419     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-math-errno")
420   endif()
421 endif(NOT DEBUG_FPU_CHECKS AND NOT NSWITCH)
424 ##########################################
425 ## unfuck idiotic gcc code downgradizer ##
426 ##########################################
428 # WARNING! do not touch anything here even if you think you know what you're doing.
429 #          any change may and WILL break the code.
431 # actually, we don't need strict floating point math compliance, so let's use "-ffast-math"
432 # no, no fuckin' way. with "-ffast-math" not-a-number is EQUAL TO ZERO!
433 # fuck you, gcc.
434 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-unsafe-math-optimizations")
435 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-associative-math")
436 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-reciprocal-math")
437 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fno-finite-math-only")
438 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fsigned-zeros")
439 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fsignaling-nans") # do not touch my NaNs!
440 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -frounding-math") # get lost!
441 set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -ffp-contract=off") # do not use fused fmadd, even if it is available
442 # we don't need strict standards compliance
443 # note that this may modify NaNs, so if we'll use NaN-boxing, we should put "-fsignaling-nans" after fastmath
444 #set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -ffast-math")
446 # force gcc to unroll some loops
447 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -funroll-loops")
448 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -fpredictive-commoning")
450 # consider more optimisation options (from O3):
451 #   -ftree-partial-pre
452 #   -ftree-loop-distribute-patterns
454 # and force gcc to not vectrosize (whatever it is)
455 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -fno-tree-vectorize")
456 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -fvect-cost-model=cheap")
457 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -fsimd-cost-model=cheap")
459 # pointer alias analysis; no wai
460 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -fno-tree-pta")
461 # but allow function inlining
462 set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -finline-functions")
463 # duplicate loop invariant branches (whatever it is)
464 #set(K8_OPT_GCC_FLAGS "${K8_OPT_GCC_FLAGS} -funswitch-loops")
466 if("$ENV{USER}" STREQUAL "ketmar")
467   set(K8_NATIVE_ARCH "-march=nehalem")
468   set(K8_NATIVE_TUNE "-mtune=nehalem")
469 else()
470   set(K8_NATIVE_ARCH "-march=native")
471   set(K8_NATIVE_TUNE "-mtune=native")
472 endif()
474 if(NOT NO_SSE)
475   if(DEBUG_FPU_CHECKS)
476     message(STATUS "BUILD: using FPU")
477     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=387")
478     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -ffloat-store")
479     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -fsignaling-nans")
480     add_definitions(-DUSE_FPU_MATH=1)
481   elseif(INSANE_AVX)
482     message(STATUS "BUILD: using AVX2 instriction set")
483     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_ARCH}")
484     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_TUNE}")
485     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mavx2")
486     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
487   elseif (WITH_SSE42)
488     message(STATUS "BUILD: using SSE4.2 instriction set")
489     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_ARCH}")
490     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_TUNE}")
491     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -msse4.2")
492     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mno-avx")
493     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
494   elseif (WITH_SSE41)
495     message(STATUS "BUILD: using SSE4.1 instriction set")
496     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_ARCH}")
497     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_TUNE}")
498     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -msse4.1")
499     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mno-avx")
500     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
501   elseif (WITH_SSE4)
502     message(STATUS "BUILD: using SSE4 instriction set")
503     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_ARCH}")
504     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_TUNE}")
505     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -msse4")
506     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mno-avx")
507     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
508   elseif (WITH_SSE3)
509     message(STATUS "BUILD: using SSE3 instriction set")
510     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_ARCH}")
511     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_TUNE}")
512     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -msse3")
513     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mno-avx")
514     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
515   else()
516     if(NOT WIN32)
517       if(WITH_OLD_CPU)
518         message(STATUS "BUILD: using SSE2/p4 instriction set")
519         set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -march=pentium4")
520         set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mtune=pentium4")
521       else(WITH_OLD_CPU)
522         message(STATUS "BUILD: using SSE2/native instriction set")
523         set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_ARCH}")
524         set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} ${K8_NATIVE_TUNE}")
525       endif(WITH_OLD_CPU)
526       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -msse2")
527       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mno-avx")
528       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
529     else(NOT WIN32)
530       message(STATUS "BUILD: using SSE2/p4 instriction set")
531       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -march=pentium4")
532       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mtune=pentium4")
533       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -msse2")
534       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mno-avx")
535       set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -mfpmath=sse")
536     endif(NOT WIN32)
537   endif()
538 endif(NOT NO_SSE)
540 if(NOT WIN32)
541   if(NOT NO_PTHREAD)
542     set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -pthread")
543     set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} -pthread")
544     set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -pthread")
545   endif(NOT NO_PTHREAD)
546 else(NOT WIN32)
547   set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} -mwindows")
548   set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -mwindows")
549   set(NO_RAWTTY ON)
550 endif(NOT WIN32)
553 #if(ENABLE_SIGNAL_HANDLER)
554 #  set(UNFUCK_GCC_FLAGS "${UNFUCK_GCC_FLAGS} -Wno-frame-address")
555 #endif(ENABLE_SIGNAL_HANDLER)
558 if(UNSTABLE_OPTIMISATIONS)
559   set(VV_OPTIM "-O3")
560   message(STATUS "USING UNSTABLE GCC CODE DEGRADIZER OPTIONS!")
561 else(UNSTABLE_OPTIMISATIONS)
562   set(VV_OPTIM "-O2")
563 endif(UNSTABLE_OPTIMISATIONS)
566 ############################
567 ## unfuck all build types ##
568 ############################
569 string(REGEX REPLACE "-O[0-9]" " " CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
570 string(REGEX REPLACE "-O[0-9]" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
572 set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} -O0 -g ${UNFUCK_GCC_FLAGS}")
573 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g ${UNFUCK_GCC_FLAGS} ${UNFUCK_GXX_FLAGS}")
575 string(REGEX REPLACE "-O[0-9]" " " CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
576 string(REGEX REPLACE "-O[0-9]" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
578 set(CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} ${VV_OPTIM} ${UNFUCK_GCC_FLAGS} ${K8_OPT_GCC_FLAGS}")
579 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VV_OPTIM} ${UNFUCK_GCC_FLAGS} ${UNFUCK_GXX_FLAGS} ${K8_OPT_GCC_FLAGS}")
581 string(REGEX REPLACE "-O[0-9]" " " CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
582 string(REGEX REPLACE "-O[0-9]" " " CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
584 set(CMAKE_C_FLAGS_RELWITHDEBINFO   "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${VV_OPTIM} -g ${UNFUCK_GCC_FLAGS} ${K8_OPT_GCC_FLAGS}")
585 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${VV_OPTIM} -g ${UNFUCK_GCC_FLAGS} ${UNFUCK_GXX_FLAGS} ${K8_OPT_GCC_FLAGS}")
587 string(REGEX REPLACE "-O[0-9]" " " CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
588 string(REGEX REPLACE "-O[0-9]" " " CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
590 set(CMAKE_C_FLAGS_MINSIZEREL   "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Os ${UNFUCK_GCC_FLAGS}")
591 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Os ${UNFUCK_GCC_FLAGS} ${UNFUCK_GXX_FLAGS}")
594 add_definitions(-DZDBSP_DISABLE_SSE=1)
596 if(NOT WITH_MIMALLOC)
597   add_definitions(-DVAVOOM_DISABLE_MIMALLOC)
598   message(STATUS "Using system memory allocator")
599 endif(NOT WITH_MIMALLOC)
601 set(VAVOOM_MAIN_DEPS "")
603 if(WITH_WINE)
604   set(WINERUN "$ENV{K8VAVOOM_WINE}")
605   if(NOT WINERUN)
606     set(WINERUN "wine")
607   endif(NOT WINERUN)
608 else(WITH_WINE)
609   set(WINERUN "")
610 endif(WITH_WINE)
613 ## message(STATUS "BUILD: ${CMAKE_BUILD_TYPE}")
614 ## message(STATUS "cflags  : ${CMAKE_C_FLAGS}")
615 ## message(STATUS "cxxflags: ${CMAKE_CXX_FLAGS}")
616 ## message(STATUS "cflags  (dbg): ${CMAKE_C_FLAGS_DEBUG}")
617 ## message(STATUS "cxxflags(dbg): ${CMAKE_CXX_FLAGS_DEBUG}")
619 if(NOT DEFINED DATADIR)
620   set(DATADIR share/k8vavoom)
621 endif(NOT DEFINED DATADIR)
622 if(NOT DEFINED BINDIR)
623   set(BINDIR bin)
624 endif(NOT DEFINED BINDIR)
625 if(NOT DEFINED SPECSDIR)
626   set(SPECSDIR specs)
627 endif(NOT DEFINED SPECSDIR)
631 #  **** Check for inttypes.h ****
633 ### find_path(INTTYPES_INCLUDE_DIR inttypes.h)
634 ### if(INTTYPES_INCLUDE_DIR)
635 ###   add_definitions(-DHAVE_INTTYPES_H=1)
636 ### endif(INTTYPES_INCLUDE_DIR)
640 #  **** Check for newtwork libraries ****
642 if(WIN32)
643   set(NET_LIBRARIES wsock32)
644 else(WIN32)
645   set(NET_LIBRARIES "")
646 endif(WIN32)
650 #  **** pkg-config is required ****
652 FIND_PACKAGE(PkgConfig REQUIRED)
656 #  **** Check for zlib ****
658 #if(WITH_SYS_ZLIB)
659 #  find_package(ZLIB)
660 #  if(ZLIB_FOUND)
661 #    include_directories(${ZLIB_INCLUDE_DIR})
662 #  else(ZLIB_FOUND)
663 #    message(STATUS "WARNING: Zlib not found, using internal zlib")
664 #    set(WITH_SYS_ZLIB OFF)
665 #    set(ZLIB_LIBRARIES z)
666 #    set(VAVOOM_MAIN_DEPS ${VAVOOM_MAIN_DEPS} z)
667 #  endif(ZLIB_FOUND)
668 #else(WITH_SYS_ZLIB)
669 #  add_definitions(-DUSE_INTERNAL_ZLIB=1)
670 #  add_definitions(-DHAVE_ZLIB_H=1)
671 #  message(STATUS "Using built-in zlib")
672 #  set(ZLIB_LIBRARIES "z")
673 #  set(VAVOOM_MAIN_DEPS ${VAVOOM_MAIN_DEPS} z)
674 #endif(WITH_SYS_ZLIB)
675 #set(MAIN_LIBS z ${MAIN_LIBS})
679 #  **** Check for libjpeg ****
681 if(ENABLE_CLIENT OR ENABLE_SERVER OR ENABLE_VCCRUN)
682   if(WITH_STB_JPEG)
683   else(WITH_STB_JPEG)
684     add_definitions(-DVAVOOM_DISABLE_STB_IMAGE_JPEG=1)
685     if(WITH_SYS_LIBJPG)
686       find_package(JPEG)
687       if(JPEG_FOUND)
688         include_directories(${JPEG_INCLUDE_DIR})
689         set(MAIN_LIBS ${JPEG_LIBRARIES} ${MAIN_LIBS})
690         add_definitions(-DVAVOOM_USE_LIBJPG=1)
691       else(JPEG_FOUND)
692         message(STATUS "WARNING: LibJpeg not found, using internal jpeg reader")
693         set(WITH_SYS_LIBJPG OFF)
694       endif(JPEG_FOUND)
695     endif(WITH_SYS_LIBJPG)
697     if(NOT WITH_SYS_LIBJPG)
698       set(MAIN_LIBS jpeg ${MAIN_LIBS})
699       set(VAVOOM_MAIN_DEPS ${VAVOOM_MAIN_DEPS} jpeg)
700     endif(NOT WITH_SYS_LIBJPG)
701   endif(WITH_STB_JPEG)
702 endif(ENABLE_CLIENT OR ENABLE_SERVER OR ENABLE_VCCRUN)
706 #  **** Check for liblzma ****
708 #if(WITH_SYS_LZMA)
709 #  find_package(LibLZMA)
710 #  if(LIBLZMA_FOUND)
711 #    include_directories(${LIBLZMA_INCLUDE_DIRS})
712 #    #message(STATUS "***: " ${LIBLZMA_INCLUDE_DIRS})
713 #    #message(STATUS "***: " ${LIBLZMA_LIBRARIES})
714 #    set(MAIN_LIBS ${LIBLZMA_LIBRARIES} ${MAIN_LIBS})
715 #  else(LIBLZMA_FOUND)
716 #    message(STATUS "WARNING: LibLzma not found, using internal lzma decoder")
717 #    set(WITH_SYS_LZMA OFF)
718 #  endif(LIBLZMA_FOUND)
719 #endif(WITH_SYS_LZMA)
721 #if(NOT WITH_SYS_LZMA)
722 #  set(MAIN_LIBS lzma ${MAIN_LIBS})
723 #  set(VAVOOM_MAIN_DEPS ${VAVOOM_MAIN_DEPS} lzma)
724 #  add_definitions(-DUSE_INTERNAL_LZMA=1)
725 #endif(NOT WITH_SYS_LZMA)
727 #if(NOT WITH_SYS_LZMA)
728 #  message(STATUS "LZMA: using internal liblzma")
729 #  set(LIBLZMA_LIBRARIES "lzma")
730 #  add_definitions(-DUSE_INTERNAL_LZMA=1)
731 #endif(NOT WITH_SYS_LZMA)
735 #  **** Check for OpenAL ****
737 if(ENABLE_CLIENT OR ENABLE_VCCRUN)
738   if(WITH_MOJOAL)
739     if(NOT WITH_SDL2)
740       message(FATAL_ERROR "WITH_SDL2 required for MojoAL")
741     endif(NOT WITH_SDL2)
742     #check_include_file(SDL2/SDL_mixer.h HAVE_SDL2_SUBDIR)
743     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lSDL2_mixer")
744     add_definitions(-DVAVOOM_USE_MOJOAL=1)
745   else(WITH_MOJOAL)
746     find_package(OpenAL REQUIRED)
747     include_directories(${OPENAL_INCLUDE_DIR})
748     if(WITH_STATIC_OPENAL)
749       #k8: my MXE builds are static. live with it.
750       add_definitions(-DAL_LIBTYPE_STATIC=1)
751     endif(WITH_STATIC_OPENAL)
752     set(MAIN_LIBS ${OPENAL_LIBRARY} ${MAIN_LIBS})
753     if(WIN32)
754       set(MAIN_LIBS ${OPENAL_LIBRARY} winmm ${MAIN_LIBS})
755     endif(WIN32)
756   endif(WITH_MOJOAL)
757 endif(ENABLE_CLIENT OR ENABLE_VCCRUN)
759 if(WIN32)
760   set(VAVOOM_SHITDOZE_LIBS winmm setupapi samplerate)
761 else(WIN32)
762   set(VAVOOM_SHITDOZE_LIBS )
763 endif(WIN32)
765 set(MAIN_LIBS ${VAVOOM_SHITDOZE_LIBS} ${MAIN_LIBS})
767 set(NEED_SYS_OGG OFF)
768 if(WITH_SYS_VORBIS)
769   set(NEED_SYS_OGG ON)
770 endif(WITH_SYS_VORBIS)
772 if(WITH_SYS_OPUS)
773   set(NEED_SYS_OGG ON)
774 endif(WITH_SYS_OPUS)
777 #  **** Check for libogg ****
779 if(NEED_SYS_OGG)
780   PKG_CHECK_MODULES(OGG ogg)
781   if(OGG_FOUND)
782     message(STATUS "Found libogg: ${OGG_LIBRARIES}")
783     include_directories(${OGG_INCLUDE_DIRS})
784     set(MAIN_LIBS ${OGG_LIBRARIES} ${MAIN_LIBS})
785   endif(OGG_FOUND)
786 endif(NEED_SYS_OGG)
790 #  **** Check for Vorbis ****
792 if(WITH_SYS_VORBIS)
793   PKG_CHECK_MODULES(VORBIS vorbis)
794   if(OGG_FOUND AND VORBIS_FOUND)
795     message(STATUS "Found Vorbis: ${VORBIS_LIBRARIES}")
796     set(VORBIS_FOUND ON)
797     include_directories(${VORBIS_INCLUDE_DIRS})
798     set(MAIN_LIBS ${VORBIS_LIBRARIES} ${MAIN_LIBS})
799   else(OGG_FOUND AND VORBIS_FOUND)
800     message(STATUS "Could NOT find OggVorbis libraries")
801     set(VORBIS_FOUND OFF)
802     message(FATAL_ERROR "You need libvorbis to compile k8vavoom.")
803     return()
804   endif(OGG_FOUND AND VORBIS_FOUND)
805 else(WITH_SYS_VORBIS)
806   set(VORBIS_FOUND OFF)
807   message(STATUS "using stb_vorbis for Ogg/Vorbis decoding")
808 endif(WITH_SYS_VORBIS)
812 #  **** Check for Opus ****
814 set(OPUS_USE_INTERNAL OFF)
815 if(WITH_SYS_OPUS)
816   PKG_CHECK_MODULES(OPUS opusfile opus)
817   if(OPUS_FOUND AND OGG_FOUND)
818     message(STATUS "Found Opus: ${OPUS_LIBRARIES}")
819     set(OPUS_FOUND ON)
820     include_directories(${OPUS_INCLUDE_DIRS})
821     set(MAIN_LIBS ${OPUS_LIBRARIES} ${MAIN_LIBS})
822   else(OPUS_FOUND AND OGG_FOUND)
823     message(STATUS "Could NOT find Opus libraries")
824     set(OPUS_FOUND OFF)
825     message(FATAL_ERROR "You need libopus to compile k8vavoom.")
826     return()
827   endif(OPUS_FOUND AND OGG_FOUND)
828 else(WITH_SYS_OPUS)
829   set(OPUS_FOUND OFF)
830   set(OPUS_USE_INTERNAL ON)
831   include_directories(${CMAKE_SOURCE_DIR}/libs/opus/libopus/include)
832   include_directories(${CMAKE_SOURCE_DIR}/libs/opus/libopusfile/include)
833   if(OGG_FOUND)
834     set(MAIN_LIBS opusfile opus ${MAIN_LIBS})
835     message(STATUS "using built-in libopus and system libogg")
836   else(OGG_FOUND)
837     # use built-in libogg
838     include_directories(${CMAKE_SOURCE_DIR}/libs/opus/libogg/include)
839     set(MAIN_LIBS opusfile opus ogg ${MAIN_LIBS})
840     add_definitions(-DVV_BUILTIN_OGG)
841     message(STATUS "using built-in libopus and libogg")
842   endif(OGG_FOUND)
843   add_definitions(-DVV_BUILTIN_OPUS)
844 endif(WITH_SYS_OPUS)
849 if(ENABLE_CLIENT OR ENABLE_VCCRUN_ONLY OR ENABLE_VCCRUN)
850   set(XMPLITE_FOUND ON)
851   set(MAIN_LIBS xmplite ${MAIN_LIBS})
852   include_directories(libs/xmplite)
853   add_definitions(-DLIBXMP_CORE_PLAYER)
854   add_definitions(-DXMP_SYM_VISIBILITY)
855 endif(ENABLE_CLIENT OR ENABLE_VCCRUN_ONLY OR ENABLE_VCCRUN)
859 #  **** Check for libmad ****
861 if(WITH_LIBMAD)
862   find_path(MAD_INCLUDE_DIRS mad.h)
863   find_library(MAD_LIBRARIES NAMES mad)
864   if(MAD_LIBRARIES)
865     message(STATUS "Found LibMAD: ${MAD_LIBRARIES}")
866     set(LIBMAD_FOUND ON)
867     include_directories(${MAD_INCLUDE_DIRS})
868     set(MAIN_LIBS ${MAD_LIBRARIES} ${MAIN_LIBS})
869   else(MAD_LIBRARIES)
870     message(STATUS "Could NOT find LibMAD libraries")
871     set(LIBMAD_FOUND OFF)
872   endif(MAD_LIBRARIES)
873 else(WITH_LIBMAD)
874   set(LIBMAD_FOUND OFF)
875   message(STATUS "using dr_mp3 for MP3 decoding")
876 endif(WITH_LIBMAD)
880 #  **** Check for FLAC ****
882 if(WITH_SYS_FLAC)
883   PKG_CHECK_MODULES(FLAC flac)
884   if(FLAC_FOUND)
885     message(STATUS "Found FLAC: ${FLAC_LIBRARIES}")
886     include_directories(${FLAC_INCLUDE_DIRS})
887     set(MAIN_LIBS ${FLAC_LIBRARIES} ${MAIN_LIBS})
888   else(FLAC_FOUND)
889     message(STATUS "Could NOT find FLAC library")
890     set(FLAC_FOUND OFF)
891   endif(FLAC_FOUND)
892 else(WITH_SYS_FLAC)
893   set(FLAC_FOUND OFF)
894   message(STATUS "using dr_flac for FLAC decoding")
895 endif(WITH_SYS_FLAC)
899 #  **** Check for LibJIT ****
901 if(WITH_LIBJIT)
902   PKG_CHECK_MODULES(LIBJIT libjit)
903   if(LIBJIT_FOUND)
904     message(STATUS "Found LibJIT: ${LIBJIT_LIBRARIES}")
905     include_directories(${LIBJIT_INCLUDE_DIRS})
906     set(MAIN_LIBS ${LIBJIT_LIBRARIES} ${MAIN_LIBS})
907   else(LIBJIT_FOUND)
908     message(STATUS "Could not find LibJIT library (this is OK)")
909     set(LIBJIT_FOUND OFF)
910   endif(LIBJIT_FOUND)
911 else(WITH_LIBJIT)
912   set(LIBJIT_FOUND OFF)
913   #message(STATUS "LibJIT disabled by user")
914 endif(WITH_LIBJIT)
916 if(LIBJIT_FOUND)
917   add_definitions(-DUSE_LIBJIT)
918 endif(LIBJIT_FOUND)
922 #  **** Check for FluidSynth ****
924 if(WITH_FLUID AND ENABLE_CLIENT)
925   if(WITH_SYS_FLUID)
926     PKG_CHECK_MODULES(FLUID fluidsynth)
927     #message(STATUS, "FINC:" ${FLUID_INCLUDE_DIRS})
928     #message(STATUS, "FLIB:" ${FLUID_LIBRARIES})
929     if(WIN32 AND FLUID_FOUND)
930       PKG_CHECK_MODULES(GLIB glib-2.0)
931       if(GLIB_FOUND)
932         include_directories(${GLIB_INCLUDE_DIRS})
933         set(MAIN_LIBS ${GLIB_LIBRARIES} ${MAIN_LIBS})
934       else(GLIB_FOUND)
935         set(FLUID_FOUND OFF)
936       endif(GLIB_FOUND)
937     endif(WIN32 AND FLUID_FOUND)
938     if(FLUID_FOUND)
939       message(STATUS "Found FluidSynth: ${FLUID_LIBRARIES}")
940       set(FLUID_FOUND ON)
941       include_directories(${FLUID_INCLUDE_DIRS})
942       set(MAIN_LIBS ${FLUID_LIBRARIES} ${MAIN_LIBS})
943     else(FLUID_INCLUDE_DIRS AND FLUID_LIBRARIES)
944       message(STATUS "Could NOT find FluidSynth libraries")
945       if(NOT WIN32)
946         message(STATUS "Using built-in FluidSynth")
947         set(WITH_SYS_FLUID OFF)
948         set(FLUID_FOUND ON)
949       endif(NOT WIN32)
950     endif(FLUID_FOUND)
951   else(WITH_SYS_FLUID)
952     message(STATUS "Using built-in FluidSynth")
953     set(FLUID_FOUND ON)
954   endif(WITH_SYS_FLUID)
955 else(WITH_FLUID)
956   set(FLUID_FOUND OFF)
957 endif(WITH_FLUID AND ENABLE_CLIENT)
959 if(FLUID_FOUND AND NOT WITH_SYS_FLUID AND ENABLE_CLIENT)
960   add_definitions(-DBUILTIN_FLUID)
961   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/fluidsynth_lite/include)
962   include_directories(${CMAKE_CURRENT_BINARY_DIR}/libs/fluidsynth_lite/include)
963   set(MAIN_LIBS libfluidsynth_lite ${MAIN_LIBS})
964 endif(FLUID_FOUND AND NOT WITH_SYS_FLUID AND ENABLE_CLIENT)
968 #  **** Platform specific library checks ****
970 #if(NOT WIN32)
971   # ---------------- Other *NIX platforms ----------------
972   if(WITH_SDL2)
973     if(CMAKE_CROSSCOMPILING AND ANDROID)
974       if(SDL2_INCLUDE_DIRS STREQUAL "")
975         message(FATAL_ERROR "SDL2_INCLUDE_DIRS not specified")
976       endif()
977       if(SDL2_LIBRARIES STREQUAL "")
978         message(FATAL_ERROR "SDL2_LIBRARIES not specified")
979       endif()
980       set(SDL2_FOUND ON)
981     else()
982       find_package(SDL2 REQUIRED)
983       #PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
984     endif()
985     include_directories(${SDL2_INCLUDE_DIRS})
986     set(MAIN_LIBS ${SDL2_LIBRARIES} ${MAIN_LIBS})
987     #message(STATUS "SDL2 INCLUDES:" ${SDL2_INCLUDE_DIRS})
988     #message(STATUS "SDL2 LIBS:" ${SDL2_LIBRARIES})
989   else(WITH_SDL2)
990     set(OPENGL_FOUND OFF)
991     set(WITH_OPENGL OFF)
992   endif(WITH_SDL2)
994   if(WITH_OPENGL)
995     if(NOT WITH_SDL2)
996       message(SEND_ERROR "SDL2 required for OpenGL")
997       return()
998     endif(NOT WITH_SDL2)
999     set(OpenGL_GL_PREFERENCE LEGACY)
1000     if(NSWITCH)
1001       # massive fucking hack because nothing works right
1002       set(OPENGL_gl_LIBRARY "-L$ENV{PORTLIBS_PREFIX}/lib -lEGL -lglapi -ldrm_nouveau")
1003       set(OPENGL_INCLUDE_DIR "$ENV{PORTLIBS_PREFIX}/include")
1004       set(OPENGL_FOUND ON)
1005     elseif(WITH_GL4ES)
1006       set(OPENGL_gl_LIBRARY "-L${GL4ES_LIBRARY_DIR} -lGL")
1007       set(OPENGL_INCLUDE_DIR "${GL4ES_INCLUDE_DIR}")
1008       set(OPENGL_FOUND ON)
1009     else()
1010       find_package(OpenGL REQUIRED)
1011     endif()
1012     if(OPENGL_FOUND)
1013       message(STATUS "Found OpenGL")
1014       include_directories(${OPENGL_INCLUDE_DIR})
1015       if(NSWITCH OR WITH_GL4ES)
1016         # have to reorder this shit or else it doesn't link
1017         set(MAIN_LIBS ${MAIN_LIBS} ${OPENGL_gl_LIBRARY})
1018       else()
1019         set(MAIN_LIBS ${OPENGL_gl_LIBRARY} ${MAIN_LIBS})
1020       endif()
1021     endif(OPENGL_FOUND)
1022   else(WITH_OPENGL)
1023     set(OPENGL_FOUND OFF)
1024   endif(WITH_OPENGL)
1025 #endif(NOT WIN32)
1027 if(WITH_OPENGL)
1028   if(WITH_GLES)
1029     add_definitions(-DGL4ES_HACKS)
1030   endif()
1031   if(WITH_GL4ES)
1032     add_definitions(-DGL4ES_NO_CONSTRUCTOR)
1033   endif()
1034 endif()
1036 if(ANDROID)
1037   add_definitions(-UDEBUG)
1038   set(MAIN_LIBS log android ${MAIN_LIBS})
1039 endif()
1041 if(WITH_GLAD)
1042   add_definitions(-DUSE_GLAD=1)
1043   if(GLAD_INCLUDE_DIR AND GLAD_LIBRARY)
1044     include_directories(${GLAD_INCLUDE_DIR})
1045     set(MAIN_LIBS ${GLAD_LIBRARY} ${MAIN_LIBS})
1046   else(GLAD_INCLUDE_DIR AND GLAD_LIBRARY)
1047     include_directories("libs/glad")
1048     set(MAIN_LIBS glad ${MAIN_LIBS})
1049     set(VAVOOM_MAIN_DEPS ${VAVOOM_MAIN_DEPS} glad)
1050   endif(GLAD_INCLUDE_DIR AND GLAD_LIBRARY)
1051 endif(WITH_GLAD)
1053 if(CYGWIN)
1054   set(NO_SINCOS ON)
1055 endif()
1057 if(NSWITCH)
1058   message(STATUS "Building for Switch")
1059   include_directories("$ENV{DEVKITPRO}/libnx/include")
1060   include_directories("$ENV{PORTLIBS_PREFIX}/include")
1061   add_definitions(-D__SWITCH__)
1062   # add libnx at the end of lib list
1063   set(MAIN_LIBS ${MAIN_LIBS} "-L$ENV{PORTLIBS_PREFIX}/lib -lnx")
1064   message(STATUS "Libs: ${MAIN_LIBS}")
1065   # why the fuck does this not work properly in the toolchain file
1066   set(CMAKE_C_COMPILER "aarch64-none-elf-gcc")
1067   set(CMAKE_CXX_COMPILER "aarch64-none-elf-g++")
1068   set(CMAKE_AR "aarch64-none-elf-gcc-ar")
1069   set(CMAKE_RANLIB "aarch64-none-elf-gcc-ranlib")
1070   # enable necessary switches
1071   set(NO_SSE ON)
1072   set(NO_SIGNALS ON)
1073   set(NO_SYSCONF ON)
1074   set(NO_SINCOS ON)
1075   set(NO_MEMRCHR ON)
1076   set(NO_RAWTTY ON)
1077   set(WITH_MIMALLOC OFF)
1078   # turn on nxlink if necessary
1079   if(WITH_NXLINK)
1080     add_definitions(-DSWITCH_NXLINK=1)
1081   endif(WITH_NXLINK)
1082 else(NSWITCH)
1083   ### GnuTLS
1084   # # #FindGnuTLS()
1085   # # find_package(GnuTLS)
1086   # # if(GNUTLS_FOUND)
1087   # #   include_directories(${GNUTLS_INCLUDE_DIR})
1088   # #   set(MAIN_LIBS ${GNUTLS_LIBRARIES} ${MAIN_LIBS})
1089   # #   add_definitions(${GNUTLS_DEFINITIONS})
1090   # #   add_definitions(-DUSE_GNU_TLS)
1091   # # endif(GNUTLS_FOUND)
1093   if(ENABLE_VCCRUN)
1094     PKG_CHECK_MODULES(GNUTLS gnutls)
1095     if(GNUTLS_FOUND)
1096       #message(STATUS "GnuTLS INC: " ${GNUTLS_INCLUDE_DIR})
1097       #message(STATUS "GnuTLS LIB: " ${GNUTLS_LIBRARIES})
1098       #message(STATUS "GnuTLS DEF: " ${GNUTLS_DEFINITIONS})
1099       include_directories(${GNUTLS_INCLUDE_DIR})
1100       set(MAIN_LIBS ${GNUTLS_LIBRARIES} ${MAIN_LIBS})
1101       add_definitions(${GNUTLS_DEFINITIONS})
1102       add_definitions(-DUSE_GNU_TLS)
1103     endif(GNUTLS_FOUND)
1104   endif(ENABLE_VCCRUN)
1105 endif(NSWITCH)
1109 ## XRandR
1111 if(WITH_XRANDR)
1112   PKG_CHECK_MODULES(XRANDR xrandr)
1113   PKG_CHECK_MODULES(X11 x11)
1114   if(XRANDR_FOUND AND X11_FOUND)
1115     message(STATUS "Found XRandR: ${XRANDR_LIBRARIES}")
1116     include_directories(${XRANDR_INCLUDE_DIRS})
1117     include_directories(${X11_INCLUDE_DIRS})
1118     set(MAIN_LIBS ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${MAIN_LIBS})
1119     add_definitions(-DUSE_XRANDR=1)
1120   else(XRANDR_FOUND AND X11_FOUND)
1121     message(STATUS "Could NOT find XRandR")
1122   endif(XRANDR_FOUND AND X11_FOUND)
1123   #add_definitions(-DUSE_XRANDR=1)
1124   #set(MAIN_LIBS xrandr X11 Xrandr ${MAIN_LIBS})
1125 endif(WITH_XRANDR)
1128 if(NO_SSE)
1129   add_definitions(-DNO_SSE=1)
1130 endif(NO_SSE)
1132 if(NO_PTHREAD)
1133   add_definitions(-DNO_PTHREAD=1)
1134 endif(NO_PTHREAD)
1136 if(NO_SINCOS)
1137   add_definitions(-DNO_SINCOS=1)
1138 endif(NO_SINCOS)
1140 if(NO_SIGNALS)
1141   add_definitions(-DNO_SIGNALS=1)
1142 endif(NO_SIGNALS)
1144 if(NO_SYSCONF)
1145   add_definitions(-DNO_SYSCONF=1)
1146 endif(NO_SYSCONF)
1148 if(NO_MEMRCHR)
1149   add_definitions(-DNO_MEMRCHR=1)
1150 endif(NO_MEMRCHR)
1152 if(NO_RAWTTY)
1153   add_definitions(-DNO_RAWTTY=1)
1154 endif(NO_RAWTTY)
1156 ### if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
1157 ###   add_subdirectory(libs/libbacktrace)
1158 ###   #include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbacktrace)
1159 ###   set(MAIN_LIBS backtrace ${MAIN_LIBS})
1160 ###   add_definitions(-DHAVE_BACKTRACE=1)
1161 ### endif()
1164 message(STATUS "=== BUILD OPTIONS ===")
1165 message(STATUS "BUILD: ${CMAKE_BUILD_TYPE}")
1166 if(WITH_WINE)
1167   message(STATUS "WINE COMMAND: " ${WINERUN})
1168 endif(WITH_WINE)
1169 #message(STATUS "cflags  : ${CMAKE_C_FLAGS}")
1170 #message(STATUS "cxxflags: ${CMAKE_CXX_FLAGS}")
1172 message(STATUS "=== COMPONENTS ===")
1173 message(STATUS "  Vavoom Client: " ${ENABLE_CLIENT})
1174 message(STATUS "  Vavoom Server: " ${ENABLE_SERVER})
1175 message(STATUS "  Vavoom Master: " ${ENABLE_MASTER})
1176 message(STATUS "  Vavoom Query : " ${ENABLE_QUERY_DEMO})
1177 message(STATUS "  VccRun       : " ${ENABLE_VCCRUN})
1178 message(STATUS "  strtodEx     : " ${WITH_STRTODEX})
1179 if(ENABLE_VCCRUN)
1180   if(GNUTLS_FOUND)
1181     message(STATUS "  GNUTLS       : ON")
1182   endif(GNUTLS_FOUND)
1183 endif(ENABLE_VCCRUN)
1184 if(SDL2_OVERRIDE)
1185   message(STATUS "SDL2 override mode")
1186 else(SDL2_OVERRIDE)
1187   if(NOT HAVE_SDL2_SUBDIR)
1188     message(STATUS "SDL2 non-subdir mode")
1189   endif(NOT HAVE_SDL2_SUBDIR)
1190 endif(SDL2_OVERRIDE)
1193 add_subdirectory(libs)
1195 if(ENABLE_UTILS_ONLY)
1196   add_subdirectory(utils)
1197 elseif(NOT ENABLE_VCCRUN_ONLY)
1198   if(NOT CMAKE_CROSSCOMPILING OR WIN32)
1199     add_subdirectory(utils)
1200   endif(NOT CMAKE_CROSSCOMPILING OR WIN32)
1201   add_subdirectory(source)
1202   if(NOT CMAKE_CROSSCOMPILING OR WIN32)
1203     #add_subdirectory(progs)
1204     add_subdirectory(basev)
1205   endif(NOT CMAKE_CROSSCOMPILING OR WIN32)
1206   #foreach(DIR ${EXTRA_SUBDIRS})
1207   #  add_subdirectory(${DIR})
1208   #endforeach(DIR)
1209 endif()
1211 if(ENABLE_VCCRUN)
1212   add_subdirectory(vccrun)
1213 endif(ENABLE_VCCRUN)