2013-02-06 23:18:36 +08:00
|
|
|
#Cross compile TBB from source
|
2020-03-24 04:37:08 +08:00
|
|
|
project(tbb CXX)
|
2012-02-25 02:16:05 +08:00
|
|
|
|
2013-06-26 17:31:47 +08:00
|
|
|
if (WIN32 AND NOT ARM)
|
|
|
|
message(FATAL_ERROR "BUILD_TBB option supports Windows on ARM only!\nUse regular official TBB build instead of the BUILD_TBB option!")
|
|
|
|
endif()
|
|
|
|
|
2020-06-08 19:04:33 +08:00
|
|
|
ocv_update(OPENCV_TBB_RELEASE "v2020.2")
|
|
|
|
ocv_update(OPENCV_TBB_RELEASE_MD5 "5af6f6c2a24c2043e62e47205e273b1f")
|
2019-06-29 00:32:59 +08:00
|
|
|
ocv_update(OPENCV_TBB_FILENAME "${OPENCV_TBB_RELEASE}.tar.gz")
|
2019-12-19 07:14:38 +08:00
|
|
|
string(REGEX REPLACE "^v" "" OPENCV_TBB_RELEASE_ "${OPENCV_TBB_RELEASE}")
|
2020-03-24 04:37:08 +08:00
|
|
|
#ocv_update(OPENCV_TBB_SUBDIR ...)
|
2014-12-26 17:13:42 +08:00
|
|
|
|
2017-03-15 18:19:59 +08:00
|
|
|
set(tbb_src_dir "${OpenCV_BINARY_DIR}/3rdparty/tbb")
|
2019-06-29 00:32:59 +08:00
|
|
|
ocv_download(FILENAME ${OPENCV_TBB_FILENAME}
|
|
|
|
HASH ${OPENCV_TBB_RELEASE_MD5}
|
2017-03-15 18:19:59 +08:00
|
|
|
URL
|
|
|
|
"${OPENCV_TBB_URL}"
|
|
|
|
"$ENV{OPENCV_TBB_URL}"
|
|
|
|
"https://github.com/01org/tbb/archive/"
|
|
|
|
DESTINATION_DIR ${tbb_src_dir}
|
2017-03-28 23:21:13 +08:00
|
|
|
ID TBB
|
2017-03-15 18:19:59 +08:00
|
|
|
STATUS res
|
|
|
|
UNPACK RELATIVE_URL)
|
|
|
|
if(NOT res)
|
|
|
|
return()
|
2012-02-25 02:16:05 +08:00
|
|
|
endif()
|
2020-03-24 04:37:08 +08:00
|
|
|
if(OPENCV_TBB_SUBDIR)
|
|
|
|
# use current value
|
|
|
|
ocv_assert(EXISTS "${tbb_src_dir}/${OPENCV_TBB_SUBDIR}")
|
|
|
|
elseif(EXISTS "${tbb_src_dir}/oneTBB-${OPENCV_TBB_RELEASE_}")
|
|
|
|
set(OPENCV_TBB_SUBDIR "oneTBB-${OPENCV_TBB_RELEASE_}")
|
|
|
|
elseif(EXISTS "${tbb_src_dir}/tbb-${OPENCV_TBB_RELEASE_}")
|
|
|
|
set(OPENCV_TBB_SUBDIR "oneTBB-${OPENCV_TBB_RELEASE_}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "TBB: Can't configure TBB. Specify OPENCV_TBB_SUBDIR through command-line.")
|
|
|
|
endif()
|
2019-06-29 00:32:59 +08:00
|
|
|
set(tbb_src_dir "${tbb_src_dir}/${OPENCV_TBB_SUBDIR}")
|
2012-02-25 02:16:05 +08:00
|
|
|
|
2012-03-03 23:49:23 +08:00
|
|
|
ocv_include_directories("${tbb_src_dir}/include"
|
|
|
|
"${tbb_src_dir}/src/"
|
|
|
|
"${tbb_src_dir}/src/rml/include"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}")
|
2012-02-25 02:16:05 +08:00
|
|
|
|
|
|
|
file(GLOB lib_srcs "${tbb_src_dir}/src/tbb/*.cpp")
|
|
|
|
file(GLOB lib_hdrs "${tbb_src_dir}/src/tbb/*.h")
|
|
|
|
list(APPEND lib_srcs "${tbb_src_dir}/src/rml/client/rml_tbb.cpp")
|
2019-12-19 07:14:38 +08:00
|
|
|
ocv_list_filterout(lib_srcs "${tbb_src_dir}/src/tbb/tbbbind.cpp") # hwloc.h requirement
|
2020-03-24 04:37:08 +08:00
|
|
|
ocv_list_filterout(lib_srcs "${tbb_src_dir}/src/tbb/tbb_bind.cpp") # hwloc.h requirement 2020.1+
|
2012-02-25 02:16:05 +08:00
|
|
|
|
2013-03-20 08:46:01 +08:00
|
|
|
if (WIN32)
|
2013-06-26 17:31:47 +08:00
|
|
|
add_definitions(/D__TBB_DYNAMIC_LOAD_ENABLED=0
|
|
|
|
/D__TBB_BUILD=1
|
|
|
|
/DTBB_NO_LEGACY=1
|
|
|
|
/D_UNICODE
|
|
|
|
/DUNICODE
|
|
|
|
/DWINAPI_FAMILY=WINAPI_FAMILY_APP
|
|
|
|
/DDO_ITT_NOTIFY=0
|
|
|
|
/DUSE_WINTHREAD
|
2013-03-20 08:46:01 +08:00
|
|
|
) # defines were copied from windows.cl.inc
|
2013-05-22 22:26:43 +08:00
|
|
|
|
2013-06-26 17:31:47 +08:00
|
|
|
if (ARM)
|
|
|
|
add_definitions(/D_WIN32_WINNT=0x0602
|
|
|
|
/D__TBB_WIN32_USE_CL_BUILTINS
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2013-03-20 08:46:01 +08:00
|
|
|
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} /APPCONTAINER")
|
|
|
|
else()
|
|
|
|
add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required
|
2014-12-26 17:13:42 +08:00
|
|
|
-D__TBB_WEAK_SYMBOLS_PRESENT=0 #required for 4.3
|
2013-03-20 08:46:01 +08:00
|
|
|
-D__TBB_BUILD=1 #required
|
|
|
|
-D__TBB_SURVIVE_THREAD_SWITCH=0 #no cilk support
|
|
|
|
-DTBB_USE_DEBUG=0 #just to be sure
|
|
|
|
-DTBB_NO_LEGACY=1 #don't need backward compatibility
|
|
|
|
-DDO_ITT_NOTIFY=0 #it seems that we don't need these notifications
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-08-14 15:59:38 +08:00
|
|
|
if(HAVE_PTHREAD)
|
2013-03-20 08:46:01 +08:00
|
|
|
add_definitions(-DUSE_PTHREAD) #required for Unix
|
|
|
|
endif()
|
|
|
|
|
2018-03-26 19:30:49 +08:00
|
|
|
if(CV_GCC)
|
2013-03-20 08:46:01 +08:00
|
|
|
add_definitions(-DTBB_USE_GCC_BUILTINS=1) #required for ARM GCC
|
2017-08-21 22:43:56 +08:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_VERSION LESS 6.0)
|
2016-11-23 17:44:44 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flifetime-dse=1") # workaround for GCC 6.x
|
|
|
|
endif()
|
2013-03-20 08:46:01 +08:00
|
|
|
endif()
|
2012-02-25 02:16:05 +08:00
|
|
|
|
2012-11-19 19:16:13 +08:00
|
|
|
if(ANDROID_COMPILER_IS_CLANG)
|
|
|
|
add_definitions(-D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1)
|
|
|
|
endif()
|
|
|
|
|
2019-06-29 00:32:59 +08:00
|
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS
|
|
|
|
/wd4702
|
|
|
|
-Wshadow
|
|
|
|
-Wunused-parameter
|
|
|
|
-Wclass-memaccess # TBB 2018 under GCC 8+
|
|
|
|
-Wimplicit-fallthrough # TBB 2018 under GCC 7+
|
|
|
|
-Wmissing-prototypes # MacOSX, Android/Clang
|
|
|
|
-Wundef -Wmissing-declarations # TBB 2019
|
|
|
|
)
|
2013-02-06 16:55:37 +08:00
|
|
|
|
2019-06-29 00:32:59 +08:00
|
|
|
set(TBB_SOURCE_FILES ${lib_srcs} ${lib_hdrs})
|
2013-01-10 21:18:01 +08:00
|
|
|
|
2017-12-11 20:22:48 +08:00
|
|
|
set(tbb_version_file "version_string.ver")
|
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${tbb_version_file}.cmakein" "${CMAKE_CURRENT_BINARY_DIR}/${tbb_version_file}" @ONLY)
|
|
|
|
list(APPEND TBB_SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/${tbb_version_file}")
|
2013-02-06 16:55:37 +08:00
|
|
|
|
2020-10-28 03:00:25 +08:00
|
|
|
add_library(tbb ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${TBB_SOURCE_FILES})
|
2020-03-24 04:37:08 +08:00
|
|
|
target_compile_definitions(tbb PUBLIC
|
|
|
|
TBB_USE_GCC_BUILTINS=1
|
|
|
|
__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1
|
|
|
|
TBB_SUPPRESS_DEPRECATED_MESSAGES=1
|
|
|
|
)
|
2017-12-11 20:22:48 +08:00
|
|
|
target_include_directories(tbb SYSTEM PUBLIC $<BUILD_INTERFACE:${tbb_src_dir}/include>
|
|
|
|
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
)
|
2013-04-09 09:13:49 +08:00
|
|
|
|
2013-06-26 17:31:47 +08:00
|
|
|
if (WIN32)
|
|
|
|
if (ARM)
|
|
|
|
set(platform_macro /D_M_ARM=1)
|
|
|
|
endif()
|
|
|
|
|
2013-04-09 09:13:49 +08:00
|
|
|
add_custom_command(TARGET tbb
|
|
|
|
PRE_BUILD
|
2013-06-26 17:31:47 +08:00
|
|
|
COMMAND ${CMAKE_C_COMPILER} /nologo /TC /EP ${tbb_src_dir}\\src\\tbb\\win32-tbb-export.def /DTBB_NO_LEGACY=1 /D_CRT_SECURE_NO_DEPRECATE /D__TBB_BUILD=1 ${platform_macro} /I${tbb_src_dir}\\src /I${tbb_src_dir}\\include > "${tbb_src_dir}\\src\\tbb\\tbb.def"
|
2013-04-09 09:13:49 +08:00
|
|
|
WORKING_DIRECTORY ${tbb_src_dir}\\src\\tbb
|
|
|
|
COMMENT "Generating tbb.def file" VERBATIM
|
|
|
|
)
|
|
|
|
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEF:${tbb_src_dir}/src/tbb/tbb.def /DLL /MAP /fixed:no /INCREMENTAL:NO")
|
2013-05-22 22:26:43 +08:00
|
|
|
else()
|
2013-04-09 09:13:49 +08:00
|
|
|
target_link_libraries(tbb c m dl)
|
|
|
|
endif()
|
2012-02-25 02:16:05 +08:00
|
|
|
|
2015-09-12 18:19:44 +08:00
|
|
|
# filter out flags that are not handled well by the TBB code
|
|
|
|
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
|
|
|
|
string(REPLACE "-Werror=non-virtual-dtor" "" ${var} "${${var}}")
|
|
|
|
string(REPLACE "-fvisibility=hidden" "" ${var} "${${var}}")
|
|
|
|
string(REPLACE "-fvisibility-inlines-hidden" "" ${var} "${${var}}")
|
|
|
|
endforeach()
|
2012-02-25 02:16:05 +08:00
|
|
|
|
2013-07-16 22:37:09 +08:00
|
|
|
if (WIN32)
|
|
|
|
set(tbb_debug_postfix "_debug") # to fit pragmas in _windef.h inside TBB
|
|
|
|
else()
|
|
|
|
set(tbb_debug_postfix ${OPENCV_DEBUG_POSTFIX})
|
|
|
|
endif()
|
|
|
|
|
2012-02-25 02:16:05 +08:00
|
|
|
set_target_properties(tbb
|
2012-06-08 18:32:51 +08:00
|
|
|
PROPERTIES OUTPUT_NAME tbb
|
2013-07-16 22:37:09 +08:00
|
|
|
DEBUG_POSTFIX "${tbb_debug_postfix}"
|
2015-08-17 08:28:22 +08:00
|
|
|
COMPILE_PDB_NAME tbb
|
|
|
|
COMPILE_PDB_NAME_DEBUG "tbb${OPENCV_DEBUG_POSTFIX}"
|
2012-06-27 14:22:26 +08:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
|
2013-05-22 22:26:43 +08:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
2012-06-08 18:32:51 +08:00
|
|
|
)
|
|
|
|
|
2012-02-25 02:16:05 +08:00
|
|
|
if(ENABLE_SOLUTION_FOLDERS)
|
|
|
|
set_target_properties(tbb PROPERTIES FOLDER "3rdparty")
|
|
|
|
endif()
|
2012-06-08 18:32:51 +08:00
|
|
|
|
2013-10-22 23:13:13 +08:00
|
|
|
ocv_install_target(tbb EXPORT OpenCVModules
|
2014-01-17 20:30:31 +08:00
|
|
|
RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs
|
|
|
|
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs
|
|
|
|
ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev
|
2020-10-28 03:00:25 +08:00
|
|
|
OPTIONAL
|
2013-09-27 18:44:58 +08:00
|
|
|
)
|
2012-04-14 05:50:59 +08:00
|
|
|
|
2018-02-27 02:10:21 +08:00
|
|
|
ocv_install_3rdparty_licenses(tbb "${tbb_src_dir}/LICENSE" "${tbb_src_dir}/README")
|
|
|
|
|
2016-11-23 17:44:44 +08:00
|
|
|
ocv_tbb_read_version("${tbb_src_dir}/include")
|