@@ -8,6 +8,8 @@ string(TOLOWER ${TARGET_PLATFORM} TARGET_PLATFORM)
8
8
9
9
option (DRAW_FPS "Draw FPS on the top left corner of the window." OFF )
10
10
option (SYSTEM_LIBS "Use system libraries when available." ON )
11
+ option (EMSCRIPTEN_LOAD_SDL_PORTS "Load SDL and SDL_mixer emscripten ports instead of compiling them" OFF )
12
+ option (LINK_MPG123 "Link mpg123 statically to Julius instead of relying on a library." OFF )
11
13
12
14
if (${TARGET_PLATFORM} STREQUAL "vita" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
13
15
if (DEFINED ENV{VITASDK})
@@ -26,6 +28,15 @@ if(${TARGET_PLATFORM} STREQUAL "switch" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
26
28
endif ()
27
29
endif ()
28
30
31
+ if (${TARGET_PLATFORM} STREQUAL "emscripten" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
32
+ if (DEFINED ENV{EMSDK})
33
+ set (EMSDK $ENV{EMSDK} )
34
+ set (CMAKE_TOOLCHAIN_FILE "$ENV{EMSDK} /upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" CACHE PATH "toolchain file" )
35
+ else ()
36
+ message (FATAL_ERROR "Please define EMSDK to point to your Emscripten SDK path!" )
37
+ endif ()
38
+ endif ()
39
+
29
40
set (SHORT_NAME augustus)
30
41
set (USER_FRIENDLY_NAME Augustus)
31
42
project (${SHORT_NAME} C)
@@ -131,6 +142,10 @@ configure_file(${PROJECT_SOURCE_DIR}/gen/version.c.in ${PROJECT_SOURCE_DIR}/src/
131
142
configure_file (${PROJECT_SOURCE_DIR} /gen/version .rc.in ${PROJECT_SOURCE_DIR} /res/version .rc)
132
143
configure_file (${PROJECT_SOURCE_DIR} /gen/version .txt.in ${PROJECT_SOURCE_DIR} /res/version .txt)
133
144
145
+ if (${TARGET_PLATFORM} STREQUAL "emscripten" )
146
+ configure_file (${PROJECT_SOURCE_DIR} /gen/shell.html.in ${PROJECT_SOURCE_DIR} /res/shell.html)
147
+ endif ()
148
+
134
149
if (DRAW_FPS)
135
150
add_definitions (-DDRAW_FPS)
136
151
endif ()
@@ -633,6 +648,11 @@ if(APPLE)
633
648
)
634
649
endif ()
635
650
651
+ set (EMSCRIPTEN_FILES "" )
652
+ if (${TARGET_PLATFORM} STREQUAL "emscripten" )
653
+ set (EMSCRIPTEN_FILES ${PROJECT_SOURCE_DIR} /res/shell.html)
654
+ endif ()
655
+
636
656
set (SOURCE_FILES
637
657
${PLATFORM_FILES}
638
658
${CORE_FILES}
@@ -657,36 +677,54 @@ set(SOURCE_FILES
657
677
${MACOSX_FILES}
658
678
)
659
679
660
- function (GET_SDL_EXT_DIR result module)
661
- if (NOT module STREQUAL "" )
662
- set (module "_${module} " )
663
- endif ()
664
- set (SDL_LOCATION ${PROJECT_SOURCE_DIR} /ext /SDL2)
665
- file (GLOB children
666
- RELATIVE ${SDL_LOCATION}
667
- CONFIGURE_DEPENDS
668
- ${SDL_LOCATION} /SDL${module}
669
- ${SDL_LOCATION} /SDL2${module}
670
- ${SDL_LOCATION} /SDL${module} -*
671
- ${SDL_LOCATION} /SDL2${module} -*
672
- )
673
- foreach (child ${children} )
674
- if (IS_DIRECTORY "${SDL_LOCATION} /${child} " )
675
- set (${result} "${SDL_LOCATION} /${child} " PARENT_SCOPE)
676
- break ()
680
+ if (${TARGET_PLATFORM} STREQUAL "emscripten" AND EMSCRIPTEN_LOAD_SDL_PORTS)
681
+ set (USE_FLAGS "-s USE_SDL=2 -s USE_SDL_MIXER=2 -s SDL2_MIXER_FORMATS=[\" mp3\" ] -s USE_MPG123=1" )
682
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS} " )
683
+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS} " )
684
+ else ()
685
+ function (GET_SDL_EXT_DIR result module)
686
+ if (NOT module STREQUAL "" )
687
+ set (module "_${module} " )
677
688
endif ()
678
- endforeach ()
679
- endfunction ()
689
+ set (SDL_LOCATION ${PROJECT_SOURCE_DIR} /ext /SDL2)
690
+ file (GLOB children
691
+ RELATIVE ${SDL_LOCATION}
692
+ CONFIGURE_DEPENDS
693
+ ${SDL_LOCATION} /SDL${module}
694
+ ${SDL_LOCATION} /SDL2${module}
695
+ ${SDL_LOCATION} /SDL${module} -*
696
+ ${SDL_LOCATION} /SDL2${module} -*
697
+ )
698
+ foreach (child ${children} )
699
+ if (IS_DIRECTORY "${SDL_LOCATION} /${child} " )
700
+ set (${result} "${SDL_LOCATION} /${child} " PARENT_SCOPE)
701
+ break ()
702
+ endif ()
703
+ endforeach ()
704
+ endfunction ()
705
+
706
+ find_package (SDL2 REQUIRED)
707
+ find_package (SDL2_mixer REQUIRED)
708
+ if (${TARGET_PLATFORM} STREQUAL "emscripten" )
709
+ set (LINK_MPG123 true )
710
+ endif ()
711
+ endif ()
680
712
681
- find_package (SDL2 REQUIRED)
682
- find_package (SDL2_mixer REQUIRED)
713
+ if (LINK_MPG123)
714
+ find_package (MPG123 REQUIRED)
715
+ endif ()
683
716
684
717
if (${TARGET_PLATFORM} STREQUAL "android" )
685
718
add_library (${SHORT_NAME} SHARED ${SDL2_ANDROID_HOOK} ${SOURCE_FILES} )
686
719
else ()
687
720
add_executable (${SHORT_NAME} WIN32 ${SOURCE_FILES} )
688
721
endif ()
689
722
723
+ if (${TARGET_PLATFORM} STREQUAL "emscripten" )
724
+ set (CMAKE_EXECUTABLE_SUFFIX .html)
725
+ set_target_properties (${SHORT_NAME} PROPERTIES LINK_FLAGS "-lidbfs.js -s SINGLE_FILE=1 -s DEMANGLE_SUPPORT=1 -s DYNCALLS=1 --shell-file ${PROJECT_SOURCE_DIR} /res/shell.html --preload-file ${PROJECT_SOURCE_DIR} /assets@/assets -s INITIAL_MEMORY=268435456 -s ALLOW_MEMORY_GROWTH=1 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 -s SAFE_HEAP=1 -s INVOKE_RUN=0 -s EXPORTED_FUNCTIONS=[\" _main\" ] -s EXPORTED_RUNTIME_METHODS=[\" callMain\" ,\" FS\" ] --bind" )
726
+ endif ()
727
+
690
728
if (MSVC )
691
729
add_compile_definitions (_CRT_SECURE_NO_WARNINGS)
692
730
endif ()
@@ -753,8 +791,12 @@ if(APPLE)
753
791
" BUNDLE DESTINATION ${CMAKE_BINARY_DIR} )
754
792
endif ()
755
793
756
- include_directories (${SDL2_INCLUDE_DIR} )
757
- include_directories (${SDL2_MIXER_INCLUDE_DIR} )
794
+ if (SDL2_INCLUDE_DIR)
795
+ include_directories (${SDL2_INCLUDE_DIR} )
796
+ endif ()
797
+ if (SDL2_MIXER_INCLUDE_DIR)
798
+ include_directories (${SDL2_MIXER_INCLUDE_DIR} )
799
+ endif ()
758
800
759
801
if (SYSTEM_LIBS)
760
802
find_package (ZLIB)
@@ -903,6 +945,9 @@ else()
903
945
find_library (android-lib android)
904
946
target_link_libraries (${SHORT_NAME} ${log -lib} ${android-lib})
905
947
endif ()
948
+ if (LINK_MPG123)
949
+ target_link_libraries (${SHORT_NAME} ${MPG123_LIBRARY} )
950
+ endif ()
906
951
target_link_libraries (${SHORT_NAME} ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY} )
907
952
if (NOT APPLE AND NOT ${TARGET_PLATFORM} STREQUAL "android" )
908
953
install (TARGETS ${SHORT_NAME} RUNTIME DESTINATION bin)
0 commit comments