-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
159 lines (139 loc) · 6.22 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# I don't know what I'm doing with cmake. This is all vodoo...
cmake_minimum_required(VERSION 3.22.1)
include(CMakeDependentOption)
project(Brplot)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release Debug)
message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
if ((NOT DEFINED CMAKE_BUILD_TYPE) OR (CMAKE_BUILD_TYPE STREQUAL ""))
set(CMAKE_BUILD_TYPE Release)
endif ()
message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
set(GUI imgui CACHE STRING "What gui to use")
set_property(CACHE GUI PROPERTY STRINGS raylib imgui headless)
message("GUI=${GUI}")
cmake_dependent_option(USE_LTO "Enable LTO" ON "CMAKE_BUILD_TYPE STREQUAL Release" OFF)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${USE_LTO})
message("USE_LTO=${USE_LTO}")
option(USE_TRACY OFF "Use tracy for profiling")
cmake_dependent_option(USE_HOTRELOAD "Enable Hot reload" ON "CMAKE_BUILD_TYPE STREQUAL Debug; GUI STREQUAL imgui" OFF)
# I don't how msvc can hot reload...
if (MSVC)
set(USE_HOTRELOAD OFF)
endif ()
add_library(raylib STATIC
./external/raylib-5.0/src/rmodels.c
./external/raylib-5.0/src/rshapes.c
./external/raylib-5.0/src/rtext.c
./external/raylib-5.0/src/rtextures.c
./external/raylib-5.0/src/utils.c
./external/raylib-5.0/src/rcore.c
)
target_include_directories(raylib PUBLIC . ./external/glfw/include)
add_library(imgui STATIC
./external/imgui-docking/imgui.cpp
./external/imgui-docking/imgui_draw.cpp
./external/imgui-docking/imgui_tables.cpp
./external/imgui-docking/imgui_widgets.cpp
./external/imgui-docking/backends/imgui_impl_glfw.cpp
./external/imgui-docking/backends/imgui_impl_opengl3.cpp
)
target_include_directories(imgui PUBLIC ./external/imgui-docking/ ./external/glfw/include)
add_executable(brplot
src/main.c src/help.c src/data.c src/smol_mesh.c src/q.c
src/read_input.c src/plotter.c src/keybindings.c src/str.c src/memory.cpp
src/resampling2.c src/graph_utils.c src/shaders.c src/plot.c src/filesystem++.cpp
src/permastate.c src/gui++.cpp src/gui.c src/filesystem.c src/data_generator.c
src/platform.c
)
target_compile_features(brplot PUBLIC cxx_std_17)
if (MSVC)
else ()
target_compile_options(brplot PUBLIC -Wconversion -Wall -Wpedantic -Wextra)
endif ()
if (USE_TRACY)
message("Using tracy")
target_compile_definitions(brplot PUBLIC TRACY_ENABLE=1)
target_link_libraries(brplot tracy)
endif ()
if (USE_HOTRELOAD)
message("Using hot reload")
target_link_options(brplot PUBLIC -fpie -rdynamic)
target_compile_options(brplot PUBLIC -fpie)
endif ()
add_executable(font_export tools/font_export.c)
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/misc/default_font.h
COMMAND font_export fonts/PlayfairDisplayRegular-ywLOY.ttf src/misc/default_font.h
DEPENDS font_export fonts/PlayfairDisplayRegular-ywLOY.ttf
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
if (MSVC)
else ()
target_link_libraries(font_export PUBLIC m)
endif ()
target_sources(brplot PRIVATE src/misc/default_font.h)
if (CMAKE_BUILD_TYPE STREQUAL Debug)
target_compile_definitions(brplot PUBLIC DEBUG)
elseif (CMAKE_BUILD_TYPE STREQUAL Release)
target_compile_definitions(brplot PUBLIC RELEASE IMGUI_DISABLE_DEMO_WINDOWS IMGUI_DISABLE_DEBUG_TOOLS)
if (MSVC)
else ()
target_compile_options(imgui PUBLIC -fdata-sections -ffunction-sections)
target_compile_options(raylib PUBLIC -fdata-sections -ffunction-sections)
target_compile_options(brplot PUBLIC -fdata-sections -ffunction-sections)
target_link_options(raylib PUBLIC -fdata-sections -ffunction-sections -Wl,--gc-sections)
target_link_options(imgui PUBLIC -fdata-sections -ffunction-sections -Wl,--gc-sections)
target_link_options(brplot PUBLIC -fdata-sections -ffunction-sections -Wl,--gc-sections)
endif ()
add_executable(shaders_bake tools/shaders_bake.c src/str.c)
target_include_directories(shaders_bake PUBLIC . ./external/raylib-5.0/src)
file(GLOB shaders src/desktop/shaders/*)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/misc/shaders.h
COMMAND shaders_bake ${CMAKE_SYSTEM_NAME} src/misc/shaders.h
DEPENDS shaders_bake ${shaders}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
target_sources(brplot PUBLIC ./src/misc/shaders.h)
else ()
message(FATAL_ERROR "CMAKE_BUILD_TYPE=`${CMAKE_BUILD_TYPE}` not supported. (Debug|Release)")
endif()
if (GUI STREQUAL raylib)
target_compile_definitions(brplot PUBLIC RAYLIB)
target_link_libraries(brplot raylib)
elseif (GUI STREQUAL imgui)
target_compile_definitions(brplot PUBLIC IMGUI)
target_link_libraries(brplot imgui raylib)
target_include_directories(brplot PUBLIC external/imgui-docking)
elseif (GUI STREQUAL headless)
target_compile_definitions(brplot PUBLIC HEADLESS)
else ()
message(FATAL_ERROR "GUI=${GUI} not supported. (raylib|imgui|headless)")
endif ()
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
target_compile_definitions(brplot PUBLIC PLATFORM_DESKTOP=1 LINUX=1)
target_compile_definitions(raylib PUBLIC PLATFORM_DESKTOP=1)
target_link_libraries(raylib glfw)
elseif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
target_compile_definitions(brplot PUBLIC PLATFORM_DESKTOP=1 LINUX=1)
target_compile_definitions(raylib PUBLIC PLATFORM_DESKTOP=1)
target_link_libraries(raylib glfw pthread)
target_include_directories(imgui PUBLIC /usr/local/include)
target_link_directories(brplot PUBLIC /usr/local/lib /usr/lib)
elseif (CMAKE_SYSTEM_NAME STREQUAL Windows)
target_compile_definitions(brplot PUBLIC PLATFORM_DESKTOP=1 WINDOWS=1 _WIN32=1 WIN32_LEAN_AND_MEAN=1)
target_compile_definitions(raylib PUBLIC PLATFORM_DESKTOP=1 _WIN32=1 WIN32_LEAN_AND_MEAN=1)
target_compile_definitions(imgui PUBLIC PLATFORM_DESKTOP=1 _WIN32=1 WIN32_LEAN_AND_MEAN=1)
target_link_libraries(brplot opengl32 gdi32 winmm)
target_sources(raylib PUBLIC ./external/raylib-5.0/src/rglfw.c)
else ()
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} not supported")
endif ()
set(PLAT_CONF ${CMAKE_SYSTEM_NAME}_${CMAKE_BUILD_TYPE})
if (PLAT_CONF STREQUAL Linux_Debug)
elseif (PLAT_CONF STREQUAL Linux_Release)
elseif (PLAT_CONF STREQUAL FreeBSD_Release)
elseif (PLAT_CONF STREQUAL Windows_Release)
elseif (PLAT_CONF STREQUAL Windows_Debug)
else ()
message(FATAL_ERROR "${PLAT_CONF} not supported")
endif ()
target_include_directories(brplot PUBLIC . external/Tracy external/raylib-5.0/src)