-
Notifications
You must be signed in to change notification settings - Fork 157
/
CMakeLists.txt
427 lines (363 loc) · 10.5 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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
cmake_minimum_required(VERSION 3.1)
set(HL_VERSION_MAJOR 1)
set(HL_VERSION_MINOR 14)
set(HL_VERSION_PATCH 0)
set(HL_VERSION ${HL_VERSION_MAJOR}.${HL_VERSION_MINOR}.${HL_VERSION_PATCH})
cmake_policy(SET CMP0042 NEW)
if(WIN32)
set(CMAKE_SYSTEM_VERSION 10.0)
project(hashlink C CXX) # C++ required for directx
else()
project(hashlink C)
endif()
include(GNUInstallDirs)
include(FindPkgConfig)
include(CTest)
set(WITH_VM_DEFAULT ON)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
set(WITH_VM_DEFAULT OFF)
endif()
option(WITH_VM "Whether to build the Hashlink virtual machine" ${WITH_VM_DEFAULT})
# force Unicode over Multi-byte
if(MSVC)
add_definitions(-DUNICODE -D_UNICODE)
endif()
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/other/cmake
)
if(CMAKE_VERSION VERSION_LESS "3.1")
set(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
else()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()
# put output in "bin"
set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR})
# avoid the extra "Debug", "Release" directories
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUTPUT_DIR} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUTPUT_DIR} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUTPUT_DIR} )
endforeach()
include_directories(
src
include
include/pcre
)
file(GLOB pcre_srcs
include/pcre/pcre2_auto_possess.c
include/pcre/pcre2_chartables.c
include/pcre/pcre2_compile.c
include/pcre/pcre2_config.c
include/pcre/pcre2_context.c
include/pcre/pcre2_convert.c
include/pcre/pcre2_dfa_match.c
include/pcre/pcre2_error.c
include/pcre/pcre2_extuni.c
include/pcre/pcre2_find_bracket.c
include/pcre/pcre2_jit_compile.c
include/pcre/pcre2_maketables.c
include/pcre/pcre2_match_data.c
include/pcre/pcre2_match.c
include/pcre/pcre2_newline.c
include/pcre/pcre2_ord2utf.c
include/pcre/pcre2_pattern_info.c
include/pcre/pcre2_script_run.c
include/pcre/pcre2_serialize.c
include/pcre/pcre2_string_utils.c
include/pcre/pcre2_study.c
include/pcre/pcre2_substitute.c
include/pcre/pcre2_substring.c
include/pcre/pcre2_tables.c
include/pcre/pcre2_ucd.c
include/pcre/pcre2_valid_utf.c
include/pcre/pcre2_xclass.c
)
file(GLOB std_srcs
src/std/array.c
src/std/buffer.c
src/std/bytes.c
src/std/cast.c
src/std/date.c
src/std/debug.c
src/std/error.c
src/std/file.c
src/std/fun.c
src/std/maps.c
src/std/math.c
src/std/obj.c
src/std/random.c
src/std/regexp.c
src/std/socket.c
src/std/string.c
src/std/sys.c
src/std/track.c
src/std/types.c
src/std/ucs2.c
src/std/thread.c
src/std/process.c
)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND std_srcs
include/mdbg/mdbg.c
include/mdbg/mach_excServer.c
include/mdbg/mach_excUser.c
)
endif()
if(ANDROID)
list(APPEND std_srcs
src/std/sys_android.c
)
endif()
if(IOS_PLATFORM)
list(APPEND std_srcs
src/std/sys_ios.m
)
endif()
add_library(libhl SHARED
${pcre_srcs}
src/gc.c
${std_srcs}
)
set(public_headers
src/hl.h
src/hlc.h
)
set_target_properties(libhl
PROPERTIES
PUBLIC_HEADER "${public_headers}"
)
if(WIN32)
set_target_properties(libhl
PROPERTIES
OUTPUT_NAME libhl
)
else()
set_target_properties(libhl
PROPERTIES
OUTPUT_NAME hl
)
endif()
set_target_properties(libhl
PROPERTIES
VERSION ${HL_VERSION}
SOVERSION ${HL_VERSION_MAJOR}
COMPILE_DEFINITIONS "_USRDLL;LIBHL_EXPORTS;HAVE_CONFIG_H;PCRE2_CODE_UNIT_WIDTH=16"
)
if (WITH_VM)
add_executable(hl
src/code.c
src/jit.c
src/main.c
src/module.c
src/debugger.c
src/profile.c
)
if (UNIX AND NOT APPLE)
set_target_properties(hl PROPERTIES INSTALL_RPATH "$ORIGIN;${CMAKE_INSTALL_PREFIX}/lib")
endif()
target_link_libraries(hl libhl)
if (WIN32)
target_link_libraries(hl user32)
endif()
endif()
if(WIN32)
target_link_libraries(libhl ws2_32 user32)
else()
target_link_libraries(libhl m dl pthread)
endif()
if(BUILD_TESTING)
find_program(
HAXE_COMPILER
haxe
)
#####################
# hello.hl
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
-cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld
)
add_custom_target(hello.hl ALL
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
)
#####################
# threads.hl
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads.hl
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads.hl
-cp ${CMAKE_SOURCE_DIR}/other/tests -main Threads
)
add_custom_target(threads.hl ALL
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads.hl
)
#####################
# uvsample.hl
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
-cp ${CMAKE_SOURCE_DIR}/other/uvsample -main UVSample
)
add_custom_target(uvsample.hl ALL
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
)
#####################
# hello.c
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello/hello.c
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello/hello.c
-cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld
)
add_executable(hello
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello/hello.c
)
set_target_properties(hello
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello
)
target_include_directories(hello
PRIVATE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello
)
target_link_libraries(hello
libhl
)
#####################
# threads.c
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads/threads.c
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads/threads.c
-cp ${CMAKE_SOURCE_DIR}/other/tests -main Threads
)
add_executable(threads
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads/threads.c
)
set_target_properties(threads
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads
)
target_include_directories(threads
PRIVATE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads
)
target_link_libraries(threads
libhl
)
#####################
# uvsample.c
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample/uvsample.c
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample/uvsample.c
-cp ${CMAKE_SOURCE_DIR}/other/uvsample -main UVSample
)
add_executable(uvsample
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample/uvsample.c
)
set_target_properties(uvsample
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample
)
target_include_directories(uvsample
PRIVATE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample
)
target_link_libraries(uvsample
libhl
uv.hdll
)
#####################
# Tests
if (WITH_VM)
add_test(NAME version
COMMAND hl --version
)
set_tests_properties(version
PROPERTIES
PASS_REGULAR_EXPRESSION "${HL_VERSION}"
)
add_test(NAME hello.hl
COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
)
add_test(NAME threads.hl
COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads.hl
)
add_test(NAME uvsample.hl
COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl 6001
)
endif()
add_test(NAME hello
COMMAND hello
)
add_test(NAME threads
COMMAND threads
)
add_test(NAME uvsample
COMMAND uvsample 6002
)
endif()
#####################
# Packaging
set(CPACK_OUTPUT_FILE_PREFIX ${OUTPUT_DIR})
set(CPACK_PACKAGE_VENDOR "Haxe Foundation")
set(CPACK_PACKAGE_VERSION_MAJOR ${HL_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${HL_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${HL_VERSION_PATCH})
if(WIN32)
set(CPACK_GENERATOR "ZIP")
else()
set(CPACK_GENERATOR "TGZ")
endif()
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
if(MSVC)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "C:/HaxeToolkit/hashlink" CACHE PATH "default install path" FORCE)
endif()
set(CMAKE_INSTALL_BINDIR .)
set(CMAKE_INSTALL_LIBDIR .)
endif()
set(HDLL_DESTINATION
${CMAKE_INSTALL_LIBDIR}
)
set(INSTALL_TARGETS libhl)
if (WITH_VM)
list(APPEND INSTALL_TARGETS hl)
endif()
install(
TARGETS
${INSTALL_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES src/hlc_main.c
TYPE INCLUDE
)
# uninstall target
# https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/other/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
if(
NOT DEFINED ENV{APPVEYOR_REPO_TAG_NAME}
AND
DEFINED ENV{APPVEYOR_REPO_COMMIT}
)
string(SUBSTRING $ENV{APPVEYOR_REPO_COMMIT} 0 7 short_commit)
endif()
if(NOT DEFINED ENV{TRAVIS_TAG} AND DEFINED ENV{TRAVIS_COMMIT})
string(SUBSTRING $ENV{TRAVIS_COMMIT} 0 7 short_commit)
endif()
if(DEFINED short_commit)
set(CPACK_PACKAGE_VERSION "${HL_VERSION}+${short_commit}")
endif()
include(CPack)
add_subdirectory(libs)