diff --git a/CI/before_script.osx.sh b/CI/before_script.osx.sh index 164208f49..c3822291d 100755 --- a/CI/before_script.osx.sh +++ b/CI/before_script.osx.sh @@ -17,7 +17,6 @@ cmake \ -D CMAKE_BUILD_TYPE=Debug \ -D OPENMW_OSX_DEPLOYMENT=TRUE \ -D DESIRED_QT_VERSION=5 \ --D OSG_PLUGIN_LIB_SEARCH_PATH="$DEPENDENCIES_ROOT/lib/osgPlugins-3.4.0" \ -D BUILD_ESMTOOL=FALSE \ -D BUILD_MYGUI_PLUGIN=FALSE \ -G"Unix Makefiles" \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d73644b4..77ff2416d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,55 +221,16 @@ IF(BOOST_STATIC) endif() find_package(OpenSceneGraph 3.3.4 REQUIRED osgDB osgViewer osgText osgGA osgAnimation osgParticle osgUtil osgFX) - include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}) +get_filename_component(OSG_LIB_DIR ${OSGDB_LIBRARY} DIRECTORY) +set(OSGPlugins_LIB_DIR "${OSG_LIB_DIR}/osgPlugins-${OPENSCENEGRAPH_VERSION}") + if(OSG_STATIC) - macro(use_static_osg_plugin_library PLUGIN_NAME) - set(PLUGIN_NAME_DBG ${PLUGIN_NAME}d ${PLUGIN_NAME}D ${PLUGIN_NAME}_d ${PLUGIN_NAME}_D ${PLUGIN_NAME}_debug ${PLUGIN_NAME}) - - # For now, users wishing to do a static build will need to pass the path to where the plugins reside - # More clever logic would need to deduce the path, probably installed under /lib/osgPlugins- - include(FindPkgMacros) - find_library(${PLUGIN_NAME}_LIBRARY_REL NAMES ${PLUGIN_NAME} HINTS ${OSG_PLUGIN_LIB_SEARCH_PATH}) - find_library(${PLUGIN_NAME}_LIBRARY_DBG NAMES ${PLUGIN_NAME_DBG} HINTS ${OSG_PLUGIN_LIB_SEARCH_PATH}) - make_library_set(${PLUGIN_NAME}_LIBRARY) - - if("${${PLUGIN_NAME}_LIBRARY}" STREQUAL "") - message(FATAL_ERROR "Unable to find static OpenSceneGraph plugin: ${PLUGIN_NAME}") - endif() + add_definitions(-DOSG_LIBRARY_STATIC) - set(OPENSCENEGRAPH_LIBRARIES ${OPENSCENEGRAPH_LIBRARIES} ${${PLUGIN_NAME}_LIBRARY}) - endmacro() - - add_definitions(-DOSG_LIBRARY_STATIC) - - set(PLUGIN_LIST - osgdb_png # depends on libpng, zlib - osgdb_tga - osgdb_dds - osgdb_jpeg # depends on libjpeg - ) - - foreach(PLUGIN ${PLUGIN_LIST}) - use_static_osg_plugin_library(${PLUGIN}) - endforeach() - - # OSG static plugins need to linked against their respective dependencies - set(PLUGIN_DEPS_LIST - PNG # needed by osgdb_png - ZLIB # needed by osgdb_png - JPEG # needed by osgdb_jpeg - ) - - macro(use_static_osg_plugin_dep DEPENDENCY) - find_package(${DEPENDENCY} REQUIRED) - - set(OPENSCENEGRAPH_LIBRARIES ${OPENSCENEGRAPH_LIBRARIES} ${${DEPENDENCY}_LIBRARIES}) - endmacro() - foreach(DEPENDENCY ${PLUGIN_DEPS_LIST}) - use_static_osg_plugin_dep(${DEPENDENCY}) - endforeach() + find_package(OSGPlugins REQUIRED COMPONENTS osgdb_png osgdb_tga osgdb_dds osgdb_jpeg) + list(APPEND OPENSCENEGRAPH_LIBRARIES ${OSGPlugins_LIBRARIES}) endif() if(QT_STATIC) @@ -764,11 +725,14 @@ if (APPLE) ) foreach (PLUGIN_NAME ${USED_OSG_PLUGINS}) - set(PLUGIN_ABS "${OSG_PLUGIN_LIB_SEARCH_PATH}/${PLUGIN_NAME}.so") + set(PLUGIN_ABS "${OSGPlugins_LIB_DIR}/${PLUGIN_NAME}.so") set(ABSOLUTE_PLUGINS ${PLUGIN_ABS} ${ABSOLUTE_PLUGINS}) endforeach () - get_filename_component(OSG_PLUGIN_PREFIX_DIR "${OSG_PLUGIN_LIB_SEARCH_PATH}" NAME) + get_filename_component(OSG_PLUGIN_PREFIX_DIR "${OSGPlugins_LIB_DIR}" NAME) + if (NOT OSG_PLUGIN_PREFIX_DIR) + message(FATAL_ERROR "Can't get directory name for OSG plugins from '${OSGPlugins_LIB_DIR}'") + endif() # installs used plugins in bundle at given path (bundle_path must be relative to ${CMAKE_INSTALL_PREFIX}) # and returns list of install paths for all installed plugins diff --git a/cmake/FindOSGPlugins.cmake b/cmake/FindOSGPlugins.cmake new file mode 100644 index 000000000..8220f33d4 --- /dev/null +++ b/cmake/FindOSGPlugins.cmake @@ -0,0 +1,50 @@ +# This module accepts the following env variable +# OSGPlugins_LIB_DIR - /lib/osgPlugins- , path to search plugins +# +# Once done this will define +# OSGPlugins_FOUND - System has the all required components. +# OSGPlugins_LIBRARIES - Link these to use the required osg plugins components. +# +# Components: +# - osgdb_png +# - osgdb_tga +# - osgdb_dds +# - osgdb_jpeg + +include(LibFindMacros) +include(Findosg_functions) + +if (NOT OSGPlugins_LIB_DIR) + set(_mode WARNING) + if (OSGPlugins_FIND_REQUIRED) + set(_mode FATAL_ERROR) + endif() + message(${_mode} "OSGPlugins_LIB_DIR variable must be set") +endif() + +foreach(_library ${OSGPlugins_FIND_COMPONENTS}) + string(TOUPPER ${_library} _library_uc) + set(_component OSGPlugins_${_library}) + + set(${_library_uc}_DIR ${OSGPlugins_LIB_DIR}) # to help function osg_find_library + set(_saved_lib_prefix ${CMAKE_FIND_LIBRARY_PREFIXES}) # save CMAKE_FIND_LIBRARY_PREFIXES + set(CMAKE_FIND_LIBRARY_PREFIXES "") # search libraries with no prefix + osg_find_library(${_library_uc} ${_library}) # find it into ${_library_uc}_LIBRARIES + set(CMAKE_FIND_LIBRARY_PREFIXES ${_saved_lib_prefix}) # restore prefix + + if (${_library_uc}_LIBRARIES) + set(${_component}_LIBRARY ${${_library_uc}_LIBRARIES}) # fake as if we call find_library + else() + set(${_component}_LIBRARY ${_component}_LIBRARY-NOTFOUND) + endif() + + list(APPEND OSGPlugins_PROCESS_LIBS ${_component}_LIBRARY) +endforeach() + +foreach(_dependency PNG ZLIB JPEG) # needed by osgdb_png or osgdb_jpeg + libfind_package(OSGPlugins ${_dependency}) + set(${_dependency}_LIBRARY_OPTS ${_dependency}_LIBRARY) + #list(APPEND OSGPlugins_PROCESS_LIBS ${_dependency}_LIBRARY) +endforeach() + +libfind_process(OSGPlugins)