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