Files
ashlar/cmake/FindOSGPlugins.cmake
AnyOldName3 a6d9765b4c Fix GitHub Actions Windows build
Lists don't round-trip being set correctly if unquoted - each element is treated as a separate argument to the set call.
This stripped out the empty entry on Windows, so made the lib prefix mandatory.
For whatever reason, our GitLab builds don't search for anything without a lib prefix after searching for the OSG plugins, but the GitHub ones do.

That discrepancy can be induced locally by choosing to use or not use before_script.msvc.sh.
2026-10-11 00:41:08 +01:00

79 lines
3.1 KiB
CMake

# This module accepts the following env variable
# OSGPlugins_LIB_DIR - <OpenSceneGraph>/lib/osgPlugins-<X.X.X> , path to search plugins
# OSGPlugins_DONT_FIND_DEPENDENCIES - Set to skip also finding png, zlib and jpeg
#
# 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)
unset(OSGPlugins_LIB_DIR)
foreach(OSGDB_LIB ${OSGDB_LIBRARY})
# Skip library type names
if(EXISTS ${OSGDB_LIB} AND NOT IS_DIRECTORY ${OSGDB_LIB})
get_filename_component(OSG_LIB_DIR ${OSGDB_LIB} DIRECTORY)
list(APPEND OSGPlugins_LIB_DIR "${OSG_LIB_DIR}/osgPlugins-${OPENSCENEGRAPH_VERSION}")
endif()
endforeach(OSGDB_LIB)
if (WIN32)
set(OSGPlugins_BIN_DIR ${OSGPlugins_LIB_DIR})
list(TRANSFORM OSGPlugins_BIN_DIR REPLACE lib bin)
list(APPEND OSGPlugins_LIB_DIR ${OSGPlugins_BIN_DIR})
endif ()
endif()
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})
# On some systems, notably Debian and Ubuntu, the OSG plugins do not have
# the usual "lib" prefix. We temporarily add the empty string to the list
# of prefixes CMake searches for (via osg_find_library) to support these systems.
set(_saved_lib_prefix "${CMAKE_FIND_LIBRARY_PREFIXES}") # save CMAKE_FIND_LIBRARY_PREFIXES
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "") # search libraries with no prefix
set(_saved_lib_suffix "${CMAKE_FIND_LIBRARY_SUFFIXES}")
if(WIN32)
# find_library isn't supposed to find DLLs, it's supposed to find their import libraries, but these are modules, so don't have import libraries
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
endif()
set(${_library_uc}_DIR ${OSGPlugins_LIB_DIR}) # to help function osg_find_library
osg_find_library(${_library_uc} ${_library}) # find it into ${_library_uc}_LIBRARIES
set(CMAKE_FIND_LIBRARY_PREFIXES "${_saved_lib_prefix}") # restore prefix
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_saved_lib_suffix}")
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()
if(NOT DEFINED OSGPlugins_DONT_FIND_DEPENDENCIES)
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()
endif()
libfind_process(OSGPlugins)