forked from nesbox/TIC-80
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
977 lines (761 loc) · 29.1 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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
cmake_minimum_required(VERSION 3.3)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 90)
set(VERSION_REVISION 0)
set(VERSION_STATUS "-dev")
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} status
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
ERROR_VARIABLE RESULT_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(LENGTH "${RESULT_STRING}" LENGTH_RESULT_STRING)
if(${LENGTH_RESULT_STRING} EQUAL 0)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
project(TIC-80 VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION} LANGUAGES C CXX)
message("Building for target : ${CMAKE_SYSTEM_NAME}")
message("PROJECT_VERSION: ${PROJECT_VERSION}${VERSION_STATUS}")
configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h")
if(ANDROID OR EMSCRIPTEN OR N3DS OR RPI)
set(BUILD_LIBRETRO_DEFAULT OFF)
set(BUILD_DEMO_CARTS_DEFAULT OFF)
set(BUILD_PLAYER_DEFAULT OFF)
else()
set(BUILD_LIBRETRO_DEFAULT ON)
set(BUILD_DEMO_CARTS_DEFAULT ON)
set(BUILD_PLAYER_DEFAULT ON)
endif()
set(BUILD_TOUCH_INPUT_DEFAULT ${ANDROID})
option(BUILD_SDL "SDL Enabled" ON)
option(BUILD_SDLGPU "SDL GPU Enabled" OFF)
option(BUILD_SOKOL "Sokol Enabled" OFF)
option(BUILD_LIBRETRO "libretro Enabled" ${BUILD_LIBRETRO_DEFAULT})
option(BUILD_DEMO_CARTS "Demo Carts Enabled" ${BUILD_DEMO_CARTS_DEFAULT})
option(BUILD_PRO "Build PRO version" FALSE)
option(BUILD_PLAYER "Build standalone players" ${BUILD_PLAYER_DEFAULT})
option(BUILD_TOUCH_INPUT "Build with touch input support" ${BUILD_TOUCH_INPUT_DEFAULT})
if(NOT BUILD_SDL)
set(BUILD_SDLGPU OFF)
endif()
message("BUILD_SDLGPU: ${BUILD_SDLGPU}")
message("BUILD_TOUCH_INPUT: ${BUILD_TOUCH_INPUT}")
if (N3DS)
set(BUILD_SDL off)
# disable CURL linking - use HTTPC instead
set(DISABLE_NETWORKING TRUE)
endif()
if (BAREMETALPI)
set(BUILD_SDL OFF)
set(BUILD_DEMO_CARTS OFF)
set(DISABLE_NETWORKING TRUE)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
if(MINGW OR CYGWIN OR WIN32)
set(UTIL_SEARCH_CMD where)
elseif(UNIX OR APPLE)
set(UTIL_SEARCH_CMD which)
endif()
set(TOOLCHAIN_PREFIX arm-none-eabi-)
execute_process(
COMMAND ${UTIL_SEARCH_CMD} ${TOOLCHAIN_PREFIX}gcc
OUTPUT_VARIABLE BINUTILS_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("Crosscompiler path is ${BINUTILS_PATH}")
get_filename_component(ARM_TOOLCHAIN_DIR ${BINUTILS_PATH} DIRECTORY)
# Without that flag CMake is not able to pass test compilation check
if (${CMAKE_VERSION} VERSION_EQUAL "3.6.0" OR ${CMAKE_VERSION} VERSION_GREATER "3.6")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
else()
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-E")
endif()
# removed squirrel language as it doesn't seem to compile under arm. Needs investigation.
# Ideally should use the CFLAGS defined in circle build files, not hardwire them here too.
# For RPI2
#set(CMAKE_C_FLAGS " -DTIC_BUILD_WITH_FENNEL -DTIC_BUILD_WITH_MOON -DTIC_BUILD_WITH_JS -DTIC_BUILD_WITH_WREN -DTIC_BUILD_WITH_LUA -DLUA_32BITS -std=c99 -march=armv7-a+neon-vfpv4 -D AARCH=32 -D __circle__ -D BAREMETALPI --specs=nosys.specs -O3 -mabi=aapcs -marm -mfloat-abi=hard -mfpu=neon-vfpv4 -D__DYNAMIC_REENT__")
# For RPI3
# investigate -funsafe-math-optimizations and -march=armv8-a+crc -mcpu=cortex-a53
set(CMAKE_C_FLAGS " -DTIC_BUILD_WITH_FENNEL -DTIC_BUILD_WITH_MOON -DTIC_BUILD_WITH_JS -DTIC_BUILD_WITH_WREN -DTIC_BUILD_WITH_LUA -DLUA_32BITS -std=c99 -march=armv8-a -D AARCH=32 -mtune=cortex-a53 -D __circle__ -D BAREMETALPI --specs=nosys.specs -O3 -marm -mfloat-abi=hard -mfpu=neon-fp-armv8 -funsafe-math-optimizations -D__DYNAMIC_REENT__")
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_OBJCOPY ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}objcopy CACHE INTERNAL "objcopy tool")
set(CMAKE_SIZE_UTIL ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}size CACHE INTERNAL "size tool")
set(CMAKE_SYSROOT ${ARM_TOOLCHAIN_DIR}/../arm-none-eabi)
set(CMAKE_FIND_ROOT_PATH ${BINUTILS_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif()
if (DISABLE_NETWORKING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDISABLE_NETWORKING")
endif()
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID AND NOT N3DS)
set(LINUX TRUE)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if(MSVC)
add_definitions("/D\"_CRT_SECURE_NO_WARNINGS\"")
add_definitions("/D\"_CRT_NONSTDC_NO_DEPRECATE\"")
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/lib )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/lib )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/bin )
# use static runtime
if(CMAKE_C_FLAGS_${OUTPUTCONFIG} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS_${OUTPUTCONFIG} "${CMAKE_C_FLAGS_${OUTPUTCONFIG}}")
endif()
if(CMAKE_CXX_FLAGS_${OUTPUTCONFIG} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_${OUTPUTCONFIG} "${CMAKE_CXX_FLAGS_${OUTPUTCONFIG}}")
endif()
endforeach()
else()
set(CMAKE_C_STANDARD 99)
endif()
set(THIRDPARTY_DIR ${CMAKE_SOURCE_DIR}/vendor)
################################
# LUA
################################
set(LUA_DIR ${THIRDPARTY_DIR}/lua)
set(LUA_SRC
${LUA_DIR}/lapi.c
${LUA_DIR}/lcode.c
${LUA_DIR}/lctype.c
${LUA_DIR}/ldebug.c
${LUA_DIR}/ldo.c
${LUA_DIR}/ldump.c
${LUA_DIR}/lfunc.c
${LUA_DIR}/lgc.c
${LUA_DIR}/llex.c
${LUA_DIR}/lmem.c
${LUA_DIR}/lobject.c
${LUA_DIR}/lopcodes.c
${LUA_DIR}/lparser.c
${LUA_DIR}/lstate.c
${LUA_DIR}/lstring.c
${LUA_DIR}/ltable.c
${LUA_DIR}/ltm.c
${LUA_DIR}/lundump.c
${LUA_DIR}/lvm.c
${LUA_DIR}/lzio.c
${LUA_DIR}/lauxlib.c
${LUA_DIR}/lbaselib.c
${LUA_DIR}/lcorolib.c
${LUA_DIR}/ldblib.c
${LUA_DIR}/liolib.c
${LUA_DIR}/lmathlib.c
${LUA_DIR}/loslib.c
${LUA_DIR}/lstrlib.c
${LUA_DIR}/ltablib.c
${LUA_DIR}/lutf8lib.c
${LUA_DIR}/loadlib.c
${LUA_DIR}/linit.c
)
add_library(lua STATIC ${LUA_SRC})
target_compile_definitions(lua PRIVATE LUA_COMPAT_5_2)
target_include_directories(lua INTERFACE ${THIRDPARTY_DIR}/lua)
if(N3DS)
target_compile_definitions(lua PUBLIC LUA_32BITS)
endif()
################################
# LPEG
################################
set(LPEG_DIR ${THIRDPARTY_DIR}/lpeg)
set(LPEG_SRC
${LPEG_DIR}/lpcap.c
${LPEG_DIR}/lpcode.c
${LPEG_DIR}/lpprint.c
${LPEG_DIR}/lptree.c
${LPEG_DIR}/lpvm.c
)
add_library(lpeg STATIC ${LPEG_SRC})
target_include_directories(lpeg PRIVATE ${LUA_DIR})
################################
# WREN
################################
set(WREN_DIR ${THIRDPARTY_DIR}/wren/src)
set(WREN_SRC
${WREN_DIR}/optional/wren_opt_meta.c
${WREN_DIR}/optional/wren_opt_random.c
${WREN_DIR}/vm/wren_compiler.c
${WREN_DIR}/vm/wren_core.c
${WREN_DIR}/vm/wren_debug.c
${WREN_DIR}/vm/wren_primitive.c
${WREN_DIR}/vm/wren_utils.c
${WREN_DIR}/vm/wren_value.c
${WREN_DIR}/vm/wren_vm.c
)
add_library(wren STATIC ${WREN_SRC})
target_include_directories(wren PUBLIC ${THIRDPARTY_DIR}/wren/src/include)
target_include_directories(wren PRIVATE ${THIRDPARTY_DIR}/wren/src/optional)
target_include_directories(wren PRIVATE ${THIRDPARTY_DIR}/wren/src/vm)
################################
# SQUIRREL
################################
set(SQUIRREL_DIR ${THIRDPARTY_DIR}/squirrel)
set(SQUIRREL_SRC
${SQUIRREL_DIR}/squirrel/sqapi.cpp
${SQUIRREL_DIR}/squirrel/sqbaselib.cpp
${SQUIRREL_DIR}/squirrel/sqclass.cpp
${SQUIRREL_DIR}/squirrel/sqcompiler.cpp
${SQUIRREL_DIR}/squirrel/sqdebug.cpp
${SQUIRREL_DIR}/squirrel/sqfuncstate.cpp
${SQUIRREL_DIR}/squirrel/sqlexer.cpp
${SQUIRREL_DIR}/squirrel/sqmem.cpp
${SQUIRREL_DIR}/squirrel/sqobject.cpp
${SQUIRREL_DIR}/squirrel/sqstate.cpp
${SQUIRREL_DIR}/squirrel/sqtable.cpp
${SQUIRREL_DIR}/squirrel/sqvm.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdaux.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdblob.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdio.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdmath.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdrex.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdstream.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdstring.cpp
${SQUIRREL_DIR}/sqstdlib/sqstdsystem.cpp
)
add_library(squirrel STATIC ${SQUIRREL_SRC})
set_target_properties(squirrel PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(squirrel PUBLIC ${SQUIRREL_DIR}/include)
target_include_directories(squirrel PRIVATE ${SQUIRREL_DIR}/squirrel)
target_include_directories(squirrel PRIVATE ${SQUIRREL_DIR}/sqstdlib)
################################
# GIFLIB
################################
set(GIFLIB_DIR ${THIRDPARTY_DIR}/giflib)
set(GIFLIB_SRC
${GIFLIB_DIR}/dgif_lib.c
${GIFLIB_DIR}/egif_lib.c
${GIFLIB_DIR}/gif_err.c
${GIFLIB_DIR}/gif_font.c
${GIFLIB_DIR}/gif_hash.c
${GIFLIB_DIR}/gifalloc.c
${GIFLIB_DIR}/openbsd-reallocarray.c
)
add_library(giflib STATIC ${GIFLIB_SRC})
target_include_directories(giflib
PRIVATE ${GIFLIB_DIR}
INTERFACE ${THIRDPARTY_DIR}/giflib)
################################
# Blipbuf
################################
add_library(blipbuf STATIC ${THIRDPARTY_DIR}/blip-buf/blip_buf.c)
target_include_directories(blipbuf INTERFACE ${THIRDPARTY_DIR}/blip-buf)
################################
# Duktape
################################
add_library(duktape STATIC ${THIRDPARTY_DIR}/duktape/src/duktape.c)
target_include_directories(duktape INTERFACE ${THIRDPARTY_DIR}/duktape/src)
################################
# TIC-80 core
################################
set(TIC80CORE_DIR ${CMAKE_SOURCE_DIR}/src)
set(TIC80CORE_SRC
${TIC80CORE_DIR}/core/core.c
${TIC80CORE_DIR}/core/draw.c
${TIC80CORE_DIR}/core/io.c
${TIC80CORE_DIR}/core/sound.c
${TIC80CORE_DIR}/api/js.c
${TIC80CORE_DIR}/api/lua.c
${TIC80CORE_DIR}/api/wren.c
${TIC80CORE_DIR}/api/squirrel.c
${TIC80CORE_DIR}/ext/gif.c
${TIC80CORE_DIR}/tic.c
${TIC80CORE_DIR}/cart.c
${TIC80CORE_DIR}/tools.c
${TIC80CORE_DIR}/tilesheet.c
)
add_library(tic80core STATIC ${TIC80CORE_SRC})
target_include_directories(tic80core
PRIVATE
${THIRDPARTY_DIR}/moonscript
${THIRDPARTY_DIR}/fennel
PUBLIC
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src)
target_link_libraries(tic80core lua lpeg wren squirrel giflib blipbuf duktape zlib)
if(LINUX)
target_link_libraries(tic80core m)
endif()
################################
# SDL2
################################
if(BUILD_SDL AND NOT EMSCRIPTEN AND NOT RPI)
if(WIN32)
set(HAVE_LIBC TRUE)
endif()
if(ANDROID)
include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
endif()
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
add_subdirectory(${THIRDPARTY_DIR}/sdl2)
endif()
################################
# SDL2 standalone cart player
################################
if(BUILD_SDL AND BUILD_PLAYER AND NOT RPI)
add_executable(player-sdl WIN32 ${CMAKE_SOURCE_DIR}/src/system/sdl/player.c)
target_include_directories(player-sdl PRIVATE
${THIRDPARTY_DIR}/sdl2/include
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src)
if(MINGW)
target_link_libraries(player-sdl mingw32)
endif()
target_link_libraries(player-sdl tic80core SDL2-static SDL2main)
endif()
################################
# Sokol
################################
if(BUILD_SOKOL)
set(SOKOL_LIB_SRC ${CMAKE_SOURCE_DIR}/src/system/sokol/sokol_gfx.c)
if(APPLE)
set(SOKOL_LIB_SRC ${SOKOL_LIB_SRC} ${CMAKE_SOURCE_DIR}/src/system/sokol/sokol_impl.m)
else()
set(SOKOL_LIB_SRC ${SOKOL_LIB_SRC} ${CMAKE_SOURCE_DIR}/src/system/sokol/sokol_impl.c)
endif()
add_library(sokol STATIC ${SOKOL_LIB_SRC})
if(APPLE)
target_compile_definitions(sokol PRIVATE SOKOL_METAL)
elseif(WIN32)
target_compile_definitions(sokol PRIVATE SOKOL_D3D11 SOKOL_D3D11_SHADER_COMPILER)
elseif(LINUX)
target_compile_definitions(sokol PRIVATE SOKOL_GLCORE33)
endif()
if(APPLE)
set_property (TARGET sokol APPEND_STRING PROPERTY
COMPILE_FLAGS "-fobjc-arc")
target_link_libraries(sokol
"-framework Cocoa"
"-framework QuartzCore"
"-framework Metal"
"-framework MetalKit"
"-framework AudioToolbox"
)
elseif(WIN32)
target_link_libraries(sokol D3D11)
if(MINGW)
target_link_libraries(sokol D3dcompiler_47)
endif()
elseif(LINUX)
find_package (Threads)
target_link_libraries(sokol X11 GL m dl asound ${CMAKE_THREAD_LIBS_INIT})
endif()
target_include_directories(sokol PRIVATE ${THIRDPARTY_DIR}/sokol)
endif()
################################
# Sokol standalone cart player
################################
if(BUILD_PLAYER AND BUILD_SOKOL)
add_executable(player-sokol WIN32 ${CMAKE_SOURCE_DIR}/src/system/sokol/player.c)
if(MINGW)
target_link_libraries(player-sokol mingw32)
endif()
target_include_directories(player-sokol PRIVATE
${CMAKE_SOURCE_DIR}/include
${THIRDPARTY_DIR}/sokol
${CMAKE_SOURCE_DIR}/src)
target_link_libraries(player-sokol tic80core sokol)
endif()
################################
# libretro renderer example
################################
if(BUILD_LIBRETRO)
set(LIBRETRO_DIR ${TIC80CORE_DIR}/system/libretro)
set(LIBRETRO_SRC
${LIBRETRO_DIR}/tic80_libretro.c
)
if (LIBRETRO_STATIC)
add_library(tic80_libretro STATIC
${LIBRETRO_SRC}
)
set_target_properties(tic80_libretro PROPERTIES SUFFIX "_partial.a")
add_custom_command(TARGET tic80_libretro
POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/build/libretro/merge_static.sh $(AR) ${CMAKE_BINARY_DIR}/lib/tic80_libretro${LIBRETRO_SUFFIX}.a ${CMAKE_BINARY_DIR}/lib/tic80_libretro_partial.a ${CMAKE_BINARY_DIR}/lib/libtic80core.a ${CMAKE_BINARY_DIR}/lib/liblua.a ${CMAKE_BINARY_DIR}/lib/libblipbuf.a ${CMAKE_BINARY_DIR}/lib/libduktape.a ${CMAKE_BINARY_DIR}/lib/libwren.a ${CMAKE_BINARY_DIR}/lib/libsquirrel.a ${CMAKE_BINARY_DIR}/lib/libgiflib.a ${CMAKE_BINARY_DIR}/lib/liblpeg.a)
else()
add_library(tic80_libretro SHARED
${LIBRETRO_SRC}
)
endif()
target_include_directories(tic80_libretro PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${TIC80CORE_DIR})
if(MINGW)
target_link_libraries(tic80_libretro mingw32)
endif()
if(ANDROID)
set_target_properties(tic80_libretro PROPERTIES SUFFIX "_android.so")
endif()
if(EMSCRIPTEN)
set_target_properties(tic80_libretro PROPERTIES SUFFIX "_emscripten.bc")
endif()
# MSYS2 builds libretro to ./bin, despite it being a DLL. This forces it to ./lib.
set_target_properties(tic80_libretro PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)
target_link_libraries(tic80_libretro tic80core)
set_target_properties(tic80_libretro PROPERTIES PREFIX "")
endif()
################################
# CURL
################################
if (NOT DISABLE_NETWORKING)
if (NOT N3DS AND NOT EMSCRIPTEN)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
if(WIN32)
set(CURL_STATIC_CRT ON CACHE BOOL "")
endif()
set(CMAKE_USE_OPENSSL OFF CACHE BOOL "" )
set(CMAKE_USE_LIBSSH2 OFF CACHE BOOL "")
set(HTTP_ONLY ON CACHE BOOL "")
set(BUILD_CURL_EXE OFF CACHE BOOL "")
set(CURL_CA_BUNDLE "none" CACHE STRING "")
set(CURL_CA_PATH "none" CACHE STRING "")
if(RPI)
set(CURL_ZLIB OFF CACHE BOOL "" )
endif()
add_subdirectory(${THIRDPARTY_DIR}/curl)
if(RPI)
target_compile_definitions(libcurl PRIVATE NOT_USE_FILE_OFFSET64)
endif()
endif()
endif()
################################
# ZLIB
################################
if (NOT N3DS)
set(ZLIB_DIR ${THIRDPARTY_DIR}/zlib)
set(ZLIB_SRC
${ZLIB_DIR}/adler32.c
${ZLIB_DIR}/compress.c
${ZLIB_DIR}/crc32.c
${ZLIB_DIR}/deflate.c
${ZLIB_DIR}/inflate.c
${ZLIB_DIR}/infback.c
${ZLIB_DIR}/inftrees.c
${ZLIB_DIR}/inffast.c
${ZLIB_DIR}/trees.c
${ZLIB_DIR}/uncompr.c
${ZLIB_DIR}/zutil.c
)
add_library(zlib STATIC ${ZLIB_SRC})
target_include_directories(zlib INTERFACE ${THIRDPARTY_DIR}/zlib)
else ()
add_library(zlib STATIC IMPORTED)
set_target_properties( zlib PROPERTIES IMPORTED_LOCATION ${DEVKITPRO}/portlibs/3ds/lib/libz.a )
target_include_directories(zlib INTERFACE ${DEVKITPRO}/portlibs/3ds/include)
endif ()
################################
# ZIP
################################
set(CMAKE_DISABLE_TESTING ON CACHE BOOL "" FORCE)
add_subdirectory(${THIRDPARTY_DIR}/zip)
set(TOOLS_DIR ${CMAKE_SOURCE_DIR}/build/tools)
################################
# bin2txt cart2prj prj2cart
################################
if(BUILD_DEMO_CARTS)
add_executable(cart2prj ${TOOLS_DIR}/cart2prj.c ${CMAKE_SOURCE_DIR}/src/studio/project.c)
target_include_directories(cart2prj PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(cart2prj tic80core)
add_executable(prj2cart ${TOOLS_DIR}/prj2cart.c ${CMAKE_SOURCE_DIR}/src/studio/project.c)
target_include_directories(prj2cart PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(prj2cart tic80core)
add_executable(bin2txt ${TOOLS_DIR}/bin2txt.c)
target_link_libraries(bin2txt zlib)
file(GLOB DEMO_CARTS ${CMAKE_SOURCE_DIR}/demos/*.* )
list(APPEND DEMO_CARTS
${CMAKE_SOURCE_DIR}/config.lua
)
set(DEMO_CARTS_OUT)
foreach(CART_FILE ${DEMO_CARTS})
get_filename_component(CART_NAME ${CART_FILE} NAME_WE)
set(OUTNAME ${CMAKE_SOURCE_DIR}/build/assets/${CART_NAME}.tic.dat)
set(OUTPRJ ${CMAKE_SOURCE_DIR}/build/${CART_NAME}.tic)
list(APPEND DEMO_CARTS_OUT ${OUTNAME})
add_custom_command(OUTPUT ${OUTNAME}
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/prj2cart ${CART_FILE} ${OUTPRJ} && ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bin2txt ${OUTPRJ} ${OUTNAME} -z
DEPENDS bin2txt prj2cart ${CART_FILE}
)
endforeach(CART_FILE)
endif()
################################
# Wave writer
################################
add_library(wave_writer STATIC ${THIRDPARTY_DIR}/blip-buf/wave_writer.c)
target_include_directories(wave_writer INTERFACE ${THIRDPARTY_DIR}/blip-buf)
################################
# ArgParse lib
################################
add_library(argparse STATIC ${THIRDPARTY_DIR}/argparse/argparse.c)
target_include_directories(argparse INTERFACE ${THIRDPARTY_DIR}/argparse)
################################
# TIC-80 studio
################################
set(TIC80LIB_DIR ${CMAKE_SOURCE_DIR}/src)
set(TIC80STUDIO_SRC
${TIC80LIB_DIR}/studio/screens/console.c
${TIC80LIB_DIR}/studio/screens/run.c
${TIC80LIB_DIR}/studio/screens/dialog.c
${TIC80LIB_DIR}/studio/screens/menu.c
${TIC80LIB_DIR}/studio/screens/surf.c
${TIC80LIB_DIR}/studio/screens/start.c
${TIC80LIB_DIR}/studio/editors/code.c
${TIC80LIB_DIR}/studio/editors/sprite.c
${TIC80LIB_DIR}/studio/editors/map.c
${TIC80LIB_DIR}/studio/editors/world.c
${TIC80LIB_DIR}/studio/editors/sfx.c
${TIC80LIB_DIR}/studio/editors/music.c
${TIC80LIB_DIR}/studio/studio.c
${TIC80LIB_DIR}/studio/config.c
${TIC80LIB_DIR}/studio/project.c
${TIC80LIB_DIR}/studio/fs.c
${TIC80LIB_DIR}/ext/md5.c
${TIC80LIB_DIR}/ext/gif.c
${TIC80LIB_DIR}/ext/history.c
${TIC80LIB_DIR}/ext/net.c
)
set(TIC80_OUTPUT tic80)
add_library(tic80studio STATIC ${TIC80STUDIO_SRC} ${DEMO_CARTS_OUT})
if(WIN32)
target_include_directories(tic80studio PRIVATE ${THIRDPARTY_DIR}/dirent/include)
endif()
target_include_directories(tic80studio PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(tic80studio tic80core zip wave_writer argparse)
if(N3DS)
target_include_directories(tic80studio PRIVATE ${DEVKITPRO}/portlibs/3ds/include)
target_link_directories(tic80studio PUBLIC ${DEVKITPRO}/portlibs/3ds/lib)
endif()
if(NOT DISABLE_NETWORKING)
if(N3DS)
target_link_libraries(tic80studio curl mbedtls mbedx509 mbedcrypto)
elseif(NOT EMSCRIPTEN)
target_link_libraries(tic80studio libcurl)
endif()
endif()
if(BUILD_PRO)
target_compile_definitions(tic80studio PRIVATE TIC80_PRO)
endif()
if(BUILD_SDLGPU)
target_compile_definitions(tic80studio PUBLIC CRT_SHADER_SUPPORT)
endif()
################################
# SDL GPU
################################
if(BUILD_SDLGPU)
set(SDLGPU_DIR ${THIRDPARTY_DIR}/sdl-gpu/src)
set(SDLGPU_SRC
${SDLGPU_DIR}/renderer_GLES_2.c
${SDLGPU_DIR}/SDL_gpu.c
${SDLGPU_DIR}/SDL_gpu_matrix.c
${SDLGPU_DIR}/SDL_gpu_renderer.c
${SDLGPU_DIR}/externals/stb_image/stb_image.c
${SDLGPU_DIR}/externals/stb_image_write/stb_image_write.c
)
if(NOT ANDROID)
list(APPEND SDLGPU_SRC
${SDLGPU_DIR}/renderer_GLES_1.c
${SDLGPU_DIR}/renderer_GLES_3.c
${SDLGPU_DIR}/renderer_OpenGL_1.c
${SDLGPU_DIR}/renderer_OpenGL_1_BASE.c
${SDLGPU_DIR}/renderer_OpenGL_2.c
${SDLGPU_DIR}/renderer_OpenGL_3.c
${SDLGPU_DIR}/renderer_OpenGL_4.c
${SDLGPU_DIR}/SDL_gpu_shapes.c
${SDLGPU_DIR}/externals/glew/glew.c
)
endif()
add_library(sdlgpu STATIC ${SDLGPU_SRC})
if(EMSCRIPTEN OR ANDROID)
target_compile_definitions(sdlgpu PRIVATE GLEW_STATIC SDL_GPU_DISABLE_GLES_1 SDL_GPU_DISABLE_GLES_3 SDL_GPU_DISABLE_OPENGL)
else()
target_compile_definitions(sdlgpu PRIVATE GLEW_STATIC SDL_GPU_DISABLE_GLES SDL_GPU_DISABLE_OPENGL_3 SDL_GPU_DISABLE_OPENGL_4)
endif()
target_include_directories(sdlgpu PUBLIC ${THIRDPARTY_DIR}/sdl-gpu/include)
target_include_directories(sdlgpu PRIVATE ${THIRDPARTY_DIR}/sdl-gpu/src/externals/glew)
target_include_directories(sdlgpu PRIVATE ${THIRDPARTY_DIR}/sdl-gpu/src/externals/glew/GL)
target_include_directories(sdlgpu PRIVATE ${THIRDPARTY_DIR}/sdl-gpu/src/externals/stb_image)
target_include_directories(sdlgpu PRIVATE ${THIRDPARTY_DIR}/sdl-gpu/src/externals/stb_image_write)
if(WIN32)
target_link_libraries(sdlgpu opengl32)
endif()
if(LINUX)
target_link_libraries(sdlgpu GL)
endif()
if(APPLE)
find_library(OPENGL_LIBRARY OpenGL)
target_link_libraries(sdlgpu ${OPENGL_LIBRARY})
endif()
if(ANDROID)
find_library( ANDROID_LOG_LIBRARY log )
find_library( ANDROID_GLES2_LIBRARY GLESv2 )
find_library( ANDROID_GLES1_LIBRARY GLESv1_CM )
target_link_libraries(sdlgpu
${ANDROID_LOG_LIBRARY}
${ANDROID_GLES2_LIBRARY}
${ANDROID_GLES1_LIBRARY}
)
endif()
if(NOT EMSCRIPTEN)
target_link_libraries(sdlgpu SDL2-static)
endif()
endif()
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
################################
# TIC-80 app
################################
if(BUILD_SDL)
set(TIC80_SRC src/system/sdl/main.c)
if(WIN32)
configure_file("${PROJECT_SOURCE_DIR}/build/windows/tic80.rc.in" "${PROJECT_SOURCE_DIR}/build/windows/tic80.rc")
set(TIC80_SRC ${TIC80_SRC} "${PROJECT_SOURCE_DIR}/build/windows/tic80.rc")
# Debug build is a console app.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
else()
set(SYSTEM_TYPE WIN32)
endif()
add_executable(tic80 ${SYSTEM_TYPE} ${TIC80_SRC})
elseif(ANDROID)
set(TIC80_SRC ${TIC80_SRC} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
add_library(tic80 SHARED ${TIC80_SRC})
target_link_libraries(tic80 hidapi)
else()
add_executable(tic80 ${TIC80_SRC})
endif()
if(MINGW)
target_link_libraries(tic80 mingw32)
endif()
if(EMSCRIPTEN)
set_target_properties(tic80 PROPERTIES LINK_FLAGS "-s WASM=1 -s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s FETCH=1 --pre-js ${CMAKE_SOURCE_DIR}/build/html/prejs.js -lidbfs.js")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_SDL=2")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ASSERTIONS=1")
endif()
elseif(NOT ANDROID)
target_link_libraries(tic80 SDL2main)
endif()
target_link_libraries(tic80 tic80studio)
if(BUILD_TOUCH_INPUT)
target_compile_definitions(tic80 PRIVATE TOUCH_INPUT_SUPPORT)
endif()
if(RPI)
target_include_directories(tic80 PRIVATE ${SYSROOT_PATH}/usr/local/include/SDL2)
target_link_directories(tic80 PRIVATE ${SYSROOT_PATH}/usr/local/lib ${SYSROOT_PATH}/opt/vc/lib)
endif()
if(BUILD_SDLGPU)
target_link_libraries(tic80 sdlgpu)
else()
if(EMSCRIPTEN)
elseif(RPI)
target_link_libraries(tic80 libSDL2.a bcm_host)
else()
target_link_libraries(tic80 SDL2-static)
endif()
endif()
if(LINUX)
configure_file("${PROJECT_SOURCE_DIR}/build/linux/tic80.desktop.in" "${PROJECT_SOURCE_DIR}/build/linux/tic80.desktop")
install(TARGETS tic80 DESTINATION bin)
SET(TIC80_DESKTOP_DIR "share/applications/")
SET(TIC80_PIXMAPS_DIR "share/icons/")
install (FILES ${PROJECT_SOURCE_DIR}/build/linux/tic80.desktop DESTINATION ${TIC80_DESKTOP_DIR})
install (FILES ${PROJECT_SOURCE_DIR}/build/linux/tic80.xml DESTINATION ${TIC80_DESKTOP_DIR})
install (FILES ${PROJECT_SOURCE_DIR}/build/linux/tic80.png DESTINATION ${TIC80_PIXMAPS_DIR})
endif()
endif()
################################
# TIC-80 app (Sokol)
################################
if(BUILD_SOKOL)
set(TIC80_SRC ${CMAKE_SOURCE_DIR}/src/system/sokol/sokol.c)
if(WIN32)
configure_file("${PROJECT_SOURCE_DIR}/build/windows/tic80.rc.in" "${PROJECT_SOURCE_DIR}/build/windows/tic80.rc")
set(TIC80_SRC ${TIC80_SRC} "${PROJECT_SOURCE_DIR}/build/windows/tic80.rc")
add_executable(tic80-sokol WIN32 ${TIC80_SRC})
else()
add_executable(tic80-sokol ${TIC80_SRC})
endif()
target_include_directories(tic80-sokol PRIVATE
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
${THIRDPARTY_DIR}/sokol)
if(MINGW)
target_link_libraries(tic80-sokol mingw32)
endif()
target_link_libraries(tic80-sokol tic80studio sokol)
endif()
################################
# TIC-80 app (N3DS)
################################
if(N3DS)
set(TIC80_SRC ${TIC80_SRC}
${CMAKE_SOURCE_DIR}/src/system/n3ds/utils.c
${CMAKE_SOURCE_DIR}/src/system/n3ds/keyboard.c
${CMAKE_SOURCE_DIR}/src/system/n3ds/net_httpc.c
${CMAKE_SOURCE_DIR}/src/system/n3ds/main.c
)
if (DISABLE_NETWORKING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_HTTPC")
endif()
add_executable(tic80_n3ds ${TIC80_SRC})
target_include_directories(tic80_n3ds PRIVATE
${DEVKITPRO}/portlibs/3ds/include
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src)
target_link_directories(tic80_n3ds PRIVATE ${DEVKITPRO}/libctru/lib)
target_link_libraries(tic80_n3ds tic80studio png citro3d)
add_custom_command(TARGET tic80_n3ds
POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/build/n3ds/elf_to_3dsx.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build
)
endif()
set(CPACK_PACKAGE_NAME "TIC-80")
set(CPACK_PACKAGE_VENDOR "Nesbox")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fantasy computer for making, playing and sharing tiny games.")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_REVISION}")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "TIC-80")
if (APPLE)
set(CPACK_GENERATOR "Bundle")
set(CPACK_BUNDLE_NAME "tic80")
configure_file(${CMAKE_SOURCE_DIR}/build/macosx/tic80.plist.in ${CMAKE_SOURCE_DIR}/build/macosx/tic80.plist)
set(CPACK_BUNDLE_PLIST ${CMAKE_SOURCE_DIR}/build/macosx/tic80.plist)
set(CPACK_BUNDLE_ICON ${CMAKE_SOURCE_DIR}/build/macosx/tic80.icns)
set(CPACK_BUNDLE_STARTUP_COMMAND "${CMAKE_BINARY_DIR}/bin/tic80")
install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY true)")
include(CPack)
elseif (LINUX)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_NAME "tic80")
set(CPACK_DEBIAN_FILE_NAME "tic80.deb")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://tic80.com")
set(CPACK_DEBIAN_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Nesbox <grigoruk@gmail.com>")
set(CPACK_DEBIAN_PACKAGE_SECTION "education")
if(RPI)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE armhf)
endif()
install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY true)")
include(CPack)
endif()