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/wgpu)
100link_directories(webgpu/wgpu)
101
102# WebGPU using dawn
103#include_directories(webgpu/dawn/include)
104#link_directories(webgpu/dawn)
105
106# Prepare shader code
107add_custom_command(
108        OUTPUT ${CMAKE_BINARY_DIR}/shaders/shaders.o
109        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
110        COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/shaders/shaders.o shaders.wgsl
111        DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders.wgsl
112)
113
114# Default fonts
115add_custom_command(
116        OUTPUT ${CMAKE_BINARY_DIR}/data/roboto-regular.o
117        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
118        COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o Roboto-Regular.ttf
119        DEPENDS ${CMAKE_SOURCE_DIR}/data/Roboto-Regular.ttf
120)
121
122# Library
123add_library(
124        alba STATIC src/glfw_surface.c src/window.c src/dynarray.c src/drawing.c src/text.c
125        src/atlas.c ${hashmap_SOURCE_DIR}/hashmap.c
126        ${CMAKE_BINARY_DIR}/shaders/shaders.o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o
127)
128target_include_directories(alba PRIVATE src)
129target_link_libraries(alba PRIVATE glfw wgpu freetype harfbuzz)
130#target_link_libraries(alba PRIVATE glfw dawn freetype harfbuzz)
131
132if (GLFW_BUILD_COCOA)
133    target_compile_definitions(alba PRIVATE GLFW_COCOA)
134endif ()
135if (GLFW_BUILD_WIN32)
136    target_compile_definitions(alba PRIVATE GLFW_WIN32)
137endif ()
138if (GLFW_BUILD_X11)
139    target_compile_definitions(alba PRIVATE GLFW_X11)
140endif ()
141if (GLFW_BUILD_WAYLAND)
142    target_compile_definitions(alba PRIVATE GLFW_WAYLAND)
143endif ()
144
145# Examples
146include_directories(include)
147
148add_executable(tests tests/test_dynarray.c)
149target_link_libraries(tests PRIVATE alba check)
150
151add_executable(shapes examples/shapes.c)
152target_link_libraries(shapes PRIVATE alba)
153
154add_executable(text examples/text.c)
155target_link_libraries(text PRIVATE alba)