Salome HOME
Copyright update 2022
[tools/configuration.git] / cmake / FindTBB.cmake
1 # - Find TBB
2 # Sets the following variables:
3 #   TBB_INCLUDE_DIRS - path to the TBB include directory
4 #   TBB_LIBRARIES    - path to the TBB libraries to be linked against
5 #
6
7 #########################################################################
8 # Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23 #
24 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 #
26
27 # ------
28
29 MESSAGE(STATUS "Check for TBB ...")
30
31 # ------
32
33 SET(TBB_ROOT_DIR $ENV{TBB_ROOT_DIR})
34
35 IF(TBB_ROOT_DIR)
36   LIST(APPEND CMAKE_PREFIX_PATH "${TBB_ROOT_DIR}")
37 ENDIF(TBB_ROOT_DIR)
38
39 FIND_PATH(TBB_INCLUDE_DIRS tbb/tbb.h PATH_SUFFIXES include)
40
41 IF(MACHINE_IS_64)
42   SET(PLT_SUFFIX intel64)
43 ELSE(MACHINE_IS_64)
44   SET(PLT_SUFFIX ia32)
45 ENDIF(MACHINE_IS_64)
46
47 include(CheckCXXSourceCompiles)
48
49 SET(_PATH_SUFFIXES)
50 IF(TBB_ROOT_DIR)
51   FOREACH(_PATH cc4.1.0_libc2.4_kernel2.6.16.21 gcc4.4 gcc4.1)
52     LIST(APPEND _PATH_SUFFIXES ${PLT_SUFFIX}/${_PATH})
53   ENDFOREACH()
54 ENDIF()
55
56 FIND_LIBRARY(_tbb_library_tbb       
57              NAMES tbb   
58              PATH_SUFFIXES ${_PATH_SUFFIXES})
59 FIND_LIBRARY(_tbb_library_tbbmalloc 
60              NAMES tbbmalloc 
61              PATH_SUFFIXES ${_PATH_SUFFIXES})
62
63 SET(_tbb_libraries ${_tbb_library_tbb} ${_tbb_library_tbbmalloc})
64
65 IF(_tbb_libraries)
66
67   SET(CMAKE_REQUIRED_INCLUDES_SAVE  ${CMAKE_REQUIRED_INCLUDES})
68   SET(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
69   SET(CMAKE_REQUIRED_INCLUDES  "${CMAKE_REQUIRED_INCLUDES} ${TBB_INCLUDE_DIRS}")
70   SET(CMAKE_REQUIRED_LIBRARIES "${_tbb_libraries}")
71
72   CHECK_CXX_SOURCE_COMPILES("
73     #include <tbb/parallel_for.h>
74     using namespace tbb;
75     size_t testme(size_t n)
76     {
77       return n*n;
78     }
79     int main(int argc, char* argv[])
80     {
81       parallel_for<size_t>( 1, 10, 1, testme );
82     }
83     "
84     _tbb_link_ok
85     )
86     
87   SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
88   SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
89
90   IF(_tbb_link_ok)
91     SET(TBB_LIBRARY_tbb       ${_tbb_library_tbb}       CACHE FILEPATH "Path to a library")
92     SET(TBB_LIBRARY_tbbmalloc ${_tbb_library_tbbmalloc} CACHE FILEPATH "Path to a library")
93     SET(TBB_LIBRARIES ${TBB_LIBRARY_tbb} ${TBB_LIBRARY_tbbmalloc})
94   ENDIF()
95
96 ENDIF(_tbb_libraries)
97
98 INCLUDE(FindPackageHandleStandardArgs)
99 FIND_PACKAGE_HANDLE_STANDARD_ARGS(TBB REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARY_tbb TBB_LIBRARY_tbbmalloc)