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.
pull/3236/head
elsid 2 years ago
parent 2e0e0f53b6
commit 9b0362fba8
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -1,22 +1,25 @@
# local files set(OPENMW_SOURCES
set(GAME
main.cpp
engine.cpp engine.cpp
options.cpp options.cpp
)
set(OPENMW_RESOURCES
${CMAKE_SOURCE_DIR}/files/windows/openmw.rc ${CMAKE_SOURCE_DIR}/files/windows/openmw.rc
${CMAKE_SOURCE_DIR}/files/windows/openmw.exe.manifest ${CMAKE_SOURCE_DIR}/files/windows/openmw.exe.manifest
) )
if (ANDROID) if (ANDROID)
set(GAME ${GAME} android_main.cpp) set(OPENMW_SOURCES ${OPENMW_SOURCES} android_main.cpp)
endif() endif()
set(GAME_HEADER set(OPENMW_HEADERS
doc.hpp
engine.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 add_openmw_dir (mwrender
actors objects renderingmanager animation rotatecontroller sky skyutil npcanimation esm4npcanimation vismask actors objects renderingmanager animation rotatecontroller sky skyutil npcanimation esm4npcanimation vismask
@ -120,16 +123,27 @@ add_openmw_dir (mwbase
# Main executable # Main executable
if (NOT ANDROID) if (NOT ANDROID)
openmw_add_executable(openmw add_library(openmw-lib STATIC
${OPENMW_FILES} ${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} ${APPLE_BUNDLE_RESOURCES}
${OPENMW_RESOURCES}
main.cpp
) )
target_link_libraries(openmw openmw-lib)
else () else ()
add_library(openmw add_library(openmw-lib SHARED
SHARED
${OPENMW_FILES} ${OPENMW_FILES}
${GAME} ${GAME_HEADER} ${OPENMW_SOURCES}
) )
endif () endif ()
@ -139,7 +153,7 @@ include_directories(
${FFmpeg_INCLUDE_DIRS} ${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 # CMake's built-in OSG finder does not use pkgconfig, so we have to
# manually ensure the order is correct for inter-library dependencies. # manually ensure the order is correct for inter-library dependencies.
# This only makes a difference with `-DOPENMW_USE_SYSTEM_OSG=ON -DOSG_STATIC=ON`. # 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) if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
target_precompile_headers(openmw PRIVATE target_precompile_headers(openmw-lib PRIVATE
<boost/program_options/options_description.hpp> <boost/program_options/options_description.hpp>
<sol/sol.hpp> <sol/sol.hpp>
@ -191,20 +205,20 @@ endif()
add_definitions(-DMYGUI_DONT_USE_OBSOLETE=ON) add_definitions(-DMYGUI_DONT_USE_OBSOLETE=ON)
if (ANDROID) if (ANDROID)
target_link_libraries(openmw EGL android log z) target_link_libraries(openmw-lib EGL android log z)
endif (ANDROID) endif (ANDROID)
if (USE_SYSTEM_TINYXML) if (USE_SYSTEM_TINYXML)
target_link_libraries(openmw ${TinyXML_LIBRARIES}) target_link_libraries(openmw-lib ${TinyXML_LIBRARIES})
endif() endif()
if (NOT UNIX) if (NOT UNIX)
target_link_libraries(openmw ${SDL2MAIN_LIBRARY}) target_link_libraries(openmw-lib ${SDL2MAIN_LIBRARY})
endif() endif()
# Fix for not visible pthreads functions for linker with glibc 2.15 # Fix for not visible pthreads functions for linker with glibc 2.15
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
target_link_libraries(openmw ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(openmw-lib ${CMAKE_THREAD_LIBS_INIT})
endif() endif()
if(APPLE) if(APPLE)
@ -236,8 +250,12 @@ if(APPLE)
endif(APPLE) endif(APPLE)
if (BUILD_WITH_CODE_COVERAGE) if (BUILD_WITH_CODE_COVERAGE)
target_compile_options(openmw PRIVATE --coverage) target_compile_options(openmw-lib PRIVATE --coverage)
target_link_libraries(openmw gcov) target_link_libraries(openmw-lib gcov)
if (NOT ANDROID)
target_compile_options(openmw PRIVATE --coverage)
target_link_libraries(openmw gcov)
endif()
endif() endif()
if (WIN32) if (WIN32)

Loading…
Cancel
Save