Permalink
Browse files

Merge pull request #660 from mxgrey/modernize_cmake

Create a config-file and export library targets for downstream users
  • Loading branch information...
openscenegraph committed Nov 26, 2018
2 parents c8ad06a + 0bad4aa commit 3ea101df66709d1a16c4b9f75d6afe160d883a30
Showing with 707 additions and 277 deletions.
  1. +61 −29 CMakeLists.txt
  2. +72 −16 CMakeModules/ModuleInstall.cmake
  3. +7 −0 CMakeModules/OsgMacroUtils.cmake
  4. +16 −0 examples/osgCMakeExampleModern/CMakeLists.txt
  5. +183 −0 examples/osgCMakeExampleModern/main.cpp
  6. +192 −0 packaging/cmake/OpenSceneGraphConfig.cmake.in
  7. +23 −0 packaging/cmake/openscenegraph-component-import-targets.cmake
  8. +4 −4 packaging/pkgconfig/{openscenegraph-osg.pc.in → component.pc.in}
  9. +0 −14 packaging/pkgconfig/openscenegraph-osgAnimation.pc.in
  10. +0 −14 packaging/pkgconfig/openscenegraph-osgDB.pc.in
  11. +0 −14 packaging/pkgconfig/openscenegraph-osgFX.pc.in
  12. +0 −14 packaging/pkgconfig/openscenegraph-osgGA.pc.in
  13. +0 −14 packaging/pkgconfig/openscenegraph-osgManipulator.pc.in
  14. +0 −14 packaging/pkgconfig/openscenegraph-osgParticle.pc.in
  15. +0 −14 packaging/pkgconfig/openscenegraph-osgShadow.pc.in
  16. +0 −14 packaging/pkgconfig/openscenegraph-osgSim.pc.in
  17. +0 −14 packaging/pkgconfig/openscenegraph-osgTerrain.pc.in
  18. +0 −14 packaging/pkgconfig/openscenegraph-osgText.pc.in
  19. +0 −14 packaging/pkgconfig/openscenegraph-osgUtil.pc.in
  20. +0 −14 packaging/pkgconfig/openscenegraph-osgViewer.pc.in
  21. +0 −14 packaging/pkgconfig/openscenegraph-osgVolume.pc.in
  22. +0 −14 packaging/pkgconfig/openscenegraph-osgWidget.pc.in
  23. +55 −10 src/OpenThreads/pthreads/CMakeLists.txt
  24. +44 −6 src/OpenThreads/win32/CMakeLists.txt
  25. +2 −0 src/osg/CMakeLists.txt
  26. +2 −0 src/osgAnimation/CMakeLists.txt
  27. +2 −0 src/osgDB/CMakeLists.txt
  28. +4 −2 src/osgFX/CMakeLists.txt
  29. +2 −0 src/osgGA/CMakeLists.txt
  30. +2 −0 src/osgManipulator/CMakeLists.txt
  31. +4 −2 src/osgParticle/CMakeLists.txt
  32. +3 −1 src/osgPresentation/CMakeLists.txt
  33. +3 −1 src/osgShadow/CMakeLists.txt
  34. +3 −1 src/osgSim/CMakeLists.txt
  35. +3 −1 src/osgTerrain/CMakeLists.txt
  36. +3 −1 src/osgText/CMakeLists.txt
  37. +5 −3 src/osgUI/CMakeLists.txt
  38. +2 −0 src/osgUtil/CMakeLists.txt
  39. +2 −0 src/osgViewer/CMakeLists.txt
  40. +4 −2 src/osgVolume/CMakeLists.txt
  41. +4 −2 src/osgWidget/CMakeLists.txt
@@ -880,6 +880,67 @@ IF(NOT DEFINED LIB_POSTFIX)
SET(LIB_POSTFIX "")
ENDIF()
# Set installation variables
SET(INSTALL_INCDIR include)
SET(INSTALL_BINDIR bin)
IF(WIN32)
SET(INSTALL_LIBDIR bin)
SET(INSTALL_ARCHIVEDIR lib)
ELSE()
SET(INSTALL_LIBDIR lib${LIB_POSTFIX})
SET(INSTALL_ARCHIVEDIR lib${LIB_POSTFIX})
ENDIF()
# If the version is equal to or greater than 2.8.8, then we can use the
# CMakePackageConfigHelpers module, which we use for configuring the package
# config file. If we are not producing the package config file, then there is no
# point in exporting the targets.
IF(CMAKE_VERSION VERSION_EQUAL "2.8.8" OR
CMAKE_VERSION VERSION_GREATER "2.8.8")
# Tell the project that we will be exporting targets
SET(OSG_EXPORT_TARGETS TRUE CACHE BOOL "Install a config-file and export targets")
# Set the package namespace for exporting
SET(PKG_NAMESPACE osg${OPENSCENEGRAPH_MAJOR_VERSION})
IF(WIN32)
SET(INSTALL_CONFIGDIR cmake)
ELSE()
SET(INSTALL_CONFIGDIR lib${LIB_POSTFIX}/cmake/OpenSceneGraph)
ENDIF()
INCLUDE(CMakePackageConfigHelpers)
CONFIGURE_PACKAGE_CONFIG_FILE(
${PROJECT_SOURCE_DIR}/packaging/cmake/OpenSceneGraphConfig.cmake.in
configure/OpenSceneGraphConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
PATH_VARS INSTALL_INCDIR
)
WRITE_BASIC_PACKAGE_VERSION_FILE(
configure/OpenSceneGraphConfigVersion.cmake
VERSION ${OPENSCENEGRAPH_VERSION}
COMPATIBILITY SameMajorVersion
)
INSTALL(
FILES
${PROJECT_BINARY_DIR}/configure/OpenSceneGraphConfig.cmake
${PROJECT_BINARY_DIR}/configure/OpenSceneGraphConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
COMPONENT libopenscenegraph-dev
)
ELSE()
# We don't support exporting creating config files or exporting targets without >=2.8.8
SET(OSG_EXPORT_TARGETS FALSE CACHE BOOL "Cannot install config files without CMake >= 2.8.8" FORCE)
ENDIF()
SET(INSTALL_PKGCONFIGDIR lib${LIB_POSTFIX}/pkgconfig)
# Here we apparently do some funky stuff with making the bin/ and lib/
# folders which is probably needed to work around a very old CMake bug?
@@ -1237,35 +1298,6 @@ IF(CMAKE_CPACK_COMMAND)
ENDIF()
ENDIF()
# Generate pkg-config configuration files
SET(PKGCONFIG_FILES
openscenegraph
openscenegraph-osg
openscenegraph-osgDB
openscenegraph-osgFX
openscenegraph-osgGA
openscenegraph-osgParticle
openscenegraph-osgSim
openscenegraph-osgText
openscenegraph-osgUtil
openscenegraph-osgTerrain
openscenegraph-osgManipulator
openscenegraph-osgViewer
openscenegraph-osgWidget
openscenegraph-osgShadow
openscenegraph-osgAnimation
openscenegraph-osgVolume
)
FOREACH(PKGCONFIG_FILE ${PKGCONFIG_FILES})
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/packaging/pkgconfig/${PKGCONFIG_FILE}.pc.in
${PROJECT_BINARY_DIR}/packaging/pkgconfig/${PKGCONFIG_FILE}.pc
@ONLY
)
INSTALL(FILES ${PROJECT_BINARY_DIR}/packaging/pkgconfig/${PKGCONFIG_FILE}.pc DESTINATION lib${LIB_POSTFIX}/pkgconfig COMPONENT libopenscenegraph-dev)
ENDFOREACH(PKGCONFIG_FILE)
# Run this as late as possible so users can easier spot the message
IF (NOT DEFINED REQUIRES_LIBPATH_MESSAGE AND ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local")
@@ -4,16 +4,6 @@
# ${LIB_NAME}
# ${TARGET_H}
SET(INSTALL_INCDIR include)
SET(INSTALL_BINDIR bin)
IF(WIN32)
SET(INSTALL_LIBDIR bin)
SET(INSTALL_ARCHIVEDIR lib)
ELSE()
SET(INSTALL_LIBDIR lib${LIB_POSTFIX})
SET(INSTALL_ARCHIVEDIR lib${LIB_POSTFIX})
ENDIF()
SET(HEADERS_GROUP "Header Files")
SOURCE_GROUP(
@@ -25,12 +15,55 @@ IF(MSVC AND OSG_MSVC_VERSIONED_DLL)
HANDLE_MSVC_DLL()
ENDIF()
INSTALL(
TARGETS ${LIB_NAME}
RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT libopenscenegraph
LIBRARY DESTINATION ${INSTALL_LIBDIR} COMPONENT libopenscenegraph
ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR} COMPONENT libopenscenegraph-dev
)
IF(OSG_EXPORT_TARGETS)
INSTALL(
TARGETS ${LIB_NAME}
EXPORT ${LIB_NAME}
RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT libopenscenegraph
LIBRARY DESTINATION ${INSTALL_LIBDIR} COMPONENT libopenscenegraph
ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR} COMPONENT libopenscenegraph-dev
)
INSTALL(
EXPORT ${LIB_NAME}
NAMESPACE ${PKG_NAMESPACE}::
DESTINATION ${INSTALL_CONFIGDIR}
FILE ${LIB_NAME}-targets.cmake
COMPONENT libopenscenegraph-dev
)
SET(COMPONENT_CMAKE_DEPENDENCIES ${TARGET_LIBRARIES})
# These two libraries are special cases because they will always be included
# by the config-file.
LIST(REMOVE_ITEM COMPONENT_CMAKE_DEPENDENCIES OpenThreads)
LIST(REMOVE_ITEM COMPONENT_CMAKE_DEPENDENCIES osg)
SET(TARGET_IMPORT_INPUT_FILE "${PROJECT_SOURCE_DIR}/packaging/cmake/openscenegraph-component-import-targets.cmake")
SET(TARGET_IMPORT_OUTPUT_FILE "${PROJECT_BINARY_DIR}/packaging/cmake/openscenegraph-${LIB_NAME}-import-targets.cmake")
CONFIGURE_FILE(
${TARGET_IMPORT_INPUT_FILE}
${TARGET_IMPORT_OUTPUT_FILE}
@ONLY
)
INSTALL(
FILES ${TARGET_IMPORT_OUTPUT_FILE}
DESTINATION ${INSTALL_CONFIGDIR}
COMPONENT libopenscenegraph-dev
)
ELSE()
INSTALL(
TARGETS ${LIB_NAME}
RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT libopenscenegraph
LIBRARY DESTINATION ${INSTALL_LIBDIR} COMPONENT libopenscenegraph
ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR} COMPONENT libopenscenegraph-dev
)
ENDIF()
IF(MSVC AND DYNAMIC_OPENSCENEGRAPH)
GET_TARGET_PROPERTY(PREFIX ${LIB_NAME} PREFIX)
@@ -57,3 +90,26 @@ ELSE()
# MESSAGE("${OSG_COMPILE_FRAMEWORKS_INSTALL_NAME_DIR}")
ENDIF()
# Install pkgconfig file for this component
SET(COMPONENT_PKGCONFIG_REQUIRES)
FOREACH(component ${TARGET_LIBRARIES})
IF(${component} STREQUAL "OpenThreads")
# Skip OpenThreads because that's handled separately
CONTINUE()
ENDIF()
SET(COMPONENT_PKGCONFIG_REQUIRES "${COMPONENT_PKGCONFIG_REQUIRES} openscenegraph-${component}")
ENDFOREACH()
SET(PKGCONFIG_INPUT_FILE "${PROJECT_SOURCE_DIR}/packaging/pkgconfig/component.pc.in")
SET(PKGCONFIG_OUTPUT_FILE "${PROJECT_BINARY_DIR}/packaging/pkgconfig/openscenegraph-${LIB_NAME}.pc")
CONFIGURE_FILE(
${PKGCONFIG_INPUT_FILE}
${PKGCONFIG_OUTPUT_FILE}
@ONLY
)
INSTALL(
FILES ${PKGCONFIG_OUTPUT_FILE}
DESTINATION ${INSTALL_PKGCONFIGDIR}
COMPONENT libopenscenegraph-dev
)
@@ -223,6 +223,13 @@ MACRO(SETUP_LIBRARY LIB_NAME)
${TARGET_H_NO_MODULE_INSTALL}
${TARGET_SRC}
)
TARGET_INCLUDE_DIRECTORIES(${LIB_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INSTALL_INCDIR}>
)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES FOLDER "OSG Core")
IF(APPLE)
IF(OSG_BUILD_PLATFORM_IPHONE)
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8.8)
SET(PROJECT_NAME osgCMakeExampleModern)
PROJECT(${PROJECT_NAME})
FIND_PACKAGE (OpenSceneGraph REQUIRED COMPONENTS osgUtil osgDB osgText osgGA osgFX osgSim osgViewer CONFIG)
SET(SOURCES
main.cpp
)
ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} osg3::osg osg3::osgUtil osg3::osgDB osg3::osgText osg3::osgGA osg3::osgFX osg3::osgSim osg3::osgViewer)
Oops, something went wrong.

0 comments on commit 3ea101d

Please sign in to comment.