Skip to content

Commit

Permalink
Fix target exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mxgrey committed Nov 15, 2018
1 parent 3a850d8 commit ea9d619
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ IF(CMAKE_VERSION VERSION_EQUAL "2.8.8" OR

INCLUDE(CMakePackageConfigHelpers)
CONFIGURE_PACKAGE_CONFIG_FILE(
${PROJECT_SOURCE_DIR}/CMakeModules/OpenSceneGraphConfig.cmake.in
${PROJECT_SOURCE_DIR}/packaging/cmake/OpenSceneGraphConfig.cmake.in
configure/OpenSceneGraphConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
PATH_VARS INSTALL_INCDIR
Expand Down
20 changes: 20 additions & 0 deletions CMakeModules/ModuleInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ IF(OSG_EXPORT_TARGETS)
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(
Expand Down
7 changes: 7 additions & 0 deletions CMakeModules/OsgMacroUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# OpenSceneGraph_FOUND : Set to true if all required components can be found
# OPENSCENEGRAPH_FOUND
#
# OpenSceneGraph_<comp>_FOUND : Set to true if this component was found
# OPENSCENEGRAPH_<COMP>_FOUND
#
# OSG_LIBRARY : The library for the core OSG component
# OSG_LIBRARIES
#
Expand All @@ -37,6 +40,12 @@
# Use target_link_libraries(tgt [PUBLIC|PRIVATE] @PKG_NAMESPACE@::<comp>)
# for each component that you want to link to.
#
# For convenience, this will also produce a variable
#
# OpenSceneGraph_TARGETS
#
# which will contain the targets of all the requested components.
#
################################################################################


Expand All @@ -48,6 +57,10 @@
# guaranteed to work with lower versions of cmake.
cmake_minimum_required(VERSION 2.8.8)

# Assume we have succeeded unless a required component is missing
set(OpenSceneGraph_FOUND TRUE)
set(OPENSCENEGRAPH_FOUND TRUE)

# Shortcut if find_package(OpenSceneGraph ...) has been called before
if(OpenSceneGraph_CONFIG_INCLUDED)

Expand Down Expand Up @@ -76,33 +89,43 @@ set(OPENSCENEGRAPH_INCLUDE_DIRS ${OpenSceneGraph_INCLUDE_DIRS})

set(OpenSceneGraph_LIBRARIES)

foreach(component OpenThreads osg ${OpenSceneGraph_FIND_COMPONENTS})
set(OpenSceneGraph_TARGETS)

message(STATUS "Looking for [${component}] component of OpenSceneGraph")
foreach(component OpenThreads osg ${OpenSceneGraph_FIND_COMPONENTS})

if(TARGET @PKG_NAMESPACE@::${component})
# This component has already been found, so we'll skip it
continue()
endif()

if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${component}-targets.cmake)
string(TOUPPER ${component} UC_COMPONENT)

set(osg_component_import_target_file ${CMAKE_CURRENT_LIST_DIR}/openscenegraph-${component}-import-targets.cmake)

if(NOT EXISTS ${osg_component_import_target_file})

if(OpenSceneGraph_FIND_REQUIRED_${component} OR NOT OpenSceneGraph_FIND_QUIETLY)
message("Could not find [${component}] component of OpenSceneGraph")
endif()

set(OpenSceneGraph_${component}_FOUND FALSE)
set(OPENSCENEGRAPH_${UC_COMPONENT}_FOUND FALSE)

continue()

endif()

include(${CMAKE_CURRENT_LIST_DIR}/${component}-targets.cmake)
include(${osg_component_import_target_file})

list(APPEND OpenSceneGraph_TARGETS @PKG_NAMESPACE@::${component})

set(OpenSceneGraph_${component}_FOUND TRUE)
set(OPENSCENEGRAPH_${component}_FOUND TRUE)

if(NOT OpenSceneGraph_FIND_QUIETLY)
message(STATUS "Found [${component}] component of OpenSceneGraph")
endif()

string(TOUPPER ${component} UC_COMPONENT)

# Components all get installed to the same include directory
set(${UC_COMPONENT}_INCLUDE_DIR ${OpenSceneGraph_INCLUDE_DIRS})

Expand Down Expand Up @@ -166,3 +189,4 @@ endforeach()
set(OPENSCENEGRAPH_LIBRARIES ${OpenSceneGraph_LIBRARIES})

check_required_components(OpenSceneGraph)
set(OPENSCENEGRAPH_FOUND ${OpenSceneGraph_FOUND})
23 changes: 23 additions & 0 deletions packaging/cmake/openscenegraph-component-import-targets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is a utility file for importing the target (and its dependencies) of
# @LIB_NAME@, a component library of OpenSceneGraph. This is designed to be used
# by OpenSceneGraphConfig.cmake and should not be invoked directly.

# First we import all dependent targets (as well as their dependencies, recursively)
foreach(dependency @COMPONENT_CMAKE_DEPENDENCIES@)
set(osg_component_dependency_target_file ${CMAKE_CURRENT_LIST_DIR}/openscenegraph-${dependency}-import-targets.cmake)
if(NOT EXISTS ${osg_component_dependency_target_file})
# Note: This should never happen, because if this library was installed
# and its target was exported, then its dependencies should have been
# installed with their targets alongside it. If we ever land here, then
# either there is a bug in the build system, or the user has broken
# their installation of OpenSceneGraph.
message(FATAL_ERROR
"Could not find [${dependency}] which is a dependency of [@LIB_NAME@]."
" This may indicate a broken installation of OpenSceneGraph.")
endif()

include(${osg_component_dependency_target_file})
endforeach()

# Then we import our own target file
include(${CMAKE_CURRENT_LIST_DIR}/@[email protected])
63 changes: 43 additions & 20 deletions src/OpenThreads/pthreads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ ELSE()
${TARGET_SRC}
)

TARGET_INCLUDE_DIRECTORIES(${LIB_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INSTALL_INCDIR}>
)

IF(OPENTHREADS_SONAMES)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
ENDIF()
Expand All @@ -150,29 +156,46 @@ ELSE()

IF(OSG_EXPORT_TARGETS)

INSTALL(
TARGETS OpenThreads
EXPORT OpenThreads
ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
RUNTIME DESTINATION bin COMPONENT libopenthreads
)

INSTALL(
EXPORT OpenThreads
NAMESPACE ${PKG_NAMESPACE}::
DESTINATION ${INSTALL_CONFIGDIR}
FILE OpenThreads-targets.cmake
COMPONENT libopenthreads-dev)
INSTALL(
TARGETS ${LIB_NAME}
EXPORT ${LIB_NAME}
ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
RUNTIME DESTINATION bin COMPONENT libopenthreads
)

INSTALL(
EXPORT ${LIB_NAME}
NAMESPACE ${PKG_NAMESPACE}::
DESTINATION ${INSTALL_CONFIGDIR}
FILE ${LIB_NAME}-targets.cmake
COMPONENT libopenthreads-dev
)

# Intentionally blank
SET(COMPONENT_CMAKE_DEPENDENCIES)

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 OpenThreads
ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
RUNTIME DESTINATION bin COMPONENT libopenthreads
)
INSTALL(
TARGETS ${LIB_NAME}
ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
RUNTIME DESTINATION bin COMPONENT libopenthreads
)

ENDIF()

Expand Down

0 comments on commit ea9d619

Please sign in to comment.