CMakeLists.txt 6.6 KB
Newer Older
1 2 3
#build TBB for Android from source
project(tbb)

4 5 6 7
# 4.1 update 1 - works fine
set(tbb_ver "tbb41_20121003oss")
set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20121003oss_src.tgz")
set(tbb_md5 "2a684fefb855d2d0318d1ef09afa75ff")
8 9
set(tbb_version_file "version_string.ver")

10 11 12 13 14 15
# 4.1 - works fine
#set(tbb_ver "tbb41_20120718oss")
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20120718oss_src.tgz")
#set(tbb_md5 "31b9ec300f3d09da2504d5d882788dd4")
#set(tbb_version_file "version_string.ver")

A
Andrey Kamaev 已提交
16 17
# 4.0 update 5 - works fine
#set(tbb_ver "tbb40_20120613oss")
18
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120613oss_src.tgz")
A
Andrey Kamaev 已提交
19 20 21
#set(tbb_md5 "da01ed74944ec5950cfae3476901a172")
#set(tbb_version_file "version_string.ver")

22 23
# 4.0 update 4 - works fine
#set(tbb_ver "tbb40_20120408oss")
24
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120408oss_src.tgz")
25 26 27
#set(tbb_md5 "734b356da7fe0ed308741f3e6018251e")
#set(tbb_version_file "version_string.ver")

28 29
# 4.0 update 3 - build broken
#set(tbb_ver "tbb40_20120201oss")
30
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120201oss_src.tgz")
31
#set(tbb_md5 "4669e7d4adee018de7a7b8b972987218")
32
#set(tbb_version_file "version_string.tmp")
33 34

# 4.0 update 2 - works fine
35
#set(tbb_ver "tbb40_20111130oss")
36
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111130oss_src.tgz")
37 38 39
#set(tbb_md5 "1e6926b21e865e79772119cd44fc3ad8")
#set(tbb_version_file "version_string.tmp")
#set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE)
40 41 42

# 4.0 update 1 - works fine
#set(tbb_ver "tbb40_20111003oss")
43
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111003oss_src.tgz")
44
#set(tbb_md5 "7b5d94eb35a563b29ef402e0fd8f15c9")
45 46
#set(tbb_version_file "version_string.tmp")
#set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

set(tbb_tarball "${CMAKE_CURRENT_SOURCE_DIR}/${tbb_ver}_src.tgz")
set(tbb_src_dir "${CMAKE_CURRENT_BINARY_DIR}/${tbb_ver}")

macro(getMD5 filename varname)
  if(CMAKE_VERSION VERSION_GREATER 2.8.6)
    file(MD5 "${filename}" ${varname})
  else()
    execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum "${filename}"
              RESULT_VARIABLE getMD5_RESULT
              OUTPUT_VARIABLE getMD5_OUTPUT
              OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(getMD5_RESULT EQUAL 0)
      string(REGEX MATCH "^[a-z0-9]+" ${varname} "${getMD5_OUTPUT}")
    else()
      set(${varname} "invalid_md5")
    endif()
  endif()
endmacro()

if(EXISTS "${tbb_tarball}")
  getMD5("${tbb_tarball}" tbb_local_md5)
  if(NOT tbb_local_md5 STREQUAL tbb_md5)
    message(WARNING "Local copy of TBB source tarball has invalid MD5 hash: ${tbb_local_md5} (expected: ${tbb_md5})")
    file(REMOVE "${tbb_tarball}")
    if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${tbb_ver}")
      file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/${tbb_ver}")
    endif()
  endif()
endif()

if(NOT EXISTS "${tbb_tarball}")
  message(STATUS "Downloading ${tbb_ver}_src.tgz")
  file(DOWNLOAD "${tbb_url}" "${tbb_tarball}" TIMEOUT 600 STATUS __statvar)
  if(NOT __statvar EQUAL 0)
    message(FATAL_ERROR "Failed to download TBB sources: ${tbb_url}")
  endif()
  getMD5("${tbb_tarball}" tbb_local_md5)
  if(NOT tbb_local_md5 STREQUAL tbb_md5)
    file(REMOVE "${tbb_tarball}")
    message(FATAL_ERROR "Downloaded TBB source tarball has invalid MD5 hash: ${tbb_local_md5} (expected: ${tbb_md5})")
  endif()
A
Andrey Kamaev 已提交
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  if(EXISTS "${tbb_src_dir}")
    file(REMOVE_RECURSE "${tbb_src_dir}")
  endif()
endif()

# untar TBB sources
if(NOT EXISTS "${tbb_src_dir}")
  message(STATUS "Unpacking ${tbb_ver}_src.tgz to ${tbb_src_dir}")
  execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${tbb_tarball}"
              WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
              RESULT_VARIABLE tbb_untar_RESULT)

  if(NOT tbb_untar_RESULT EQUAL 0 OR NOT EXISTS "${tbb_src_dir}")
    message(FATAL_ERROR "Failed to unpack TBB sources")
  endif()
endif()

107
set(TBB_INCLUDE_DIRS "${tbb_src_dir}/include" PARENT_SCOPE)
108

109 110 111 112
ocv_include_directories("${tbb_src_dir}/include"
                        "${tbb_src_dir}/src/"
                        "${tbb_src_dir}/src/rml/include"
                        "${CMAKE_CURRENT_SOURCE_DIR}")
113 114 115 116 117

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")

A
Alexander Smorkalov 已提交
118 119 120 121 122 123 124 125
add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0         #required
                -D__TBB_BUILD=1                        #required
                -D__TBB_SURVIVE_THREAD_SWITCH=0        #no cilk on Android?
                -DUSE_PTHREAD                          #required
                -DTBB_USE_GCC_BUILTINS=1               #required
                -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 on Android
126 127
               )

128 129 130 131 132
if(ANDROID_COMPILER_IS_CLANG)
  add_definitions(-D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1)
  ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-prototypes)
endif()

133 134 135
if(tbb_need_GENERIC_DWORD_LOAD_STORE)
  #needed by TBB 4.0 update 1,2; fixed in TBB 4.0 update 3 but it has 2 new problems
  add_definitions(-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1)
136
  set(tbb_need_GENERIC_DWORD_LOAD_STORE ON PARENT_SCOPE)
137 138
endif()

139 140 141 142 143 144
if (ANDROID)
  set(TBB_SOURCE_FILES ${lib_srcs} ${lib_hdrs} "${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h" "${CMAKE_CURRENT_SOURCE_DIR}/${tbb_version_file}")
else()
  set(TBB_SOURCE_FILES ${lib_srcs} ${lib_hdrs} "${CMAKE_CURRENT_SOURCE_DIR}/${tbb_version_file}")
endif()

A
Alexander Smorkalov 已提交
145 146
add_library(tbb ${TBB_SOURCE_FILES})
target_link_libraries(tbb c m dl)
147

A
Andrey Kamaev 已提交
148 149
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations)
string(REPLACE "-Werror=non-virtual-dtor" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
150

151 152 153
if(ANDROID)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
endif()
154

155
set_target_properties(tbb
A
Andrey Kamaev 已提交
156 157
  PROPERTIES OUTPUT_NAME tbb
  DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
158
  ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
A
Andrey Kamaev 已提交
159 160
  )

161 162 163
if(ENABLE_SOLUTION_FOLDERS)
  set_target_properties(tbb PROPERTIES FOLDER "3rdparty")
endif()
A
Andrey Kamaev 已提交
164

165
if(NOT BUILD_SHARED_LIBS)
166
  install(TARGETS tbb ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
167
endif()
168 169 170 171

# get TBB version
ocv_parse_header("${tbb_src_dir}/include/tbb/tbb_stddef.h" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION CACHE)