Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/cmake/Modules/FindTBB.cmake is written in an unsupported language. File is not indexed.

0001 # - Find ThreadingBuildingBlocks include dirs and libraries
0002 # Use this module by invoking find_package with the form:
0003 #  find_package(TBB
0004 #    [REQUIRED]             # Fail with error if TBB is not found
0005 #    )                      #
0006 # Once done, this will define
0007 #
0008 #  TBB_FOUND - system has TBB
0009 #  TBB_INCLUDE_DIRS - the TBB include directories
0010 #  TBB_LIBRARIES - TBB libraries to be lined, doesn't include malloc or
0011 #                  malloc proxy
0012 #  TBB::tbb - imported target for the TBB library
0013 #
0014 #  TBB_VERSION_MAJOR - Major Product Version Number
0015 #  TBB_VERSION_MINOR - Minor Product Version Number
0016 #  TBB_INTERFACE_VERSION - Engineering Focused Version Number
0017 #  TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major interface version
0018 #                                     still supported. This uses the engineering
0019 #                                     focused interface version numbers.
0020 #
0021 #  TBB_MALLOC_FOUND - system has TBB malloc library
0022 #  TBB_MALLOC_INCLUDE_DIRS - the TBB malloc include directories
0023 #  TBB_MALLOC_LIBRARIES - The TBB malloc libraries to be lined
0024 #  TBB::malloc - imported target for the TBB malloc library
0025 #
0026 #  TBB_MALLOC_PROXY_FOUND - system has TBB malloc proxy library
0027 #  TBB_MALLOC_PROXY_INCLUDE_DIRS = the TBB malloc proxy include directories
0028 #  TBB_MALLOC_PROXY_LIBRARIES - The TBB malloc proxy libraries to be lined
0029 #  TBB::malloc_proxy - imported target for the TBB malloc proxy library
0030 #
0031 #
0032 # This module reads hints about search locations from variables:
0033 #  ENV TBB_ARCH_PLATFORM - for eg. set it to "mic" for Xeon Phi builds
0034 #  ENV TBB_ROOT or just TBB_ROOT - root directory of tbb installation
0035 #  ENV TBB_BUILD_PREFIX - specifies the build prefix for user built tbb
0036 #                         libraries. Should be specified with ENV TBB_ROOT
0037 #                         and optionally...
0038 #  ENV TBB_BUILD_DIR - if build directory is different than ${TBB_ROOT}/build
0039 #
0040 #
0041 # Modified by Robert Maynard from the original OGRE source
0042 #
0043 #-------------------------------------------------------------------
0044 # This file is part of the CMake build system for OGRE
0045 #     (Object-oriented Graphics Rendering Engine)
0046 # For the latest info, see http://www.ogre3d.org/
0047 #
0048 # The contents of this file are placed in the public domain. Feel
0049 # free to make use of it in any way you like.
0050 #-------------------------------------------------------------------
0051 #
0052 #=============================================================================
0053 # Copyright 2010-2012 Kitware, Inc.
0054 # Copyright 2012      Rolf Eike Beer <eike@sf-mail.de>
0055 #
0056 # Distributed under the OSI-approved BSD License (the "License");
0057 # see accompanying file COPYING-CMAKE-SCRIPTS for details.
0058 #
0059 # This software is distributed WITHOUT ANY WARRANTY; without even the
0060 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0061 # See the License for more information.
0062 #=============================================================================
0063 
0064 #=============================================================================
0065 #  FindTBB helper functions and macros
0066 #
0067 
0068 # Use TBBConfig.cmake if possible.
0069 
0070 set(_tbb_find_quiet)
0071 if (TBB_FIND_QUIETLY)
0072   set(_tbb_find_quiet QUIET)
0073 endif ()
0074 set(_tbb_find_components)
0075 set(_tbb_find_optional_components)
0076 foreach (_tbb_find_component IN LISTS TBB_FIND_COMPONENTS)
0077   if (TBB_FIND_REQUIRED_${_tbb_find_component})
0078     list(APPEND _tbb_find_components "${_tbb_find_component}")
0079   else ()
0080     list(APPEND _tbb_find_optional_components "${_tbb_find_component}")
0081   endif ()
0082 endforeach ()
0083 unset(_tbb_find_component)
0084 find_package(TBB CONFIG ${_tbb_find_quiet}
0085   COMPONENTS ${_tbb_find_components}
0086   OPTIONAL_COMPONENTS ${_tbb_find_optional_components})
0087 unset(_tbb_find_quiet)
0088 unset(_tbb_find_components)
0089 unset(_tbb_find_optional_components)
0090 if (TBB_FOUND)
0091   return ()
0092 endif ()
0093 
0094 #====================================================
0095 # Fix the library path in case it is a linker script
0096 #====================================================
0097 function(tbb_extract_real_library library real_library)
0098   if(NOT UNIX OR NOT EXISTS ${library})
0099     set(${real_library} "${library}" PARENT_SCOPE)
0100     return()
0101   endif()
0102 
0103   #Read in the first 4 bytes and see if they are the ELF magic number
0104   set(_elf_magic "7f454c46")
0105   file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX)
0106   if(_hex_data STREQUAL _elf_magic)
0107     #we have opened a elf binary so this is what
0108     #we should link to
0109     set(${real_library} "${library}" PARENT_SCOPE)
0110     return()
0111   endif()
0112 
0113   file(READ ${library} _data OFFSET 0 LIMIT 1024)
0114   if("${_data}" MATCHES "INPUT \\(([^(]+)\\)")
0115     #extract out the .so name from REGEX MATCH command
0116     set(_proper_so_name "${CMAKE_MATCH_1}")
0117 
0118     #construct path to the real .so which is presumed to be in the same directory
0119     #as the input file
0120     get_filename_component(_so_dir "${library}" DIRECTORY)
0121     set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE)
0122   else()
0123     #unable to determine what this library is so just hope everything works
0124     #and pass it unmodified.
0125     set(${real_library} "${library}" PARENT_SCOPE)
0126   endif()
0127 endfunction()
0128 
0129 #===============================================
0130 # Do the final processing for the package find.
0131 #===============================================
0132 macro(findpkg_finish PREFIX TARGET_NAME)
0133   if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
0134     set(${PREFIX}_FOUND TRUE)
0135     set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
0136     set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
0137   else ()
0138     if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY)
0139       message(FATAL_ERROR "Required library ${PREFIX} not found.")
0140     endif ()
0141   endif ()
0142 
0143   if (NOT TARGET "TBB::${TARGET_NAME}")
0144     if (${PREFIX}_LIBRARY_RELEASE)
0145       tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release)
0146     endif ()
0147     if (${PREFIX}_LIBRARY_DEBUG)
0148       tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug)
0149     endif ()
0150     add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED)
0151     set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0152       INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}")
0153     if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE)
0154       set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0155         IMPORTED_LOCATION "${real_release}"
0156         IMPORTED_LOCATION_DEBUG "${real_debug}"
0157         IMPORTED_LOCATION_RELEASE "${real_release}")
0158     elseif (${PREFIX}_LIBRARY_RELEASE)
0159       set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0160         IMPORTED_LOCATION "${real_release}")
0161     elseif (${PREFIX}_LIBRARY_DEBUG)
0162       set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0163         IMPORTED_LOCATION "${real_debug}")
0164     endif ()
0165   endif ()
0166 
0167   #mark the following variables as internal variables
0168   mark_as_advanced(${PREFIX}_INCLUDE_DIR
0169                    ${PREFIX}_LIBRARY
0170                    ${PREFIX}_LIBRARY_DEBUG
0171                    ${PREFIX}_LIBRARY_RELEASE)
0172 endmacro()
0173 
0174 #===============================================
0175 # Generate debug names from given release names
0176 #===============================================
0177 macro(get_debug_names PREFIX)
0178   foreach(i ${${PREFIX}})
0179     set(${PREFIX}_DEBUG ${${PREFIX}_DEBUG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
0180   endforeach()
0181 endmacro()
0182 
0183 #===============================================
0184 # See if we have env vars to help us find tbb
0185 #===============================================
0186 macro(getenv_path VAR)
0187    set(ENV_${VAR} $ENV{${VAR}})
0188    # replace won't work if var is blank
0189    if (ENV_${VAR})
0190      string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
0191    endif ()
0192 endmacro()
0193 
0194 #===============================================
0195 # Couple a set of release AND debug libraries
0196 #===============================================
0197 macro(make_library_set PREFIX)
0198   if (${PREFIX}_RELEASE AND ${PREFIX}_DEBUG)
0199     set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG})
0200   elseif (${PREFIX}_RELEASE)
0201     set(${PREFIX} ${${PREFIX}_RELEASE})
0202   elseif (${PREFIX}_DEBUG)
0203     set(${PREFIX} ${${PREFIX}_DEBUG})
0204   endif ()
0205 endmacro()
0206 
0207 
0208 #=============================================================================
0209 #  Now to actually find TBB
0210 #
0211 
0212 # Get path, convert backslashes as ${ENV_${var}}
0213 getenv_path(TBB_ROOT)
0214 
0215 # initialize search paths
0216 set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT})
0217 set(TBB_INC_SEARCH_PATH "")
0218 set(TBB_LIB_SEARCH_PATH "")
0219 
0220 
0221 # If user built from sources
0222 set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX})
0223 if (TBB_BUILD_PREFIX AND ENV_TBB_ROOT)
0224   getenv_path(TBB_BUILD_DIR)
0225   if (NOT ENV_TBB_BUILD_DIR)
0226     set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build)
0227   endif ()
0228 
0229   # include directory under ${ENV_TBB_ROOT}/include
0230   list(APPEND TBB_LIB_SEARCH_PATH
0231     ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release
0232     ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug)
0233 endif ()
0234 
0235 
0236 # For Windows, let's assume that the user might be using the precompiled
0237 # TBB packages from the main website. These use a rather awkward directory
0238 # structure (at least for automatically finding the right files) depending
0239 # on platform and compiler, but we'll do our best to accommodate it.
0240 # Not adding the same effort for the precompiled linux builds, though. Those
0241 # have different versions for CC compiler versions and linux kernels which
0242 # will never adequately match the user's setup, so there is no feasible way
0243 # to detect the "best" version to use. The user will have to manually
0244 # select the right files. (Chances are the distributions are shipping their
0245 # custom version of tbb, anyway, so the problem is probably nonexistent.)
0246 if (WIN32 AND MSVC)
0247   set(COMPILER_PREFIX "vc7.1")
0248   if (MSVC_VERSION EQUAL 1400)
0249     set(COMPILER_PREFIX "vc8")
0250   elseif(MSVC_VERSION EQUAL 1500)
0251     set(COMPILER_PREFIX "vc9")
0252   elseif(MSVC_VERSION EQUAL 1600)
0253     set(COMPILER_PREFIX "vc10")
0254   elseif(MSVC_VERSION EQUAL 1700)
0255     set(COMPILER_PREFIX "vc11")
0256   elseif(MSVC_VERSION EQUAL 1800)
0257     set(COMPILER_PREFIX "vc12")
0258   elseif(MSVC_VERSION GREATER_EQUAL 1900)
0259     set(COMPILER_PREFIX "vc14")
0260   endif ()
0261 
0262   # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path
0263   foreach (dir IN LISTS TBB_PREFIX_PATH)
0264     if (CMAKE_CL_64)
0265       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib)
0266       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX})
0267       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${COMPILER_PREFIX}/lib)
0268       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${COMPILER_PREFIX})
0269     else ()
0270       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib)
0271       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX})
0272     endif ()
0273   endforeach ()
0274 endif ()
0275 
0276 # For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9)
0277 # and above and AppleClang
0278 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
0279     NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0)
0280   set (USE_LIBCXX OFF)
0281   cmake_policy(GET CMP0025 POLICY_VAR)
0282 
0283   if (POLICY_VAR STREQUAL "NEW")
0284     if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
0285       set (USE_LIBCXX ON)
0286     endif ()
0287   else ()
0288     if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
0289       set (USE_LIBCXX ON)
0290     endif ()
0291   endif ()
0292 
0293   if (USE_LIBCXX)
0294     foreach (dir IN LISTS TBB_PREFIX_PATH)
0295       list (APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib)
0296     endforeach ()
0297   endif ()
0298 endif ()
0299 
0300 # check compiler ABI
0301 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
0302   set(COMPILER_PREFIX)
0303   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
0304     list(APPEND COMPILER_PREFIX "gcc4.8")
0305   endif()
0306   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
0307     list(APPEND COMPILER_PREFIX "gcc4.7")
0308   endif()
0309   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
0310     list(APPEND COMPILER_PREFIX "gcc4.4")
0311   endif()
0312   list(APPEND COMPILER_PREFIX "gcc4.1")
0313 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
0314   set(COMPILER_PREFIX)
0315   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess
0316     list(APPEND COMPILER_PREFIX "gcc4.8")
0317   endif()
0318   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
0319     list(APPEND COMPILER_PREFIX "gcc4.7")
0320   endif()
0321   list(APPEND COMPILER_PREFIX "gcc4.4")
0322 else() # Assume compatibility with 4.4 for other compilers
0323   list(APPEND COMPILER_PREFIX "gcc4.4")
0324 endif ()
0325 
0326 # if platform architecture is explicitly specified
0327 set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
0328 if (TBB_ARCH_PLATFORM)
0329   foreach (dir IN LISTS TBB_PREFIX_PATH)
0330     list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib)
0331     list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM})
0332   endforeach ()
0333 endif ()
0334 
0335 foreach (dir IN LISTS TBB_PREFIX_PATH)
0336   foreach (prefix IN LISTS COMPILER_PREFIX)
0337     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
0338       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64)
0339       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix})
0340       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib)
0341       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib)
0342     else ()
0343       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32)
0344       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix})
0345       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib)
0346       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib)
0347     endif ()
0348   endforeach()
0349 endforeach ()
0350 
0351 # add general search paths
0352 foreach (dir IN LISTS TBB_PREFIX_PATH)
0353   list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib ${dir}/Lib ${dir}/lib/tbb
0354     ${dir}/Libs)
0355   list(APPEND TBB_INC_SEARCH_PATH ${dir}/include ${dir}/Include
0356     ${dir}/include/tbb)
0357 endforeach ()
0358 
0359 set(TBB_LIBRARY_NAMES tbb)
0360 get_debug_names(TBB_LIBRARY_NAMES)
0361 
0362 
0363 find_path(TBB_INCLUDE_DIR
0364           NAMES tbb/tbb.h
0365           PATHS ${TBB_INC_SEARCH_PATH})
0366 
0367 find_library(TBB_LIBRARY_RELEASE
0368              NAMES ${TBB_LIBRARY_NAMES}
0369              PATHS ${TBB_LIB_SEARCH_PATH})
0370 find_library(TBB_LIBRARY_DEBUG
0371              NAMES ${TBB_LIBRARY_NAMES_DEBUG}
0372              PATHS ${TBB_LIB_SEARCH_PATH})
0373 make_library_set(TBB_LIBRARY)
0374 
0375 findpkg_finish(TBB tbb)
0376 
0377 #if we haven't found TBB no point on going any further
0378 if (NOT TBB_FOUND)
0379   return()
0380 endif ()
0381 
0382 #=============================================================================
0383 # Look for TBB's malloc package
0384 set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc)
0385 get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
0386 
0387 find_path(TBB_MALLOC_INCLUDE_DIR
0388           NAMES tbb/tbb.h
0389           PATHS ${TBB_INC_SEARCH_PATH})
0390 
0391 find_library(TBB_MALLOC_LIBRARY_RELEASE
0392              NAMES ${TBB_MALLOC_LIBRARY_NAMES}
0393              PATHS ${TBB_LIB_SEARCH_PATH})
0394 find_library(TBB_MALLOC_LIBRARY_DEBUG
0395              NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG}
0396              PATHS ${TBB_LIB_SEARCH_PATH})
0397 make_library_set(TBB_MALLOC_LIBRARY)
0398 
0399 findpkg_finish(TBB_MALLOC tbbmalloc)
0400 
0401 #=============================================================================
0402 # Look for TBB's malloc proxy package
0403 set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy)
0404 get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
0405 
0406 find_path(TBB_MALLOC_PROXY_INCLUDE_DIR
0407           NAMES tbb/tbbmalloc_proxy.h
0408           PATHS ${TBB_INC_SEARCH_PATH})
0409 
0410 find_library(TBB_MALLOC_PROXY_LIBRARY_RELEASE
0411              NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES}
0412              PATHS ${TBB_LIB_SEARCH_PATH})
0413 find_library(TBB_MALLOC_PROXY_LIBRARY_DEBUG
0414              NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG}
0415              PATHS ${TBB_LIB_SEARCH_PATH})
0416 make_library_set(TBB_MALLOC_PROXY_LIBRARY)
0417 
0418 findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)
0419 
0420 
0421 #=============================================================================
0422 #parse all the version numbers from tbb
0423 if(NOT TBB_VERSION)
0424   if (EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h")
0425     file(STRINGS
0426       "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h"
0427       TBB_VERSION_CONTENTS
0428       REGEX "VERSION")
0429   else()
0430     #only read the start of the file
0431     file(STRINGS
0432       "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h"
0433       TBB_VERSION_CONTENTS
0434       REGEX "VERSION")
0435   endif()
0436 
0437   string(REGEX REPLACE
0438     ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
0439     TBB_VERSION_MAJOR "${TBB_VERSION_CONTENTS}")
0440 
0441   string(REGEX REPLACE
0442     ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
0443     TBB_VERSION_MINOR "${TBB_VERSION_CONTENTS}")
0444 
0445   string(REGEX REPLACE
0446         ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
0447         TBB_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
0448 
0449   string(REGEX REPLACE
0450         ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1"
0451         TBB_COMPATIBLE_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
0452 
0453   set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
0454 
0455 endif()
0456 
0457 include(FindPackageHandleStandardArgs)
0458 find_package_handle_standard_args(TBB
0459   REQUIRED_VARS TBB_INCLUDE_DIR TBB_LIBRARY
0460   VERSION_VAR TBB_VERSION)