1 add_library(common INTERFACE)
2 target_compile_definitions(common INTERFACE -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES)
6 # Build a version string for the engine.
8 COMMAND git rev-parse --short HEAD
9 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
10 OUTPUT_VARIABLE revision
11 OUTPUT_STRIP_TRAILING_WHITESPACE
15 COMMAND "git show -s --format=%ad --date='format-local:%a %b %d %Y %H:%I:%S UTC'"
16 OUTPUT_VARIABLE timestamp
17 OUTPUT_STRIP_TRAILING_WHITESPACE
19 set(DP_BUILD_REVISION "${timestamp} - ${revision}")
21 if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x|i[36])86|AMD64")
22 option(ENGINE_CONFIG_SSE "Build with SSE support (x86 and x86_64 only)" ON)
24 set(ENGINE_CONFIG_SSE OFF)
28 # Flags for gcc, clang, tcc...
30 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
31 # Also, since gcc 5, -ffinite-math-only makes NaN and zero compare equal inside engine code but not inside QC, which causes error spam for seemingly valid QC code like if (x != 0) return 1 / x;
33 target_compile_options(common INTERFACE
34 -Wall -Winline -Werror=c++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
35 $<$<CONFIG:RELEASE>:-O3 -fno-strict-aliasing -fno-math-errno -fno-rounding-math -fno-trapping-math>
36 $<$<CONFIG:DEBUG>:-ggdb>
37 $<$<CONFIG:PROFILE>:-g -pg -ggdb -fprofile-arcs>
38 $<$<CONFIG:PROFILERELEASE>:-fbranch-probabilities>
41 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
42 target_compile_options(common INTERFACE $<$<CONFIG:RELEASE>:-fno-signaling-nans>)
45 target_link_libraries(common INTERFACE -lm)
47 if(CMAKE_C_COMPILER_ID STREQUAL "TinyCC")
48 target_compile_definitions(common INTERFACE -DSDL_DISABLE_IMMINTRIN_H)
51 if(ENGINE_CONFIG_PEDANTIC)
52 target_compile_options(common INTERFACE -std=c11 -pedantic)
53 target_compile_definitions(common INTERFACE -D_POSIX_C_SOURCE=200809L -DCONFIG_PEDANTIC)
57 target_compile_options(common INTERFACE -msse)
60 if(WIN32) # Windows MinGW
61 if(CMAKE_SYSTEM_PROCESSOR MATCHES "i[36]86")
62 target_link_options(common INTERFACE --large-address-aware)
64 target_link_libraries(common INTERFACE -lwinmm -limm32 -lversion -lwsock32 -lws2_32)
65 elseif(APPLE) # MacOS, iOS
66 target_link_libraries(common INTERFACE -ldl -framework IOKit -framework CoreFoundation)
67 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS") # SunOS, Solaris, OpenSolaris, illumos (OpenIndiana and friends)
68 target_link_libraries(common INTERFACE -lrt -ldl -lsocket -lnsl)
69 else() # Linux, the BSDs, and probably everything else
70 target_link_libraries(common INTERFACE -lrt -ldl)
73 # Flags for Visual Studio
74 target_compile_options(common INTERFACE
75 /W4 /Wd4706;4127;4100;4055;4054;4244;4305;4702;4201 /MP
76 $<$<CONFIG:RELEASE>:/MD /Gy /O2 /Oi /Zi>
77 $<$<CONFIG:DEBUG>:/Od /RTC1 /MDd /Gm>
80 target_link_options(common INTERFACE
82 $<$<CONFIG:RELEASE>:/OPT:REF /OPT:ICF>
83 $<$<CONFIG:DEBUG>:/DEBUG /NODEFAULTLIB:msvcrt.lib>
86 if(CMAKE_SYSTEM_PROCESOR STREQUAL "AMD64")
87 target_compile_options(client INTERFACE /Zi)
89 target_compile_options(client INTERFACE /ZI)
90 target_link_options(common INTERFACE /LARGEADDRESSAWARE)
95 target_compile_definitions(common INTERFACE -DSVNREVISION=${ENGINE_VERSION})
99 target_compile_definitions(common INTERFACE -DBUILDTYPE=${CMAKE_BUILD_TYPE})
102 if(ENGINE_NO_BUILD_TIMESTAMPS)
103 target_compile_definitions(common INTERFACE -DNO_BUILD_TIMESTAMPS)
106 if(ENGINE_BUILD_CLIENT)
107 include(buildsys/target/engine/client.cmake)
110 if(ENGINE_BUILD_SERVER)
111 include(buildsys/target/engine/server.cmake)