CMakeLists.txt
1cmake_minimum_required(VERSION 3.20)
2project(canvas C)
3set(CMAKE_C_STANDARD 11)
4
5include(FetchContent)
6
7# GLFW
8FetchContent_Declare(
9 glfw
10 GIT_REPOSITORY https://github.com/glfw/glfw
11 GIT_TAG 3.4
12 GIT_SHALLOW TRUE
13)
14
15# FreeType
16FetchContent_Declare(
17 freetype
18 GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype.git
19 GIT_TAG VER-2-13-2
20 GIT_SHALLOW TRUE
21)
22
23FetchContent_MakeAvailable(glfw freetype)
24
25# WebGPU using wgpu
26include_directories(webgpu)
27link_directories(webgpu)
28
29# Prepare shader code
30add_custom_command(
31 OUTPUT ${CMAKE_BINARY_DIR}/shaders/shaders.o
32 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
33 COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/shaders/shaders.o shaders.wgsl
34 DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders.wgsl
35)
36
37# Library
38include_directories(include)
39add_library(alba STATIC src/glfw_surface.c src/window.c src/dynarray.c src/drawing.c
40 ${CMAKE_BINARY_DIR}/shaders/shaders.o)
41target_link_libraries(alba PRIVATE glfw wgpu)
42
43if (GLFW_BUILD_COCOA)
44 target_compile_definitions(alba PRIVATE GLFW_COCOA)
45endif ()
46if (GLFW_BUILD_WIN32)
47 target_compile_definitions(alba PRIVATE GLFW_WIN32)
48endif ()
49if (GLFW_BUILD_X11)
50 target_compile_definitions(alba PRIVATE GLFW_X11)
51endif ()
52if (GLFW_BUILD_WAYLAND)
53 target_compile_definitions(alba PRIVATE GLFW_WAYLAND)
54endif ()
55
56# Binary
57add_executable(demo demo.c)
58target_link_libraries(demo PRIVATE alba)