summaryrefslogtreecommitdiff
path: root/xmake.lua
blob: 355953421e9cb5e84767178f039f593466a41e1e (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
set_project("celeritas")
set_version("0.1.0")
set_config("cc", "clang")

add_rules("mode.debug", "mode.release") -- we have two modes: debug & release

-- -Wall     : base set of warnings
-- -Wextra   : additional warnings not covered by -Wall
-- -Wundef   : undefined macros
-- -Wdouble-promotion : catch implicit converion of float to double
add_cflags("-Wall", "-Wextra", "-Wundef", "-Wdouble-promotion")

if is_mode("debug") then
    add_cflags("-g") -- Add debug symbols in debug mode
    add_defines("CDEBUG")
elseif is_mode("release") then
    add_defines("CRELEASE")
end

-- Platform defines and system packages
if is_plat("linux") then
    add_defines("CEL_PLATFORM_LINUX")
    add_syslinks("dl", "X11", "pthread") --, "vulkan")
elseif is_plat("windows") then
    add_defines("CEL_PLATFORM_WINDOWS")
    add_syslinks("user32", "gdi32", "kernel32", "shell32")
    -- add_requires("vulkansdk", { system = true })
    -- add_links("pthreadVC2-w64")
elseif is_plat("macosx") then
    add_defines("CEL_PLATFORM_MAC")
    add_frameworks("Cocoa", "IOKit", "CoreVideo", "OpenGL")
    add_frameworks("Foundation", "Metal", "QuartzCore")
    set_runenv("MTL_DEBUG_LAYER", "1")
    add_requires("vulkansdk", { system = true })
    -- add_syslinks("GL")
end

-- Compile GLFW from source
package("local_glfw")
    add_deps("cmake")
    set_sourcedir(path.join(os.scriptdir(), "deps/glfw-3.3.8"))
    on_install(function(package)
        local configs = {}
        -- NOTE(omni): Keeping these around as comments in case we need to modify glfw flags
        -- table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
        -- table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
        import("package.tools.cmake").install(package, configs)
    end)
    on_test(function(package)
        -- assert(package:has_cfuncs("add", {includes = "foo.h"}))
    end)
package_end()

add_requires("local_glfw")

local core_sources = {
    "deps/glad/src/glad.c",
    "src/*.c",
    "src/core/*.c",
    "src/logos/*.c",
    "src/maths/*.c",
    "src/platform/*.c",
    "src/ral/*.c",
    "src/ral/backends/opengl/*.c",
    "src/render/*.c",
    "src/resources/*.c",
    "src/std/*.c",
    "src/std/containers/*.c",
    "src/systems/*.c",
}

local unity_sources = {
    "deps/Unity/src/unity.c",
    "deps/Unity/extras/fixture/src/unity_fixture.c",
    "deps/Unity/extras/memory/src/unity_memory.c",
}

rule("compile_glsl_vert_shaders")
    set_extensions(".vert")
    on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
        local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".vert.spv")

        print("Compiling shader: %s to %s", sourcefile, targetfile)
        batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile })
        -- batchcmds:add_depfiles(sourcefile)
    end)

rule("compile_glsl_frag_shaders")
    set_extensions(".frag")
    on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
        local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".frag.spv")

        print("Compiling shader: %s to %s", sourcefile, targetfile)
        batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile })
        -- batchcmds:add_depfiles(sourcefile)
    end)
-- TODO: Metal shaders compilation

-- common configuration for both static and shared libraries
target("core_config")
    set_kind("static") -- kind is required but you can ignore it since it's just for common settings
    add_packages("local_glfw")
    add_defines("CEL_REND_BACKEND_OPENGL")
    add_includedirs("deps/cgltf", { public = true })
    add_includedirs("deps/glfw-3.3.8/include/GLFW", { public = true })
    add_includedirs("deps/glad/include", { public = true })
    add_includedirs("deps/stb_image", { public = true })
    add_includedirs("deps/stb_image_write", { public = true })
    add_includedirs("deps/stb_truetype", { public = true })
    add_includedirs("include/", { public = true })
    add_includedirs("src/", { public = true })
    add_includedirs("src/core", { public = true })
    add_includedirs("src/logos/", { public = true })
    add_includedirs("src/maths/", { public = true })
    add_includedirs("src/platform/", { public = true })
    add_includedirs("src/ral", { public = true })
    add_includedirs("src/ral/backends/opengl", { public = true })
    add_includedirs("src/render", { public = true })
    add_includedirs("src/ral/backends/vulkan", { public = true })
    add_includedirs("src/resources/", { public = true })
    add_includedirs("src/std/", { public = true })
    add_includedirs("src/std/containers", { public = true })
    add_includedirs("src/systems/", { public = true })
    add_files("src/empty.c") -- for some reason we need this on Mac so it doesnt call 'ar' with no files and error
    -- add_rules("compile_glsl_vert_shaders")
    -- add_rules("compile_glsl_frag_shaders")
    -- add_files("assets/shaders/*.frag")
    if is_plat("windows") then
        -- add_includedirs("$(env VULKAN_SDK)/Include", { public = true })
        -- add_linkdirs("$(env VULKAN_SDK)/Lib", { public = true })
        -- add_links("vulkan-1")
    end
    if is_plat("macosx") then
        -- add_files("src/renderer/backends/metal/*.m")
        -- add_files("src/ral/backends/vulkan/*.c")
    end
    set_default(false) -- prevents standalone building of this target

target("core_static")
    set_kind("static")
    add_deps("core_config") -- inherit common configurations
    set_policy("build.merge_archive", true)
    add_files(core_sources)
    -- Link against static CRT
    if is_plat("windows") then
        add_links("libcmt", "legacy_stdio_definitions")  -- for release builds
        add_links("libcmtd", "legacy_stdio_definitions") -- for debug builds
    end

target("core_shared")
    set_kind("shared")
    add_deps("core_config") -- inherit common configurations
    add_files(core_sources)
    -- Link against dynamic CRT
    if is_plat("windows") then
        add_links("msvcrt", "legacy_stdio_definitions")  -- for release builds
        add_links("msvcrtd", "legacy_stdio_definitions") -- for debug builds
    end

-- target("main_loop")
--     set_kind("binary")
--     set_group("examples")
--     add_deps("core_static")
--     add_files("examples/main_loop/ex_main_loop.c")
--     set_rundir("$(projectdir)")

-- target("tri")
--     set_kind("binary")
--     set_group("examples")
--     add_deps("core_static")
--     add_files("examples/triangle/ex_triangle.c")
--     set_rundir("$(projectdir)")
--     if is_plat("macosx") then
--         before_build(function (target)
--             print("build metal shaders lib")
--             os.exec("mkdir -p build/shaders")
--             os.exec("xcrun -sdk macosx metal -c assets/shaders/triangle.metal -o build/shaders/gfx.air")
--             os.exec("xcrun -sdk macosx metallib build/shaders/gfx.air -o build/gfx.metallib")
--         end)
--     end

target("skinned")
    set_kind("binary")
    set_group("examples")
    add_deps("core_shared")
    add_files("examples/skinned_animation/ex_skinned_animation.c")
    set_rundir("$(projectdir)")

target("game")
    set_kind("binary")
    set_group("examples")
    add_deps("core_static")
    add_files("examples/game_demo/game_demo.c")
    set_rundir("$(projectdir)")

target("pool_tests")
    set_kind("binary")
    set_group("tests")
    add_deps("core_static")
    add_files(unity_sources)
    add_includedirs("deps/Unity/src", {public = true})
    add_includedirs("deps/Unity/extras/fixture/src", {public = true})
    add_includedirs("deps/Unity/extras/memory/src", {public = true})
    add_files("tests/pool_tests.c")
    add_files("tests/pool_test_runner.c")