-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
161 lines (129 loc) · 5.06 KB
/
Copy pathCMakeLists.txt
File metadata and controls
161 lines (129 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
cmake_minimum_required(VERSION 4.0.0)
project(rl_harfbuzz_textlib VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(FetchContent)
option(RLHB_BUILD_EXAMPLES "Build rl_harfbuzz_textlib examples" OFF)
option(RLHB_FETCH_RAYLIB "Fetch raylib if no compatible target is already available" OFF)
option(RLHB_BUNDLE_DEFAULT_FONT "Embed a bundled default font into the library" ON)
set(RLHB_HARFBUZZ_SOURCE_DIR
""
CACHE PATH
"Optional path to a HarfBuzz source tree used for the internal amalgamated build"
)
set(RLHB_DEFAULT_FONT_HEADER
"${CMAKE_CURRENT_SOURCE_DIR}/src/rlhb_default_font_data.h"
CACHE FILEPATH
"Pre-generated header that embeds the bundled default font bytes"
)
function(rlhb_ensure_dependency_bridge bridge_name target_name)
if(TARGET ${bridge_name} OR NOT TARGET ${target_name})
return()
endif()
add_library(${bridge_name} INTERFACE IMPORTED GLOBAL)
set_target_properties(${bridge_name} PROPERTIES
INTERFACE_LINK_LIBRARIES ${target_name}
)
endfunction()
function(rlhb_find_or_fetch_raylib)
if(TARGET raylib OR TARGET raylib::raylib)
rlhb_ensure_dependency_bridge(raylib::raylib raylib)
return()
endif()
find_package(raylib QUIET CONFIG)
if(TARGET raylib OR TARGET raylib::raylib)
rlhb_ensure_dependency_bridge(raylib::raylib raylib)
return()
endif()
if(NOT RLHB_FETCH_RAYLIB)
message(FATAL_ERROR "raylib was not found. Provide raylib::raylib or enable RLHB_FETCH_RAYLIB.")
endif()
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 5.5
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(raylib)
rlhb_ensure_dependency_bridge(raylib::raylib raylib)
endfunction()
function(rlhb_prepare_harfbuzz_source outVar)
if(RLHB_HARFBUZZ_SOURCE_DIR)
set(harfbuzz_source_dir "${RLHB_HARFBUZZ_SOURCE_DIR}")
else()
FetchContent_Populate(
rlhb_harfbuzz_source
DOWNLOAD_EXTRACT_TIMESTAMP OFF
URL https://github.com/harfbuzz/harfbuzz/archive/refs/tags/14.1.0.tar.gz
)
set(harfbuzz_source_dir "${rlhb_harfbuzz_source_SOURCE_DIR}")
endif()
set(${outVar} "${harfbuzz_source_dir}" PARENT_SCOPE)
endfunction()
rlhb_find_or_fetch_raylib()
rlhb_prepare_harfbuzz_source(RLHB_HARFBUZZ_SOURCE_ROOT)
if(NOT TARGET raylib::raylib)
message(FATAL_ERROR "raylib target resolution failed.")
endif()
if(RLHB_BUNDLE_DEFAULT_FONT)
if(NOT EXISTS "${RLHB_DEFAULT_FONT_HEADER}")
message(FATAL_ERROR "RLHB_BUNDLE_DEFAULT_FONT is ON but RLHB_DEFAULT_FONT_HEADER does not exist: ${RLHB_DEFAULT_FONT_HEADER}")
endif()
endif()
add_library(rl_harfbuzz_textlib
src/rl_harfbuzz_textlib.cpp
"${RLHB_HARFBUZZ_SOURCE_ROOT}/src/harfbuzz-world.cc"
)
add_library(rl_harfbuzz_textlib::rl_harfbuzz_textlib ALIAS rl_harfbuzz_textlib)
target_compile_features(rl_harfbuzz_textlib PUBLIC cxx_std_17)
if(BUILD_SHARED_LIBS)
target_compile_definitions(rl_harfbuzz_textlib PRIVATE RLHB_BUILD_SHARED)
target_compile_definitions(rl_harfbuzz_textlib INTERFACE RLHB_USE_SHARED)
endif()
if(RLHB_BUNDLE_DEFAULT_FONT)
target_compile_definitions(rl_harfbuzz_textlib PRIVATE RLHB_HAS_DEFAULT_FONT=1)
endif()
target_compile_definitions(rl_harfbuzz_textlib PRIVATE HB_HAS_GPU=1)
target_include_directories(rl_harfbuzz_textlib
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"${RLHB_HARFBUZZ_SOURCE_ROOT}/src"
)
target_link_libraries(rl_harfbuzz_textlib
PUBLIC
raylib::raylib
)
if(APPLE) # shouldn't raylib be linking these things?
find_library(COCOA_LIBRARY Cocoa)
find_library(IOKIT_LIBRARY IOKit)
find_library(OPENGL_LIBRARY OpenGL)
if(COCOA_LIBRARY)
target_link_libraries(rl_harfbuzz_textlib PUBLIC "${COCOA_LIBRARY}")
endif()
if(IOKIT_LIBRARY)
target_link_libraries(rl_harfbuzz_textlib PUBLIC "${IOKIT_LIBRARY}")
endif()
if(OPENGL_LIBRARY)
target_link_libraries(rl_harfbuzz_textlib PUBLIC "${OPENGL_LIBRARY}")
endif()
endif()
if(WIN32)
target_link_libraries(rl_harfbuzz_textlib PUBLIC winmm opengl32) # shouldn't raylib be linking this?
endif()
if(RLHB_BUILD_EXAMPLES)
add_executable(rlhb_c_api_example examples/c_api.c)
add_executable(rlhb_cpp_api_example examples/cpp_api.cpp)
add_executable(rlhb_type_lab_example examples/type_lab.cpp)
target_link_libraries(rlhb_c_api_example PRIVATE rl_harfbuzz_textlib::rl_harfbuzz_textlib)
target_link_libraries(rlhb_cpp_api_example PRIVATE rl_harfbuzz_textlib::rl_harfbuzz_textlib)
target_link_libraries(rlhb_type_lab_example PRIVATE rl_harfbuzz_textlib::rl_harfbuzz_textlib)
target_compile_features(rlhb_cpp_api_example PRIVATE cxx_std_17)
target_compile_features(rlhb_type_lab_example PRIVATE cxx_std_17)
set_target_properties(rlhb_c_api_example PROPERTIES LINKER_LANGUAGE CXX)
if(MSVC)
target_compile_options(rlhb_cpp_api_example PRIVATE /utf-8)
target_compile_options(rlhb_type_lab_example PRIVATE /utf-8)
endif()
endif()