forked from zauonlok/renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
141 lines (123 loc) · 4.21 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
130
131
132
133
134
135
136
137
138
139
140
141
cmake_minimum_required(VERSION 3.10)
project(Renderer LANGUAGES C)
# ==============================================================================
# Headers and sources
# ==============================================================================
set(HEADERS
renderer/core/api.h
renderer/core/camera.h
renderer/core/darray.h
renderer/core/draw2d.h
renderer/core/graphics.h
renderer/core/image.h
renderer/core/macro.h
renderer/core/maths.h
renderer/core/mesh.h
renderer/core/platform.h
renderer/core/private.h
renderer/core/scene.h
renderer/core/skeleton.h
renderer/core/texture.h
renderer/scenes/blinn_scenes.h
renderer/scenes/pbr_scenes.h
renderer/scenes/scene_helper.h
renderer/shaders/blinn_shader.h
renderer/shaders/cache_helper.h
renderer/shaders/pbr_shader.h
renderer/shaders/skybox_shader.h
renderer/tests/test_blinn.h
renderer/tests/test_helper.h
renderer/tests/test_pbr.h
)
set(SOURCES
renderer/core/camera.c
renderer/core/darray.c
renderer/core/draw2d.c
renderer/core/graphics.c
renderer/core/image.c
renderer/core/maths.c
renderer/core/mesh.c
renderer/core/private.c
renderer/core/scene.c
renderer/core/skeleton.c
renderer/core/texture.c
renderer/scenes/blinn_scenes.c
renderer/scenes/pbr_scenes.c
renderer/scenes/scene_helper.c
renderer/shaders/blinn_shader.c
renderer/shaders/cache_helper.c
renderer/shaders/pbr_shader.c
renderer/shaders/skybox_shader.c
renderer/tests/test_blinn.c
renderer/tests/test_helper.c
renderer/tests/test_pbr.c
renderer/main.c
)
if(WIN32)
set(SOURCES ${SOURCES} renderer/platforms/win32.c)
elseif(APPLE)
set(SOURCES ${SOURCES} renderer/platforms/macos.m)
else()
set(SOURCES ${SOURCES} renderer/platforms/linux.c)
endif()
source_group(TREE "${CMAKE_SOURCE_DIR}/renderer" FILES ${HEADERS} ${SOURCES})
# ==============================================================================
# Target definition
# ==============================================================================
set(TARGET Viewer)
add_executable(${TARGET} ${HEADERS} ${SOURCES})
# ==============================================================================
# Target properties
# ==============================================================================
set_target_properties(${TARGET} PROPERTIES C_STANDARD 90)
set_target_properties(${TARGET} PROPERTIES C_EXTENSIONS OFF)
set_target_properties(${TARGET} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
# ==============================================================================
# Compile options
# ==============================================================================
if(MSVC)
target_compile_options(${TARGET} PRIVATE /W4)
target_compile_options(${TARGET} PRIVATE /fp:fast)
else()
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -pedantic)
target_compile_options(${TARGET} PRIVATE -ffast-math)
endif()
if(WIN32)
target_compile_options(${TARGET} PRIVATE /D_CRT_SECURE_NO_WARNINGS)
elseif(APPLE)
# nothing to do for now
else()
target_compile_options(${TARGET} PRIVATE -D_POSIX_C_SOURCE=200809L)
endif()
# ==============================================================================
# Link libraries
# ==============================================================================
if(WIN32)
# nothing to do for now
elseif(APPLE)
target_link_libraries(${TARGET} PRIVATE "-framework Cocoa")
else()
target_link_libraries(${TARGET} PRIVATE m X11)
endif()
# ==============================================================================
# Asset files
# ==============================================================================
set(SRC_ASSETS "${CMAKE_SOURCE_DIR}/assets")
set(DST_ASSETS "$<TARGET_FILE_DIR:${TARGET}>/assets")
if(WIN32)
set(ASSETS_CMD copy_directory)
set(ASSETS_MSG "Copy assets")
else()
set(ASSETS_CMD create_symlink)
set(ASSETS_MSG "Link assets")
endif()
add_custom_command(
TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo
"${ASSETS_MSG}: ${SRC_ASSETS} to ${DST_ASSETS}"
)
add_custom_command(
TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E ${ASSETS_CMD}
"${SRC_ASSETS}" "${DST_ASSETS}"
)