From 9b0362fba888aaf5648e329b04aed4e357669719 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 11 Mar 2023 13:16:27 +0100 Subject: [PATCH] Split openmw into binary and library To make it possible to create a new binary for the tests by linking this library to it. Rename openmw-lib into openmw to have libopenmw.a on Linux. Do not rename it on Windows to avoid conflict with automatically generated lib for exe due to __declspec(dllexport) presence. --- apps/openmw/CMakeLists.txt | 56 +++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b1d17b0a61..7ea3421ed4 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -1,22 +1,25 @@ -# local files -set(GAME - main.cpp +set(OPENMW_SOURCES engine.cpp options.cpp +) +set(OPENMW_RESOURCES ${CMAKE_SOURCE_DIR}/files/windows/openmw.rc ${CMAKE_SOURCE_DIR}/files/windows/openmw.exe.manifest ) if (ANDROID) - set(GAME ${GAME} android_main.cpp) + set(OPENMW_SOURCES ${OPENMW_SOURCES} android_main.cpp) endif() -set(GAME_HEADER +set(OPENMW_HEADERS + doc.hpp engine.hpp + options.hpp + profile.hpp ) -source_group(game FILES ${GAME} ${GAME_HEADER}) +source_group(apps/openmw FILES main.cpp ${OPENMW_SOURCES} ${OPENMW_HEADERS} ${OPENMW_RESOURCES}) add_openmw_dir (mwrender actors objects renderingmanager animation rotatecontroller sky skyutil npcanimation esm4npcanimation vismask @@ -120,16 +123,27 @@ add_openmw_dir (mwbase # Main executable if (NOT ANDROID) - openmw_add_executable(openmw + add_library(openmw-lib STATIC ${OPENMW_FILES} - ${GAME} ${GAME_HEADER} + ${OPENMW_SOURCES} + ) + + # Otherwise linker fails with LNK1149 because main.cpp has __declspec(dllexport) + if(NOT WIN32) + set_target_properties(openmw-lib PROPERTIES OUTPUT_NAME openmw) + endif() + + openmw_add_executable(openmw ${APPLE_BUNDLE_RESOURCES} + ${OPENMW_RESOURCES} + main.cpp ) + + target_link_libraries(openmw openmw-lib) else () - add_library(openmw - SHARED + add_library(openmw-lib SHARED ${OPENMW_FILES} - ${GAME} ${GAME_HEADER} + ${OPENMW_SOURCES} ) endif () @@ -139,7 +153,7 @@ include_directories( ${FFmpeg_INCLUDE_DIRS} ) -target_link_libraries(openmw +target_link_libraries(openmw-lib # CMake's built-in OSG finder does not use pkgconfig, so we have to # manually ensure the order is correct for inter-library dependencies. # This only makes a difference with `-DOPENMW_USE_SYSTEM_OSG=ON -DOSG_STATIC=ON`. @@ -163,7 +177,7 @@ target_link_libraries(openmw ) if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC) - target_precompile_headers(openmw PRIVATE + target_precompile_headers(openmw-lib PRIVATE @@ -191,20 +205,20 @@ endif() add_definitions(-DMYGUI_DONT_USE_OBSOLETE=ON) if (ANDROID) - target_link_libraries(openmw EGL android log z) + target_link_libraries(openmw-lib EGL android log z) endif (ANDROID) if (USE_SYSTEM_TINYXML) - target_link_libraries(openmw ${TinyXML_LIBRARIES}) + target_link_libraries(openmw-lib ${TinyXML_LIBRARIES}) endif() if (NOT UNIX) - target_link_libraries(openmw ${SDL2MAIN_LIBRARY}) + target_link_libraries(openmw-lib ${SDL2MAIN_LIBRARY}) endif() # Fix for not visible pthreads functions for linker with glibc 2.15 if (UNIX AND NOT APPLE) - target_link_libraries(openmw ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(openmw-lib ${CMAKE_THREAD_LIBS_INIT}) endif() if(APPLE) @@ -236,8 +250,12 @@ if(APPLE) endif(APPLE) if (BUILD_WITH_CODE_COVERAGE) - target_compile_options(openmw PRIVATE --coverage) - target_link_libraries(openmw gcov) + target_compile_options(openmw-lib PRIVATE --coverage) + target_link_libraries(openmw-lib gcov) + if (NOT ANDROID) + target_compile_options(openmw PRIVATE --coverage) + target_link_libraries(openmw gcov) + endif() endif() if (WIN32)