-
Notifications
You must be signed in to change notification settings - Fork 471
/
CMakeLists.txt
409 lines (338 loc) · 10.3 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
include(GNUInstallDirs)
# configuration
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
set(HAVE_BACKTRACE ${Backtrace_FOUND})
if(HAVE_BACKTRACE)
set(BACKTRACE_HEADER <${Backtrace_HEADER}>)
endif()
set(HAVE_SPACEWARE ${SPACEWARE_FOUND})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
# platform utilities
if(WIN32)
set(util_SOURCES
platform/w32util.cpp)
else()
set(util_SOURCES
platform/unixutil.cpp)
endif()
if(APPLE)
set(util_LIBRARIES
${APPKIT_LIBRARY})
endif()
# libslvs
set(libslvs_SOURCES
util.cpp
entity.cpp
expr.cpp
constraint.cpp
constrainteq.cpp
system.cpp
platform/platform.cpp)
set(libslvs_HEADERS
solvespace.h
platform/platform.h)
add_library(slvs SHARED
${libslvs_SOURCES}
${libslvs_HEADERS}
${util_SOURCES}
lib.cpp)
target_compile_definitions(slvs
PRIVATE -DLIBRARY)
target_include_directories(slvs
PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(slvs
${util_LIBRARIES})
set_target_properties(slvs PROPERTIES
PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/include/slvs.h
VERSION ${solvespace_VERSION_MAJOR}.${solvespace_VERSION_MINOR}
SOVERSION 1)
if(NOT WIN32)
install(TARGETS slvs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
# solvespace dependencies
include_directories(
${OPENGL_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${PNG_PNG_INCLUDE_DIR}
${FREETYPE_INCLUDE_DIRS}
${CAIRO_INCLUDE_DIRS})
if(Backtrace_FOUND)
include_directories(
${Backtrace_INCLUDE_DIRS})
endif()
if(SPACEWARE_FOUND)
include_directories(
${SPACEWARE_INCLUDE_DIR})
endif()
if(OPENGL STREQUAL 3)
set(gl_SOURCES
render/gl3shader.cpp
render/rendergl3.cpp)
elseif(OPENGL STREQUAL 1)
set(gl_SOURCES
render/rendergl1.cpp)
else()
message(FATAL_ERROR "Unsupported OpenGL version ${OPENGL}")
endif()
if(WIN32)
set(platform_SOURCES
platform/w32main.cpp
platform/guiwin.cpp
${gl_SOURCES})
set(platform_LIBRARIES
comctl32
${SPACEWARE_LIBRARIES})
elseif(APPLE)
add_compile_options(
-fobjc-arc)
set(platform_SOURCES
platform/cocoamain.mm
platform/guimac.mm
render/rendergl.cpp
${gl_SOURCES})
else()
set(platform_SOURCES
platform/gtkmain.cpp
platform/guigtk.cpp
${gl_SOURCES})
set(platform_LIBRARIES
${SPACEWARE_LIBRARIES})
foreach(pkg_config_lib GTKMM JSONC FONTCONFIG)
include_directories(${${pkg_config_lib}_INCLUDE_DIRS})
link_directories(${${pkg_config_lib}_LIBRARY_DIRS})
list(APPEND platform_LIBRARIES ${${pkg_config_lib}_LIBRARIES})
endforeach()
endif()
set(every_platform_SOURCES
platform/w32main.cpp
platform/gtkmain.cpp
platform/cocoamain.mm)
# solvespace library
set(solvespace_core_HEADERS
dsc.h
expr.h
polygon.h
sketch.h
solvespace.h
ui.h
platform/platform.h
render/render.h
render/gl3shader.h
srf/surface.h)
set(solvespace_core_SOURCES
bsp.cpp
clipboard.cpp
confscreen.cpp
constraint.cpp
constrainteq.cpp
describescreen.cpp
draw.cpp
drawconstraint.cpp
drawentity.cpp
entity.cpp
export.cpp
exportstep.cpp
exportvector.cpp
expr.cpp
file.cpp
generate.cpp
graphicswin.cpp
group.cpp
groupmesh.cpp
importdxf.cpp
mesh.cpp
modify.cpp
mouse.cpp
polyline.cpp
polygon.cpp
resource.cpp
request.cpp
style.cpp
system.cpp
textscreens.cpp
textwin.cpp
toolbar.cpp
ttf.cpp
undoredo.cpp
util.cpp
view.cpp
platform/platform.cpp
platform/gui.cpp
render/render.cpp
render/render2d.cpp
srf/boolean.cpp
srf/curve.cpp
srf/merge.cpp
srf/ratpoly.cpp
srf/raycast.cpp
srf/surface.cpp
srf/surfinter.cpp
srf/triangulate.cpp)
set(solvespace_core_gl_SOURCES
solvespace.cpp)
add_library(solvespace-core STATIC
${util_SOURCES}
${solvespace_core_HEADERS}
${solvespace_core_SOURCES})
target_link_libraries(solvespace-core
dxfrw
${util_LIBRARIES}
${ZLIB_LIBRARY}
${PNG_LIBRARY}
${FREETYPE_LIBRARY})
if(Backtrace_FOUND)
target_link_libraries(solvespace-core
${Backtrace_LIBRARY})
endif()
target_compile_options(solvespace-core
PRIVATE ${COVERAGE_FLAGS})
# solvespace translations
if(HAVE_GETTEXT)
set(inputs
${solvespace_core_SOURCES}
${solvespace_core_HEADERS}
${every_platform_SOURCES})
set(templ_po ${CMAKE_CURRENT_BINARY_DIR}/../res/messages.po)
set(output_pot ${CMAKE_CURRENT_SOURCE_DIR}/../res/messages.pot)
set(output_po ${CMAKE_CURRENT_SOURCE_DIR}/../res/locales/en_US.po)
file(GLOB locale_pos ${CMAKE_CURRENT_SOURCE_DIR}/../res/locales/*.po)
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_output_pot ${output_pot}.gen)
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_output_po ${output_po}.gen)
foreach(locale_po ${locale_pos})
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_locale_po ${locale_po}.gen)
list(APPEND gen_locale_pos ${gen_locale_po})
endforeach()
add_custom_command(
OUTPUT ${gen_output_pot}
COMMAND ${XGETTEXT}
--language=C++
--keyword --keyword=_ --keyword=N_ --keyword=C_:2,1c --keyword=CN_:2,1c
--force-po --width=100 --sort-by-file
--package-name=SolveSpace
--package-version=${solvespace_VERSION_MAJOR}.${solvespace_VERSION_MINOR}
"--copyright-holder=the PACKAGE authors"
--msgid-bugs-address=whitequark@whitequark.org
--from-code=utf-8 --output=${gen_output_pot} ${inputs}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${gen_output_pot} ${output_pot}
DEPENDS ${inputs}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Extracting translations"
VERBATIM)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../res/locales)
# en_US is a bit special; we pre-fill the msgstrs from msgids, instead of (as would normally
# happen) leaving them empty.
add_custom_command(
OUTPUT ${gen_output_po}
COMMAND ${MSGINIT}
--locale=en_US --no-translator
--output=${templ_po} --input=${gen_output_pot}
COMMAND ${MSGMERGE}
--force-po --no-fuzzy-matching
--output=${gen_output_po} ${output_po} ${templ_po}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${gen_output_po} ${output_po}
DEPENDS ${gen_output_pot}
COMMENT "Updating en_US translations"
VERBATIM)
foreach(locale_po ${locale_pos})
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_locale_po ${locale_po}.gen)
get_filename_component(locale_name ${locale_po} NAME_WE)
if(locale_name STREQUAL "en_US")
continue()
endif()
add_custom_command(
OUTPUT ${gen_locale_po}
COMMAND ${MSGMERGE}
--no-fuzzy-matching
--output=${gen_locale_po} ${locale_po} ${gen_output_pot}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${gen_locale_po} ${locale_po}
DEPENDS ${gen_output_pot}
COMMENT "Updating ${locale_name} translations"
VERBATIM)
endforeach()
add_custom_target(translate_solvespace
DEPENDS ${gen_output_pot} ${gen_output_po} ${gen_locale_pos})
endif()
# solvespace graphical executable
if(ENABLE_GUI)
add_executable(solvespace WIN32 MACOSX_BUNDLE
${solvespace_core_gl_SOURCES}
${platform_SOURCES}
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>)
add_dependencies(solvespace
resources)
target_link_libraries(solvespace
solvespace-core
${OPENGL_LIBRARIES}
${platform_LIBRARIES}
${COVERAGE_LIBRARY})
if(MSVC)
set_target_properties(solvespace PROPERTIES
LINK_FLAGS "/MANIFEST:NO /SAFESEH:NO /INCREMENTAL:NO /OPT:REF /STACK:33554432")
endif()
endif()
# solvespace headless library
set(headless_SOURCES
platform/guinone.cpp
render/rendercairo.cpp)
add_library(solvespace-headless STATIC EXCLUDE_FROM_ALL
${solvespace_core_gl_SOURCES}
${headless_SOURCES})
target_compile_definitions(solvespace-headless
PRIVATE -DHEADLESS)
target_include_directories(solvespace-headless
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(solvespace-headless
solvespace-core
${CAIRO_LIBRARIES})
target_compile_options(solvespace-headless
PRIVATE ${COVERAGE_FLAGS})
# solvespace command-line executable
add_executable(solvespace-cli
platform/climain.cpp
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>)
target_link_libraries(solvespace-cli
solvespace-core
solvespace-headless)
add_dependencies(solvespace-cli
resources)
if(MSVC)
set_target_properties(solvespace-cli PROPERTIES
LINK_FLAGS "/INCREMENTAL:NO /OPT:REF")
endif()
# solvespace unix package
if(NOT (WIN32 OR APPLE))
if(ENABLE_GUI)
install(TARGETS solvespace
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
install(TARGETS solvespace-cli
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
# solvespace macOS package
if(APPLE)
set(bundle solvespace)
set(bundle_bin ${EXECUTABLE_OUTPUT_PATH}/${bundle}.app/Contents/MacOS)
add_custom_command(TARGET solvespace POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${bundle_bin}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:solvespace-cli> ${bundle_bin}
COMMENT "Bundling executable solvespace-cli"
VERBATIM)
add_custom_command(OUTPUT ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
COMMAND ${CMAKE_COMMAND} -E remove ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
COMMAND hdiutil create -srcfolder ${EXECUTABLE_OUTPUT_PATH}/${bundle}.app
${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
DEPENDS $<TARGET_FILE:${bundle}>
COMMENT "Building ${bundle}.dmg"
VERBATIM)
add_custom_target(${bundle}-dmg ALL
DEPENDS ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg)
endif()