-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
253 lines (210 loc) · 9.33 KB
/
CMakeLists.txt
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)
PROJECT("nanovg")
SET(VERSION 0.1)
INCLUDE(GNUInstallDirs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
ADD_COMPILE_OPTIONS(-Wall -Werror)
ADD_LINK_OPTIONS(LINKER:--as-needed LINKER:--no-undefined LINKER:--no-allow-shlib-undefined)
option(NANOVG_SHARED_LIBS "Build shared libraries" ON)
option(NANOVG_STATIC_LIBS "Build static liraries" ON)
option(NANOVG_BUILD_EXAMPLES "Build examples" ON)
option(NANOVG_BUILD_GL2 "Build OpenGL 2" ON)
option(NANOVG_BUILD_GL3 "Build OpenGL 3" ON)
option(NANOVG_BUILD_GLES2 "Build OpenGL ES 2" ON)
option(NANOVG_BUILD_GLES3 "Build OpenGL ES 3" ON)
option(NANOVG_BUILD_SVG "Build NanoSVG" ON)
option(NANOVG_BUILD_OUI "Build OUI/Blendish" ON)
option(NANOVG_USE_STB "Use stb-image" ON)
option(NANOVG_USE_FREETYPE "Use freetype for fontstash" OFF)
SET(NANOVG_DEFINES "")
SET(NANOVG_SOURCES "src/nanovg.c" "src/android.c")
SET(NANOVG_GL_DEFINES "")
SET(NANOVG_GL_SOURCES "src/nanovg_gl.c" "src/nanovg_gl_utils.c")
SET(NANOVG_GLES_SOURCES "src/nanovg_gl.c" "src/nanovg_gl_utils.c")
SET(NANOSVG_DEFINES "")
SET(NANOSVG_SOURCES "src/nanosvg.c" "src/nanosvgrast.c")
SET(NANOVG_OUI_DEFINES "")
SET(NANOVG_OUI_SOURCES "src/oui.c" "src/blendish.c")
IF(NANOVG_BUILD_GL2 OR NANOVG_BUILD_GL3)
LIST(APPEND NANOVG_GL_DEFINES NANOVG_USE_GLEW)
ENDIF()
IF(NANOVG_USE_FREETYPE)
LIST(APPEND NANOVG_DEFINES FONS_USE_FREETYPE)
ENDIF()
IF(NOT NANOVG_USE_STB)
LIST(APPEND NANOVG_DEFINES NVG_NO_STB)
ENDIF()
# Build Library
ADD_LIBRARY(nanovg OBJECT ${NANOVG_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanovg PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanovg PRIVATE ${NANOVG_DEFINES})
SET_PROPERTY(TARGET nanovg PROPERTY POSITION_INDEPENDENT_CODE ON)
IF(NANOVG_BUILD_GL2)
ADD_LIBRARY(nanovg_gl2 OBJECT ${NANOVG_GL_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanovg_gl2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanovg_gl2 PRIVATE ${NANOVG_GL_DEFINES} NANOVG_GL2)
SET_PROPERTY(TARGET nanovg_gl2 PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(NANOVG_BUILD_GL3)
ADD_LIBRARY(nanovg_gl3 OBJECT ${NANOVG_GL_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanovg_gl3 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanovg_gl3 PRIVATE ${NANOVG_GL_DEFINES} NANOVG_GL3)
SET_PROPERTY(TARGET nanovg_gl3 PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(NANOVG_BUILD_GLES2)
ADD_LIBRARY(nanovg_gles2 OBJECT ${NANOVG_GLES_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanovg_gles2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanovg_gles2 PRIVATE NANOVG_GLES2)
SET_PROPERTY(TARGET nanovg_gles2 PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(NANOVG_BUILD_GLES3)
ADD_LIBRARY(nanovg_gles3 OBJECT ${NANOVG_GLES_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanovg_gles3 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanovg_gles3 PRIVATE NANOVG_GLES3)
SET_PROPERTY(TARGET nanovg_gles3 PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(NANOVG_BUILD_SVG)
ADD_LIBRARY(nanosvg OBJECT ${NANOSVG_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanosvg PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanosvg PRIVATE ${NANOSVG_DEFINES})
SET_PROPERTY(TARGET nanosvg PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(NANOVG_BUILD_OUI)
ADD_LIBRARY(nanovg_oui OBJECT ${NANOVG_OUI_SOURCES})
TARGET_INCLUDE_DIRECTORIES(nanovg_oui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
TARGET_COMPILE_DEFINITIONS(nanovg_oui PRIVATE ${NANOVG_OUI_DEFINES})
SET_PROPERTY(TARGET nanovg_oui PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(NANOVG_USE_FREETYPE)
FIND_PACKAGE(Freetype REQUIRED)
TARGET_INCLUDE_DIRECTORIES(nanovg PRIVATE ${FREETYPE_INCLUDE_DIRS})
ENDIF()
SET(NANOVG_LIB_NAMES nanovg)
SET(NANOVG_LIB_OBJECTS $<TARGET_OBJECTS:nanovg>)
IF(NANOVG_BUILD_GL2)
SET(NANOVG_LIB_NAMES ${NANOVG_LIB_NAMES} nanovg_gl2)
SET(NANOVG_LIB_OBJECTS ${NANOVG_LIB_OBJECTS} $<TARGET_OBJECTS:nanovg_gl2>)
ENDIF()
IF(NANOVG_BUILD_GL3)
SET(NANOVG_LIB_NAMES ${NANOVG_LIB_NAMES} nanovg_gl3)
SET(NANOVG_LIB_OBJECTS ${NANOVG_LIB_OBJECTS} $<TARGET_OBJECTS:nanovg_gl3>)
ENDIF()
IF(NANOVG_BUILD_GLES2)
SET(NANOVG_LIB_NAMES ${NANOVG_LIB_NAMES} nanovg_gles2)
SET(NANOVG_LIB_OBJECTS ${NANOVG_LIB_OBJECTS} $<TARGET_OBJECTS:nanovg_gles2>)
ENDIF()
IF(NANOVG_BUILD_GLES3)
SET(NANOVG_LIB_NAMES ${NANOVG_LIB_NAMES} nanovg_gles3)
SET(NANOVG_LIB_OBJECTS ${NANOVG_LIB_OBJECTS} $<TARGET_OBJECTS:nanovg_gles3>)
ENDIF()
IF(NANOVG_BUILD_SVG)
SET(NANOVG_LIB_NAMES ${NANOVG_LIB_NAMES} nanosvg)
SET(NANOVG_LIB_OBJECTS ${NANOVG_LIB_OBJECTS} $<TARGET_OBJECTS:nanosvg>)
ENDIF()
IF(NANOVG_BUILD_OUI)
SET(NANOVG_LIB_NAMES ${NANOVG_LIB_NAMES} nanovg_oui)
SET(NANOVG_LIB_OBJECTS ${NANOVG_LIB_OBJECTS} $<TARGET_OBJECTS:nanovg_oui>)
ENDIF()
SET(NANOVG_DEPENDENCIES m)
IF(NANOVG_BUILD_GL2 OR NANOVG_BUILD_GL3)
SET(NANOVG_DEPENDENCIES GLEW GL ${NANOVG_DEPENDENCIES})
ELSE()
IF(NANOVG_BUILD_GLES2)
SET(NANOVG_DEPENDENCIES GLESv2 ${NANOVG_DEPENDENCIES})
ENDIF()
IF(NANOVG_BUILD_GLES2)
SET(NANOVG_DEPENDENCIES GLESv3 ${NANOVG_DEPENDENCIES})
ENDIF()
ENDIF()
IF(NANOVG_USE_FREETYPE)
SET(NANOVG_DEPENDENCIES ${FREETYPE_LIBRARIES} ${NANOVG_DEPENDENCIES})
ENDIF()
SET(NANOVG_DEPENDENCIES EGL ${NANOVG_DEPENDENCIES})
CONFIGURE_FILE(pkgconfig/nanovg.pc.in nanovg.pc @ONLY)
IF(NANOVG_SHARED_LIBS)
ADD_LIBRARY(nanovg_so SHARED ${NANOVG_LIB_OBJECTS})
SET_TARGET_PROPERTIES(nanovg_so PROPERTIES VERSION ${VERSION} SOVERSION 0)
SET_TARGET_PROPERTIES(nanovg_so PROPERTIES OUTPUT_NAME nanovg)
TARGET_LINK_LIBRARIES(nanovg_so PUBLIC ${NANOVG_LIB_NAMES})
TARGET_LINK_LIBRARIES(nanovg_so PRIVATE ${NANOVG_DEPENDENCIES})
INSTALL(TARGETS nanovg_so
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin)
ENDIF()
IF(NANOVG_STATIC_LIBS)
ADD_LIBRARY(nanovg_a STATIC ${NANOVG_LIB_OBJECTS})
SET_TARGET_PROPERTIES(nanovg_a PROPERTIES OUTPUT_NAME nanovg)
TARGET_LINK_LIBRARIES(nanovg_a PUBLIC ${NANOVG_LIB_NAMES})
TARGET_LINK_LIBRARIES(nanovg_a PRIVATE ${NANOVG_DEPENDENCIES})
INSTALL(TARGETS nanovg_a
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin)
ENDIF()
# Install header files
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nanovg
FILES_MATCHING PATTERN "nano*.h*")
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nanovg
FILES_MATCHING PATTERN "oui*.h*")
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nanovg
FILES_MATCHING PATTERN "blendish*.h*")
# Install pkg-config files
INSTALL(FILES ${CMAKE_BINARY_DIR}/nanovg.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Build Examples
IF(NANOVG_BUILD_EXAMPLES)
IF(NANOVG_BUILD_GL2)
ADD_EXECUTABLE(example_gl2
example/example_gl2.c example/demo.c example/perf.c
$<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanovg_gl2>)
TARGET_LINK_LIBRARIES(example_gl2 PRIVATE nanovg nanovg_gl2 GLEW EGL GL glfw m)
TARGET_COMPILE_DEFINITIONS(example_gl2 PRIVATE ${NANOVG_GL_DEFINES} NANOVG_GL2)
ENDIF()
IF(NANOVG_BUILD_GL3)
ADD_EXECUTABLE(example_gl3
example/example_gl3.c example/demo.c example/perf.c
$<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanovg_gl3>)
TARGET_LINK_LIBRARIES(example_gl3 PRIVATE nanovg nanovg_gl3 GLEW EGL GL glfw m)
TARGET_COMPILE_DEFINITIONS(example_gl3 PRIVATE ${NANOVG_GL_DEFINES} NANOVG_GL3)
ENDIF()
IF(NANOVG_BUILD_GL3)
ADD_EXECUTABLE(example_fbo example/example_fbo.c example/demo.c example/perf.c $<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanovg_gl3>)
TARGET_LINK_LIBRARIES(example_fbo PRIVATE nanovg_gl3 GLEW EGL GL glfw m)
TARGET_COMPILE_DEFINITIONS(example_fbo PRIVATE ${NANOVG_GL_DEFINES} NANOVG_GL3)
ENDIF()
IF(NANOVG_BUILD_GLES2)
ADD_EXECUTABLE(example_gles2
example/example_gles2.c example/demo.c example/perf.c
$<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanovg_gles2>)
TARGET_LINK_LIBRARIES(example_gles2 PRIVATE GLEW EGL GL glfw m)
TARGET_COMPILE_DEFINITIONS(example_gles2 PRIVATE NANOVG_GLES2)
ENDIF()
IF(NANOVG_BUILD_GLES3)
ADD_EXECUTABLE(example_gles3
example/example_gles3.c example/demo.c example/perf.c
$<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanovg_gles3>)
TARGET_LINK_LIBRARIES(example_gles3 PRIVATE GLEW EGL GL glfw m)
TARGET_COMPILE_DEFINITIONS(example_gles3 PRIVATE NANOVG_GLES3)
ENDIF()
IF(NANOVG_BUILD_SVG)
ADD_EXECUTABLE(example_svg1 example/example_svg1.c $<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanosvg>)
TARGET_LINK_LIBRARIES(example_svg1 PRIVATE GLEW EGL GL glfw m)
ADD_EXECUTABLE(example_svg2 example/example_svg2.c $<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanosvg>)
TARGET_LINK_LIBRARIES(example_svg2 PRIVATE GLEW EGL GL glfw m)
ENDIF()
IF(NANOVG_BUILD_GL3 AND NANOVG_BUILD_OUI)
ADD_EXECUTABLE(example_oui
example/example_oui.c
$<TARGET_OBJECTS:nanovg> $<TARGET_OBJECTS:nanovg_gl3> $<TARGET_OBJECTS:nanovg_oui>)
TARGET_LINK_LIBRARIES(example_oui PRIVATE GLEW EGL GL glfw m)
TARGET_COMPILE_DEFINITIONS(example_oui PRIVATE DATADIR="../data")
ENDIF()
IF(NANOVG_BUILD_GL2 AND NANOVG_BUILD_GL3 AND NANOVG_BUILD_GLES2 AND NANOVG_BUILD_GLES3)
ADD_EXECUTABLE(example_gl_wrapper example/example_gl_wrapper.c example/demo.c $<TARGET_OBJECTS:nanovg>)
TARGET_LINK_LIBRARIES(example_gl_wrapper PRIVATE ${NANOVG_LIB_NAMES} GLEW EGL GL glfw m)
ENDIF()
ENDIF()