diff --git a/CMakeLists.txt b/CMakeLists.txt index a0fedea951..e17f3f2826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/macros/") include(AutoInclude) # Implements automatic include_directories finding include(AddBisonTarget) # Defines add_bison_target function include(CompositeSources) # Defines composite_sources function -include(ConfigPackage) # Defines config_package function +include(PackageConfig) # Defines package_option AND target_use_packages include(Interrogate) # Defines target_interrogate AND add_python_module # Add the include path for source and header files generated by CMake @@ -21,7 +21,6 @@ include_directories("${CMAKE_BINARY_DIR}") # Configure Panda3D include(dtool/PandaVersion.cmake) include(dtool/Package.cmake) -include(dtool/PackageMacros.cmake) include(dtool/Config.cmake) # Determine which trees to build. diff --git a/cmake/macros/ConfigPackage.cmake b/cmake/macros/ConfigPackage.cmake deleted file mode 100644 index b4511faec2..0000000000 --- a/cmake/macros/ConfigPackage.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# Filename: ConfigPackage.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). -# -# Assumes the file has already been found with find_package(). -# -# Usage: -# config_package(package_name) -# -# The following variables can be set to override the cached values of USE_XYZZY -# CONFIG_DISABLE_EVERYTHING - always set USE_XYZZY to false -# CONFIG_DISABLE_MISSING - set USE_XYZZY to false if it was not found -# CONFIG_ENABLE_FOUND - set USE_XYZZY to true if the package was found -# CONFIG_ENABLE_EVERYTHING - always set USE_XYZZY to true (even if the package is missing) -# - -# Usage: -# config_package(PACKAGE_NAME []) -function(config_package PKG_NAME) - # Get package display name - foreach(arg ${ARGN}) - set(DISPLAY_NAME "${DISPLAY_NAME}${arg}") - endforeach() - - # Set function vars to defaults - if(NOT DISPLAY_NAME) - set(DISPLAY_NAME ${PKG_NAME}) - endif() - - if(${PKG_NAME}_FOUND) - # Output success after finding the package for the first time - if(NOT DEFINED USE_${PKG_NAME} AND NOT CONFIG_DISABLE_EVERYTHING) - message(STATUS "+ ${DISPLAY_NAME}") - endif() - - ### Add a USE_XYZZY config variable to the cache ### - if(CONFIG_ENABLE_EVERYTHING OR CONFIG_DISABLE_EVERYTHING OR CONFIG_ENABLE_FOUND) - unset(USE_${PKG_NAME} CACHE) - endif() - - if(CONFIG_DISABLE_EVERYTHING) - option(USE_${PKG_NAME} "If on, compile Panda3D with ${DISPLAY_NAME}" OFF) - else() - option(USE_${PKG_NAME} "If on, compile Panda3D with ${DISPLAY_NAME}" ON) - endif() - - - # Update HAVE_XYZZY - 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} CACHE) - - # If using Discovery, we want to silently disable missing packages - if(CONFIG_DISABLE_MISSING) - option(USE_${PKG_NAME} "If on, compile Panda3D with ${DISPLAY_NAME}" OFF) - endif() - endif() - - else() - # If using DISCOVERED NOTHING, we want to silently disable missing packages - if(CONFIG_DISABLE_MISSING OR CONFIG_DISABLE_EVERYTHING) - option(USE_${PKG_NAME} "If on, compile Panda3D with ${DISPLAY_NAME}" OFF) - - else() - # Otherwise, output failure to find package - message(STATUS "- Did not find ${DISPLAY_NAME}") - endif() - endif() -endfunction() diff --git a/cmake/macros/PackageConfig.cmake b/cmake/macros/PackageConfig.cmake new file mode 100644 index 0000000000..e55a83ef01 --- /dev/null +++ b/cmake/macros/PackageConfig.cmake @@ -0,0 +1,98 @@ +# Filename: PackageConfig.cmake +# +# This modules defines functions which find and configures libraries +# and packages for Panda3Ds configuration file headers (.h files). +# +# Assumes the file has already been found with find_package(). +# +# Function: package_option +# Usage: +# package_option(package_name DOCSTRING [DEFAULT ON | OFF]) +# Examples: +# add_library(mylib ${SOURCES}) +# +# If no default is given, the default is whether the package was found. +# +# +# Function: target_use_packages +# Usage: +# target_use_packages(target [PACKAGES ...]) +# Examples: +# target_use_packages(mylib PYTHON PNG) +# + + +# +# package_option +# +function(package_option name) + # Parse the arguments. + set(command) + set(default) + set(cache_string) + + foreach(arg ${ARGN}) + if(command STREQUAL "DEFAULT") + set(default "${arg}") + set(command) + + elseif(arg STREQUAL "DEFAULT") + set(command "DEFAULT") + + else() + # Yes, a list, because semicolons can be in there, and + # that gets split up into multiple args, so we have to + # join it back together here. + list(APPEND cache_string "${arg}") + + endif() + endforeach() + + if(command STREQUAL "DEFAULT") + message(SEND_ERROR "DEFAULT in package_option takes an argument") + endif() + + # If the default is not set, we set it. + if(NOT DEFINED default) + set(default "${${name}_FOUND}") + endif() + + # If it was set by the user but not found, display an error. + if(HAVE_${name} AND NOT ${name}_FOUND) + message(SEND_ERROR "NOT FOUND: ${name}. Disable HAVE_${name} to continue.") + endif() + + # Prevent the function from being called twice. + # This would indicate a cmake error. + if(PANDA_DID_SET_OPTION_${name}) + message(SEND_ERROR "package_option(${name}) was called twice. + This is a bug in the cmake build scripts.") + else() + set(PANDA_DID_SET_OPTION_${name} TRUE PARENT_SCOPE) + endif() + + # Create the option. + option("HAVE_${name}" "${cache_string}" "${default}") +endfunction() + +# +# target_use_packages +# +# Useful macro that picks up a package located using find_package +# as dependencies of a target that is going to be built. +# +macro(target_use_packages target) + set(libs ${ARGV}) + list(REMOVE_AT libs 0) + + foreach(lib ${libs}) + if(HAVE_${lib}) + target_include_directories("${target}" PUBLIC "${${lib}_INCLUDE_DIRS};${${lib}_INCLUDE_DIR}") + if(${lib}_LIBRARIES) + target_link_libraries("${target}" ${${lib}_LIBRARIES}) + else() + target_link_libraries("${target}" ${${lib}_LIBRARY}) + endif() + endif() + endforeach(lib) +endmacro(target_use_packages) diff --git a/dtool/Config.cmake b/dtool/Config.cmake index 55150c9cd6..3aee5c9b2d 100644 --- a/dtool/Config.cmake +++ b/dtool/Config.cmake @@ -422,7 +422,7 @@ avoid building this, unless you really want to make a low-footprint build (such as, for instance, for the iPhone)." ON) # Is OpenSSL installed, and where? -find_package(OpenSSL) +find_package(OpenSSL COMPONENTS ssl crypto) package_option(OPENSSL DEFAULT ON "Enable OpenSSL support") diff --git a/dtool/Package.cmake b/dtool/Package.cmake index 6fbe140182..0cbd91ad45 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -1,142 +1,52 @@ message(STATUS "") message(STATUS "Configuring support for the following optional third-party packages:") -# Settings to change USE_PACKAGE behavior (these options override cached values) -set(CONFIG_ENABLE_EVERYTHING Off) -set(CONFIG_DISABLE_EVERYTHING Off) -set(CONFIG_ENABLE_FOUND Off) -set(CONFIG_DISABLE_MISSING Off) - -# Update USE_PACKAGE settings based on CLI arguments -if(EVERYTHING) - message("Re-enabling all disabled third-party libraries.") - set(CONFIG_ENABLE_EVERYTHING On) -elseif(DISCOVERED) - message("Enabling found and disabling not-found third-party libraries.") - set(CONFIG_ENABLE_FOUND On) - set(CONFIG_DISABLE_MISSING On) -elseif(NOTHING) - message("Disabling all third-party libraries.") - set(CONFIG_DISABLE_EVERYTHING On) -endif() - -# Find and configure Eigen library -find_package(Eigen3 QUIET) -config_package(EIGEN "Eigen") -if(HAVE_EIGEN) - if(WIN32) - set(EIGEN_CFLAGS "/arch:SSE2") - else() - set(EIGEN_CFLAGS "-msse2") - endif() - - if(CONFIG_ENABLE_EVERYTHING OR CONFIG_ENABLE_FOUND) - unset(BUILD_EIGEN_VECTORIZATION) - elseif(CONFIG_DISABLE_EVERYTHING) - option(BUILD_EIGEN_VECTORIZATION "If on, vectorization is enabled in build." OFF) - endif() - - if(NOT DEFINED BUILD_EIGEN_VECTORIZATION) - message(STATUS "+ (vectorization enabled in build)") - endif() - - option(BUILD_EIGEN_VECTORIZATION "If on, vectorization is enabled in build." ON) - - if(BUILD_EIGEN_VECTORIZATION) - set(LINMATH_ALIGN TRUE) - endif() -else() - unset(BUILD_EIGEN_VECTORIZATION CACHE) -endif() - -# Find and configure OpenSSL library -find_package(OpenSSL QUIET COMPONENTS ssl crypto) -config_package(OPENSSL "OpenSSL") -if(HAVE_OPENSSL) - if(CONFIG_ENABLE_EVERYTHING OR CONFIG_ENABLE_FOUND) - unset(BUILD_OPENSSL_ERROR_REPORTS) - endif() - - if(CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") - option(BUILD_OPENSSL_ERROR_REPORTS "If on, OpenSSL reports verbose error messages when they occur." ON) - else() - set(BUILD_OPENSSL_ERROR_REPORTS "If on, OpenSSL reports verbose error messages when they occur." OFF) - endif() - - if(BUILD_OPENSSL_ERROR_REPORTS) - set(REPORT_OPENSSL_ERRORS TRUE) - endif() -else() - unset(BUILD_OPENSSL_ERROR_REPORTS CACHE) -endif() - -# Find and configure JPEG library -find_package(JPEG QUIET) -config_package(JPEG "libjpeg") - -# Find and configure PNG library -find_package(PNG QUIET) -config_package(PNG "libpng") - -# Find and configure TIFF library -find_package(TIFF QUIET COMPONENTS tiff z) -config_package(TIFF "libtiff") - -# Find and configure Tar library -find_package(Tar QUIET) -config_package(TAR "libtar") - -# Find and configure FFTW library -find_package(FFTW QUIET) -config_package(FFTW "fftw") - -# Find and configure Squish library -find_package(Squish QUIET) -config_package(SQUISH "squish") - # Find and configure Cg library find_package(Cg QUIET) -config_package(CG "Nvidia Cg Shading Langauge") -config_package(CGGL "Cg OpenGL API") -config_package(CGDX8 "Cg DX8 API") -config_package(CGDX9 "Cg DX9 API") -config_package(CGDX10 "Cg DX10 API") - -# Find and configure VRPN library -find_package(VRPN QUIET) -config_package(VRPN) - -# Find and configure zlib -find_package(ZLIB QUIET) -config_package(ZLIB "zlib") +#config_package(CG "Nvidia Cg Shading Langauge") +#config_package(CGGL "Cg OpenGL API") +#config_package(CGDX8 "Cg DX8 API") +#config_package(CGDX9 "Cg DX9 API") +#config_package(CGDX10 "Cg DX10 API") +package_option(CG) +package_option(CGGL) +package_option(CGDX8) +package_option(CGDX9) +package_option(CGDX10) # Find and configure Miles Sound System find_package(Miles QUIET) -config_package(RAD_MSS "Miles Sound System") +#config_package(RAD_MSS "Miles Sound System") +package_option(RAD_MSS) # Find and configure FMOD Ex find_package(FMODEx QUIET) -config_package(FMODEX "FMOD Ex sound library") +#config_package(FMODEX "FMOD Ex sound library") +package_option(FMODEX) # Find and configure OpenAL find_package(OpenAL QUIET) -config_package(OPENAL "OpenAL sound library") +#config_package(OPENAL "OpenAL sound library") +package_option(OPENAL) # Find and configure OpenGL find_package(OpenGL QUIET) set(GL_FOUND ${OPENGL_FOUND}) -config_package(GL "OpenGL") +#config_package(GL "OpenGL") +package_option(GL) # Find and configure Freetype find_package(Freetype QUIET) -config_package(FREETYPE "Freetype") +#config_package(FREETYPE "Freetype") +package_option(FREETYPE) # Find and configure GTK set(Freetype_FIND_QUIETLY TRUE) # Fix for builtin FindGTK2 set(GTK2_GTK_FIND_QUIETLY TRUE) # Fix for builtin FindGTK2 find_package(GTK2 QUIET COMPONENTS gtk) set(GTK_FOUND ${GTK2_FOUND}) # Mangle for convenience -config_package(GTK "gtk+-2") +#config_package(GTK "gtk+-2") +package_option(GTK) # Find and configure WxWidgets find_package(wxWidgets QUIET) @@ -147,12 +57,14 @@ if(WXWIDGETS_FOUND) mark_as_advanced(wxWidgets_CONFIG_EXECUTABLE) mark_as_advanced(wxWidgets_wxrc_EXECUTABLE) endif() -config_package(WX "WxWidgets") +#config_package(WX "WxWidgets") +package_option(WX) # Find and configure FLTK set(OpenGL_FIND_QUIETLY TRUE) # Fix for builtin FindFLTK find_package(FLTK QUIET) -config_package(FLTK) +#config_package(FLTK) +package_option(FLTK) # Cleanup after builtin FindFLTK mark_as_advanced(FLTK_DIR) @@ -164,7 +76,8 @@ set(Eigen3_FIND_QUIETLY TRUE) # Fix for builtin FindSDL set(PythonLibs_FIND_QUIETLY TRUE) # Fix for builtin FindSDL set(PythonInterp_FIND_QUIETLY TRUE) # Fix for builtin FindSDL find_package(SDL QUIET) -config_package(SDL) +#config_package(SDL) +package_option(SDL) # Cleanup after builtin FindSDL mark_as_advanced(SDLMAIN_LIBRARY) diff --git a/dtool/PackageMacros.cmake b/dtool/PackageMacros.cmake index de2822e7cc..e69de29bb2 100644 --- a/dtool/PackageMacros.cmake +++ b/dtool/PackageMacros.cmake @@ -1,77 +0,0 @@ -# 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). -# -# Assumes the file has already been found with find_package(). -# - -# -# Usage: -# package_option(PYTHON "Enables support for Python" [DEFAULT ON | OFF]) -# If no default is given, it is initialized to whether it was found on the system. -# -function(package_option name) - # Parse the arguments. - set(command) - set(default) - set(cache_string) - - foreach(arg ${ARGN}) - if(command STREQUAL "DEFAULT") - set(default "${arg}") - set(command) - - elseif(arg STREQUAL "DEFAULT") - set(command "DEFAULT") - - else() - # Yes, a list, ecause semicolons can be in there, and - # that gets split up into multiple args, so we have to - # join it back together here. - list(APPEND cache_string "${arg}") - - endif() - endforeach() - - if(command STREQUAL "DEFAULT") - message(SEND_ERROR "DEFAULT in package_option takes an argument") - endif() - - # If the default is not set, we set it. - if(NOT DEFINED default) - set(default "${${name}_FOUND}") - endif() - - # If it was set by the user but not found, display an error. - if(HAVE_${name} AND NOT ${name}_FOUND) - message(SEND_ERROR "NOT FOUND: ${name}. Disable HAVE_${name} to continue.") - endif() - - # Create the option. - option("HAVE_${name}" "${cache_string}" "${default}") -endfunction() - -# -# Useful macro that picks up a package located using find_package -# as dependencies of a target that is going to be built. -# Example use: -# add_library(mylib ${SOURCES}) -# target_use_packages(mylib PYTHON PNG) -# -macro(target_use_packages target) - set(libs ${ARGV}) - list(REMOVE_AT libs 0) - - foreach(lib ${libs}) - if(HAVE_${lib}) - target_include_directories("${target}" PUBLIC "${${lib}_INCLUDE_DIRS};${${lib}_INCLUDE_DIR}") - if(${lib}_LIBRARIES) - target_link_libraries("${target}" ${${lib}_LIBRARIES}) - else() - target_link_libraries("${target}" ${${lib}_LIBRARY}) - endif() - endif() - endforeach(lib) -endmacro(target_use_packages)