CMake: Start the process of organizing packages into Package.cmake

This commit is contained in:
Sam Edwards 2018-02-14 16:32:13 -07:00
parent b11e15cec5
commit 021728f4b3
4 changed files with 117 additions and 35 deletions

View File

@ -1,13 +1,14 @@
# Filename: PackageConfig.cmake
#
# This modules defines functions which find and configures libraries
# and packages for Panda3Ds configuration file headers (.h files).
# This module defines functions which find and configure libraries
# and packages for Panda3D.
#
# Assumes the file has already been found with find_package().
# Assumes an attempt to find the package has already been made with
# find_package(). (i.e. relies on packagename_FOUND variable)
#
# Function: package_option
# Usage:
# package_option(package_name DOCSTRING
# package_option(package_name package_doc_string
# [DEFAULT ON | OFF]
# [LICENSE license])
# Examples:
@ -15,6 +16,24 @@
#
# If no default is given, the default in normal
# builds is to enable all found third-party packages.
# In builds for redistribution, there is the additional requirement that
# the package be suitably-licensed.
#
#
# Function: config_package
# Usage:
# config_package(package_name "Package description" ["Config summary"])
# Examples:
# config_package(OpenAL "OpenAL Audio Output")
# config_package(ROCKET "Rocket" "without Python bindings")
#
#
# Function: show_packages
# Usage:
# show_packages()
#
# This prints the package usage report using the information provided in
# calls to config_package above.
#
#
# Function: target_use_packages
@ -24,10 +43,18 @@
# target_use_packages(mylib PYTHON PNG)
#
#
# package_option
#
# In order to make sure no third-party licenses are inadvertently violated,
# this imposes a few rules regarding license:
# 1) If there is no license, no special restrictions.
# 2) If there is a license, but the build is not flagged for redistribution,
# no special restrictions.
# 3) If there is a license, and this is for redistribution, the package is
# forcibly defaulted off and must be explicitly enabled, unless the license
# matches a list of licenses suitable for redistribution.
#
function(package_option name)
# Parse the arguments.
set(command)
@ -104,6 +131,8 @@ function(package_option name)
set(PANDA_DID_SET_OPTION_${name} TRUE PARENT_SCOPE)
endif()
set(PANDA_PACKAGE_DEFAULT_${name} "${default}")
# Create the option.
option("HAVE_${name}" "${cache_string}" "${default}")
if(HAVE_${name})
@ -115,6 +144,64 @@ function(package_option name)
endif()
endfunction()
set(_ALL_CONFIG_PACKAGES CACHE INTERNAL "Internal variable")
#
# config_package
#
function(config_package name desc)
set(note "")
foreach(arg ${ARGN})
set(note "${arg}")
endforeach()
if(NOT PANDA_DID_SET_OPTION_${name})
message(SEND_ERROR "config_package(${name}) was called before package_option(${name}).
This is a bug in the cmake build scripts.")
endif()
list(FIND _ALL_CONFIG_PACKAGES "${name}" called_twice)
if(called_twice GREATER -1)
message(SEND_ERROR "config_package(${name}) was called twice.
This is a bug in the cmake build scripts.")
else()
list(APPEND _ALL_CONFIG_PACKAGES "${name}")
set(_ALL_CONFIG_PACKAGES "${_ALL_CONFIG_PACKAGES}" CACHE INTERNAL "Internal variable")
endif()
set(PANDA_PACKAGE_DESC_${name} "${desc}" PARENT_SCOPE)
set(PANDA_PACKAGE_NOTE_${name} "${note}" PARENT_SCOPE)
endfunction()
#
# show_packages
#
function(show_packages)
message("")
message("Configuring support for the following optional third-party packages:")
foreach(package ${_ALL_CONFIG_PACKAGES})
set(desc "${PANDA_PACKAGE_DESC_${package}}")
set(note "${PANDA_PACKAGE_NOTE_${package}}")
if(HAVE_${package})
if(NOT note STREQUAL "")
message("+ ${desc} (${note})")
else()
message("+ ${desc}")
endif()
else()
if(NOT ${package}_FOUND)
set(reason "not found")
elseif(PANDA_PACKAGE_DEFAULT_${package})
set(reason "not requested")
else()
set(reason "disabled")
endif()
message("- ${desc} (${reason})")
endif()
endforeach()
endfunction()
#
# target_use_packages
#

View File

@ -412,24 +412,6 @@ mark_as_advanced(ANDROID_NDK_HOME ANDROID_ABI ANDROID_STL
# Now let's check for the presence of various thirdparty libraries.
#
# Is Eigen installed, and should Eigen replace internal linmath?
find_package(Eigen3 QUIET)
package_option(EIGEN
"Enables experimental support for the Eigen linear algebra library.
If this is provided, Panda will use this library as the fundamental
implementation of its own linmath library; otherwise, it will use
its own internal implementation. The primary advantage of using
Eigen is SSE2 support, which is only activated if LINMATH_ALIGN
is also enabled."
LICENSE "MPL-2")
option(LINMATH_ALIGN
"This is required for activating SSE2 support using Eigen.
Activating this does constrain most objects in Panda to 16-byte
alignment, which could impact memory usage on very-low-memory
platforms. Currently experimental." ON)
# Always include Eigen, because we include it pretty much everywhere.
if(EIGEN3_FOUND)
include_directories(${EIGEN3_INCLUDE_DIR})

View File

@ -188,18 +188,7 @@ else()
endif()
# Now go through all the packages and report whether we have them.
message("")
message("Configuring support for the following optional third-party packages:")
if(HAVE_EIGEN)
message("+ Eigen linear algebra library")
if(LINMATH_ALIGN)
message("+ (vectorization enabled in build)")
else()
message("- (vectorization NOT enabled in build)")
endif()
else()
message("- Did not find Eigen linear algebra library")
endif()
show_packages()
if(HAVE_OPENSSL)
message("+ OpenSSL")

View File

@ -1,3 +1,27 @@
# Eigen
find_package(Eigen3 QUIET)
if(Eigen3_FOUND)
set(EIGEN_FOUND ON)
endif()
package_option(EIGEN
"Enables experimental support for the Eigen linear algebra library.
If this is provided, Panda will use this library as the fundamental
implementation of its own linmath library; otherwise, it will use
its own internal implementation. The primary advantage of using
Eigen is SSE2 support, which is only activated if LINMATH_ALIGN
is also enabled."
LICENSE "MPL-2")
option(LINMATH_ALIGN
"This is required for activating SSE2 support using Eigen.
Activating this does constrain most objects in Panda to 16-byte
alignment, which could impact memory usage on very-low-memory
platforms. Currently experimental." ON)
if(LINMATH_ALIGN)
config_package(EIGEN "Eigen linear algebra library" "vectorization enabled in build")
else()
config_package(EIGEN "Eigen linear algebra library" "vectorization NOT enabled in build")
endif()
# Find and configure Miles Sound System
find_package(Miles QUIET)
#config_package(RAD_MSS "Miles Sound System")