55e284
 src/cmake/externalpackages.cmake  |   19 +++++++++++++++++++
55e284
 src/include/CMakeLists.txt        |    2 +-
55e284
 src/libOpenImageIO/CMakeLists.txt |   11 ++++++++++-
55e284
 3 files changed, 30 insertions(+), 2 deletions(-)
55e284
55e284
diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake
55e284
index ddea7e0..aa25df6 100644
55e284
--- a/src/cmake/externalpackages.cmake
55e284
+++ b/src/cmake/externalpackages.cmake
55e284
@@ -272,3 +272,22 @@ if (USE_EXTERNAL_PUGIXML)
55e284
 endif()
55e284
 
55e284
 ###########################################################################
55e284
+
55e284
+###########################################################################
55e284
+# TBB setup.  Normally we just use the version bundled with oiio, but
55e284
+# some linux distros are quite particular about having separate packages so we
55e284
+# allow this to be overridden to use the distro-provided package if desired.
55e284
+#
55e284
+# Try to find it first and fall back to built-in if not available.
55e284
+find_package (TBB REQUIRED)
55e284
+if (TBB_FOUND)
55e284
+    set (USE_EXTERNAL_TBB TRUE CACHE BOOL
55e284
+        "Use system installed TBB library if avaialble."
55e284
+    )
55e284
+    mark_as_advanced (FORCE USE_EXTERNAL_TBB)
55e284
+    # insert include path to TBB first, to ensure that the external
55e284
+    # TBB is found, and not the one in OIIO's include directory.
55e284
+    include_directories (BEFORE ${TBB_INCLUDE_DIR})
55e284
+endif()
55e284
+
55e284
+###########################################################################
55e284
diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt
55e284
index 385f98e..4a2da55 100644
55e284
--- a/src/include/CMakeLists.txt
55e284
+++ b/src/include/CMakeLists.txt
55e284
@@ -23,7 +23,7 @@ list(APPEND public_headers ${CMAKE_BINARY_DIR}/include/version.h)
55e284
 install (FILES ${public_headers} DESTINATION ${INCLUDE_INSTALL_DIR}
55e284
          COMPONENT developer)
55e284
 
55e284
-if (USE_TBB)
55e284
+if (USE_TBB AND NOT USE_EXTERNAL_TBB)
55e284
     install (DIRECTORY tbb DESTINATION ${INCLUDE_INSTALL_DIR}
55e284
              COMPONENT developer)
55e284
 endif ()
55e284
diff --git a/src/libOpenImageIO/CMakeLists.txt b/src/libOpenImageIO/CMakeLists.txt
55e284
index f4425f6..62da8dd 100644
55e284
--- a/src/libOpenImageIO/CMakeLists.txt
55e284
+++ b/src/libOpenImageIO/CMakeLists.txt
55e284
@@ -61,7 +61,12 @@ if (NOT USE_EXTERNAL_PUGIXML)
55e284
 endif ()
55e284
 
55e284
 # Include our own TBB if using it
55e284
-if (USE_TBB)
55e284
+if (USE_TBB AND USE_EXTERNAL_TBB)
55e284
+    message (STATUS "System TBB library will be used.")
55e284
+    add_definitions ("-DUSE_TBB=1")
55e284
+    set (libOpenImageIO_srcs ${libOpenImageIO_srcs})
55e284
+elseif (USE_TBB AND NOT USE_EXTERNAL_TBB)
55e284
+    message (STATUS "Built-in TBB library will be used.")
55e284
     add_definitions ("-DUSE_TBB=1")
55e284
     set (libOpenImageIO_srcs ${libOpenImageIO_srcs} ../libutil/tbb_misc.cpp)
55e284
 else ()
55e284
@@ -221,6 +226,10 @@ if (USE_EXTERNAL_PUGIXML)
55e284
     target_link_libraries (OpenImageIO ${PUGIXML_LIBRARIES})
55e284
 endif ()
55e284
 
55e284
+if (USE_EXTERNAL_TBB)
55e284
+    target_link_libraries (OpenImageIO ${TBB_LIBRARIES})
55e284
+endif ()
55e284
+
55e284
 message(STATUS "Setting SOVERSION to: ${SOVERSION}")
55e284
 set_target_properties(OpenImageIO
55e284
                          PROPERTIES