diff --git a/cmake/modules/ConfigurePackage.cmake b/cmake/modules/ConfigurePackage.cmake new file mode 100644 index 0000000000..b79734626d --- /dev/null +++ b/cmake/modules/ConfigurePackage.cmake @@ -0,0 +1,75 @@ +# Filename: ConfigurePackage.cmake +# Author: kestred (30 Nov, 2013) +# +# This modules defines a function which finds and configures libraries +# and packages for Panda3Ds configuration file headers (.h files). +# +# Additionally, it defines a macro for including Mangle modules. +# +# Assumes the file has already been found with find_package(). +# + +# Usage: +# mangle_package(LIBRARY_NAME) +macro(mangle_package PKG_NAME) + include(Mangle${PKG_NAME}) +endmacro() + +# Usage: +# config_package(PACKAGE_NAME [REQUIRED] [COMMENT ]) +function(config_package PKG_NAME) + # Set function vars to defaults + set(DISPLAY_NAME ${PKG_NAME}) + + # Handle optional function arguments + foreach(arg ${ARGN}) + if(ARG_IS_LIBRARY) + unset(ARG_IS_LIBRARY) + set(LIB_NAME ${arg}) + break() + elseif(ARG_IS_COMMENT) + unset(ARG_IS_COMMENT) + set(DISPLAY_NAME ${arg}) + break() + endif() + + if(arg MATCHES "REQUIRED") + # TODO: Implement currently ignored + elseif(arg MATCHES "COMMENT") + set(ARG_IS_COMMENT TRUE) + else() + message(AUTHOR_WARNING "configure_package() unexpected argument: '${arg}'") + return() + endif() + endforeach() + if(ARG_IS_COMMENT) + message(AUTHOR_WARNING "configure_package() expected display-name after 'COMMENT'") + endif() + + if(FOUND_${PKG_NAME}) + # Output success after finding the package for the first time + if(NOT DEFINED USE_${PKG_NAME}) + endif() + + # Add a USE_XYZZY config variable to the cache + set(USE_${PKG_NAME} TRUE CACHE BOOL "If true, compile Panda3D with ${DISPLAY_NAME}") + if(USE_${PKG_NAME}) + set(HAVE_${PKG_NAME} TRUE PARENT_SCOPE) + endif() + + elseif(DEFINED USE_${PKG_NAME}) + # If we were compiling with a particular package, but we can't find it; + # then inform the user the package was lost. + if(USE_${PKG_NAME}) + message(STATUS "- Can no longer find ${DISPLAY_NAME}") + + # Only unset if USE_XYZZY is true; + # This allows us to set USE_XYZZY to false to silence the output + unset(USE_${PKG_NAME}) + endif() + + else() + # Output failure to find package + message(STATUS "- Did not find ${DISPLAY_NAME}") + endif() +endfunction() \ No newline at end of file diff --git a/dtool/Configure.cmake b/dtool/Configure.cmake index 3e4cf4765f..bf609dfb64 100644 --- a/dtool/Configure.cmake +++ b/dtool/Configure.cmake @@ -1,6 +1,7 @@ message(STATUS "") message("Configuring support for the following optional third-party packages:") +include(ConfigurePackage) # Check for and configure Eigen library find_package(Eigen3) @@ -91,7 +92,7 @@ endif() # Check for and configure TIFF library # Mangle the builtin FindTIFF output to match Panda3D's config-style find_package(TIFF QUIET COMPONENTS tiff z) -include(MangleTIFF) +mangle_package(TIFF) if(FOUND_TIFF) set(USE_TIFF TRUE CACHE BOOL "If true, compile Panda3D with libtiff") if(USE_TIFF) @@ -107,17 +108,7 @@ endif() # Check for and configure Tar library find_package(Tar) -if(FOUND_TAR) - set(USE_TAR TRUE CACHE BOOL "If true, compile Panda3D with libtar") - if(USE_TAR) - set(HAVE_TAR TRUE) - endif() -endif() -if(HAVE_TAR) - message(STATUS "+ libtar") -else() - message(STATUS "- Did not find libtar") -endif() +config_package(TAR COMMENT "libtar") # Check for and configure FFTW library