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