diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e3070997d0..36d24e8eaf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/SourceX/main.cpp b/SourceX/main.cpp index 63acbcc4f98..71356b5f2d2 100644 --- a/SourceX/main.cpp +++ b/SourceX/main.cpp @@ -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); } - - diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 78ba2a3acb0..ad318723d66 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -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; }