external_tbb.cmake 3.39 KB
Newer Older
1
# ******************************************************************************
2
# Copyright 2017-2019 Intel Corporation
3
#
4 5 6
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10 11 12 13 14
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
15
# ******************************************************************************
16

17
#------------------------------------------------------------------------------
18
# Fetch and configure TBB
19
#------------------------------------------------------------------------------
20

21 22
set(TBB_GIT_REPO_URL https://github.com/01org/tbb)
set(NGRAPH_TBB_VERSION "2019_U3")
23

24
if(NGRAPH_TBB_ENABLE)
25 26
    set(TBB_ROOT ${CMAKE_CURRENT_BINARY_DIR}/tbb/tbb-src)

27 28
    configure_file(${CMAKE_SOURCE_DIR}/cmake/tbb_fetch.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/tbb/CMakeLists.txt)
    execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
29
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tbb")
30
    execute_process(COMMAND "${CMAKE_COMMAND}" --build .
31
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tbb")
32 33 34

    include(${TBB_ROOT}/cmake/TBBBuild.cmake)
    tbb_build(TBB_ROOT ${TBB_ROOT} MAKE_ARGS tbb_build_dir=${CMAKE_CURRENT_BINARY_DIR}/tbb_build
35
        tbb_build_prefix=tbb stdver=c++${NGRAPH_CXX_STANDARD} CONFIG_DIR TBB_DIR)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    find_package(TBB REQUIRED tbb)
    if (NOT TBB_FOUND)
        message(FATAL_ERROR "TBB is needed by the CPU backend and was not found")
    else()
        message(STATUS "Found TBB and imported target ${TBB_IMPORTED_TARGETS}")
    endif()

    set_source_files_properties(cpu_external_function.cpp
        PROPERTIES COMPILE_DEFINITIONS "NGRAPH_TBB_ENABLE")

    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
        set(TBB_LIB_NAME tbb_debug)
        set(TBB_BUILDDIR_NAME tbb_debug)
    else()
        set(TBB_LIB_NAME tbb)
        set(TBB_BUILDDIR_NAME tbb_release)
    endif()
53 54 55 56
    set(TBB_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/tbb_build/${TBB_BUILDDIR_NAME})
    set(TBB_LIB ${CMAKE_SHARED_LIBRARY_PREFIX}${TBB_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
    file(COPY
             ${TBB_BUILD_DIR}/${TBB_LIB}
57
         DESTINATION ${NGRAPH_LIBRARY_OUTPUT_DIRECTORY})
58 59 60 61 62 63
    if(LINUX)
        execute_process(COMMAND grep TBB_COMPATIBLE_INTERFACE_VERSION ${TBB_ROOT}/include/tbb/tbb_stddef.h OUTPUT_VARIABLE TBB_SOVER_LINE)
        string(REGEX MATCH "[0-9.]+" TBB_SOVER ${TBB_SOVER_LINE})
        message(STATUS "TBB so version: ${TBB_SOVER}")
        file(COPY
                ${TBB_BUILD_DIR}/${TBB_LIB}.${TBB_SOVER}
64
             DESTINATION ${NGRAPH_LIBRARY_OUTPUT_DIRECTORY})
65
    endif()
66
    install(FILES ${NGRAPH_LIBRARY_INSTALL_SRC_DIRECTORY}/${TBB_LIB}
67 68
        DESTINATION ${NGRAPH_INSTALL_LIB})
    if(LINUX)
69
        install(FILES ${NGRAPH_LIBRARY_INSTALL_SRC_DIRECTORY}/${TBB_LIB}.${TBB_SOVER}
70 71
            DESTINATION ${NGRAPH_INSTALL_LIB})
    endif()
72 73
    add_library(libtbb INTERFACE)
    target_link_libraries(libtbb INTERFACE
74
        ${NGRAPH_LIBRARY_OUTPUT_DIRECTORY}/${TBB_LIB}
75 76
    )
    target_include_directories(libtbb SYSTEM INTERFACE ${TBB_ROOT}/include)
77
endif()