-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
197 lines (173 loc) · 8.34 KB
/
Copy pathCMakeLists.txt
File metadata and controls
197 lines (173 loc) · 8.34 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
cmake_minimum_required(VERSION 3.22)
project(RTextJP VERSION 0.1.0 LANGUAGES C)
option(RTEXTJP_BUILD_EXAMPLES "Build the beginner examples" ON)
option(RTEXTJP_BUILD_TESTS "Build internal RTextJP tests" OFF)
option(RTEXTJP_BUILD_DOCS_GALLERY "Build the documentation screenshot generator" OFF)
option(RTEXTJP_ENABLE_SANITIZERS "Enable AddressSanitizer and UndefinedBehaviorSanitizer for tests" OFF)
option(RTEXTJP_FETCH_RAYLIB "Fetch the pinned raylib release when no installed package is found" OFF)
option(RTEXTJP_BUILD_DEMO_PACKAGE "Add the Windows demo ZIP packaging target" OFF)
set(RTEXTJP_RAYLIB_VERSION "6.0" CACHE STRING "Pinned raylib version used by FetchContent")
add_library(RTextJP INTERFACE)
target_include_directories(RTextJP INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(RTextJP INTERFACE c_std_99)
find_package(raylib ${RTEXTJP_RAYLIB_VERSION} QUIET)
if(TARGET raylib)
set(RTEXTJP_RAYLIB_TARGET raylib)
elseif(TARGET raylib::raylib)
set(RTEXTJP_RAYLIB_TARGET raylib::raylib)
endif()
if(NOT DEFINED RTEXTJP_RAYLIB_TARGET AND RTEXTJP_FETCH_RAYLIB)
include(FetchContent)
set(BUILD_EXAMPLES OFF CACHE BOOL "Build raylib examples" FORCE)
set(BUILD_GAMES OFF CACHE BOOL "Build raylib games" FORCE)
FetchContent_Declare(raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG ${RTEXTJP_RAYLIB_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(raylib)
FetchContent_GetProperties(raylib SOURCE_DIR rtextjp_fetched_raylib_source_dir)
set(RTEXTJP_RAYLIB_TARGET raylib)
endif()
if(NOT DEFINED RTEXTJP_RAYLIB_TARGET)
message(FATAL_ERROR
"raylib ${RTEXTJP_RAYLIB_VERSION} was not found. Install raylib or configure with "
"-DRTEXTJP_FETCH_RAYLIB=ON to download the pinned official release.")
endif()
target_link_libraries(RTextJP INTERFACE ${RTEXTJP_RAYLIB_TARGET})
function(rtextjp_configure_target target)
target_link_libraries(${target} PRIVATE RTextJP)
set_target_properties(${target} PROPERTIES C_STANDARD 99 C_STANDARD_REQUIRED YES)
if(MSVC)
target_compile_options(${target} PRIVATE /utf-8 /W4)
else()
target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/resources")
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/examples/resources"
"$<TARGET_FILE_DIR:${target}>/resources")
endif()
endfunction()
function(rtextjp_enable_test_sanitizers target)
if(NOT RTEXTJP_ENABLE_SANITIZERS)
return()
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(${target} PRIVATE
-fsanitize=address,undefined
-fno-sanitize-recover=all
-fno-omit-frame-pointer)
target_link_options(${target} PRIVATE -fsanitize=address,undefined)
if(WIN32 AND CMAKE_C_COMPILER_ID MATCHES "Clang")
execute_process(
COMMAND "${CMAKE_C_COMPILER}" -print-resource-dir
OUTPUT_VARIABLE rtextjp_clang_resource_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE rtextjp_clang_resource_result)
if(NOT rtextjp_clang_resource_result EQUAL 0)
message(FATAL_ERROR "Could not locate the Clang sanitizer runtime directory.")
endif()
file(GLOB rtextjp_asan_runtime_dlls
"${rtextjp_clang_resource_dir}/lib/windows/clang_rt.asan_dynamic-*.dll")
if(NOT rtextjp_asan_runtime_dlls)
message(FATAL_ERROR "Could not locate the Clang AddressSanitizer runtime DLL.")
endif()
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${rtextjp_asan_runtime_dlls}
"$<TARGET_FILE_DIR:${target}>"
COMMAND_EXPAND_LISTS)
endif()
else()
message(FATAL_ERROR
"RTEXTJP_ENABLE_SANITIZERS requires Clang or GCC for both ASan and UBSan.")
endif()
endfunction()
if(RTEXTJP_BUILD_EXAMPLES)
set(RTEXTJP_EXAMPLE_SOURCES
00_first_rtextjp
01_hello_japanese
02_text_box
03_alignment
04_vertical_writing
05_text_input
06_utf8_tools
07_character_sets)
foreach(example IN LISTS RTEXTJP_EXAMPLE_SOURCES)
add_executable(rtextjp_${example} "examples/${example}.c")
rtextjp_configure_target(rtextjp_${example})
endforeach()
endif()
if(RTEXTJP_BUILD_DEMO_PACKAGE)
if(NOT WIN32)
message(FATAL_ERROR "RTEXTJP_BUILD_DEMO_PACKAGE currently supports Windows only.")
endif()
if(NOT RTEXTJP_BUILD_EXAMPLES)
message(FATAL_ERROR "RTEXTJP_BUILD_DEMO_PACKAGE requires RTEXTJP_BUILD_EXAMPLES=ON.")
endif()
if(NOT RTEXTJP_FETCH_RAYLIB OR NOT DEFINED rtextjp_fetched_raylib_source_dir)
message(FATAL_ERROR
"RTEXTJP_BUILD_DEMO_PACKAGE requires the pinned fetched raylib source. "
"Configure with -DRTEXTJP_FETCH_RAYLIB=ON.")
endif()
get_target_property(rtextjp_raylib_target_type ${RTEXTJP_RAYLIB_TARGET} TYPE)
if(NOT rtextjp_raylib_target_type STREQUAL "SHARED_LIBRARY")
message(FATAL_ERROR
"RTEXTJP_BUILD_DEMO_PACKAGE requires -DBUILD_SHARED_LIBS=ON so raylib.dll can be packaged.")
endif()
foreach(required_demo_file IN ITEMS
"${CMAKE_CURRENT_SOURCE_DIR}/examples/resources/japanese.ttf"
"${CMAKE_CURRENT_SOURCE_DIR}/examples/resources/OFL.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/examples/resources/README.txt")
if(NOT EXISTS "${required_demo_file}")
message(FATAL_ERROR "Required demo package file was not found: ${required_demo_file}")
endif()
endforeach()
add_custom_target(rtextjp_demo_archive
COMMAND ${CMAKE_COMMAND}
"-DDEMO_EXECUTABLE=$<TARGET_FILE:rtextjp_01_hello_japanese>"
"-DRAYLIB_RUNTIME=$<TARGET_FILE:${RTEXTJP_RAYLIB_TARGET}>"
"-DFONT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/examples/resources/japanese.ttf"
"-DFONT_LICENSE=${CMAKE_CURRENT_SOURCE_DIR}/examples/resources/OFL.txt"
"-DFONT_README=${CMAKE_CURRENT_SOURCE_DIR}/examples/resources/README.txt"
"-DRTEXTJP_LICENSE=${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
"-DRAYLIB_LICENSE=${rtextjp_fetched_raylib_source_dir}/LICENSE"
"-DDEMO_README=${CMAKE_CURRENT_SOURCE_DIR}/packaging/windows-demo/README.md"
"-DDEMO_README_JA=${CMAKE_CURRENT_SOURCE_DIR}/packaging/windows-demo/README_ja.md"
"-DOUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/packages"
"-DARCHIVE_NAME=RTextJP-demo-windows"
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/PackageDemo.cmake"
DEPENDS rtextjp_01_hello_japanese ${RTEXTJP_RAYLIB_TARGET}
VERBATIM)
endif()
if(RTEXTJP_BUILD_TESTS)
include(CTest)
add_executable(rtextjp_test_utf8 tests/test_utf8.c)
rtextjp_configure_target(rtextjp_test_utf8)
rtextjp_enable_test_sanitizers(rtextjp_test_utf8)
set_target_properties(rtextjp_test_utf8 PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_test(NAME rtextjp_utf8 COMMAND rtextjp_test_utf8)
add_executable(rtextjp_test_layout tests/test_layout.c)
rtextjp_configure_target(rtextjp_test_layout)
rtextjp_enable_test_sanitizers(rtextjp_test_layout)
set_target_properties(rtextjp_test_layout PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_test(NAME rtextjp_layout COMMAND rtextjp_test_layout)
add_executable(rtextjp_test_character_sets tests/test_character_sets.c)
rtextjp_configure_target(rtextjp_test_character_sets)
rtextjp_enable_test_sanitizers(rtextjp_test_character_sets)
set_target_properties(rtextjp_test_character_sets PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_test(NAME rtextjp_character_sets COMMAND rtextjp_test_character_sets)
endif()
if(RTEXTJP_BUILD_DOCS_GALLERY)
add_executable(rtextjp_capture_gallery tools/capture_gallery.c)
rtextjp_configure_target(rtextjp_capture_gallery)
endif()
install(FILES include/rtextjp.h DESTINATION include)
install(FILES LICENSE THIRD_PARTY_NOTICES.md DESTINATION share/licenses/RTextJP)