From 455be9dbbbeccfcbb9a222aa94777d1c79bcf687 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 6 Mar 2021 19:21:23 +0000 Subject: [PATCH] Fix linking with `-DOPENMW_USE_SYSTEM_OSG=ON -DOSG_STATIC=ON` 1. CMake's built-in OSG finder does not use pkgconfig, so we have to manually ensure the order is correct for inter-library dependencies. https://gitlab.kitware.com/cmake/cmake/-/issues/21701 2. OSG plugin pkgconfig files are missing dependencies on the underlying libraries (e.g. freetype, png, jpeg), so we have to link them manually. https://github.com/openscenegraph/OpenSceneGraph/issues/1052 --- apps/opencs/CMakeLists.txt | 23 +++++++++++++++++------ apps/openmw/CMakeLists.txt | 22 +++++++++++++++++----- components/CMakeLists.txt | 26 ++++++++++++++++---------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 8be1fa4d30..65575580ad 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -215,12 +215,16 @@ if(APPLE) endif(APPLE) target_link_libraries(openmw-cs - ${OSG_LIBRARIES} - ${OSGTEXT_LIBRARIES} - ${OSGUTIL_LIBRARIES} + # 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`. + # https://gitlab.kitware.com/cmake/cmake/-/issues/21701 ${OSGVIEWER_LIBRARIES} - ${OSGGA_LIBRARIES} ${OSGFX_LIBRARIES} + ${OSGGA_LIBRARIES} + ${OSGUTIL_LIBRARIES} + ${OSGTEXT_LIBRARIES} + ${OSG_LIBRARIES} ${EXTERN_OSGQT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} @@ -233,17 +237,24 @@ if(OSG_STATIC) add_library(openmw_cs_osg_plugins INTERFACE) foreach(_plugin ${USED_OSG_PLUGINS}) string(TOUPPER ${_plugin} _plugin_uc) - if (${_plugin_uc}_LIBRARY MATCHES "[/.]") + if(OPENMW_USE_SYSTEM_OSG) list(APPEND _osg_plugins_static_files ${${_plugin_uc}_LIBRARY}) else() list(APPEND _osg_plugins_static_files $) + target_link_libraries(openmw_cs_osg_plugins INTERFACE $) + add_dependencies(openmw_cs_osg_plugins ${${_plugin_uc}_LIBRARY}) endif() - target_link_libraries(openmw_cs_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() # We use --whole-archive because OSG plugins use registration. get_whole_archive_options(_opts ${_osg_plugins_static_files}) target_link_options(openmw_cs_osg_plugins INTERFACE ${_opts}) target_link_libraries(openmw-cs openmw_cs_osg_plugins) + + if(OPENMW_USE_SYSTEM_OSG) + # OSG plugin pkgconfig files are missing these dependencies. + # https://github.com/openscenegraph/OpenSceneGraph/issues/1052 + target_link_libraries(openmw freetype jpeg png) + endif() endif(OSG_STATIC) target_link_libraries(openmw-cs Qt5::Widgets Qt5::Core Qt5::Network Qt5::OpenGL) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index dda517c44b..5e5bb8a9f6 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -122,13 +122,18 @@ include_directories( ) target_link_libraries(openmw - ${OSG_LIBRARIES} + # 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`. + # https://gitlab.kitware.com/cmake/cmake/-/issues/21701 ${OSGPARTICLE_LIBRARIES} - ${OSGUTIL_LIBRARIES} - ${OSGDB_LIBRARIES} ${OSGVIEWER_LIBRARIES} ${OSGGA_LIBRARIES} ${OSGSHADOW_LIBRARIES} + ${OSGDB_LIBRARIES} + ${OSGUTIL_LIBRARIES} + ${OSG_LIBRARIES} + ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} @@ -148,17 +153,24 @@ if(OSG_STATIC) add_library(openmw_osg_plugins INTERFACE) foreach(_plugin ${USED_OSG_PLUGINS}) string(TOUPPER ${_plugin} _plugin_uc) - if (${_plugin_uc}_LIBRARY MATCHES "[/.]") + if(OPENMW_USE_SYSTEM_OSG) list(APPEND _osg_plugins_static_files ${${_plugin_uc}_LIBRARY}) else() list(APPEND _osg_plugins_static_files $) + target_link_libraries(openmw_osg_plugins INTERFACE $) + add_dependencies(openmw_osg_plugins ${${_plugin_uc}_LIBRARY}) endif() - target_link_libraries(openmw_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() # We use --whole-archive because OSG plugins use registration. get_whole_archive_options(_opts ${_osg_plugins_static_files}) target_link_options(openmw_osg_plugins INTERFACE ${_opts}) target_link_libraries(openmw openmw_osg_plugins) + + if(OPENMW_USE_SYSTEM_OSG) + # OSG plugin pkgconfig files are missing these dependencies. + # https://github.com/openscenegraph/OpenSceneGraph/issues/1052 + target_link_libraries(openmw freetype jpeg png) + endif() endif(OSG_STATIC) if (ANDROID) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 2120afc1a4..4da75c97ca 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -223,20 +223,26 @@ include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR}) target_link_libraries(components + # 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`. + # https://gitlab.kitware.com/cmake/cmake/-/issues/21701 + ${OSGPARTICLE_LIBRARIES} + ${OSGVIEWER_LIBRARIES} + ${OSGSHADOW_LIBRARIES} + ${OSGANIMATION_LIBRARIES} + ${OSGGA_LIBRARIES} + ${OSGTEXT_LIBRARIES} + ${OSGDB_LIBRARIES} + ${OSGUTIL_LIBRARIES} + ${OSG_LIBRARIES} + ${OPENTHREADS_LIBRARIES} + ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_IOSTREAMS_LIBRARY} - ${OSG_LIBRARIES} - ${OPENTHREADS_LIBRARIES} - ${OSGPARTICLE_LIBRARIES} - ${OSGUTIL_LIBRARIES} - ${OSGDB_LIBRARIES} - ${OSGVIEWER_LIBRARIES} - ${OSGTEXT_LIBRARIES} - ${OSGGA_LIBRARIES} - ${OSGSHADOW_LIBRARIES} - ${OSGANIMATION_LIBRARIES} + ${SDL2_LIBRARIES} ${OPENGL_gl_LIBRARY} ${MyGUI_LIBRARIES}