1 add_library(common INTERFACE)
2 #target_sources(common INTERFACE ${OBJ_COMMON})
3 target_compile_definitions(common INTERFACE -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES)
7 # Build a version string for the engine.
9 COMMAND git rev-parse --short HEAD
10 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
11 OUTPUT_VARIABLE revision
12 OUTPUT_STRIP_TRAILING_WHITESPACE
16 COMMAND "git show -s --format=%ad --date='format-local:%a %b %d %Y %H:%I:%S UTC'"
17 OUTPUT_VARIABLE timestamp
18 OUTPUT_STRIP_TRAILING_WHITESPACE
20 set(DP_BUILD_REVISION "${timestamp} - ${revision}")
22 if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x|i[36])86|AMD64")
23 option(ENGINE_CONFIG_SSE "Build with SSE support (x86 and x86_64 only)" ON)
25 set(ENGINE_CONFIG_SSE OFF)
29 # Flags for gcc, clang, tcc...
31 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
32 # 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;
34 target_compile_options(common INTERFACE
35 -Wall -Winline -Werror=c++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
36 $<$<CONFIG:RELEASE>:-O3 -fno-strict-aliasing -fno-math-errno -fno-rounding-math -fno-trapping-math>
37 $<$<CONFIG:DEBUG>:-ggdb>
38 $<$<CONFIG:PROFILE>:-g -pg -ggdb -fprofile-arcs>
39 $<$<CONFIG:PROFILERELEASE>:-fbranch-probabilities>
42 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
43 target_compile_options(common INTERFACE $<$<CONFIG:RELEASE>:-fno-signaling-nans>)
46 target_link_libraries(common INTERFACE -lm)
48 if(CMAKE_C_COMPILER_ID STREQUAL "TinyCC")
49 target_compile_definitions(common INTERFACE -DSDL_DISABLE_IMMINTRIN_H)
52 if(ENGINE_CONFIG_PEDANTIC)
53 target_compile_options(common INTERFACE -std=c11 -pedantic)
54 target_compile_definitions(common INTERFACE -D_POSIX_C_SOURCE=200809L -DCONFIG_PEDANTIC)
58 target_compile_options(common INTERFACE -msse)
61 if(WIN32) # Windows MinGW
62 if(CMAKE_SYSTEM_PROCESSOR MATCHES "i[36]86")
63 target_link_options(common INTERFACE --large-address-aware)
65 target_link_libraries(common INTERFACE -lwinmm -limm32 -lversion -lwsock32 -lws2_32)
66 elseif(APPLE) # MacOS, iOS
67 target_link_libraries(common INTERFACE -ldl -framework IOKit -framework CoreFoundation)
68 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS") # SunOS, Solaris, OpenSolaris, illumos (OpenIndiana and friends)
69 target_link_libraries(common INTERFACE -lrt -ldl -lsocket -lnsl)
70 else() # Linux, the BSDs, and probably everything else
71 target_link_libraries(common INTERFACE -lrt -ldl)
74 # Flags for Visual Studio
75 target_compile_options(common INTERFACE
76 /W4 /Wd4706;4127;4100;4055;4054;4244;4305;4702;4201 /MP
77 $<$<CONFIG:RELEASE>:/MD /Gy /O2 /Oi /Zi>
78 $<$<CONFIG:DEBUG>:/Od /RTC1 /MDd /Gm>
81 target_link_options(common INTERFACE
83 $<$<CONFIG:RELEASE>:/OPT:REF /OPT:ICF>
84 $<$<CONFIG:DEBUG>:/DEBUG /NODEFAULTLIB:msvcrt.lib>
87 if(CMAKE_SYSTEM_PROCESOR STREQUAL "AMD64")
88 target_compile_options(client INTERFACE /Zi)
90 target_compile_options(client INTERFACE /ZI)
91 target_link_options(common INTERFACE /LARGEADDRESSAWARE)
96 target_compile_definitions(common INTERFACE -DSVNREVISION=${ENGINE_VERSION})
100 target_compile_definitions(common INTERFACE -DBUILDTYPE=${CMAKE_BUILD_TYPE})
103 if(ENGINE_NO_BUILD_TIMESTAMPS)
104 target_compile_definitions(common INTERFACE -DNO_BUILD_TIMESTAMPS)
107 if(ENGINE_BUILD_CLIENT)
108 include(buildsys/target/engine/client.cmake)
111 if(ENGINE_BUILD_SERVER)
112 include(buildsys/target/engine/server.cmake)