Skip to content

Commit

Permalink
Move platform_main into an OBJECT lib
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Sep 19, 2023
1 parent 96a7822 commit 8862ac1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Bin/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 2 additions & 3 deletions src/Bin/OpenEnroth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions src/Bin/OpenEnroth/libmain.map
Original file line number Diff line number Diff line change
@@ -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: *;
};
11 changes: 10 additions & 1 deletion src/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
5 changes: 2 additions & 3 deletions src/Platform/Sdl/SdlMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion test/Bin/GameTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8862ac1

Please sign in to comment.