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
 72FetchContent_MakeAvailable(glfw freetype harfbuzz hashmap check)
 73#include_directories("${wayland_SOURCE_DIR}/src")
 74#include_directories("${x11_SOURCE_DIR}/include")
 75include_directories("${glfw_SOURCE_DIR}/include")
 76include_directories("${freetype_SOURCE_DIR}/include")
 77include_directories("${harfbuzz_SOURCE_DIR}/include")
 78include_directories("${hashmap_SOURCE_DIR}")
 79
 80include_directories("${check_SOURCE_DIR}/src")
 81include_directories("${check_BINARY_DIR}")
 82include_directories("${check_BINARY_DIR}/src")
 83
 84# WebGPU using wgpu
 85include_directories(webgpu)
 86link_directories(webgpu)
 87
 88# Prepare shader code
 89add_custom_command(
 90        OUTPUT ${CMAKE_BINARY_DIR}/shaders/shaders.o
 91        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
 92        COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/shaders/shaders.o shaders.wgsl
 93        DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders.wgsl
 94)
 95
 96# Default fonts
 97add_custom_command(
 98        OUTPUT ${CMAKE_BINARY_DIR}/data/roboto-regular.o
 99        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
100        COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o Roboto-Regular.ttf
101        DEPENDS ${CMAKE_SOURCE_DIR}/data/Roboto-Regular.ttf
102)
103
104# Library
105add_library(
106        alba STATIC src/glfw_surface.c src/window.c src/dynarray.c src/drawing.c src/text.c
107        src/atlas.c ${hashmap_SOURCE_DIR}/hashmap.c
108        ${CMAKE_BINARY_DIR}/shaders/shaders.o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o
109)
110target_include_directories(alba PRIVATE src)
111target_link_libraries(alba PRIVATE glfw wgpu freetype harfbuzz)
112
113if (GLFW_BUILD_COCOA)
114    target_compile_definitions(alba PRIVATE GLFW_COCOA)
115endif ()
116if (GLFW_BUILD_WIN32)
117    target_compile_definitions(alba PRIVATE GLFW_WIN32)
118endif ()
119if (GLFW_BUILD_X11)
120    target_compile_definitions(alba PRIVATE GLFW_X11)
121endif ()
122if (GLFW_BUILD_WAYLAND)
123    target_compile_definitions(alba PRIVATE GLFW_WAYLAND)
124endif ()
125
126# Examples
127include_directories(include)
128
129add_executable(tests tests/test_dynarray.c)
130target_link_libraries(tests PRIVATE alba check)
131
132add_executable(shapes examples/shapes.c)
133target_link_libraries(shapes PRIVATE alba)
134
135add_executable(text examples/text.c)
136target_link_libraries(text PRIVATE alba)