diff --git a/src/Bin/CodeGen/CMakeLists.txt b/src/Bin/CodeGen/CMakeLists.txt index 75a008692701..c70a359040f7 100644 --- a/src/Bin/CodeGen/CMakeLists.txt +++ b/src/Bin/CodeGen/CMakeLists.txt @@ -13,6 +13,6 @@ set(BIN_CODEGEN_HEADERS if(NOT BUILD_PLATFORM STREQUAL "android") add_executable(CodeGen ${BIN_CODEGEN_SOURCES} ${BIN_CODEGEN_HEADERS}) target_fix_libcxx_assertions(CodeGen) - target_link_libraries(CodeGen PUBLIC application CLI11::CLI11) + target_link_libraries(CodeGen PUBLIC platform_main application CLI11::CLI11) target_check_style(CodeGen) endif() diff --git a/src/Bin/OpenEnroth/CMakeLists.txt b/src/Bin/OpenEnroth/CMakeLists.txt index b86fe90fad84..80518d2c1a2b 100644 --- a/src/Bin/OpenEnroth/CMakeLists.txt +++ b/src/Bin/OpenEnroth/CMakeLists.txt @@ -11,15 +11,14 @@ if(BUILD_PLATFORM STREQUAL "android") add_library(main SHARED) target_sources(main PUBLIC ${BIN_OPENENROTH_HEADERS} ${BIN_OPENENROTH_SOURCES}) target_check_style(main) - target_link_libraries(main PUBLIC application CLI11::CLI11) + target_link_libraries(main PUBLIC platform_main application CLI11::CLI11) target_link_options(main PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libmain.map") else() add_executable(OpenEnroth MACOSX_BUNDLE) target_sources(OpenEnroth PUBLIC ${BIN_OPENENROTH_HEADERS} ${BIN_OPENENROTH_SOURCES}) target_check_style(OpenEnroth) target_fix_libcxx_assertions(OpenEnroth) - - target_link_libraries(OpenEnroth PUBLIC application CLI11::CLI11) + target_link_libraries(OpenEnroth PUBLIC platform_main application CLI11::CLI11) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT OpenEnroth) endif() diff --git a/src/Bin/OpenEnroth/libmain.map b/src/Bin/OpenEnroth/libmain.map index 1b3c234a7187..cb815c5811bd 100644 --- a/src/Bin/OpenEnroth/libmain.map +++ b/src/Bin/OpenEnroth/libmain.map @@ -1,6 +1,6 @@ /* Linker script used when linking libmain.so for Android. * Note that SDL_main is declared in SdlMain.cpp. */ { - global: SDL_main; - local: *; + global: SDL_main; + local: *; }; diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index ed087528d5d0..b9752d7596f4 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -17,7 +17,6 @@ set(PLATFORM_SOURCES Sdl/SdlEventLoop.cpp Sdl/SdlGamepad.cpp Sdl/SdlLogger.cpp - Sdl/SdlMain.cpp Sdl/SdlOpenGLContext.cpp Sdl/SdlPlatform.cpp Sdl/SdlPlatformSharedState.cpp @@ -64,6 +63,16 @@ else() list(APPEND PLATFORM_SOURCES Posix/PosixPlatform.cpp) endif() +set(PLATFORM_MAIN_SOURCES + Sdl/SdlMain.cpp) + +set(PLATFORM_MAIN_HEADERS) + +# Need to have main in an OBJECT lib so that it's properly exported from Android .so. +add_library(platform_main OBJECT ${PLATFORM_MAIN_SOURCES} ${PLATFORM_MAIN_HEADERS}) +target_check_style(platform_main) +target_link_libraries(platform_main PRIVATE SDL2::SDL2OE) + add_library(platform STATIC ${PLATFORM_SOURCES} ${PLATFORM_HEADERS}) target_check_style(platform) target_link_libraries(platform PRIVATE SDL2::SDL2OE) diff --git a/src/Platform/Sdl/SdlMain.cpp b/src/Platform/Sdl/SdlMain.cpp index 8c32fcd93798..2dfa993e42a9 100644 --- a/src/Platform/Sdl/SdlMain.cpp +++ b/src/Platform/Sdl/SdlMain.cpp @@ -2,8 +2,7 @@ int platformMain(int argc, char **argv); -// This gets #defined by SDL into SDL_main. Marking it as extern "C" is important for name mangling as on Android -// it gets exported from the resulting .so. -extern "C" int main(int argc, char **argv) { +// This gets #defined by SDL into SDL_main. +int main(int argc, char **argv) { return platformMain(argc, argv); } diff --git a/test/Bin/GameTest/CMakeLists.txt b/test/Bin/GameTest/CMakeLists.txt index 288e0021ae84..bb19b970a9f4 100644 --- a/test/Bin/GameTest/CMakeLists.txt +++ b/test/Bin/GameTest/CMakeLists.txt @@ -10,7 +10,7 @@ if(OE_BUILD_TESTS) add_executable(OpenEnroth_GameTest ${GAME_TEST_MAIN_SOURCES} ${GAME_TEST_MAIN_HEADERS}) target_fix_libcxx_assertions(OpenEnroth_GameTest) - target_link_libraries(OpenEnroth_GameTest PUBLIC application testing_game GTest::gtest CLI11::CLI11) + target_link_libraries(OpenEnroth_GameTest PUBLIC platform_main application testing_game GTest::gtest CLI11::CLI11) target_check_style(OpenEnroth_GameTest)