diff --git a/CMakeLists.txt b/CMakeLists.txt index 36fb5a6cfe..c5d8274d8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,3 +166,13 @@ if(INTERROGATE_PYTHON_INTERFACE) add_test(pytest "${PYTHON_EXECUTABLE}" -m pytest "${PROJECT_SOURCE_DIR}/tests") endif() + +# Generate the Panda3DConfig.cmake file so find_package(Panda3D) works, and +# also register the build directory with CMake's package registry. + +file(COPY "${PROJECT_SOURCE_DIR}/cmake/install/Panda3DConfig.cmake" + DESTINATION "${PROJECT_BINARY_DIR}") +install(FILES "${PROJECT_SOURCE_DIR}/cmake/install/Panda3DConfig.cmake" + DESTINATION "lib/cmake/Panda3D") + +export(PACKAGE Panda3D) diff --git a/cmake/install/Panda3DConfig.cmake b/cmake/install/Panda3DConfig.cmake new file mode 100644 index 0000000000..6320da8fdf --- /dev/null +++ b/cmake/install/Panda3DConfig.cmake @@ -0,0 +1,141 @@ +# PANDA 3D SOFTWARE +# Copyright (c) Carnegie Mellon University. All rights reserved. +# +# All use of this software is subject to the terms of the revised BSD +# license. You should have received a copy of this license along +# with this source code in a file named "LICENSE." +# +# Author: CFSworks (Dec. 11, 2018) + +# This file is installed to CMake's package search path, and is invoked for +# find_package(Panda3D [COMPONENTS ...]) +# +# The following components are available for importing: +# +# Core - The core Panda3D libraries; this component is always included. +# +# Panda3D::Core::panda +# Panda3D::Core::pandaexpress +# etc. +# +# +# Python - Python targets, which can be used for linking against the Python +# extension modules directly. Note that this also imports the +# Python bindings for other requested components that have them. +# +# Panda3D::Python::panda3d.core +# Panda3D::Python::panda3d.physics +# etc. +# +# +# Tools - Various tools used in asset manipulation and debugging. +# +# Panda3D::Tools::egg2bam +# Panda3D::Tools::egg-optchar +# Panda3D::Tools::pview +# etc. +# +# +# Direct - Panda's "direct" Python framework; C++ support library. +# +# Panda3D::Direct::p3direct +# +# +# Egg - Support for the Egg file format. +# +# Panda3D::Egg::pandaegg +# +# +# Bullet - Support for Bullet physics. +# +# Panda3D::Bullet::p3bullet +# +# +# ODE - Support for the ODE physics engine. +# +# Panda3D::ODE::p3ode +# +# +# FFmpeg - Support for FFmpeg media format loading. +# +# Panda3D::FFmpeg::p3ffmpeg +# +# +# OpenAL - Support for OpenAL audio output. +# +# Panda3D::OpenAL::p3openal_audio +# +# +# FMOD - Support for FMOD audio output. +# +# Panda3D::OpenAL::p3fmod_audio +# +# +# OpenGL - Support for OpenGL rendering. +# +# Panda3D::OpenGL::pandagl +# +# +# DX9 - Support for Direct3D 9 rendering. +# +# Panda3D::DX9::pandadx9 +# +# +# GLES - Support for OpenGL ES rendering. +# +# Panda3D::GLES::pandagles +# Panda3D::GLES::pandagles2 +# +# +# Vision - Support for vision processing. +# +# Panda3D::Vision::p3vision +# +# +# VRPN - Support for connecting to a VRPN virtual reality server. +# +# Panda3D::VRPN::p3vrpn + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 3.0) + message(FATAL_ERROR "CMake >= 3.0.2 required") +endif() + +get_filename_component(_panda_config_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH) + +include("${_panda_config_prefix}/Panda3DPackages.cmake") + +set(_panda_components + Core Python Tools + Direct Egg + Bullet ODE + FFmpeg + OpenAL FMOD + OpenGL DX9 GLES + Vision VRPN +) + +set(Panda3D_FIND_REQUIRED_Core ON) + +foreach(_comp Core ${Panda3D_FIND_COMPONENTS}) + if(";${_panda_components};" MATCHES ";${_comp};" AND + EXISTS "${_panda_config_prefix}/Panda3D${_comp}Targets.cmake") + + include("${_panda_config_prefix}/Panda3D${_comp}Targets.cmake") + + if(";${Panda3D_FIND_COMPONENTS};" MATCHES ";Python;" AND + EXISTS "${_panda_config_prefix}/Panda3D${_comp}PythonTargets.cmake") + + include("${_panda_config_prefix}/Panda3D${_comp}PythonTargets.cmake") + + endif() + + elseif(Panda3D_FIND_REQUIRED_${_comp}) + + message(FATAL_ERROR "Panda3D REQUIRED component ${_comp} not found") + + endif() + +endforeach(_comp) +unset(_comp) + +unset(_panda_components) diff --git a/cmake/macros/PackageConfig.cmake b/cmake/macros/PackageConfig.cmake index a3414e7176..dfbbaf55d6 100644 --- a/cmake/macros/PackageConfig.cmake +++ b/cmake/macros/PackageConfig.cmake @@ -370,6 +370,47 @@ function(export_packages filename) file(GENERATE OUTPUT "${filename}" CONTENT "${exports}") endfunction(export_packages) +# +# export_targets(set [NAMESPACE namespace] [COMPONENT component]) +# +# Export targets in the export set named by "set" +# +# NAMESPACE overrides the namespace prefixed to the exported targets; it +# defaults to "Panda3D::[set]::" if no explicit override is given. +# +# COMPONENT overrides the install component for the generated .cmake file; it +# defaults to "[set]" if no explicit override is given. +# +function(export_targets set) + set(namespace "Panda3D::${set}::") + set(component "${set}") + set(keyword) + foreach(arg ${ARGN}) + if(arg STREQUAL "NAMESPACE" OR + arg STREQUAL "COMPONENT") + + set(keyword "${arg}") + + elseif(keyword STREQUAL "NAMESPACE") + set(namespace "${arg}") + + elseif(keyword STREQUAL "COMPONENT") + set(component "${arg}") + + else() + message(FATAL_ERROR "export_targets() given unexpected arg: ${arg}") + + endif() + endforeach(arg) + + export(EXPORT "${set}" NAMESPACE "${namespace}" + FILE "${PROJECT_BINARY_DIR}/Panda3D${set}Targets.cmake") + install(EXPORT "${set}" NAMESPACE "${namespace}" + FILE "Panda3D${set}Targets.cmake" + COMPONENT "${component}" DESTINATION lib/cmake/Panda3D) + +endfunction(export_targets) + # # find_package # diff --git a/direct/CMakeLists.txt b/direct/CMakeLists.txt index e2325659ae..d10bf91aa9 100644 --- a/direct/CMakeLists.txt +++ b/direct/CMakeLists.txt @@ -80,3 +80,7 @@ except ImportError as err: # Now install ourselves: install_python_package("${PROJECT_BINARY_DIR}/pandac" LIB COMPONENT Direct) endif() + +# "Direct" component contains both the Python stuff and the non-Python stuff, +# because direct has a pretty solid dependency on Python. +export_targets(Direct NAMESPACE "Panda3D::Direct::" COMPONENT DirectDevel) diff --git a/dtool/LocalSetup.cmake b/dtool/LocalSetup.cmake index 1384f18c20..e6d9446015 100644 --- a/dtool/LocalSetup.cmake +++ b/dtool/LocalSetup.cmake @@ -192,3 +192,9 @@ configure_file(dtool_config.h.in "${PROJECT_BINARY_DIR}/include/${intdir}/dtool_ install(FILES "${PROJECT_BINARY_DIR}/include/${intdir}/dtool_config.h" COMPONENT CoreDevel DESTINATION include/panda3d) + +# Generate the package configuration file +export_packages("${PROJECT_BINARY_DIR}/Panda3DPackages.cmake") +install(FILES "${PROJECT_BINARY_DIR}/Panda3DPackages.cmake" + COMPONENT CoreDevel + DESTINATION "lib/cmake/Panda3D") diff --git a/panda/CMakeLists.txt b/panda/CMakeLists.txt index 2028613ad1..1f8bb19741 100644 --- a/panda/CMakeLists.txt +++ b/panda/CMakeLists.txt @@ -99,23 +99,37 @@ if(HAVE_PYTHON) if(HAVE_BULLET) add_python_module(bullet p3bullet IMPORT panda3d.core COMPONENT BulletPython) + + export_targets(BulletPython NAMESPACE "Panda3D::Python::" COMPONENT BulletDevel) endif() if(HAVE_EGG) add_python_module(egg p3egg p3egg2pg LINK pandaegg IMPORT panda3d.core COMPONENT EggPython) + + export_targets(EggPython NAMESPACE "Panda3D::Python::" COMPONENT EggDevel) endif() add_python_module(physics p3physics p3particlesystem LINK pandaphysics IMPORT panda3d.core) if(HAVE_ODE) add_python_module(ode p3ode IMPORT panda3d.core COMPONENT ODEPython) + + export_targets(ODEPython NAMESPACE "Panda3D::Python::" COMPONENT ODEDevel) endif() if(HAVE_OPENCV OR HAVE_ARTOOLKIT) add_python_module(vision p3vision IMPORT panda3d.core COMPONENT VisionPython) + + export_targets(VisionPython NAMESPACE "Panda3D::Python::" COMPONENT VisionDevel) endif() if(HAVE_VRPN) add_python_module(vrpn p3vrpn IMPORT panda3d.core COMPONENT VRPNPython) + + export_targets(VRPNPython NAMESPACE "Panda3D::Python::" COMPONENT VRPNDevel) endif() + + export_targets(Python NAMESPACE "Panda3D::Python::" COMPONENT CoreDevel) endif() + +export_targets(Core COMPONENT CoreDevel) diff --git a/panda/metalibs/pandaegg/CMakeLists.txt b/panda/metalibs/pandaegg/CMakeLists.txt index a41cffdbe3..b6f5e56cdb 100644 --- a/panda/metalibs/pandaegg/CMakeLists.txt +++ b/panda/metalibs/pandaegg/CMakeLists.txt @@ -14,3 +14,5 @@ install(TARGETS pandaegg DESTINATION lib RUNTIME DESTINATION bin ARCHIVE COMPONENT EggDevel) + +export_targets(Egg COMPONENT EggDevel) diff --git a/panda/metalibs/pandagl/CMakeLists.txt b/panda/metalibs/pandagl/CMakeLists.txt index 40fe9a1810..176b176ccb 100644 --- a/panda/metalibs/pandagl/CMakeLists.txt +++ b/panda/metalibs/pandagl/CMakeLists.txt @@ -40,3 +40,5 @@ install(TARGETS pandagl EXPORT OpenGL COMPONENT OpenGL DESTINATION ${MODULE_DESTINATION} ARCHIVE COMPONENT OpenGLDevel) + +export_targets(OpenGL NAMESPACE "Panda3D::OpenGL::" COMPONENT OpenGLDevel) diff --git a/panda/src/audiotraits/CMakeLists.txt b/panda/src/audiotraits/CMakeLists.txt index 2c0988288c..3ed5fbe0dd 100644 --- a/panda/src/audiotraits/CMakeLists.txt +++ b/panda/src/audiotraits/CMakeLists.txt @@ -30,6 +30,8 @@ if(HAVE_RAD_MSS) DESTINATION lib RUNTIME DESTINATION bin ARCHIVE COMPONENT MilesDevel) + + export_targets(Miles NAMESPACE "Panda3D::Miles::" COMPONENT MilesDevel) endif() if(HAVE_FMODEX) @@ -51,6 +53,8 @@ if(HAVE_FMODEX) DESTINATION lib RUNTIME DESTINATION bin ARCHIVE COMPONENT FMODDevel) + + export_targets(FMOD NAMESPACE "Panda3D::FMOD::" COMPONENT FMODDevel) endif() if(HAVE_OPENAL) @@ -73,4 +77,6 @@ if(HAVE_OPENAL) DESTINATION lib RUNTIME DESTINATION bin ARCHIVE COMPONENT OpenALDevel) + + export_targets(OpenAL NAMESPACE "Panda3D::OpenAL::" COMPONENT OpenALDevel) endif() diff --git a/panda/src/bullet/CMakeLists.txt b/panda/src/bullet/CMakeLists.txt index c001fa54d8..8dbf70954d 100644 --- a/panda/src/bullet/CMakeLists.txt +++ b/panda/src/bullet/CMakeLists.txt @@ -118,3 +118,5 @@ install(TARGETS p3bullet RUNTIME DESTINATION bin ARCHIVE COMPONENT BulletDevel) install(FILES ${P3BULLET_HEADERS} COMPONENT BulletDevel DESTINATION include/panda3d) + +export_targets(Bullet COMPONENT BulletDevel) diff --git a/panda/src/ode/CMakeLists.txt b/panda/src/ode/CMakeLists.txt index a61fa8a4ed..18ff027cb9 100644 --- a/panda/src/ode/CMakeLists.txt +++ b/panda/src/ode/CMakeLists.txt @@ -98,3 +98,5 @@ install(TARGETS p3ode RUNTIME DESTINATION bin ARCHIVE COMPONENT ODEDevel) install(FILES ${P3ODE_HEADERS} COMPONENT ODEDevel DESTINATION include/panda3d) + +export_targets(ODE COMPONENT ODEDevel) diff --git a/panda/src/vision/CMakeLists.txt b/panda/src/vision/CMakeLists.txt index 5f905ebe86..a581ef3076 100644 --- a/panda/src/vision/CMakeLists.txt +++ b/panda/src/vision/CMakeLists.txt @@ -39,3 +39,5 @@ install(TARGETS p3vision RUNTIME DESTINATION bin ARCHIVE COMPONENT VisionDevel) install(FILES ${P3VISION_HEADERS} COMPONENT VisionDevel DESTINATION include/panda3d) + +export_targets(Vision COMPONENT VisionDevel)