Skip to content

Commit

Permalink
Android port (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkszysiu authored and AJenbo committed Oct 25, 2020
1 parent 72e2637 commit 7265095
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 32 deletions.
105 changes: 73 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ if(AMIGA)
include(amiga_defs)
endif()

if(ANDROID)
set(ASAN OFF)
set(UBSAN OFF)
set(NONET ON)
endif()

if(DIST)
set(sodium_USE_STATIC_LIBS ON)
endif()
Expand All @@ -137,22 +143,21 @@ if(NOT NONET)
find_package(sodium REQUIRED)
endif()

if(USE_SDL1)
find_package(SDL REQUIRED)
find_package(SDL_ttf REQUIRED)
find_package(SDL_mixer REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
else()
if(SWITCH)
find_package(SDL2_STATIC CONFIG QUIET)
if (NOT ANDROID)
if(USE_SDL1)
find_package(SDL REQUIRED)
find_package(SDL_ttf REQUIRED)
find_package(SDL_mixer REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
else()
find_package(SDL2 MODULE QUIET)
endif()
if (NOT SDL2_FOUND)
find_package(SDL2 REQUIRED)
if(SWITCH)
find_package(SDL2_STATIC CONFIG QUIET)
else()
find_package(SDL2 MODULE QUIET)
endif()
if (NOT SDL2_FOUND)
find_package(SDL2 REQUIRED)
endif()
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
endif()

add_library(smacker STATIC
Expand Down Expand Up @@ -299,11 +304,9 @@ set(devilutionx_SRCS
SourceX/DiabloUI/text.cpp
SourceX/DiabloUI/title.cpp
SourceX/DiabloUI/ttf_render_wrapped.cpp
SourceX/main.cpp
SourceX/devilutionx.exe.manifest
Packaging/macOS/AppIcon.icns
Packaging/resources/CharisSILB.ttf
Packaging/windows/devilutionx.rc)
SourceX/main.cpp)

set(BIN_TARGET devilutionx)

if(NOT NONET)
list(APPEND devilutionx_SRCS
Expand All @@ -312,8 +315,6 @@ if(NOT NONET)
SourceX/dvlnet/udp_p2p.cpp)
endif()

set(BIN_TARGET devilutionx)

if(SWITCH)
list(APPEND devilutionx_SRCS
SourceX/platform/switch/network.cpp
Expand Down Expand Up @@ -345,7 +346,19 @@ if(HELLFIRE)
add_definitions(-DHELLFIRE)
endif()

add_executable(${BIN_TARGET} WIN32 MACOSX_BUNDLE ${devilutionx_SRCS})
if (NOT ANDROID)
add_executable(${BIN_TARGET}
WIN32
MACOSX_BUNDLE
${devilutionx_SRCS}
SourceX/devilutionx.exe.manifest
Packaging/macOS/AppIcon.icns
Packaging/resources/CharisSILB.ttf
Packaging/windows/devilutionx.rc)
else()
add_library(devilutionx SHARED ${devilutionx_SRCS})
endif()


# Copy the font to the build directory to it works from the build directory
file(COPY "Packaging/resources/CharisSILB.ttf" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
Expand Down Expand Up @@ -376,6 +389,33 @@ if(RUN_TESTS)
gtest_add_tests(${BIN_TARGET} "" AUTO)
endif()

if (ANDROID)
target_include_directories(devilution PUBLIC
SourceX
${CMAKE_CURRENT_SOURCE_DIR}/android-project/app/libs/include
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2/include

# SDL_internal.h is located in src required by SDL_android_main.c bridge
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2/src

${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_mixer
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_ttf)
target_include_directories(devilutionx PUBLIC
SourceX
${CMAKE_CURRENT_SOURCE_DIR}/android-project/app/libs/include
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2/include

# SDL_internal.h is located in src required by SDL_android_main.c bridge
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2/src

${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_mixer
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_ttf)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2/ ${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_mixer/ ${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_mixer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_ttf/ ${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_ttf)
configure_file(SourceS/config.h.in config.h @ONLY)
endif()
target_include_directories(devilution PUBLIC Source SourceS ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${BIN_TARGET} PRIVATE
SourceX
Expand Down Expand Up @@ -478,17 +518,18 @@ foreach(target devilution ${BIN_TARGET})
target_compile_options(${target} PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>)
target_link_libraries(${target} PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>)

if(USE_SDL1)
target_link_libraries(${target} PRIVATE
${SDL_TTF_LIBRARY}
${SDL_MIXER_LIBRARY}
${SDL_LIBRARY})
target_compile_definitions(${target} PRIVATE USE_SDL1)
if (NOT ANDROID)
if(USE_SDL1)
target_link_libraries(${target} PRIVATE
${SDL_TTF_LIBRARY}
${SDL_MIXER_LIBRARY}
${SDL_LIBRARY})
target_compile_definitions(${target} PRIVATE USE_SDL1)
else()
target_link_libraries(${target} PRIVATE
SDL2::SDL2main
SDL2::SDL2_ttf
SDL2::SDL2_mixer)
target_link_libraries(devilutionx PRIVATE
SDL2
SDL2_ttf
SDL2_mixer)
endif()

if(SWITCH)
Expand Down
5 changes: 5 additions & 0 deletions SourceX/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ extern "C" const char *__asan_default_options()
}
#endif


#ifdef __ANDROID__
int SDL_main(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
#ifdef RUN_TESTS
testing::InitGoogleTest(&argc, argv);
Expand Down
4 changes: 4 additions & 0 deletions SourceX/storm/storm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void GetBasePath(char *buffer, size_t size)
return;
}

#ifdef __ANDROID__
snprintf(buffer, size, "%s", "/sdcard/");
#else
char *path = SDL_GetBasePath();
if (path == NULL) {
SDL_Log(SDL_GetError());
Expand All @@ -60,6 +63,7 @@ void GetBasePath(char *buffer, size_t size)

snprintf(buffer, size, "%s", path);
SDL_free(path);
#endif
}

void GetPrefPath(char *buffer, size_t size)
Expand Down

0 comments on commit 7265095

Please sign in to comment.