From c3b9198ec393265e9b6d343a75ef9f0ec63ce1a1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 19 Feb 2015 15:19:52 -0800 Subject: [PATCH] cleanup handling of external projects if OS not handled --- cmake/externals/bullet/CMakeLists.txt | 7 +- cmake/externals/tbb/CMakeLists.txt | 23 +-- cmake/externals/zlib/CMakeLists.txt | 22 +++ .../AddDependencyExternalProjects.cmake | 31 +++- cmake/modules/FindZLIB.cmake | 162 ++++++++++++++++++ interface/CMakeLists.txt | 2 +- 6 files changed, 226 insertions(+), 21 deletions(-) create mode 100644 cmake/externals/zlib/CMakeLists.txt create mode 100644 cmake/modules/FindZLIB.cmake diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index 1cf82032bf..38bf031387 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -33,7 +33,6 @@ ExternalProject_Add( ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) -set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIR ${INSTALL_DIR}/include/bullet CACHE TYPE "Path to bullet include directory") set(BULLET_LIB_DIR "${INSTALL_DIR}/lib") @@ -47,8 +46,6 @@ if (APPLE OR UNIX OR ANDROID) set(LIB_PREFIX "lib") elseif (WIN32) set(BULLET_LIB_EXT "lib") -else () - message(STATUS "Your OS is not handled by our Bullet external project CMakeLists.txt. Please install Bullet yourself and pass -DGET_BULLET=0 when running CMake.") endif () if (DEFINED SHARED_LIB_EXT) @@ -63,4 +60,8 @@ if (DEFINED SHARED_LIB_EXT) set(${EXTERNAL_NAME_UPPER}_SOFTBODY_LIBRARY_RELEASE ${BULLET_LIB_DIR}/${LIB_PREFIX}BulletSoftBody.${BULLET_LIB_EXT} CACHE TYPE "Bullet softbody release library location") set(${EXTERNAL_NAME_UPPER}_SOFTBODY_LIBRARY_DEBUG NOTFOUND CACHE TYPE "Bullet softbody debug library location") +endif () + +if (DEFINED ${EXTERNAL_NAME_UPPER}_DYNAMICS_LIBRARY_RELEASE) + set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIR ${INSTALL_DIR}/include/bullet CACHE TYPE "Path to bullet include directory") endif () \ No newline at end of file diff --git a/cmake/externals/tbb/CMakeLists.txt b/cmake/externals/tbb/CMakeLists.txt index b26adc559c..39ec4aa8f2 100644 --- a/cmake/externals/tbb/CMakeLists.txt +++ b/cmake/externals/tbb/CMakeLists.txt @@ -43,7 +43,6 @@ endif () ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) -set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE "List of tbb include directories") if (APPLE) set(_TBB_APPLE_LIB_DIR "${SOURCE_DIR}/lib/libc++") @@ -85,14 +84,18 @@ elseif (UNIX) elseif (GCC_VERSION VERSION_GREATER 4.1 OR GCC_VERSION VERSION_EQUAL 4.1) set(_TBB_LINUX_LIB_DIR "${SOURCE_DIR}/lib/${_TBB_ARCH_DIR}/gcc4.1") else () - message(FATAL_ERROR "Could not find a compatible version of Threading Building Blocks library for your compiler.") + message(STATUS "Could not find a compatible version of Threading Building Blocks library for your compiler.") endif () - set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${_TBB_LINUX_LIB_DIR}/libtbb_debug.so CACHE TYPE "TBB debug library location") - set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${_TBB_LINUX_LIB_DIR}/libtbb.so CACHE TYPE "TBB release library location") - set(${EXTERNAL_NAME_UPPER}_MALLOC_LIBRARY_DEBUG ${_TBB_LINUX_LIB_DIR}/libtbbmalloc_debug.so CACHE TYPE "TBB malloc debug library location") - set(${EXTERNAL_NAME_UPPER}_MALLOC_LIBRARY_RELEASE ${_TBB_LINUX_LIB_DIR}/libtbbmalloc.so CACHE TYPE "TBB malloc release library location") - -else () - message(STATUS "Your OS is not handled by our TBB external project CMakeLists.txt. Please install TBB yourself and pass -DGET_TBB=0 when running CMake.") -endif () \ No newline at end of file + if (DEFINED _TBB_LINUX_LIB_DIR) + set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${_TBB_LINUX_LIB_DIR}/libtbb_debug.so CACHE TYPE "TBB debug library location") + set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${_TBB_LINUX_LIB_DIR}/libtbb.so CACHE TYPE "TBB release library location") + set(${EXTERNAL_NAME_UPPER}_MALLOC_LIBRARY_DEBUG ${_TBB_LINUX_LIB_DIR}/libtbbmalloc_debug.so CACHE TYPE "TBB malloc debug library location") + set(${EXTERNAL_NAME_UPPER}_MALLOC_LIBRARY_RELEASE ${_TBB_LINUX_LIB_DIR}/libtbbmalloc.so CACHE TYPE "TBB malloc release library location") + endif () +endif () + +if (DEFINED ${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE) + + set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE "List of tbb include directories") +endif () \ No newline at end of file diff --git a/cmake/externals/zlib/CMakeLists.txt b/cmake/externals/zlib/CMakeLists.txt new file mode 100644 index 0000000000..af980484be --- /dev/null +++ b/cmake/externals/zlib/CMakeLists.txt @@ -0,0 +1,22 @@ +set(EXTERNAL_NAME zlib) + +include(ExternalProject) + +if (WIN32) + ExternalProject_Add( + ${EXTERNAL_NAME} + URL http://zlib.net/zlib128-dll.zip + URL_MD5 42eccc2af5bac6b7a1188d7817d03549 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD 1 + ) + + ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) + + set(${EXTERNAL_NAME_UPPER}_LIBRARY ${SOURCE_DIR}/lib/zdll.lib CACHE TYPE "Location of zlib library") + set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIR ${SOURCE_DIR}/include CACHE TYPE "Location of zlib includes") + set(${EXTERNAL_NAME_UPPER}_DLL_PATH ${SOURCE_DIR} CACHE TYPE "Location of zlib DLL") +endif () + diff --git a/cmake/macros/AddDependencyExternalProjects.cmake b/cmake/macros/AddDependencyExternalProjects.cmake index 72dbad6639..816036fc81 100644 --- a/cmake/macros/AddDependencyExternalProjects.cmake +++ b/cmake/macros/AddDependencyExternalProjects.cmake @@ -14,14 +14,31 @@ macro(ADD_DEPENDENCY_EXTERNAL_PROJECTS) foreach(_PROJ_NAME ${ARGN}) string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER) - - if (NOT DEFINED GET_${_PROJ_NAME_UPPER} OR GET_${_PROJ_NAME_UPPER}) - if (NOT TARGET ${_PROJ_NAME}) - add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${EXTERNALS_BINARY_DIR}/${_PROJ_NAME}) - endif () - - add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) + # has the user told us they specific don't want this as an external project? + if (NOT DEFINED GET_${_PROJ_NAME_UPPER} OR GET_${_PROJ_NAME_UPPER}) + # have we already detected we can't have this as external project on this OS? + if (NOT DEFINED ${_PROJ_NAME_UPPER}_EXTERNAL_PROJECT OR ${EXTERNAL_NAME_UPPER}_EXTERNAL_PROJECT) + # have we already setup the target? + if (NOT TARGET ${_PROJ_NAME}) + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${EXTERNALS_BINARY_DIR}/${_PROJ_NAME}) + + # did we end up adding an external project target? + if (NOT TARGET ${_PROJ_NAME}) + set(${_PROJ_NAME_UPPER}_EXTERNAL_PROJECT FALSE CACHE TYPE "Presence of ${_PROJ_NAME} as external target") + + message(STATUS "${_PROJ_NAME} was not added as an external project target for your OS." + " Either your system should already have the external library or you will need to install it separately.") + else () + set(${_PROJ_NAME_UPPER}_EXTERNAL_PROJECT TRUE CACHE TYPE "Presence of ${_PROJ_NAME} as external target") + endif () + endif () + + if (TARGET ${_PROJ_NAME}) + add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) + endif () + + endif () endif () endforeach() diff --git a/cmake/modules/FindZLIB.cmake b/cmake/modules/FindZLIB.cmake new file mode 100644 index 0000000000..f052939d04 --- /dev/null +++ b/cmake/modules/FindZLIB.cmake @@ -0,0 +1,162 @@ +#.rst: +# FindZLIB +# -------- +# +# Find the native ZLIB includes and library. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``ZLIB::ZLIB``, if +# ZLIB has been found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc. +# ZLIB_LIBRARIES - List of libraries when using zlib. +# ZLIB_FOUND - True if zlib found. +# +# :: +# +# ZLIB_VERSION_STRING - The version of zlib found (x.y.z) +# ZLIB_VERSION_MAJOR - The major version of zlib +# ZLIB_VERSION_MINOR - The minor version of zlib +# ZLIB_VERSION_PATCH - The patch version of zlib +# ZLIB_VERSION_TWEAK - The tweak version of zlib +# +# Backward Compatibility +# ^^^^^^^^^^^^^^^^^^^^^^ +# +# The following variable are provided for backward compatibility +# +# :: +# +# ZLIB_MAJOR_VERSION - The major version of zlib +# ZLIB_MINOR_VERSION - The minor version of zlib +# ZLIB_PATCH_VERSION - The patch version of zlib +# +# Hints +# ^^^^^ +# +# A user may set ``ZLIB_ROOT`` to a zlib installation root to tell this +# module where to look. + +#============================================================================= +# Copyright 2000-2014 Kitware, Inc. +# Copyright 2000-2011 Insight Software Consortium +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +# Modified on 2/19/2015 by Stephen Birarda +# The High Fidelity modification adds a ZLIB_DLL_PATH variable for fixup_bundle on windows + +set(_ZLIB_SEARCHES) + +# Search ZLIB_ROOT first if it is set. +if(ZLIB_ROOT) + set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH) + list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT) +endif() + +# Normal search. +set(_ZLIB_SEARCH_NORMAL + PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]" + "$ENV{PROGRAMFILES}/zlib" + ) +list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL) + +set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1) + +# Try each search configuration. +foreach(search ${_ZLIB_SEARCHES}) + find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include) + find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib) + + if (WIN32) + find_path(ZLIB_DLL_PATH NAMES zlib.dll ${${search}} PATH_SUFFIXES bin) + endif () +endforeach() + +mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) + +if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") + file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") + + string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") + string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") + string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") + set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") + + # only append a TWEAK version if it exists: + set(ZLIB_VERSION_TWEAK "") + if( "${ZLIB_H}" MATCHES "ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)") + set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") + set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}") + endif() + + set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}") + set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}") + set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}") +endif() + +set(ZLIB_REQUIREMENTS ZLIB_LIBRARY ZLIB_INCLUDE_DIR VERSION_VAR ZLIB_VERSION_STRING) +if (WIN32) + list(APPEND ZLIB_REQUIREMENTS ZLIB_DLL_PATH) +endif () + +# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ${ZLIB_REQUIREMENTS}) + +if(ZLIB_FOUND) + set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + set(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) + + if(NOT TARGET ZLIB::ZLIB) + add_library(ZLIB::ZLIB UNKNOWN IMPORTED) + set_target_properties(ZLIB::ZLIB PROPERTIES + IMPORTED_LOCATION "${ZLIB_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}") + endif() + + if (WIN32) + add_path_to_lib_paths(${ZLIB_DLL_PATH}) + endif () +endif() diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index ad42dd97cf..c54199dfe8 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -106,7 +106,7 @@ endif() add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) # set up the external glm library -add_dependency_external_projects(glm bullet) +add_dependency_external_projects(glm bullet zlib) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS})