Commit 5889d2b8 authored by Jakob Weiss's avatar Jakob Weiss
Browse files

Further necessary updates for VS 17

parent 3a2fa399
Loading
Loading
Loading
Loading

cmake/FindTBB.cmake

deleted100644 → 0
+0 −112
Original line number Diff line number Diff line
# Try to find TBB library and include path. Once done this will define:
# TBB_FOUND
# TBB_DEFINITIONS
# TBB_INCLUDE_DIR
# TBB_LIBRARY (containing both debug and release libraries on win32)
# TBB_LICENSE_FILE

IF (WIN32)
    IF(NOT TBB_ROOT)
        # check environment variables
        IF(NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
            SET(TbbDirectory $ENV{TBB_INSTALL_DIR})
        ENDIF(NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
        
        # check default install directory
        set(_TbbSeachPaths "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB" "${CampvisHome}/ext/tbb")
        FIND_PATH( 
            TBB_ROOT 
            NAMES include/tbb/tbb.h
            PATHS ${_TbbSeachPaths}
            DOC "Intel TBB directory with includes, libs and dlls (i.e. where you extracted the binary distribution from threadingbuildingblocks.org.)"
        )
        
        IF(NOT TBB_ROOT)
            MESSAGE(FATAL_ERROR "Could not find Intel TBB. Please set TBB_ROOT to the Intel TBB directory with includes, libs and dlls (i.e. where you extracted the binary distribution from threadingbuildingblocks.org.)")
        ENDIF()
    ENDIF()
    
    SET(TbbDirectory ${TBB_ROOT})
   
    IF(CAMPVIS_MSVC2010)
        SET(TbbCompilerDirectory "vc10")
    ELSEIF(CAMPVIS_MSVC11)
        SET(TbbCompilerDirectory "vc11")
    ELSEIF(CAMPVIS_MSVC12)
        SET(TbbCompilerDirectory "vc12")    
	ELSEIF(CAMPVIS_MSVC14)
        SET(TbbCompilerDirectory "vc14")
    ELSEIF(CAMPVIS_MSVC15)
        SET(TbbCompilerDirectory "vc14")
    ELSE()
        MESSAGE(WARNING "Compiler not supported by makefile, you might be able to fix that...")
    ENDIF(CAMPVIS_MSVC2010)
    
    FIND_PATH( 
        TBB_INCLUDE_DIR 
        NAMES tbb/tbb.h
        PATHS ${TbbDirectory}/include
        DOC "Intel TBB include directory (i.e. where tbb/tbb.h is)"
    )
    
    # set debug and release library
    IF(CAMPVIS_WIN32)
        SET(TbbPlatformDirectory "ia32")
    ELSEIF(CAMPVIS_WIN64)
        SET(TbbPlatformDirectory "intel64")
    ELSE()
        MESSAGE(FATAL_ERROR "Neither CAMPVIS_WIN32 nor CAMPVIS_WIN64 defined!")
    ENDIF(CAMPVIS_WIN32)

    SET(TBB_LIBRARY_DEBUG      "${TbbDirectory}/lib/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbb_debug.lib")
    SET(TBB_DLL_DEBUG          "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbb_debug.dll")
    SET(TBB_PDB_DEBUG          "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbb_debug.pdb")
    SET(TBB_LIBRARY_RELEASE    "${TbbDirectory}/lib/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbb.lib")
    SET(TBB_DLL_RELEASE        "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbb.dll")
    SET(TBB_PDB_RELEASE        "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbb.pdb")
    IF(TBB_LIBRARY_DEBUG AND TBB_LIBRARY_RELEASE)
        SET(TBB_LIBRARY debug ${TBB_LIBRARY_DEBUG} optimized ${TBB_LIBRARY_RELEASE})
    ENDIF(TBB_LIBRARY_DEBUG AND TBB_LIBRARY_RELEASE)
    

    SET(TBB_MALLOC_LIBRARY_DEBUG      "${TbbDirectory}/lib/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbbmalloc_debug.lib")
    SET(TBB_MALLOC_DLL_DEBUG          "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbbmalloc_debug.dll")
    SET(TBB_MALLOC_PDB_DEBUG          "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbbmalloc_debug.pdb")
    SET(TBB_MALLOC_LIBRARY_RELEASE    "${TbbDirectory}/lib/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbbmalloc.lib")
    SET(TBB_MALLOC_DLL_RELEASE        "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbbmalloc.dll")
    SET(TBB_MALLOC_PDB_RELEASE        "${TbbDirectory}/bin/${TbbPlatformDirectory}/${TbbCompilerDirectory}/tbbmalloc.pdb")
    IF(TBB_MALLOC_LIBRARY_DEBUG AND TBB_MALLOC_LIBRARY_RELEASE)
        SET(TBB_MALLOC_LIBRARY debug ${TBB_MALLOC_LIBRARY_DEBUG} optimized ${TBB_MALLOC_LIBRARY_RELEASE})
    ENDIF(TBB_MALLOC_LIBRARY_DEBUG AND TBB_MALLOC_LIBRARY_RELEASE)
    
    SET(TBB_LICENSE_FILE "${TbbDirectory}/COPYING")
    
ELSE (WIN32)
    FIND_PATH( 
        TBB_INCLUDE_DIR 
        NAMES tbb/mutex.h
        PATHS ${TbbDirectory}/include /usr/include /usr/local/include /sw/include /opt/local/include
        DOC "The directory where tbb/*.h resides"
    )
    FIND_LIBRARY(
        TBB_LIBRARY
        NAMES libtbb.so
        PATHS ${TbbDirectory}/lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /sw/lib /opt/local/lib
        DOC "The TBB library"
    )
    FIND_LIBRARY(
        TBB_MALLOC_LIBRARY
        NAMES libtbbmalloc.so
        PATHS ${TbbDirectory}/lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /sw/lib /opt/local/lib
        DOC "The TBB malloc library"
    )
ENDIF (WIN32)

IF(TBB_INCLUDE_DIR AND TBB_LIBRARY)
    SET(TBB_FOUND TRUE)
ELSE(TBB_INCLUDE_DIR AND TBB_LIBRARY)
    SET(TBB_FOUND FALSE)
ENDIF(TBB_INCLUDE_DIR AND TBB_LIBRARY)

UNSET(TbbDirectory)
MARK_AS_ADVANCED(TbbDirectory TbbDirectory TBB_INCLUDE_DIR TBB_LIBRARY TBB_LIBRARY_DEBUG TBB_LIBRARY_RELEASE TBB_DLL_DEBUG TBB_DLL_RELEASE)

cmake/_FindTBB.cmake

0 → 100644
+303 −0
Original line number Diff line number Diff line
# The MIT License (MIT)
#
# Copyright (c) 2015 Justus Calvin
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

#
# FindTBB
# -------
#
# Find TBB include directories and libraries.
#
# Usage:
#
#  find_package(TBB [major[.minor]] [EXACT]
#               [QUIET] [REQUIRED]
#               [[COMPONENTS] [components...]]
#               [OPTIONAL_COMPONENTS components...]) 
#
# where the allowed components are tbbmalloc and tbb_preview. Users may modify 
# the behavior of this module with the following variables:
#
# * TBB_ROOT_DIR          - The base directory the of TBB installation.
# * TBB_INCLUDE_DIR       - The directory that contains the TBB headers files.
# * TBB_LIBRARY           - The directory that contains the TBB library files.
# * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library. 
#                           These libraries, if specified, override the 
#                           corresponding library search results, where <library>
#                           may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug,
#                           tbb_preview, or tbb_preview_debug.
# * TBB_USE_DEBUG_BUILD   - The debug version of tbb libraries, if present, will
#                           be used instead of the release version.
#
# Users may modify the behavior of this module with the following environment
# variables:
#
# * TBB_INSTALL_DIR 
# * TBBROOT
# * LIBRARY_PATH
#
# This module will set the following variables:
#
# * TBB_FOUND             - Set to false, or undefined, if we haven’t found, or
#                           don’t want to use TBB.
# * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is
#                           not available.
# * TBB_VERSION           - The full version string
# * TBB_VERSION_MAJOR     - The major version
# * TBB_VERSION_MINOR     - The minor version
# * TBB_INTERFACE_VERSION - The interface version number defined in 
#                           tbb/tbb_stddef.h.
# * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of 
#                           <library>, where <library> may be tbb, tbb_debug,
#                           tbbmalloc, tbbmalloc_debug, tbb_preview, or 
#                           tbb_preview_debug.
# * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of 
#                           <library>, where <library> may be tbb, tbb_debug,
#                           tbbmalloc, tbbmalloc_debug, tbb_preview, or 
#                           tbb_preview_debug.
#
# The following varibles should be used to build and link with TBB:
#
# * TBB_INCLUDE_DIRS        - The include directory for TBB.
# * TBB_LIBRARIES           - The libraries to link against to use TBB.
# * TBB_LIBRARIES_RELEASE   - The release libraries to link against to use TBB.
# * TBB_LIBRARIES_DEBUG     - The debug libraries to link against to use TBB.
# * TBB_DEFINITIONS         - Definitions to use when compiling code that uses
#                             TBB.
# * TBB_DEFINITIONS_RELEASE - Definitions to use when compiling release code that
#                             uses TBB.
# * TBB_DEFINITIONS_DEBUG   - Definitions to use when compiling debug code that
#                             uses TBB.
#
# This module will also create the "tbb" target that may be used when building
# executables and libraries.

include(FindPackageHandleStandardArgs)

if(NOT TBB_FOUND)

  ##################################
  # Check the build type
  ##################################
  
  if(NOT DEFINED TBB_USE_DEBUG_BUILD)
    if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)")
      set(TBB_BUILD_TYPE DEBUG)
    else()
      set(TBB_BUILD_TYPE RELEASE)
    endif()
  elseif(TBB_USE_DEBUG_BUILD)
    set(TBB_BUILD_TYPE DEBUG)
  else()
    set(TBB_BUILD_TYPE RELEASE)
  endif()
  
  ##################################
  # Set the TBB search directories
  ##################################
  
  # Define search paths based on user input and environment variables
  set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT})
  
  # Define the search directories based on the current platform
  if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
    set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB"
                               "C:/Program Files (x86)/Intel/TBB")

    # Set the target architecture
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
      set(TBB_ARCHITECTURE "intel64")
    else()
      set(TBB_ARCHITECTURE "ia32")
    endif()

    # Set the TBB search library path search suffix based on the version of VC
    if(WINDOWS_STORE)
      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui")
    elseif(MSVC14)
      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14")
    elseif(MSVC12)
      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12")
    elseif(MSVC11)
      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11")
    elseif(MSVC10)
      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10")
    endif()

    # Add the library path search suffix for the VC independent version of TBB
    list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt")

  elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
    # OS X
    set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
    
    # TODO: Check to see which C++ library is being used by the compiler.
    if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0)
      # The default C++ library on OS X 10.9 and later is libc++
      set(TBB_LIB_PATH_SUFFIX "lib/libc++" "lib")
    else()
      set(TBB_LIB_PATH_SUFFIX "lib")
    endif()
  elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    # Linux
    set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
    
    # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or
    #       <arch>/gcc4.1. For now, assume that the compiler is more recent than
    #       gcc 4.4.x or later.
    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
      set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4")
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
      set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4")
    endif()
  endif()
  
  ##################################
  # Find the TBB include dir
  ##################################
  
  find_path(TBB_INCLUDE_DIRS tbb/tbb.h
      HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR}
      PATHS ${TBB_DEFAULT_SEARCH_DIR}
      PATH_SUFFIXES include)

  ##################################
  # Set version strings
  ##################################

  if(TBB_INCLUDE_DIRS)
    file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file)
    string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
        TBB_VERSION_MAJOR "${_tbb_version_file}")
    string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
        TBB_VERSION_MINOR "${_tbb_version_file}")
    string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
        TBB_INTERFACE_VERSION "${_tbb_version_file}")
    set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
  endif()

  ##################################
  # Find TBB components
  ##################################

  if(TBB_VERSION VERSION_LESS 4.3)
    set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb)
  else()
    set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb)
  endif()

  # Find each component
  foreach(_comp ${TBB_SEARCH_COMPOMPONENTS})
    if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};")

      # Search for the libraries
      find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}
          HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
          PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
          PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})

      find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug
          HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
          PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
          PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})

      if(TBB_${_comp}_LIBRARY_DEBUG)
        list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}")
      endif()
      if(TBB_${_comp}_LIBRARY_RELEASE)
        list(APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}")
      endif()
      if(TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp}_LIBRARY)
        set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}")
      endif()

      if(TBB_${_comp}_LIBRARY AND EXISTS "${TBB_${_comp}_LIBRARY}")
        set(TBB_${_comp}_FOUND TRUE)
      else()
        set(TBB_${_comp}_FOUND FALSE)
      endif()

      # Mark internal variables as advanced
      mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE)
      mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG)
      mark_as_advanced(TBB_${_comp}_LIBRARY)

    endif()
  endforeach()

  ##################################
  # Set compile flags and libraries
  ##################################

  set(TBB_DEFINITIONS_RELEASE "")
  set(TBB_DEFINITIONS_DEBUG "-DTBB_USE_DEBUG=1")
    
  if(TBB_LIBRARIES_${TBB_BUILD_TYPE})
    set(TBB_DEFINITIONS "${TBB_DEFINITIONS_${TBB_BUILD_TYPE}}")
    set(TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE}}")
  elseif(TBB_LIBRARIES_RELEASE)
    set(TBB_DEFINITIONS "${TBB_DEFINITIONS_RELEASE}")
    set(TBB_LIBRARIES "${TBB_LIBRARIES_RELEASE}")
  elseif(TBB_LIBRARIES_DEBUG)
    set(TBB_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}")
    set(TBB_LIBRARIES "${TBB_LIBRARIES_DEBUG}")
  endif()

  find_package_handle_standard_args(TBB 
      REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
      HANDLE_COMPONENTS
      VERSION_VAR TBB_VERSION)

  ##################################
  # Create targets
  ##################################

  if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND)
    add_library(tbb SHARED IMPORTED)
    set_target_properties(tbb PROPERTIES
          INTERFACE_INCLUDE_DIRECTORIES  ${TBB_INCLUDE_DIRS}
          IMPORTED_LOCATION              ${TBB_LIBRARIES})
    if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG)
      set_target_properties(tbb PROPERTIES
          INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>"
          IMPORTED_LOCATION_DEBUG          ${TBB_LIBRARIES_DEBUG}
          IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_DEBUG}
          IMPORTED_LOCATION_RELEASE        ${TBB_LIBRARIES_RELEASE}
          IMPORTED_LOCATION_MINSIZEREL     ${TBB_LIBRARIES_RELEASE}
          )
    elseif(TBB_LIBRARIES_RELEASE)
      set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE})
    else()
      set_target_properties(tbb PROPERTIES
          INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}"
          IMPORTED_LOCATION              ${TBB_LIBRARIES_DEBUG}
          )
    endif()
  endif()

  mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)

  unset(TBB_ARCHITECTURE)
  unset(TBB_BUILD_TYPE)
  unset(TBB_LIB_PATH_SUFFIX)
  unset(TBB_DEFAULT_SEARCH_DIR)

endif()
+7 −5
Original line number Diff line number Diff line
@@ -254,13 +254,15 @@ ENDIF(GLEW_FOUND)
FIND_PACKAGE(TBB REQUIRED)
IF(TBB_FOUND)
    MESSAGE(STATUS "* Found TBB")
    LIST(APPEND CampvisGlobalDefinitions ${TBB_DEFINITIONS})
    LIST(APPEND CampvisGlobalIncludeDirs ${TBB_INCLUDE_DIR})
    LIST(APPEND CampvisGlobalExternalLibs ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY})
    #LIST(APPEND CampvisGlobalDefinitions ${TBB_DEFINITIONS})
    #LIST(APPEND CampvisGlobalIncludeDirs ${TBB_INCLUDE_DIR})
    LIST(APPEND CampvisGlobalExternalLibs TBB::tbb TBB::tbbmalloc)
    LIST(APPEND CampvisExternalDllsDebug ${TBB_DLL_DEBUG} ${TBB_MALLOC_DLL_DEBUG})
    LIST(APPEND CampvisExternalDllsRelease ${TBB_DLL_RELEASE} ${TBB_MALLOC_DLL_RELEASE})
    LIST(APPEND CampvisExternalLicenseFiles ${TBB_LICENSE_FILE})

    if(WIN32 AND NOT TBB_DLL_DEBUG)
        message(WARNING "TBB DLL Paths could not resolved. Please copy TBB dlls manually to output directory. (VCPKG takes care of that for you if you use it..)")
    endif()
    #LIST(APPEND CampvisExternalLicenseFiles ${TBB_LICENSE_FILE})
    # unfortunately, the new TBB API does no longer allow copying of mutexes, hence we need to set a fallback define
    LIST(APPEND CampvisGlobalDefinitions "-DTBB_DEPRECATED_MUTEX_COPYING")
ELSE(TBB_FOUND)