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 Sep 13, 2019
1 parent 14f8c93 commit e9881f2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
62 changes: 54 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ if(HAIKU)
set(ASAN OFF)
endif()

if(ANDROID)
set(ASAN OFF)
endif()

if(DIST)
set(sodium_USE_STATIC_LIBS ON)
endif()
Expand All @@ -65,13 +69,15 @@ if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()

find_package(Threads REQUIRED)
find_package(SDL2 CONFIG QUIET)
if (NOT SDL2_FOUND)
find_package(SDL2 REQUIRED)
if (NOT ANDROID)
find_package(SDL2 CONFIG QUIET)
if (NOT SDL2_FOUND)
find_package(SDL2 REQUIRED)
endif()
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(sodium REQUIRED)
endif()
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(sodium REQUIRED)

add_library(smacker STATIC
3rdParty/libsmacker/smk_bitstream.c
Expand Down Expand Up @@ -171,7 +177,7 @@ add_library(devilution STATIC
Source/trigs.cpp
Source/wave.cpp)

add_executable(devilutionx
SET(devilutionx_SRCS
SourceX/dx.cpp
SourceX/miniwin/misc.cpp
SourceX/miniwin/misc_io.cpp
Expand Down Expand Up @@ -205,6 +211,32 @@ add_executable(devilutionx
SourceX/DiabloUI/title.cpp
SourceX/main.cpp)

if (NOT ANDROID)
add_executable(devilutionx
${devilutionx_SRCS})
else()
add_library(devilutionx SHARED
${devilutionx_SRCS})
endif()

if (ANDROID)
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/include
${CMAKE_CURRENT_SOURCE_DIR}/android-project/SDL2_ttf/include
)

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)
endif()

target_include_directories(devilution PUBLIC Source SourceS)
target_include_directories(devilutionx PRIVATE
SourceX
Expand All @@ -218,11 +250,21 @@ target_link_libraries(devilutionx PRIVATE
PKWare
StormLib
smacker
Radon
Radon)

if (NOT ANDROID)
target_link_libraries(devilutionx PRIVATE
SDL2::SDL2main
SDL2::SDL2_ttf
SDL2::SDL2_mixer
sodium)
else()
target_link_libraries(devilutionx PRIVATE
SDL2
SDL2_ttf
SDL2_mixer
${CMAKE_CURRENT_SOURCE_DIR}/android-project/app/libs/jni/${ANDROID_ARCH_NAME}/libsodiumjni.so)
endif()

target_compile_definitions(devilution PRIVATE DEVILUTION_ENGINE)
target_compile_definitions(devilution PUBLIC
Expand Down Expand Up @@ -289,3 +331,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Silence appfat.cpp warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
endif()

if (ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-security")
endif()
6 changes: 4 additions & 2 deletions SourceX/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ static std::string build_cmdline(int argc, char **argv)
return str;
}

#ifdef __ANDROID__
int SDL_main(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
auto cmdline = build_cmdline(argc, argv);
return dvl::WinMain(NULL, NULL, (char *)cmdline.c_str(), 0);
}


8 changes: 5 additions & 3 deletions SourceX/storm/storm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ bool directFileAccess = false;
static std::string getIniPath()
{
char path[DVL_MAX_PATH];
int len = GetModuleFileNameA(ghInst, path, DVL_MAX_PATH);
path[len - 1] = '/';
strcat(path, "diablo.ini");
char *name = SDL_GetPrefPath("diasurgical", "devilution");
strncpy(path, name, DVL_MAX_PATH);
SDL_free(name);

strncat(path, "diablo.ini", DVL_MAX_PATH - strlen(path) - 1);

return path;
}
Expand Down

0 comments on commit e9881f2

Please sign in to comment.