]> git.xonotic.org Git - xonotic/darkplaces.git/blob - buildsys/target/engine.cmake
cmake: Fix timestamp format
[xonotic/darkplaces.git] / buildsys / target / engine.cmake
1 add_library(common INTERFACE)
2 target_compile_definitions(common INTERFACE -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES)
3
4 set(ENV{TZ} "UTC")
5
6 # Build a version string for the engine.
7 execute_process(
8         COMMAND git rev-parse --short HEAD
9         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
10         OUTPUT_VARIABLE revision
11         OUTPUT_STRIP_TRAILING_WHITESPACE
12 )
13
14 execute_process(
15         COMMAND "git show -s --format=%ad --date='format-local:%a %b %d %Y %H:%M:%S UTC'"
16         OUTPUT_VARIABLE timestamp
17         OUTPUT_STRIP_TRAILING_WHITESPACE
18 )
19 set(DP_BUILD_REVISION "${timestamp} - ${revision}")
20
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)
23 else()
24         set(ENGINE_CONFIG_SSE OFF)
25 endif()
26
27 if(NOT MSVC)
28         # Flags for gcc, clang, tcc...
29
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;
32
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>
39         )
40
41         if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
42                 target_compile_options(common INTERFACE $<$<CONFIG:RELEASE>:-fno-signaling-nans>)
43         endif()
44
45         target_link_libraries(common INTERFACE -lm)
46
47         if(CMAKE_C_COMPILER_ID STREQUAL "TinyCC")
48                 target_compile_definitions(common INTERFACE -DSDL_DISABLE_IMMINTRIN_H)
49         endif()
50
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)
54         endif()
55
56         if(ENGINE_CONFIG_SSE)
57                 target_compile_options(common INTERFACE -msse)
58         endif()
59
60         if(WIN32) # Windows MinGW
61                 if(CMAKE_SYSTEM_PROCESSOR MATCHES "i[36]86")
62                         target_link_options(common INTERFACE --large-address-aware)
63                 endif()
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)
71         endif()
72 else()
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>
78         )
79
80         target_link_options(common INTERFACE
81                 /SUBSYSTEM:WINDOWS
82                 $<$<CONFIG:RELEASE>:/OPT:REF /OPT:ICF>
83                 $<$<CONFIG:DEBUG>:/DEBUG /NODEFAULTLIB:msvcrt.lib>
84         )
85
86         if(CMAKE_SYSTEM_PROCESOR STREQUAL "AMD64")
87                 target_compile_options(client INTERFACE /Zi)
88         else()
89                 target_compile_options(client INTERFACE /ZI)
90                 target_link_options(common INTERFACE /LARGEADDRESSAWARE)
91         endif()
92 endif()
93
94 if(ENGINE_VERSION)
95         target_compile_definitions(common INTERFACE -DSVNREVISION=${ENGINE_VERSION})
96 endif()
97
98 if(CMAKE_BUILD_TYPE)
99         target_compile_definitions(common INTERFACE -DBUILDTYPE=${CMAKE_BUILD_TYPE})
100 endif()
101
102 if(ENGINE_NO_BUILD_TIMESTAMPS)
103         target_compile_definitions(common INTERFACE -DNO_BUILD_TIMESTAMPS)
104 endif()
105
106 if(ENGINE_BUILD_CLIENT)
107         include(buildsys/target/engine/client.cmake)
108 endif()
109
110 if(ENGINE_BUILD_SERVER)
111         include(buildsys/target/engine/server.cmake)
112 endif()