CMakeLists.txt
1cmake_minimum_required(VERSION 3.20)
2project(canvas C)
3set(CMAKE_C_STANDARD 11)
4
5## Disable system libraries
6#set(CMAKE_FIND_USE_PACKAGE_ROOT_PATH FALSE)
7#set(CMAKE_FIND_USE_CMAKE_PATH FALSE)
8#set(CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH FALSE)
9#set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
10#set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY FALSE)
11#set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
12#set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY FALSE)
13
14include(FetchContent)
15
16## Wayland
17#FetchContent_Declare(
18# wayland
19# GIT_REPOSITORY https://gitlab.freedesktop.org/wayland/wayland.git
20# GIT_TAG 1.23.0
21# GIT_SHALLOW TRUE
22#)
23#
24## X11
25#FetchContent_Declare(
26# x11
27# GIT_REPOSITORY https://gitlab.freedesktop.org/xorg/lib/libx11.git
28# GIT_TAG libX11-1.8.9
29# GIT_SHALLOW TRUE
30#)
31
32# GLFW
33FetchContent_Declare(
34 glfw
35 GIT_REPOSITORY https://github.com/glfw/glfw
36 GIT_TAG 3.4
37 GIT_SHALLOW TRUE
38)
39
40# FreeType
41FetchContent_Declare(
42 freetype
43 GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype.git
44 GIT_TAG VER-2-13-2
45 GIT_SHALLOW TRUE
46)
47
48# HarfBuzz
49FetchContent_Declare(
50 harfbuzz
51 GIT_REPOSITORY https://github.com/harfbuzz/harfbuzz.git
52 GIT_TAG 8.5.0
53 GIT_SHALLOW TRUE
54)
55
56# HashMap
57FetchContent_Declare(
58 hashmap
59 GIT_REPOSITORY https://github.com/tidwall/hashmap.c.git
60 GIT_TAG v0.8.0
61 GIT_SHALLOW TRUE
62)
63
64# Check
65FetchContent_Declare(
66 check
67 GIT_REPOSITORY https://github.com/libcheck/check.git
68 GIT_TAG 0.15.2
69 GIT_SHALLOW TRUE
70)
71
72# PNG
73# TODO: zlib
74FetchContent_Declare(
75 png
76 GIT_REPOSITORY https://github.com/pnggroup/libpng.git
77 GIT_TAG v1.6.43
78 GIT_SHALLOW TRUE
79)
80
81#FetchContent_Declare(
82# https://github.com/madler/zlib.git
83#)
84
85FetchContent_MakeAvailable(glfw freetype harfbuzz hashmap check png)
86#include_directories("${wayland_SOURCE_DIR}/src")
87#include_directories("${x11_SOURCE_DIR}/include")
88include_directories("${glfw_SOURCE_DIR}/include")
89include_directories("${freetype_SOURCE_DIR}/include")
90include_directories("${harfbuzz_SOURCE_DIR}/include")
91include_directories("${hashmap_SOURCE_DIR}")
92include_directories("${png_SOURCE_DIR}")
93
94include_directories("${check_SOURCE_DIR}/src")
95include_directories("${check_BINARY_DIR}")
96include_directories("${check_BINARY_DIR}/src")
97
98# WebGPU using wgpu
99include_directories(webgpu)
100link_directories(webgpu)
101
102# Prepare shader code
103add_custom_command(
104 OUTPUT ${CMAKE_BINARY_DIR}/shaders/shaders.o
105 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
106 COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/shaders/shaders.o shaders.wgsl
107 DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders.wgsl
108)
109
110# Default fonts
111add_custom_command(
112 OUTPUT ${CMAKE_BINARY_DIR}/data/roboto-regular.o
113 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
114 COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o Roboto-Regular.ttf
115 DEPENDS ${CMAKE_SOURCE_DIR}/data/Roboto-Regular.ttf
116)
117
118# Library
119add_library(
120 alba STATIC src/glfw_surface.c src/window.c src/dynarray.c src/drawing.c src/text.c
121 src/atlas.c ${hashmap_SOURCE_DIR}/hashmap.c
122 ${CMAKE_BINARY_DIR}/shaders/shaders.o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o
123)
124target_include_directories(alba PRIVATE src)
125target_link_libraries(alba PRIVATE glfw wgpu freetype harfbuzz)
126
127if (GLFW_BUILD_COCOA)
128 target_compile_definitions(alba PRIVATE GLFW_COCOA)
129endif ()
130if (GLFW_BUILD_WIN32)
131 target_compile_definitions(alba PRIVATE GLFW_WIN32)
132endif ()
133if (GLFW_BUILD_X11)
134 target_compile_definitions(alba PRIVATE GLFW_X11)
135endif ()
136if (GLFW_BUILD_WAYLAND)
137 target_compile_definitions(alba PRIVATE GLFW_WAYLAND)
138endif ()
139
140# Examples
141include_directories(include)
142
143add_executable(tests tests/test_dynarray.c)
144target_link_libraries(tests PRIVATE alba check)
145
146add_executable(shapes examples/shapes.c)
147target_link_libraries(shapes PRIVATE alba)
148
149add_executable(text examples/text.c)
150target_link_libraries(text PRIVATE alba)