added emscripten build to cmake

This commit is contained in:
Vadim Grigoruk 2018-06-06 17:50:52 +03:00
parent 7fb6a86484
commit 5fcc7c99e0
2 changed files with 47 additions and 30 deletions

1
.gitignore vendored
View File

@ -129,3 +129,4 @@ CMakeFiles/
lib/ lib/
*.cmake *.cmake
CMakeCache.txt CMakeCache.txt
Makefile

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.9)
project(TIC-80 C) project(TIC-80 C)
message("Building for target : ${CMAKE_SYSTEM_NAME}") message("Building for target : ${CMAKE_SYSTEM_NAME}")
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
set(LINUX TRUE) set(LINUX TRUE)
endif() endif()
@ -29,6 +29,11 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
endif() endif()
if(EMSCRIPTEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_SDL=2 -s TOTAL_MEMORY=67108864 --pre-js build/html/prejs.js --memory-init-file 0")
# TODO: add: -s \'EXTRA_EXPORTED_RUNTIME_METHODS=[\"writeArrayToMemory\"]\'
endif()
endif() endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
@ -170,35 +175,41 @@ target_link_libraries(tic80core lua lpeg wren giflib)
# SDL2 # SDL2
################################ ################################
if(WIN32) if(NOT EMSCRIPTEN)
set(HAVE_LIBC TRUE)
endif()
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) if(WIN32)
add_subdirectory(3rd-party/SDL2-2.0.7) set(HAVE_LIBC TRUE)
endif()
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
add_subdirectory(3rd-party/SDL2-2.0.7)
endif()
################################ ################################
# SDL2 renderer example # SDL2 renderer example
################################ ################################
set(EXAMPLE_DIR examples) if(NOT EMSCRIPTEN)
set(EXAMPLE_SRC set(EXAMPLE_DIR examples)
${EXAMPLE_DIR}/sdl-renderer.c set(EXAMPLE_SRC
) ${EXAMPLE_DIR}/sdl-renderer.c
)
if(WIN32) if(WIN32)
add_executable(sdl-renderer WIN32 ${EXAMPLE_SRC}) add_executable(sdl-renderer WIN32 ${EXAMPLE_SRC})
else() else()
add_executable(sdl-renderer ${EXAMPLE_SRC}) add_executable(sdl-renderer ${EXAMPLE_SRC})
endif()
target_include_directories(sdl-renderer PRIVATE 3rd-party/SDL2-2.0.7/include)
target_include_directories(sdl-renderer PRIVATE include)
target_include_directories(sdl-renderer PRIVATE src)
add_dependencies(sdl-renderer tic80core SDL2-static SDL2main)
target_link_libraries(sdl-renderer tic80core SDL2-static SDL2main)
endif() endif()
target_include_directories(sdl-renderer PRIVATE 3rd-party/SDL2-2.0.7/include)
target_include_directories(sdl-renderer PRIVATE include)
target_include_directories(sdl-renderer PRIVATE src)
add_dependencies(sdl-renderer tic80core SDL2-static SDL2main)
target_link_libraries(sdl-renderer tic80core SDL2-static SDL2main)
################################ ################################
# SDL GPU # SDL GPU
################################ ################################
@ -224,7 +235,11 @@ set(SDLGPU_SRC
add_library(sdlgpu STATIC ${SDLGPU_SRC}) add_library(sdlgpu STATIC ${SDLGPU_SRC})
target_compile_definitions(sdlgpu PRIVATE GLEW_STATIC SDL_GPU_DISABLE_GLES SDL_GPU_DISABLE_OPENGL_3 SDL_GPU_DISABLE_OPENGL_4) if(EMSCRIPTEN)
target_compile_definitions(sdlgpu PRIVATE GLEW_STATIC DSDL_GPU_DISABLE_OPENGL SDL_GPU_DISABLE_GLES_1 SDL_GPU_DISABLE_GLES_3)
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 PRIVATE 3rd-party/sdl-gpu/include) target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/include)
target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/src/externals/glew) target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/src/externals/glew)
@ -233,8 +248,8 @@ target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/src/externals/stb_im
target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/src/externals/stb_image_write) target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/src/externals/stb_image_write)
target_include_directories(sdlgpu PRIVATE 3rd-party/SDL2-2.0.7/include) target_include_directories(sdlgpu PRIVATE 3rd-party/SDL2-2.0.7/include)
add_dependencies(sdlgpu SDL2-static) #add_dependencies(sdlgpu SDL2-static)
target_link_libraries(sdlgpu SDL2-static) #target_link_libraries(sdlgpu SDL2-static)
if(WIN32) if(WIN32)
target_link_libraries(sdlgpu opengl32) target_link_libraries(sdlgpu opengl32)
@ -277,10 +292,6 @@ set(ZLIB_SRC
${ZLIB_DIR}/compress.c ${ZLIB_DIR}/compress.c
${ZLIB_DIR}/crc32.c ${ZLIB_DIR}/crc32.c
${ZLIB_DIR}/deflate.c ${ZLIB_DIR}/deflate.c
${ZLIB_DIR}/gzclose.c
${ZLIB_DIR}/gzlib.c
${ZLIB_DIR}/gzread.c
${ZLIB_DIR}/gzwrite.c
${ZLIB_DIR}/inflate.c ${ZLIB_DIR}/inflate.c
${ZLIB_DIR}/infback.c ${ZLIB_DIR}/infback.c
${ZLIB_DIR}/inftrees.c ${ZLIB_DIR}/inftrees.c
@ -363,8 +374,13 @@ target_include_directories(tic80 PRIVATE 3rd-party/SDL2-2.0.7/include)
target_include_directories(tic80 PRIVATE 3rd-party/sdl-gpu/include) target_include_directories(tic80 PRIVATE 3rd-party/sdl-gpu/include)
target_include_directories(tic80 PRIVATE 3rd-party/SDL2_net-2.0.1) target_include_directories(tic80 PRIVATE 3rd-party/SDL2_net-2.0.1)
add_dependencies(tic80 tic80lib sdlgpu sdlnet SDL2main) if(NOT EMSCRIPTEN)
target_link_libraries(tic80 tic80lib sdlgpu sdlnet SDL2main) add_dependencies(tic80 SDL2-static SDL2main)
target_link_libraries(tic80 SDL2-static SDL2main)
endif()
add_dependencies(tic80 tic80lib sdlnet sdlgpu)
target_link_libraries(tic80 tic80lib sdlnet sdlgpu)
if(LINUX) if(LINUX)
include(FindPkgConfig) include(FindPkgConfig)