-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
129 lines (104 loc) · 3.46 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)
project(Minecraft4k C CXX)
include_directories(include)
set(PROJECT_NAME Minecraft4k)
set(Header_Files
"Constants.h"
"Shader.h"
"TextureGenerator.h"
"Util.h"
"World.h"
"Vector.h"
)
source_group("Header Files" FILES ${Header_Files})
set(Resource_Files
"res/raytrace.comp"
"res/screen.frag"
"res/screen.vert"
)
source_group("Resource Files" FILES ${Resource_Files})
set(Source_Files
"Minecraft4k.cpp"
"Shader.cpp"
"TextureGenerator.cpp"
"Util.cpp"
"World.cpp"
"Vector.cpp"
"glad.c"
)
source_group("Source Files" FILES ${Source_Files})
set(ALL_FILES
${Header_Files}
${Resource_Files}
${Source_Files}
)
# Don't link stdlib
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
find_package(SDL REQUIRED)
add_executable(${PROJECT_NAME} ${ALL_FILES})
set(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
if(UNIX)
set(FAKE_TARGET fakeTarget)
add_custom_target(fakeTarget
cd ${CMAKE_CURRENT_SOURCE_DIR} && mono shader_minifier.exe --preserve-externals -o shader_code.h ${Resource_Files} &&
sed -i 's/int SHADER_MINIFIER_WORKAROUND/in/g' shader_code.h
)
add_dependencies(${PROJECT_NAME} ${FAKE_TARGET})
# for debugging
# target_compile_options(${PROJECT_NAME} PRIVATE -g -DDEBUG)
# TODO -m32, use C libs
target_compile_options(${PROJECT_NAME} PRIVATE -DSDL_stdinc_h_
-Os -s -fno-rtti -fno-stack-protector -ffunction-sections -fdata-sections -fno-math-errno
-fno-unroll-loops -fmerge-all-constants -fno-ident -mfpmath=387 -mfancy-math-387 #-e _start
-fsingle-precision-constant -ffast-math -fno-exceptions -nostartfiles -nostdlib -nodefaultlibs
-fcf-protection=none -N -fno-align-functions -fomit-frame-pointer -fno-threadsafe-statics
-finline-limit=10 -fno-asynchronous-unwind-tables
)
target_link_options(${PROJECT_NAME} PRIVATE
-Wl,--hash-style=gnu,--build-id=none,--gc-sections#,-z,max-page-size=2048#,-e,_start
)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag -R .note -R .comment -R .eh_frame -R .eh_frame_hdr -s ${PROJECT_NAME}
COMMAND objcopy --remove-section .note.gnu.property --remove-section .gnu.version --remove-section .fini --remove-section .init_array --remove-section .got ${PROJECT_NAME}
COMMAND sstrip ${PROJECT_NAME}
COMMAND gzexe ${PROJECT_NAME}
)
endif()
# Compile and link options
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/Oi-;
/Gy
>
/permissive-;
/O1;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
/Os;
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/INCREMENTAL
# >
$<$<CONFIG:Release>:
/INCREMENTAL:NO
>
/DEBUG;
/SUBSYSTEM:CONSOLE;
/OPT:REF;
/OPT:ICF
)
endif()
if(UNIX)
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"dl"
)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES} ${SDL_LIBRARY}")
link_directories(${PROJECT_NAME} PRIVATE
"lib"
)