Fix paths used when used as a library

Francesco Pasa 9 months ago

CMakeLists.txt   M +15 -17

1 cmake_minimum_required(VERSION 3.20)
2 project(canvas C)
3-set(CMAKE_C_STANDARD 11)
4+set(CMAKE_C_STANDARD 23)
5 
6 # LTO
7 #set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
15 #set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
16 #set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY FALSE)
17 
18+# Dependencies
19 include(FetchContent)
20 
21 ## Wayland
110 include_directories("${check_BINARY_DIR}/src")
111 
112 # WebGPU using wgpu
113-include_directories(webgpu/wgpu)
114-link_directories(webgpu/wgpu)
115-
116+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/webgpu/wgpu")
117 # WebGPU using dawn
118 #include_directories(webgpu/dawn/include)
119-#link_directories(webgpu/dawn)
120 
121 # Prepare shader code
122 add_custom_command(
123-        OUTPUT ${CMAKE_BINARY_DIR}/shaders/shaders.o
124-        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
125-        COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/shaders/shaders.o shaders.wgsl
126-        DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders.wgsl
127+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shaders/shaders.o
128+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
129+        COMMAND ld -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/shaders/shaders.o shaders.wgsl
130+        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders.wgsl
131 )
132 
133 
134 # Default fonts
135 add_custom_command(
136-        OUTPUT ${CMAKE_BINARY_DIR}/data/roboto-regular.o
137-        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
138-        COMMAND ld -r -b binary -o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o Roboto-Regular.ttf
139-        DEPENDS ${CMAKE_SOURCE_DIR}/data/Roboto-Regular.ttf
140+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/data/Roboto-Regular.o
141+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
142+        COMMAND ld -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/data/Roboto-Regular.o Roboto-Regular.ttf
143+        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/data/Roboto-Regular.ttf
144 )
145 
146 # Library
147 add_library(
148         alba STATIC
149-        ${CMAKE_BINARY_DIR}/shaders/shaders.o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o
150+        ${CMAKE_CURRENT_BINARY_DIR}/shaders/shaders.o ${CMAKE_CURRENT_BINARY_DIR}/data/Roboto-Regular.o
151         src/glfw_surface.c src/window.c src/array.c src/drawing.c src/text.c
152         src/atlas.c ${hashmap_SOURCE_DIR}/hashmap.c src/helpers.c
153         src/draw_call.c
154         src/string.c
155 )
156 target_include_directories(alba PRIVATE src)
157-target_link_libraries(alba PRIVATE glfw wgpu freetype harfbuzz)
158-#target_link_libraries(alba PRIVATE glfw dawn freetype harfbuzz)
159+target_link_libraries(alba PRIVATE glfw freetype harfbuzz
160+        ${CMAKE_CURRENT_SOURCE_DIR}/webgpu/wgpu/libwgpu.a)
161 
162 if (GLFW_BUILD_COCOA)
163     target_compile_definitions(alba PRIVATE GLFW_COCOA)
157     target_compile_definitions(alba PRIVATE GLFW_WAYLAND)
158 endif ()
159 
160-# Examples
161+# Examples & tests
162 include_directories(include)
163 
164 add_executable(tests tests/test_array.c)