1From d359098d9989ac7dbd149611d6ac941529fb4157 Mon Sep 17 00:00:00 2001
2From: tamasmeszaros <meszaros.q@gmail.com>
3Date: Thu, 23 Jan 2020 17:17:36 +0100
4Subject: [PATCH] openvdb-mods
5
6---
7 CMakeLists.txt                  |   3 -
8 cmake/CheckAtomic.cmake         | 106 ++++++
9 cmake/FindBlosc.cmake           | 218 ------------
10 cmake/FindCppUnit.cmake         |   4 +-
11 cmake/FindIlmBase.cmake         | 337 ------------------
12 cmake/FindOpenEXR.cmake         | 329 ------------------
13 cmake/FindOpenVDB.cmake         |  19 +-
14 cmake/FindTBB.cmake             | 599 ++++++++++++++++----------------
15 openvdb/CMakeLists.txt          |  16 +-
16 openvdb/Grid.cc                 |   3 +
17 openvdb/PlatformConfig.h        |   9 +-
18 openvdb/cmd/CMakeLists.txt      |   4 +-
19 openvdb/unittest/CMakeLists.txt |   3 +-
20 openvdb/unittest/TestFile.cc    |   2 +-
21 14 files changed, 442 insertions(+), 1210 deletions(-)
22 create mode 100644 cmake/CheckAtomic.cmake
23 delete mode 100644 cmake/FindBlosc.cmake
24 delete mode 100644 cmake/FindIlmBase.cmake
25 delete mode 100644 cmake/FindOpenEXR.cmake
26
27diff --git a/CMakeLists.txt b/CMakeLists.txt
28index 580b353..6d364c1 100644
29--- a/CMakeLists.txt
30+++ b/CMakeLists.txt
31@@ -267,12 +267,9 @@ endif()
32
33 if(OPENVDB_INSTALL_CMAKE_MODULES)
34   set(OPENVDB_CMAKE_MODULES
35-    cmake/FindBlosc.cmake
36     cmake/FindCppUnit.cmake
37     cmake/FindJemalloc.cmake
38-    cmake/FindIlmBase.cmake
39     cmake/FindLog4cplus.cmake
40-    cmake/FindOpenEXR.cmake
41     cmake/FindOpenVDB.cmake
42     cmake/FindTBB.cmake
43     cmake/OpenVDBGLFW3Setup.cmake
44diff --git a/cmake/CheckAtomic.cmake b/cmake/CheckAtomic.cmake
45new file mode 100644
46index 0000000..c045e30
47--- /dev/null
48+++ b/cmake/CheckAtomic.cmake
49@@ -0,0 +1,106 @@
50+# atomic builtins are required for threading support.
51+
52+INCLUDE(CheckCXXSourceCompiles)
53+INCLUDE(CheckLibraryExists)
54+
55+# Sometimes linking against libatomic is required for atomic ops, if
56+# the platform doesn't support lock-free atomics.
57+
58+function(check_working_cxx_atomics varname)
59+  set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
60+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
61+  CHECK_CXX_SOURCE_COMPILES("
62+#include <atomic>
63+std::atomic<int> x;
64+int main() {
65+  return x;
66+}
67+" ${varname})
68+  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
69+endfunction(check_working_cxx_atomics)
70+
71+function(check_working_cxx_atomics64 varname)
72+  set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
73+  set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
74+  CHECK_CXX_SOURCE_COMPILES("
75+#include <atomic>
76+#include <cstdint>
77+std::atomic<uint64_t> x (0);
78+int main() {
79+  uint64_t i = x.load(std::memory_order_relaxed);
80+  return 0;
81+}
82+" ${varname})
83+  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
84+endfunction(check_working_cxx_atomics64)
85+
86+
87+# This isn't necessary on MSVC, so avoid command-line switch annoyance
88+# by only running on GCC-like hosts.
89+if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
90+  # First check if atomics work without the library.
91+  check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
92+  # If not, check if the library exists, and atomics work with it.
93+  if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
94+    check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
95+    if( HAVE_LIBATOMIC )
96+      list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
97+      check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
98+      if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
99+	message(FATAL_ERROR "Host compiler must support std::atomic!")
100+      endif()
101+    else()
102+      message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
103+    endif()
104+  endif()
105+endif()
106+
107+# Check for 64 bit atomic operations.
108+if(MSVC)
109+  set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
110+else()
111+  check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
112+endif()
113+
114+# If not, check if the library exists, and atomics work with it.
115+if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
116+  check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
117+  if(HAVE_CXX_LIBATOMICS64)
118+    list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
119+    check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
120+    if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
121+      message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
122+    endif()
123+  else()
124+    message(FATAL_ERROR "Host compiler appears to require libatomic for 64-bit operations, but cannot find it.")
125+  endif()
126+endif()
127+
128+## TODO: This define is only used for the legacy atomic operations in
129+## llvm's Atomic.h, which should be replaced.  Other code simply
130+## assumes C++11 <atomic> works.
131+CHECK_CXX_SOURCE_COMPILES("
132+#ifdef _MSC_VER
133+#include <windows.h>
134+#endif
135+int main() {
136+#ifdef _MSC_VER
137+        volatile LONG val = 1;
138+        MemoryBarrier();
139+        InterlockedCompareExchange(&val, 0, 1);
140+        InterlockedIncrement(&val);
141+        InterlockedDecrement(&val);
142+#else
143+        volatile unsigned long val = 1;
144+        __sync_synchronize();
145+        __sync_val_compare_and_swap(&val, 1, 0);
146+        __sync_add_and_fetch(&val, 1);
147+        __sync_sub_and_fetch(&val, 1);
148+#endif
149+        return 0;
150+      }
151+" LLVM_HAS_ATOMICS)
152+
153+if( NOT LLVM_HAS_ATOMICS )
154+  message(STATUS "Warning: LLVM will be built thread-unsafe because atomic builtins are missing")
155+endif()
156\ No newline at end of file
157diff --git a/cmake/FindBlosc.cmake b/cmake/FindBlosc.cmake
158deleted file mode 100644
159index 5aacfdd..0000000
160--- a/cmake/FindBlosc.cmake
161+++ /dev/null
162@@ -1,218 +0,0 @@
163-# Copyright (c) DreamWorks Animation LLC
164-#
165-# All rights reserved. This software is distributed under the
166-# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
167-#
168-# Redistributions of source code must retain the above copyright
169-# and license notice and the following restrictions and disclaimer.
170-#
171-# *     Neither the name of DreamWorks Animation nor the names of
172-# its contributors may be used to endorse or promote products derived
173-# from this software without specific prior written permission.
174-#
175-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
177-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
178-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
179-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
180-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
181-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
182-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
183-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
184-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
185-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
186-# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
187-# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
188-#
189-#[=======================================================================[.rst:
190-
191-FindBlosc
192----------
193-
194-Find Blosc include dirs and libraries
195-
196-Use this module by invoking find_package with the form::
197-
198-  find_package(Blosc
199-    [version] [EXACT]      # Minimum or EXACT version e.g. 1.5.0
200-    [REQUIRED]             # Fail with error if Blosc is not found
201-    )
202-
203-IMPORTED Targets
204-^^^^^^^^^^^^^^^^
205-
206-``Blosc::blosc``
207-  This module defines IMPORTED target Blosc::Blosc, if Blosc has been found.
208-
209-Result Variables
210-^^^^^^^^^^^^^^^^
211-
212-This will define the following variables:
213-
214-``Blosc_FOUND``
215-  True if the system has the Blosc library.
216-``Blosc_VERSION``
217-  The version of the Blosc library which was found.
218-``Blosc_INCLUDE_DIRS``
219-  Include directories needed to use Blosc.
220-``Blosc_LIBRARIES``
221-  Libraries needed to link to Blosc.
222-``Blosc_LIBRARY_DIRS``
223-  Blosc library directories.
224-
225-Cache Variables
226-^^^^^^^^^^^^^^^
227-
228-The following cache variables may also be set:
229-
230-``Blosc_INCLUDE_DIR``
231-  The directory containing ``blosc.h``.
232-``Blosc_LIBRARY``
233-  The path to the Blosc library.
234-
235-Hints
236-^^^^^
237-
238-Instead of explicitly setting the cache variables, the following variables
239-may be provided to tell this module where to look.
240-
241-``BLOSC_ROOT``
242-  Preferred installation prefix.
243-``BLOSC_INCLUDEDIR``
244-  Preferred include directory e.g. <prefix>/include
245-``BLOSC_LIBRARYDIR``
246-  Preferred library directory e.g. <prefix>/lib
247-``SYSTEM_LIBRARY_PATHS``
248-  Paths appended to all include and lib searches.
249-
250-#]=======================================================================]
251-
252-mark_as_advanced(
253-  Blosc_INCLUDE_DIR
254-  Blosc_LIBRARY
255-)
256-
257-# Append BLOSC_ROOT or $ENV{BLOSC_ROOT} if set (prioritize the direct cmake var)
258-set(_BLOSC_ROOT_SEARCH_DIR "")
259-
260-if(BLOSC_ROOT)
261-  list(APPEND _BLOSC_ROOT_SEARCH_DIR ${BLOSC_ROOT})
262-else()
263-  set(_ENV_BLOSC_ROOT $ENV{BLOSC_ROOT})
264-  if(_ENV_BLOSC_ROOT)
265-    list(APPEND _BLOSC_ROOT_SEARCH_DIR ${_ENV_BLOSC_ROOT})
266-  endif()
267-endif()
268-
269-# Additionally try and use pkconfig to find blosc
270-
271-find_package(PkgConfig)
272-pkg_check_modules(PC_Blosc QUIET blosc)
273-
274-# ------------------------------------------------------------------------
275-#  Search for blosc include DIR
276-# ------------------------------------------------------------------------
277-
278-set(_BLOSC_INCLUDE_SEARCH_DIRS "")
279-list(APPEND _BLOSC_INCLUDE_SEARCH_DIRS
280-  ${BLOSC_INCLUDEDIR}
281-  ${_BLOSC_ROOT_SEARCH_DIR}
282-  ${PC_Blosc_INCLUDE_DIRS}
283-  ${SYSTEM_LIBRARY_PATHS}
284-)
285-
286-# Look for a standard blosc header file.
287-find_path(Blosc_INCLUDE_DIR blosc.h
288-  NO_DEFAULT_PATH
289-  PATHS ${_BLOSC_INCLUDE_SEARCH_DIRS}
290-  PATH_SUFFIXES include
291-)
292-
293-if(EXISTS "${Blosc_INCLUDE_DIR}/blosc.h")
294-  file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h"
295-    _blosc_version_major_string REGEX "#define BLOSC_VERSION_MAJOR +[0-9]+ "
296-  )
297-  string(REGEX REPLACE "#define BLOSC_VERSION_MAJOR +([0-9]+).*$" "\\1"
298-    _blosc_version_major_string "${_blosc_version_major_string}"
299-  )
300-  string(STRIP "${_blosc_version_major_string}" Blosc_VERSION_MAJOR)
301-
302-  file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h"
303-     _blosc_version_minor_string REGEX "#define BLOSC_VERSION_MINOR +[0-9]+ "
304-  )
305-  string(REGEX REPLACE "#define BLOSC_VERSION_MINOR +([0-9]+).*$" "\\1"
306-    _blosc_version_minor_string "${_blosc_version_minor_string}"
307-  )
308-  string(STRIP "${_blosc_version_minor_string}" Blosc_VERSION_MINOR)
309-
310-  unset(_blosc_version_major_string)
311-  unset(_blosc_version_minor_string)
312-
313-  set(Blosc_VERSION ${Blosc_VERSION_MAJOR}.${Blosc_VERSION_MINOR})
314-endif()
315-
316-# ------------------------------------------------------------------------
317-#  Search for blosc lib DIR
318-# ------------------------------------------------------------------------
319-
320-set(_BLOSC_LIBRARYDIR_SEARCH_DIRS "")
321-list(APPEND _BLOSC_LIBRARYDIR_SEARCH_DIRS
322-  ${BLOSC_LIBRARYDIR}
323-  ${_BLOSC_ROOT_SEARCH_DIR}
324-  ${PC_Blosc_LIBRARY_DIRS}
325-  ${SYSTEM_LIBRARY_PATHS}
326-)
327-
328-# Static library setup
329-if(UNIX AND BLOSC_USE_STATIC_LIBS)
330-  set(_BLOSC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
331-  set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
332-endif()
333-
334-set(BLOSC_PATH_SUFFIXES
335-  lib64
336-  lib
337-)
338-
339-find_library(Blosc_LIBRARY blosc
340-  NO_DEFAULT_PATH
341-  PATHS ${_BLOSC_LIBRARYDIR_SEARCH_DIRS}
342-  PATH_SUFFIXES ${BLOSC_PATH_SUFFIXES}
343-)
344-
345-if(UNIX AND BLOSC_USE_STATIC_LIBS)
346-  set(CMAKE_FIND_LIBRARY_SUFFIXES ${_BLOSC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
347-  unset(_BLOSC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
348-endif()
349-
350-# ------------------------------------------------------------------------
351-#  Cache and set Blosc_FOUND
352-# ------------------------------------------------------------------------
353-
354-include(FindPackageHandleStandardArgs)
355-find_package_handle_standard_args(Blosc
356-  FOUND_VAR Blosc_FOUND
357-  REQUIRED_VARS
358-    Blosc_LIBRARY
359-    Blosc_INCLUDE_DIR
360-  VERSION_VAR Blosc_VERSION
361-)
362-
363-if(Blosc_FOUND)
364-  set(Blosc_LIBRARIES ${Blosc_LIBRARY})
365-  set(Blosc_INCLUDE_DIRS ${Blosc_INCLUDE_DIR})
366-  set(Blosc_DEFINITIONS ${PC_Blosc_CFLAGS_OTHER})
367-
368-  get_filename_component(Blosc_LIBRARY_DIRS ${Blosc_LIBRARY} DIRECTORY)
369-
370-  if(NOT TARGET Blosc::blosc)
371-    add_library(Blosc::blosc UNKNOWN IMPORTED)
372-    set_target_properties(Blosc::blosc PROPERTIES
373-      IMPORTED_LOCATION "${Blosc_LIBRARIES}"
374-      INTERFACE_COMPILE_DEFINITIONS "${Blosc_DEFINITIONS}"
375-      INTERFACE_INCLUDE_DIRECTORIES "${Blosc_INCLUDE_DIRS}"
376-    )
377-  endif()
378-elseif(Blosc_FIND_REQUIRED)
379-  message(FATAL_ERROR "Unable to find Blosc")
380-endif()
381diff --git a/cmake/FindCppUnit.cmake b/cmake/FindCppUnit.cmake
382index e2beb93..a891624 100644
383--- a/cmake/FindCppUnit.cmake
384+++ b/cmake/FindCppUnit.cmake
385@@ -125,7 +125,7 @@ list(APPEND _CPPUNIT_INCLUDE_SEARCH_DIRS
386
387 # Look for a standard cppunit header file.
388 find_path(CppUnit_INCLUDE_DIR cppunit/Portability.h
389-  NO_DEFAULT_PATH
390+  # NO_DEFAULT_PATH
391   PATHS ${_CPPUNIT_INCLUDE_SEARCH_DIRS}
392   PATH_SUFFIXES include
393 )
394@@ -177,7 +177,7 @@ set(CPPUNIT_PATH_SUFFIXES
395 )
396
397 find_library(CppUnit_LIBRARY cppunit
398-  NO_DEFAULT_PATH
399+  # NO_DEFAULT_PATH
400   PATHS ${_CPPUNIT_LIBRARYDIR_SEARCH_DIRS}
401   PATH_SUFFIXES ${CPPUNIT_PATH_SUFFIXES}
402 )
403diff --git a/cmake/FindIlmBase.cmake b/cmake/FindIlmBase.cmake
404deleted file mode 100644
405index 9dbc252..0000000
406--- a/cmake/FindIlmBase.cmake
407+++ /dev/null
408@@ -1,337 +0,0 @@
409-# Copyright (c) DreamWorks Animation LLC
410-#
411-# All rights reserved. This software is distributed under the
412-# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
413-#
414-# Redistributions of source code must retain the above copyright
415-# and license notice and the following restrictions and disclaimer.
416-#
417-# *     Neither the name of DreamWorks Animation nor the names of
418-# its contributors may be used to endorse or promote products derived
419-# from this software without specific prior written permission.
420-#
421-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
422-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
423-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
424-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
425-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
426-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
427-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
428-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
429-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
430-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
431-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
432-# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
433-# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
434-#
435-#[=======================================================================[.rst:
436-
437-FindIlmBase
438------------
439-
440-Find IlmBase include dirs and libraries
441-
442-Use this module by invoking find_package with the form::
443-
444-  find_package(IlmBase
445-    [version] [EXACT]      # Minimum or EXACT version
446-    [REQUIRED]             # Fail with error if IlmBase is not found
447-    [COMPONENTS <libs>...] # IlmBase libraries by their canonical name
448-                           # e.g. "Half" for "libHalf"
449-    )
450-
451-IMPORTED Targets
452-^^^^^^^^^^^^^^^^
453-
454-``IlmBase::Half``
455-  The Half library target.
456-``IlmBase::Iex``
457-  The Iex library target.
458-``IlmBase::IexMath``
459-  The IexMath library target.
460-``IlmBase::IlmThread``
461-  The IlmThread library target.
462-``IlmBase::Imath``
463-  The Imath library target.
464-
465-Result Variables
466-^^^^^^^^^^^^^^^^
467-
468-This will define the following variables:
469-
470-``IlmBase_FOUND``
471-  True if the system has the IlmBase library.
472-``IlmBase_VERSION``
473-  The version of the IlmBase library which was found.
474-``IlmBase_INCLUDE_DIRS``
475-  Include directories needed to use IlmBase.
476-``IlmBase_LIBRARIES``
477-  Libraries needed to link to IlmBase.
478-``IlmBase_LIBRARY_DIRS``
479-  IlmBase library directories.
480-``IlmBase_{COMPONENT}_FOUND``
481-  True if the system has the named IlmBase component.
482-
483-Cache Variables
484-^^^^^^^^^^^^^^^
485-
486-The following cache variables may also be set:
487-
488-``IlmBase_INCLUDE_DIR``
489-  The directory containing ``IlmBase/config-auto.h``.
490-``IlmBase_{COMPONENT}_LIBRARY``
491-  Individual component libraries for IlmBase
492-``IlmBase_{COMPONENT}_DLL``
493-  Individual component dlls for IlmBase on Windows.
494-
495-Hints
496-^^^^^
497-
498-Instead of explicitly setting the cache variables, the following variables
499-may be provided to tell this module where to look.
500-
501-``ILMBASE_ROOT``
502-  Preferred installation prefix.
503-``ILMBASE_INCLUDEDIR``
504-  Preferred include directory e.g. <prefix>/include
505-``ILMBASE_LIBRARYDIR``
506-  Preferred library directory e.g. <prefix>/lib
507-``SYSTEM_LIBRARY_PATHS``
508-  Paths appended to all include and lib searches.
509-
510-#]=======================================================================]
511-
512-# Support new if() IN_LIST operator
513-if(POLICY CMP0057)
514-  cmake_policy(SET CMP0057 NEW)
515-endif()
516-
517-mark_as_advanced(
518-  IlmBase_INCLUDE_DIR
519-  IlmBase_LIBRARY
520-)
521-
522-set(_ILMBASE_COMPONENT_LIST
523-  Half
524-  Iex
525-  IexMath
526-  IlmThread
527-  Imath
528-)
529-
530-if(IlmBase_FIND_COMPONENTS)
531-  set(ILMBASE_COMPONENTS_PROVIDED TRUE)
532-  set(_IGNORED_COMPONENTS "")
533-  foreach(COMPONENT ${IlmBase_FIND_COMPONENTS})
534-    if(NOT ${COMPONENT} IN_LIST _ILMBASE_COMPONENT_LIST)
535-      list(APPEND _IGNORED_COMPONENTS ${COMPONENT})
536-    endif()
537-  endforeach()
538-
539-  if(_IGNORED_COMPONENTS)
540-    message(STATUS "Ignoring unknown components of IlmBase:")
541-    foreach(COMPONENT ${_IGNORED_COMPONENTS})
542-      message(STATUS "  ${COMPONENT}")
543-    endforeach()
544-    list(REMOVE_ITEM IlmBase_FIND_COMPONENTS ${_IGNORED_COMPONENTS})
545-  endif()
546-else()
547-  set(ILMBASE_COMPONENTS_PROVIDED FALSE)
548-  set(IlmBase_FIND_COMPONENTS ${_ILMBASE_COMPONENT_LIST})
549-endif()
550-
551-# Append ILMBASE_ROOT or $ENV{ILMBASE_ROOT} if set (prioritize the direct cmake var)
552-set(_ILMBASE_ROOT_SEARCH_DIR "")
553-
554-if(ILMBASE_ROOT)
555-  list(APPEND _ILMBASE_ROOT_SEARCH_DIR ${ILMBASE_ROOT})
556-else()
557-  set(_ENV_ILMBASE_ROOT $ENV{ILMBASE_ROOT})
558-  if(_ENV_ILMBASE_ROOT)
559-    list(APPEND _ILMBASE_ROOT_SEARCH_DIR ${_ENV_ILMBASE_ROOT})
560-  endif()
561-endif()
562-
563-# Additionally try and use pkconfig to find IlmBase
564-
565-find_package(PkgConfig)
566-pkg_check_modules(PC_IlmBase QUIET IlmBase)
567-
568-# ------------------------------------------------------------------------
569-#  Search for IlmBase include DIR
570-# ------------------------------------------------------------------------
571-
572-set(_ILMBASE_INCLUDE_SEARCH_DIRS "")
573-list(APPEND _ILMBASE_INCLUDE_SEARCH_DIRS
574-  ${ILMBASE_INCLUDEDIR}
575-  ${_ILMBASE_ROOT_SEARCH_DIR}
576-  ${PC_IlmBase_INCLUDEDIR}
577-  ${SYSTEM_LIBRARY_PATHS}
578-)
579-
580-# Look for a standard IlmBase header file.
581-find_path(IlmBase_INCLUDE_DIR IlmBaseConfig.h
582-  NO_DEFAULT_PATH
583-  PATHS ${_ILMBASE_INCLUDE_SEARCH_DIRS}
584-  PATH_SUFFIXES include/OpenEXR OpenEXR
585-)
586-
587-if(EXISTS "${IlmBase_INCLUDE_DIR}/IlmBaseConfig.h")
588-  # Get the ILMBASE version information from the config header
589-  file(STRINGS "${IlmBase_INCLUDE_DIR}/IlmBaseConfig.h"
590-    _ilmbase_version_major_string REGEX "#define ILMBASE_VERSION_MAJOR "
591-  )
592-  string(REGEX REPLACE "#define ILMBASE_VERSION_MAJOR" ""
593-    _ilmbase_version_major_string "${_ilmbase_version_major_string}"
594-  )
595-  string(STRIP "${_ilmbase_version_major_string}" IlmBase_VERSION_MAJOR)
596-
597-  file(STRINGS "${IlmBase_INCLUDE_DIR}/IlmBaseConfig.h"
598-     _ilmbase_version_minor_string REGEX "#define ILMBASE_VERSION_MINOR "
599-  )
600-  string(REGEX REPLACE "#define ILMBASE_VERSION_MINOR" ""
601-    _ilmbase_version_minor_string "${_ilmbase_version_minor_string}"
602-  )
603-  string(STRIP "${_ilmbase_version_minor_string}" IlmBase_VERSION_MINOR)
604-
605-  unset(_ilmbase_version_major_string)
606-  unset(_ilmbase_version_minor_string)
607-
608-  set(IlmBase_VERSION ${IlmBase_VERSION_MAJOR}.${IlmBase_VERSION_MINOR})
609-endif()
610-
611-# ------------------------------------------------------------------------
612-#  Search for ILMBASE lib DIR
613-# ------------------------------------------------------------------------
614-
615-set(_ILMBASE_LIBRARYDIR_SEARCH_DIRS "")
616-
617-# Append to _ILMBASE_LIBRARYDIR_SEARCH_DIRS in priority order
618-
619-list(APPEND _ILMBASE_LIBRARYDIR_SEARCH_DIRS
620-  ${ILMBASE_LIBRARYDIR}
621-  ${_ILMBASE_ROOT_SEARCH_DIR}
622-  ${PC_IlmBase_LIBDIR}
623-  ${SYSTEM_LIBRARY_PATHS}
624-)
625-
626-# Build suffix directories
627-
628-set(ILMBASE_PATH_SUFFIXES
629-  lib64
630-  lib
631-)
632-
633-if(UNIX)
634-  list(INSERT ILMBASE_PATH_SUFFIXES 0 lib/x86_64-linux-gnu)
635-endif()
636-
637-set(_ILMBASE_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
638-
639-# library suffix handling
640-if(WIN32)
641-  list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
642-    "-${IlmBase_VERSION_MAJOR}_${IlmBase_VERSION_MINOR}.lib"
643-  )
644-else()
645-  if(ILMBASE_USE_STATIC_LIBS)
646-    list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
647-      "-${IlmBase_VERSION_MAJOR}_${IlmBase_VERSION_MINOR}.a"
648-    )
649-  else()
650-    if(APPLE)
651-      list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
652-        "-${IlmBase_VERSION_MAJOR}_${IlmBase_VERSION_MINOR}.dylib"
653-      )
654-    else()
655-      list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
656-        "-${IlmBase_VERSION_MAJOR}_${IlmBase_VERSION_MINOR}.so"
657-      )
658-    endif()
659-  endif()
660-endif()
661-
662-set(IlmBase_LIB_COMPONENTS "")
663-
664-foreach(COMPONENT ${IlmBase_FIND_COMPONENTS})
665-  find_library(IlmBase_${COMPONENT}_LIBRARY ${COMPONENT}
666-    NO_DEFAULT_PATH
667-    PATHS ${_ILMBASE_LIBRARYDIR_SEARCH_DIRS}
668-    PATH_SUFFIXES ${ILMBASE_PATH_SUFFIXES}
669-  )
670-  list(APPEND IlmBase_LIB_COMPONENTS ${IlmBase_${COMPONENT}_LIBRARY})
671-
672-  if(WIN32 AND NOT ILMBASE_USE_STATIC_LIBS)
673-    set(_ILMBASE_TMP ${CMAKE_FIND_LIBRARY_SUFFIXES})
674-    set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
675-    find_library(IlmBase_${COMPONENT}_DLL ${COMPONENT}
676-      NO_DEFAULT_PATH
677-      PATHS ${_ILMBASE_LIBRARYDIR_SEARCH_DIRS}
678-      PATH_SUFFIXES bin
679-    )
680-    set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ILMBASE_TMP})
681-    unset(_ILMBASE_TMP)
682-  endif()
683-
684-  if(IlmBase_${COMPONENT}_LIBRARY)
685-    set(IlmBase_${COMPONENT}_FOUND TRUE)
686-  else()
687-    set(IlmBase_${COMPONENT}_FOUND FALSE)
688-  endif()
689-endforeach()
690-
691-# reset lib suffix
692-
693-set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ILMBASE_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
694-unset(_ILMBASE_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
695-
696-# ------------------------------------------------------------------------
697-#  Cache and set ILMBASE_FOUND
698-# ------------------------------------------------------------------------
699-
700-include(FindPackageHandleStandardArgs)
701-find_package_handle_standard_args(IlmBase
702-  FOUND_VAR IlmBase_FOUND
703-  REQUIRED_VARS
704-    IlmBase_INCLUDE_DIR
705-    IlmBase_LIB_COMPONENTS
706-  VERSION_VAR IlmBase_VERSION
707-  HANDLE_COMPONENTS
708-)
709-
710-if(IlmBase_FOUND)
711-  set(IlmBase_LIBRARIES ${IlmBase_LIB_COMPONENTS})
712-
713-  # We have to add both include and include/OpenEXR to the include
714-  # path in case OpenEXR and IlmBase are installed separately
715-
716-  set(IlmBase_INCLUDE_DIRS)
717-  list(APPEND IlmBase_INCLUDE_DIRS
718-    ${IlmBase_INCLUDE_DIR}/../
719-    ${IlmBase_INCLUDE_DIR}
720-  )
721-  set(IlmBase_DEFINITIONS ${PC_IlmBase_CFLAGS_OTHER})
722-
723-  set(IlmBase_LIBRARY_DIRS "")
724-  foreach(LIB ${IlmBase_LIB_COMPONENTS})
725-    get_filename_component(_ILMBASE_LIBDIR ${LIB} DIRECTORY)
726-    list(APPEND IlmBase_LIBRARY_DIRS ${_ILMBASE_LIBDIR})
727-  endforeach()
728-  list(REMOVE_DUPLICATES IlmBase_LIBRARY_DIRS)
729-
730-  # Configure imported targets
731-
732-  foreach(COMPONENT ${IlmBase_FIND_COMPONENTS})
733-    if(NOT TARGET IlmBase::${COMPONENT})
734-      add_library(IlmBase::${COMPONENT} UNKNOWN IMPORTED)
735-      set_target_properties(IlmBase::${COMPONENT} PROPERTIES
736-        IMPORTED_LOCATION "${IlmBase_${COMPONENT}_LIBRARY}"
737-        INTERFACE_COMPILE_OPTIONS "${IlmBase_DEFINITIONS}"
738-        INTERFACE_INCLUDE_DIRECTORIES "${IlmBase_INCLUDE_DIRS}"
739-      )
740-    endif()
741-  endforeach()
742-
743-elseif(IlmBase_FIND_REQUIRED)
744-  message(FATAL_ERROR "Unable to find IlmBase")
745-endif()
746diff --git a/cmake/FindOpenEXR.cmake b/cmake/FindOpenEXR.cmake
747deleted file mode 100644
748index 339c1a2..0000000
749--- a/cmake/FindOpenEXR.cmake
750+++ /dev/null
751@@ -1,329 +0,0 @@
752-# Copyright (c) DreamWorks Animation LLC
753-#
754-# All rights reserved. This software is distributed under the
755-# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
756-#
757-# Redistributions of source code must retain the above copyright
758-# and license notice and the following restrictions and disclaimer.
759-#
760-# *     Neither the name of DreamWorks Animation nor the names of
761-# its contributors may be used to endorse or promote products derived
762-# from this software without specific prior written permission.
763-#
764-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
765-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
766-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
767-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
768-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
769-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
770-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
771-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
772-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
773-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
774-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
775-# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
776-# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
777-#
778-#[=======================================================================[.rst:
779-
780-FindOpenEXR
781------------
782-
783-Find OpenEXR include dirs and libraries
784-
785-Use this module by invoking find_package with the form::
786-
787-  find_package(OpenEXR
788-    [version] [EXACT]      # Minimum or EXACT version
789-    [REQUIRED]             # Fail with error if OpenEXR is not found
790-    [COMPONENTS <libs>...] # OpenEXR libraries by their canonical name
791-                           # e.g. "IlmImf" for "libIlmImf"
792-    )
793-
794-IMPORTED Targets
795-^^^^^^^^^^^^^^^^
796-
797-``OpenEXR::IlmImf``
798-  The IlmImf library target.
799-``OpenEXR::IlmImfUtil``
800-  The IlmImfUtil library target.
801-
802-Result Variables
803-^^^^^^^^^^^^^^^^
804-
805-This will define the following variables:
806-
807-``OpenEXR_FOUND``
808-  True if the system has the OpenEXR library.
809-``OpenEXR_VERSION``
810-  The version of the OpenEXR library which was found.
811-``OpenEXR_INCLUDE_DIRS``
812-  Include directories needed to use OpenEXR.
813-``OpenEXR_LIBRARIES``
814-  Libraries needed to link to OpenEXR.
815-``OpenEXR_LIBRARY_DIRS``
816-  OpenEXR library directories.
817-``OpenEXR_DEFINITIONS``
818-  Definitions to use when compiling code that uses OpenEXR.
819-``OpenEXR_{COMPONENT}_FOUND``
820-  True if the system has the named OpenEXR component.
821-
822-Cache Variables
823-^^^^^^^^^^^^^^^
824-
825-The following cache variables may also be set:
826-
827-``OpenEXR_INCLUDE_DIR``
828-  The directory containing ``OpenEXR/config-auto.h``.
829-``OpenEXR_{COMPONENT}_LIBRARY``
830-  Individual component libraries for OpenEXR
831-``OpenEXR_{COMPONENT}_DLL``
832-  Individual component dlls for OpenEXR on Windows.
833-
834-Hints
835-^^^^^
836-
837-Instead of explicitly setting the cache variables, the following variables
838-may be provided to tell this module where to look.
839-
840-``OPENEXR_ROOT``
841-  Preferred installation prefix.
842-``OPENEXR_INCLUDEDIR``
843-  Preferred include directory e.g. <prefix>/include
844-``OPENEXR_LIBRARYDIR``
845-  Preferred library directory e.g. <prefix>/lib
846-``SYSTEM_LIBRARY_PATHS``
847-  Paths appended to all include and lib searches.
848-
849-#]=======================================================================]
850-
851-# Support new if() IN_LIST operator
852-if(POLICY CMP0057)
853-  cmake_policy(SET CMP0057 NEW)
854-endif()
855-
856-mark_as_advanced(
857-  OpenEXR_INCLUDE_DIR
858-  OpenEXR_LIBRARY
859-)
860-
861-set(_OPENEXR_COMPONENT_LIST
862-  IlmImf
863-  IlmImfUtil
864-)
865-
866-if(OpenEXR_FIND_COMPONENTS)
867-  set(OPENEXR_COMPONENTS_PROVIDED TRUE)
868-  set(_IGNORED_COMPONENTS "")
869-  foreach(COMPONENT ${OpenEXR_FIND_COMPONENTS})
870-    if(NOT ${COMPONENT} IN_LIST _OPENEXR_COMPONENT_LIST)
871-      list(APPEND _IGNORED_COMPONENTS ${COMPONENT})
872-    endif()
873-  endforeach()
874-
875-  if(_IGNORED_COMPONENTS)
876-    message(STATUS "Ignoring unknown components of OpenEXR:")
877-    foreach(COMPONENT ${_IGNORED_COMPONENTS})
878-      message(STATUS "  ${COMPONENT}")
879-    endforeach()
880-    list(REMOVE_ITEM OpenEXR_FIND_COMPONENTS ${_IGNORED_COMPONENTS})
881-  endif()
882-else()
883-  set(OPENEXR_COMPONENTS_PROVIDED FALSE)
884-  set(OpenEXR_FIND_COMPONENTS ${_OPENEXR_COMPONENT_LIST})
885-endif()
886-
887-# Append OPENEXR_ROOT or $ENV{OPENEXR_ROOT} if set (prioritize the direct cmake var)
888-set(_OPENEXR_ROOT_SEARCH_DIR "")
889-
890-if(OPENEXR_ROOT)
891-  list(APPEND _OPENEXR_ROOT_SEARCH_DIR ${OPENEXR_ROOT})
892-else()
893-  set(_ENV_OPENEXR_ROOT $ENV{OPENEXR_ROOT})
894-  if(_ENV_OPENEXR_ROOT)
895-    list(APPEND _OPENEXR_ROOT_SEARCH_DIR ${_ENV_OPENEXR_ROOT})
896-  endif()
897-endif()
898-
899-# Additionally try and use pkconfig to find OpenEXR
900-
901-find_package(PkgConfig)
902-pkg_check_modules(PC_OpenEXR QUIET OpenEXR)
903-
904-# ------------------------------------------------------------------------
905-#  Search for OpenEXR include DIR
906-# ------------------------------------------------------------------------
907-
908-set(_OPENEXR_INCLUDE_SEARCH_DIRS "")
909-list(APPEND _OPENEXR_INCLUDE_SEARCH_DIRS
910-  ${OPENEXR_INCLUDEDIR}
911-  ${_OPENEXR_ROOT_SEARCH_DIR}
912-  ${PC_OpenEXR_INCLUDEDIR}
913-  ${SYSTEM_LIBRARY_PATHS}
914-)
915-
916-# Look for a standard OpenEXR header file.
917-find_path(OpenEXR_INCLUDE_DIR OpenEXRConfig.h
918-  NO_DEFAULT_PATH
919-  PATHS ${_OPENEXR_INCLUDE_SEARCH_DIRS}
920-  PATH_SUFFIXES  include/OpenEXR OpenEXR
921-)
922-
923-if(EXISTS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h")
924-  # Get the EXR version information from the config header
925-  file(STRINGS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h"
926-    _openexr_version_major_string REGEX "#define OPENEXR_VERSION_MAJOR "
927-  )
928-  string(REGEX REPLACE "#define OPENEXR_VERSION_MAJOR" ""
929-    _openexr_version_major_string "${_openexr_version_major_string}"
930-  )
931-  string(STRIP "${_openexr_version_major_string}" OpenEXR_VERSION_MAJOR)
932-
933-  file(STRINGS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h"
934-     _openexr_version_minor_string REGEX "#define OPENEXR_VERSION_MINOR "
935-  )
936-  string(REGEX REPLACE "#define OPENEXR_VERSION_MINOR" ""
937-    _openexr_version_minor_string "${_openexr_version_minor_string}"
938-  )
939-  string(STRIP "${_openexr_version_minor_string}" OpenEXR_VERSION_MINOR)
940-
941-  unset(_openexr_version_major_string)
942-  unset(_openexr_version_minor_string)
943-
944-  set(OpenEXR_VERSION ${OpenEXR_VERSION_MAJOR}.${OpenEXR_VERSION_MINOR})
945-endif()
946-
947-# ------------------------------------------------------------------------
948-#  Search for OPENEXR lib DIR
949-# ------------------------------------------------------------------------
950-
951-set(_OPENEXR_LIBRARYDIR_SEARCH_DIRS "")
952-
953-# Append to _OPENEXR_LIBRARYDIR_SEARCH_DIRS in priority order
954-
955-list(APPEND _OPENEXR_LIBRARYDIR_SEARCH_DIRS
956-  ${OPENEXR_LIBRARYDIR}
957-  ${_OPENEXR_ROOT_SEARCH_DIR}
958-  ${PC_OpenEXR_LIBDIR}
959-  ${SYSTEM_LIBRARY_PATHS}
960-)
961-
962-# Build suffix directories
963-
964-set(OPENEXR_PATH_SUFFIXES
965-  lib64
966-  lib
967-)
968-
969-if(UNIX )
970-  list(INSERT OPENEXR_PATH_SUFFIXES 0 lib/x86_64-linux-gnu)
971-endif()
972-
973-set(_OPENEXR_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
974-
975-# library suffix handling
976-if(WIN32)
977-  list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
978-    "-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}.lib"
979-  )
980-else()
981-  if(OPENEXR_USE_STATIC_LIBS)
982-    list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
983-      "-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}.a"
984-    )
985-  else()
986-    if(APPLE)
987-      list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
988-        "-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}.dylib"
989-      )
990-    else()
991-      list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES
992-        "-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}.so"
993-      )
994-    endif()
995-  endif()
996-endif()
997-
998-set(OpenEXR_LIB_COMPONENTS "")
999-
1000-foreach(COMPONENT ${OpenEXR_FIND_COMPONENTS})
1001-  find_library(OpenEXR_${COMPONENT}_LIBRARY ${COMPONENT}
1002-    NO_DEFAULT_PATH
1003-    PATHS ${_OPENEXR_LIBRARYDIR_SEARCH_DIRS}
1004-    PATH_SUFFIXES ${OPENEXR_PATH_SUFFIXES}
1005-  )
1006-  list(APPEND OpenEXR_LIB_COMPONENTS ${OpenEXR_${COMPONENT}_LIBRARY})
1007-
1008-  if(WIN32 AND NOT OPENEXR_USE_STATIC_LIBS)
1009-    set(_OPENEXR_TMP ${CMAKE_FIND_LIBRARY_SUFFIXES})
1010-    set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
1011-    find_library(OpenEXR_${COMPONENT}_DLL ${COMPONENT}
1012-      NO_DEFAULT_PATH
1013-      PATHS ${_OPENEXR_LIBRARYDIR_SEARCH_DIRS}
1014-      PATH_SUFFIXES bin
1015-    )
1016-    set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENEXR_TMP})
1017-    unset(_OPENEXR_TMP)
1018-  endif()
1019-
1020-  if(OpenEXR_${COMPONENT}_LIBRARY)
1021-    set(OpenEXR_${COMPONENT}_FOUND TRUE)
1022-  else()
1023-    set(OpenEXR_${COMPONENT}_FOUND FALSE)
1024-  endif()
1025-endforeach()
1026-
1027-# reset lib suffix
1028-
1029-set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENEXR_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
1030-unset(_OPENEXR_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
1031-
1032-# ------------------------------------------------------------------------
1033-#  Cache and set OPENEXR_FOUND
1034-# ------------------------------------------------------------------------
1035-
1036-include(FindPackageHandleStandardArgs)
1037-find_package_handle_standard_args(OpenEXR
1038-  FOUND_VAR OpenEXR_FOUND
1039-  REQUIRED_VARS
1040-    OpenEXR_INCLUDE_DIR
1041-    OpenEXR_LIB_COMPONENTS
1042-  VERSION_VAR OpenEXR_VERSION
1043-  HANDLE_COMPONENTS
1044-)
1045-
1046-if(OpenEXR_FOUND)
1047-  set(OpenEXR_LIBRARIES ${OpenEXR_LIB_COMPONENTS})
1048-
1049-  # We have to add both include and include/OpenEXR to the include
1050-  # path in case OpenEXR and IlmBase are installed separately
1051-
1052-  set(OpenEXR_INCLUDE_DIRS)
1053-  list(APPEND OpenEXR_INCLUDE_DIRS
1054-    ${OpenEXR_INCLUDE_DIR}/../
1055-    ${OpenEXR_INCLUDE_DIR}
1056-  )
1057-  set(OpenEXR_DEFINITIONS ${PC_OpenEXR_CFLAGS_OTHER})
1058-
1059-  set(OpenEXR_LIBRARY_DIRS "")
1060-  foreach(LIB ${OpenEXR_LIB_COMPONENTS})
1061-    get_filename_component(_OPENEXR_LIBDIR ${LIB} DIRECTORY)
1062-    list(APPEND OpenEXR_LIBRARY_DIRS ${_OPENEXR_LIBDIR})
1063-  endforeach()
1064-  list(REMOVE_DUPLICATES OpenEXR_LIBRARY_DIRS)
1065-
1066-  # Configure imported target
1067-
1068-  foreach(COMPONENT ${OpenEXR_FIND_COMPONENTS})
1069-    if(NOT TARGET OpenEXR::${COMPONENT})
1070-      add_library(OpenEXR::${COMPONENT} UNKNOWN IMPORTED)
1071-      set_target_properties(OpenEXR::${COMPONENT} PROPERTIES
1072-        IMPORTED_LOCATION "${OpenEXR_${COMPONENT}_LIBRARY}"
1073-        INTERFACE_COMPILE_OPTIONS "${OpenEXR_DEFINITIONS}"
1074-        INTERFACE_INCLUDE_DIRECTORIES "${OpenEXR_INCLUDE_DIRS}"
1075-      )
1076-    endif()
1077-  endforeach()
1078-elseif(OpenEXR_FIND_REQUIRED)
1079-  message(FATAL_ERROR "Unable to find OpenEXR")
1080-endif()
1081diff --git a/cmake/FindOpenVDB.cmake b/cmake/FindOpenVDB.cmake
1082index 63a2eda..d9f6d07 100644
1083--- a/cmake/FindOpenVDB.cmake
1084+++ b/cmake/FindOpenVDB.cmake
1085@@ -244,7 +244,7 @@ set(OpenVDB_LIB_COMPONENTS "")
1086
1087 foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
1088   set(LIB_NAME ${COMPONENT})
1089-  find_library(OpenVDB_${COMPONENT}_LIBRARY ${LIB_NAME}
1090+  find_library(OpenVDB_${COMPONENT}_LIBRARY ${LIB_NAME} lib${LIB_NAME}
1091     NO_DEFAULT_PATH
1092     PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}
1093     PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES}
1094@@ -282,16 +282,13 @@ find_package_handle_standard_args(OpenVDB
1095 # ------------------------------------------------------------------------
1096
1097 # Set the ABI number the library was built against. Uses vdb_print
1098+find_program(OPENVDB_PRINT vdb_print
1099+  PATHS ${_OPENVDB_INSTALL}/bin ${OpenVDB_INCLUDE_DIR}
1100+  NO_DEFAULT_PATH)
1101
1102 if(_OPENVDB_INSTALL)
1103   OPENVDB_ABI_VERSION_FROM_PRINT(
1104-    "${_OPENVDB_INSTALL}/bin/vdb_print"
1105-    ABI OpenVDB_ABI
1106-  )
1107-else()
1108-  # Try and find vdb_print from the include path
1109-  OPENVDB_ABI_VERSION_FROM_PRINT(
1110-    "${OpenVDB_INCLUDE_DIR}/../bin/vdb_print"
1111+    "${OPENVDB_PRINT}"
1112     ABI OpenVDB_ABI
1113   )
1114 endif()
1115@@ -472,6 +469,12 @@ foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
1116       INTERFACE_LINK_LIBRARIES "${_OPENVDB_VISIBLE_DEPENDENCIES}" # visible deps (headers)
1117       INTERFACE_COMPILE_FEATURES cxx_std_11
1118    )
1119+
1120+   if (OPENVDB_USE_STATIC_LIBS)
1121+    set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
1122+      INTERFACE_COMPILE_DEFINITIONS "OPENVDB_STATICLIB;OPENVDB_OPENEXR_STATICLIB"
1123+    )
1124+   endif()
1125   endif()
1126 endforeach()
1127
1128diff --git a/cmake/FindTBB.cmake b/cmake/FindTBB.cmake
1129index bdf9c81..06093a4 100644
1130--- a/cmake/FindTBB.cmake
1131+++ b/cmake/FindTBB.cmake
1132@@ -1,333 +1,332 @@
1133-# Copyright (c) DreamWorks Animation LLC
1134+# The MIT License (MIT)
1135 #
1136-# All rights reserved. This software is distributed under the
1137-# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
1138+# Copyright (c) 2015 Justus Calvin
1139 #
1140-# Redistributions of source code must retain the above copyright
1141-# and license notice and the following restrictions and disclaimer.
1142+# Permission is hereby granted, free of charge, to any person obtaining a copy
1143+# of this software and associated documentation files (the "Software"), to deal
1144+# in the Software without restriction, including without limitation the rights
1145+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1146+# copies of the Software, and to permit persons to whom the Software is
1147+# furnished to do so, subject to the following conditions:
1148 #
1149-# *     Neither the name of DreamWorks Animation nor the names of
1150-# its contributors may be used to endorse or promote products derived
1151-# from this software without specific prior written permission.
1152+# The above copyright notice and this permission notice shall be included in all
1153+# copies or substantial portions of the Software.
1154 #
1155-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1156-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1157-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1158-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1159-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
1160-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1161-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1162-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1163-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1164-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1165-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1166-# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
1167-# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
1168+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1169+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1170+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1171+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1172+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1173+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1174+# SOFTWARE.
1175+
1176 #
1177-#[=======================================================================[.rst:
1178-
1179-FindTBB
1180--------
1181-
1182-Find Tbb include dirs and libraries
1183-
1184-Use this module by invoking find_package with the form::
1185-
1186-  find_package(TBB
1187-    [version] [EXACT]      # Minimum or EXACT version
1188-    [REQUIRED]             # Fail with error if Tbb is not found
1189-    [COMPONENTS <libs>...] # Tbb libraries by their canonical name
1190-                           # e.g. "tbb" for "libtbb"
1191-    )
1192-
1193-IMPORTED Targets
1194-^^^^^^^^^^^^^^^^
1195-
1196-``TBB::tbb``
1197-  The tbb library target.
1198-``TBB::tbbmalloc``
1199-  The tbbmalloc library target.
1200-``TBB::tbbmalloc_proxy``
1201-  The tbbmalloc_proxy library target.
1202-
1203-Result Variables
1204-^^^^^^^^^^^^^^^^
1205-
1206-This will define the following variables:
1207-
1208-``Tbb_FOUND``
1209-  True if the system has the Tbb library.
1210-``Tbb_VERSION``
1211-  The version of the Tbb library which was found.
1212-``Tbb_INCLUDE_DIRS``
1213-  Include directories needed to use Tbb.
1214-``Tbb_LIBRARIES``
1215-  Libraries needed to link to Tbb.
1216-``Tbb_LIBRARY_DIRS``
1217-  Tbb library directories.
1218-``TBB_{COMPONENT}_FOUND``
1219-  True if the system has the named TBB component.
1220-
1221-Cache Variables
1222-^^^^^^^^^^^^^^^
1223-
1224-The following cache variables may also be set:
1225-
1226-``Tbb_INCLUDE_DIR``
1227-  The directory containing ``tbb/tbb_stddef.h``.
1228-``Tbb_{COMPONENT}_LIBRARY``
1229-  Individual component libraries for Tbb
1230-
1231-Hints
1232-^^^^^
1233-
1234-Instead of explicitly setting the cache variables, the following variables
1235-may be provided to tell this module where to look.
1236-
1237-``TBB_ROOT``
1238-  Preferred installation prefix.
1239-``TBB_INCLUDEDIR``
1240-  Preferred include directory e.g. <prefix>/include
1241-``TBB_LIBRARYDIR``
1242-  Preferred library directory e.g. <prefix>/lib
1243-``SYSTEM_LIBRARY_PATHS``
1244-  Paths appended to all include and lib searches.
1245-
1246-#]=======================================================================]
1247-
1248-# Support new if() IN_LIST operator
1249-if(POLICY CMP0057)
1250-  cmake_policy(SET CMP0057 NEW)
1251-endif()
1252+# FindTBB
1253+# -------
1254+#
1255+# Find TBB include directories and libraries.
1256+#
1257+# Usage:
1258+#
1259+#  find_package(TBB [major[.minor]] [EXACT]
1260+#               [QUIET] [REQUIRED]
1261+#               [[COMPONENTS] [components...]]
1262+#               [OPTIONAL_COMPONENTS components...])
1263+#
1264+# where the allowed components are tbbmalloc and tbb_preview. Users may modify
1265+# the behavior of this module with the following variables:
1266+#
1267+# * TBB_ROOT_DIR          - The base directory the of TBB installation.
1268+# * TBB_INCLUDE_DIR       - The directory that contains the TBB headers files.
1269+# * TBB_LIBRARY           - The directory that contains the TBB library files.
1270+# * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library.
1271+#                           These libraries, if specified, override the
1272+#                           corresponding library search results, where <library>
1273+#                           may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug,
1274+#                           tbb_preview, or tbb_preview_debug.
1275+# * TBB_USE_DEBUG_BUILD   - The debug version of tbb libraries, if present, will
1276+#                           be used instead of the release version.
1277+# * TBB_STATIC            - Static linking of libraries with a _static suffix.
1278+#                           For example, on Windows a tbb_static.lib will be searched for
1279+#                           instead of tbb.lib.
1280+#
1281+# Users may modify the behavior of this module with the following environment
1282+# variables:
1283+#
1284+# * TBB_INSTALL_DIR
1285+# * TBBROOT
1286+# * LIBRARY_PATH
1287+#
1288+# This module will set the following variables:
1289+#
1290+# * TBB_FOUND             - Set to false, or undefined, if we haven’t found, or
1291+#                           don’t want to use TBB.
1292+# * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is
1293+#                           not available.
1294+# * TBB_VERSION           - The full version string
1295+# * TBB_VERSION_MAJOR     - The major version
1296+# * TBB_VERSION_MINOR     - The minor version
1297+# * TBB_INTERFACE_VERSION - The interface version number defined in
1298+#                           tbb/tbb_stddef.h.
1299+# * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of
1300+#                           <library>, where <library> may be tbb, tbb_debug,
1301+#                           tbbmalloc, tbbmalloc_debug, tbb_preview, or
1302+#                           tbb_preview_debug.
1303+# * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of
1304+#                           <library>, where <library> may be tbb, tbb_debug,
1305+#                           tbbmalloc, tbbmalloc_debug, tbb_preview, or
1306+#                           tbb_preview_debug.
1307+#
1308+# The following varibles should be used to build and link with TBB:
1309+#
1310+# * TBB_INCLUDE_DIRS        - The include directory for TBB.
1311+# * TBB_LIBRARIES           - The libraries to link against to use TBB.
1312+# * TBB_LIBRARIES_RELEASE   - The release libraries to link against to use TBB.
1313+# * TBB_LIBRARIES_DEBUG     - The debug libraries to link against to use TBB.
1314+# * TBB_DEFINITIONS         - Definitions to use when compiling code that uses
1315+#                             TBB.
1316+# * TBB_DEFINITIONS_RELEASE - Definitions to use when compiling release code that
1317+#                             uses TBB.
1318+# * TBB_DEFINITIONS_DEBUG   - Definitions to use when compiling debug code that
1319+#                             uses TBB.
1320+#
1321+# This module will also create the "tbb" target that may be used when building
1322+# executables and libraries.
1323
1324-mark_as_advanced(
1325-  Tbb_INCLUDE_DIR
1326-  Tbb_LIBRARY
1327-)
1328-
1329-set(_TBB_COMPONENT_LIST
1330-  tbb
1331-  tbbmalloc
1332-  tbbmalloc_proxy
1333-)
1334-
1335-if(TBB_FIND_COMPONENTS)
1336-  set(_TBB_COMPONENTS_PROVIDED TRUE)
1337-  set(_IGNORED_COMPONENTS "")
1338-  foreach(COMPONENT ${TBB_FIND_COMPONENTS})
1339-    if(NOT ${COMPONENT} IN_LIST _TBB_COMPONENT_LIST)
1340-      list(APPEND _IGNORED_COMPONENTS ${COMPONENT})
1341-    endif()
1342-  endforeach()
1343+unset(TBB_FOUND CACHE)
1344+unset(TBB_INCLUDE_DIRS CACHE)
1345+unset(TBB_LIBRARIES)
1346+unset(TBB_LIBRARIES_DEBUG)
1347+unset(TBB_LIBRARIES_RELEASE)
1348
1349-  if(_IGNORED_COMPONENTS)
1350-    message(STATUS "Ignoring unknown components of TBB:")
1351-    foreach(COMPONENT ${_IGNORED_COMPONENTS})
1352-      message(STATUS "  ${COMPONENT}")
1353-    endforeach()
1354-    list(REMOVE_ITEM TBB_FIND_COMPONENTS ${_IGNORED_COMPONENTS})
1355-  endif()
1356-else()
1357-  set(_TBB_COMPONENTS_PROVIDED FALSE)
1358-  set(TBB_FIND_COMPONENTS ${_TBB_COMPONENT_LIST})
1359-endif()
1360+include(FindPackageHandleStandardArgs)
1361
1362-# Append TBB_ROOT or $ENV{TBB_ROOT} if set (prioritize the direct cmake var)
1363-set(_TBB_ROOT_SEARCH_DIR "")
1364+find_package(Threads QUIET REQUIRED)
1365
1366-if(TBB_ROOT)
1367-  list(APPEND _TBB_ROOT_SEARCH_DIR ${TBB_ROOT})
1368-else()
1369-  set(_ENV_TBB_ROOT $ENV{TBB_ROOT})
1370-  if(_ENV_TBB_ROOT)
1371-    list(APPEND _TBB_ROOT_SEARCH_DIR ${_ENV_TBB_ROOT})
1372-  endif()
1373-endif()
1374+if(NOT TBB_FOUND)
1375
1376-# Additionally try and use pkconfig to find Tbb
1377-
1378-find_package(PkgConfig)
1379-pkg_check_modules(PC_Tbb QUIET tbb)
1380-
1381-# ------------------------------------------------------------------------
1382-#  Search for tbb include DIR
1383-# ------------------------------------------------------------------------
1384-
1385-set(_TBB_INCLUDE_SEARCH_DIRS "")
1386-list(APPEND _TBB_INCLUDE_SEARCH_DIRS
1387-  ${TBB_INCLUDEDIR}
1388-  ${_TBB_ROOT_SEARCH_DIR}
1389-  ${PC_Tbb_INCLUDE_DIRS}
1390-  ${SYSTEM_LIBRARY_PATHS}
1391-)
1392-
1393-# Look for a standard tbb header file.
1394-find_path(Tbb_INCLUDE_DIR tbb/tbb_stddef.h
1395-  NO_DEFAULT_PATH
1396-  PATHS ${_TBB_INCLUDE_SEARCH_DIRS}
1397-  PATH_SUFFIXES include
1398-)
1399-
1400-if(EXISTS "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h")
1401-  file(STRINGS "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h"
1402-    _tbb_version_major_string REGEX "#define TBB_VERSION_MAJOR "
1403-  )
1404-  string(REGEX REPLACE "#define TBB_VERSION_MAJOR" ""
1405-    _tbb_version_major_string "${_tbb_version_major_string}"
1406-  )
1407-  string(STRIP "${_tbb_version_major_string}" Tbb_VERSION_MAJOR)
1408-
1409-  file(STRINGS "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h"
1410-     _tbb_version_minor_string REGEX "#define TBB_VERSION_MINOR "
1411-  )
1412-  string(REGEX REPLACE "#define TBB_VERSION_MINOR" ""
1413-    _tbb_version_minor_string "${_tbb_version_minor_string}"
1414-  )
1415-  string(STRIP "${_tbb_version_minor_string}" Tbb_VERSION_MINOR)
1416-
1417-  unset(_tbb_version_major_string)
1418-  unset(_tbb_version_minor_string)
1419-
1420-  set(Tbb_VERSION ${Tbb_VERSION_MAJOR}.${Tbb_VERSION_MINOR})
1421-endif()
1422+  ##################################
1423+  # Check the build type
1424+  ##################################
1425+
1426+  if(NOT DEFINED TBB_USE_DEBUG_BUILD)
1427+    if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug)")
1428+      set(TBB_BUILD_TYPE DEBUG)
1429+    else()
1430+      set(TBB_BUILD_TYPE RELEASE)
1431+    endif()
1432+  elseif(TBB_USE_DEBUG_BUILD)
1433+    set(TBB_BUILD_TYPE DEBUG)
1434+  else()
1435+    set(TBB_BUILD_TYPE RELEASE)
1436+  endif()
1437
1438-# ------------------------------------------------------------------------
1439-#  Search for TBB lib DIR
1440-# ------------------------------------------------------------------------
1441+  ##################################
1442+  # Set the TBB search directories
1443+  ##################################
1444
1445-set(_TBB_LIBRARYDIR_SEARCH_DIRS "")
1446+  # Define search paths based on user input and environment variables
1447+  set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT})
1448
1449-# Append to _TBB_LIBRARYDIR_SEARCH_DIRS in priority order
1450+  # Define the search directories based on the current platform
1451+  if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
1452+    set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB"
1453+                               "C:/Program Files (x86)/Intel/TBB")
1454
1455-set(_TBB_LIBRARYDIR_SEARCH_DIRS "")
1456-list(APPEND _TBB_LIBRARYDIR_SEARCH_DIRS
1457-  ${TBB_LIBRARYDIR}
1458-  ${_TBB_ROOT_SEARCH_DIR}
1459-  ${PC_Tbb_LIBRARY_DIRS}
1460-  ${SYSTEM_LIBRARY_PATHS}
1461-)
1462+    # Set the target architecture
1463+    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
1464+      set(TBB_ARCHITECTURE "intel64")
1465+    else()
1466+      set(TBB_ARCHITECTURE "ia32")
1467+    endif()
1468
1469-set(TBB_PATH_SUFFIXES
1470-  lib64
1471-  lib
1472-)
1473+    # Set the TBB search library path search suffix based on the version of VC
1474+    if(WINDOWS_STORE)
1475+      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui")
1476+    elseif(MSVC14)
1477+      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14")
1478+    elseif(MSVC12)
1479+      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12")
1480+    elseif(MSVC11)
1481+      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11")
1482+    elseif(MSVC10)
1483+      set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10")
1484+    endif()
1485
1486-# platform branching
1487+    # Add the library path search suffix for the VC independent version of TBB
1488+    list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt")
1489
1490-if(UNIX)
1491-  list(INSERT TBB_PATH_SUFFIXES 0 lib/x86_64-linux-gnu)
1492-endif()
1493+  elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1494+    # OS X
1495+    set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
1496
1497-if(APPLE)
1498-  if(TBB_FOR_CLANG)
1499-    list(INSERT TBB_PATH_SUFFIXES 0 lib/libc++)
1500-  endif()
1501-elseif(WIN32)
1502-  if(MSVC10)
1503-    set(TBB_VC_DIR vc10)
1504-  elseif(MSVC11)
1505-    set(TBB_VC_DIR vc11)
1506-  elseif(MSVC12)
1507-    set(TBB_VC_DIR vc12)
1508-  endif()
1509-  list(INSERT TBB_PATH_SUFFIXES 0 lib/intel64/${TBB_VC_DIR})
1510-else()
1511-  if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
1512-    if(TBB_MATCH_COMPILER_VERSION)
1513-      string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${CMAKE_CXX_COMPILER_VERSION})
1514-      list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
1515-      list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
1516-      list(INSERT TBB_PATH_SUFFIXES 0 lib/intel64/gcc${GCC_MAJOR}.${GCC_MINOR})
1517+    # TODO: Check to see which C++ library is being used by the compiler.
1518+    if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0)
1519+      # The default C++ library on OS X 10.9 and later is libc++
1520+      set(TBB_LIB_PATH_SUFFIX "lib/libc++" "lib")
1521     else()
1522-      list(INSERT TBB_PATH_SUFFIXES 0 lib/intel64/gcc4.4)
1523+      set(TBB_LIB_PATH_SUFFIX "lib")
1524+    endif()
1525+  elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1526+    # Linux
1527+    set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
1528+
1529+    # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or
1530+    #       <arch>/gcc4.1. For now, assume that the compiler is more recent than
1531+    #       gcc 4.4.x or later.
1532+    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
1533+      set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4")
1534+    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
1535+      set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4")
1536     endif()
1537   endif()
1538-endif()
1539-
1540-if(UNIX AND TBB_USE_STATIC_LIBS)
1541-  set(_TBB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
1542-  set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
1543-endif()
1544
1545-set(Tbb_LIB_COMPONENTS "")
1546-
1547-foreach(COMPONENT ${TBB_FIND_COMPONENTS})
1548-  find_library(Tbb_${COMPONENT}_LIBRARY ${COMPONENT}
1549-    NO_DEFAULT_PATH
1550-    PATHS ${_TBB_LIBRARYDIR_SEARCH_DIRS}
1551-    PATH_SUFFIXES ${TBB_PATH_SUFFIXES}
1552-  )
1553-
1554-  # On Unix, TBB sometimes uses linker scripts instead of symlinks, so parse the linker script
1555-  # and correct the library name if so
1556-  if(UNIX AND EXISTS ${Tbb_${COMPONENT}_LIBRARY})
1557-    # Ignore files where the first four bytes equals the ELF magic number
1558-    file(READ ${Tbb_${COMPONENT}_LIBRARY} Tbb_${COMPONENT}_HEX OFFSET 0 LIMIT 4 HEX)
1559-    if(NOT ${Tbb_${COMPONENT}_HEX} STREQUAL "7f454c46")
1560-      # Read the first 1024 bytes of the library and match against an "INPUT (file)" regex
1561-      file(READ ${Tbb_${COMPONENT}_LIBRARY} Tbb_${COMPONENT}_ASCII OFFSET 0 LIMIT 1024)
1562-      if("${Tbb_${COMPONENT}_ASCII}" MATCHES "INPUT \\(([^(]+)\\)")
1563-        # Extract the directory and apply the matched text (in brackets)
1564-        get_filename_component(Tbb_${COMPONENT}_DIR "${Tbb_${COMPONENT}_LIBRARY}" DIRECTORY)
1565-        set(Tbb_${COMPONENT}_LIBRARY "${Tbb_${COMPONENT}_DIR}/${CMAKE_MATCH_1}")
1566-      endif()
1567-    endif()
1568+  ##################################
1569+  # Find the TBB include dir
1570+  ##################################
1571+
1572+  find_path(TBB_INCLUDE_DIRS tbb/tbb.h
1573+      HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR}
1574+      PATHS ${TBB_DEFAULT_SEARCH_DIR}
1575+      PATH_SUFFIXES include)
1576+
1577+  ##################################
1578+  # Set version strings
1579+  ##################################
1580+
1581+  if(TBB_INCLUDE_DIRS)
1582+    file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file)
1583+    string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
1584+        TBB_VERSION_MAJOR "${_tbb_version_file}")
1585+    string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
1586+        TBB_VERSION_MINOR "${_tbb_version_file}")
1587+    string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
1588+        TBB_INTERFACE_VERSION "${_tbb_version_file}")
1589+    set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
1590   endif()
1591
1592-  list(APPEND Tbb_LIB_COMPONENTS ${Tbb_${COMPONENT}_LIBRARY})
1593+  ##################################
1594+  # Find TBB components
1595+  ##################################
1596
1597-  if(Tbb_${COMPONENT}_LIBRARY)
1598-    set(TBB_${COMPONENT}_FOUND TRUE)
1599+  if(TBB_VERSION VERSION_LESS 4.3)
1600+    set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb)
1601   else()
1602-    set(TBB_${COMPONENT}_FOUND FALSE)
1603+    set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb)
1604   endif()
1605-endforeach()
1606
1607-if(UNIX AND TBB_USE_STATIC_LIBS)
1608-  set(CMAKE_FIND_LIBRARY_SUFFIXES ${_TBB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
1609-  unset(_TBB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
1610-endif()
1611+  if(TBB_STATIC)
1612+    set(TBB_STATIC_SUFFIX "_static")
1613+  endif()
1614
1615-# ------------------------------------------------------------------------
1616-#  Cache and set TBB_FOUND
1617-# ------------------------------------------------------------------------
1618+  # Find each component
1619+  foreach(_comp ${TBB_SEARCH_COMPOMPONENTS})
1620+    if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};")
1621+
1622+      unset(TBB_${_comp}_LIBRARY_DEBUG CACHE)
1623+      unset(TBB_${_comp}_LIBRARY_RELEASE CACHE)
1624+
1625+      # Search for the libraries
1626+      find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}${TBB_STATIC_SUFFIX}
1627+          HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
1628+          PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
1629+          PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
1630+
1631+      find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}${TBB_STATIC_SUFFIX}_debug
1632+          HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
1633+          PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
1634+          PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
1635+
1636+      if(TBB_${_comp}_LIBRARY_DEBUG)
1637+        list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}")
1638+      endif()
1639+      if(TBB_${_comp}_LIBRARY_RELEASE)
1640+        list(APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}")
1641+      endif()
1642+      if(TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp}_LIBRARY)
1643+        set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}")
1644+      endif()
1645+
1646+      if(TBB_${_comp}_LIBRARY AND EXISTS "${TBB_${_comp}_LIBRARY}")
1647+        set(TBB_${_comp}_FOUND TRUE)
1648+      else()
1649+        set(TBB_${_comp}_FOUND FALSE)
1650+      endif()
1651+
1652+      # Mark internal variables as advanced
1653+      mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE)
1654+      mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG)
1655+      mark_as_advanced(TBB_${_comp}_LIBRARY)
1656
1657-include(FindPackageHandleStandardArgs)
1658-find_package_handle_standard_args(TBB
1659-  FOUND_VAR TBB_FOUND
1660-  REQUIRED_VARS
1661-    Tbb_INCLUDE_DIR
1662-    Tbb_LIB_COMPONENTS
1663-  VERSION_VAR Tbb_VERSION
1664-  HANDLE_COMPONENTS
1665-)
1666-
1667-if(TBB_FOUND)
1668-  set(Tbb_LIBRARIES
1669-    ${Tbb_LIB_COMPONENTS}
1670-  )
1671-  set(Tbb_INCLUDE_DIRS ${Tbb_INCLUDE_DIR})
1672-  set(Tbb_DEFINITIONS ${PC_Tbb_CFLAGS_OTHER})
1673-
1674-  set(Tbb_LIBRARY_DIRS "")
1675-  foreach(LIB ${Tbb_LIB_COMPONENTS})
1676-    get_filename_component(_TBB_LIBDIR ${LIB} DIRECTORY)
1677-    list(APPEND Tbb_LIBRARY_DIRS ${_TBB_LIBDIR})
1678-  endforeach()
1679-  list(REMOVE_DUPLICATES Tbb_LIBRARY_DIRS)
1680-
1681-  # Configure imported targets
1682-
1683-  foreach(COMPONENT ${TBB_FIND_COMPONENTS})
1684-    if(NOT TARGET TBB::${COMPONENT})
1685-      add_library(TBB::${COMPONENT} UNKNOWN IMPORTED)
1686-      set_target_properties(TBB::${COMPONENT} PROPERTIES
1687-        IMPORTED_LOCATION "${Tbb_${COMPONENT}_LIBRARY}"
1688-        INTERFACE_COMPILE_OPTIONS "${Tbb_DEFINITIONS}"
1689-        INTERFACE_INCLUDE_DIRECTORIES "${Tbb_INCLUDE_DIR}"
1690-      )
1691     endif()
1692   endforeach()
1693-elseif(TBB_FIND_REQUIRED)
1694-  message(FATAL_ERROR "Unable to find TBB")
1695+
1696+  ##################################
1697+  # Set compile flags and libraries
1698+  ##################################
1699+
1700+  set(TBB_DEFINITIONS_RELEASE "")
1701+  set(TBB_DEFINITIONS_DEBUG "TBB_USE_DEBUG=1")
1702+
1703+  if(TBB_LIBRARIES_${TBB_BUILD_TYPE})
1704+    set(TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE}}")
1705+  endif()
1706+
1707+  if(NOT MSVC AND NOT TBB_LIBRARIES)
1708+    set(TBB_LIBRARIES ${TBB_LIBRARIES_RELEASE})
1709+  endif()
1710+
1711+  set(TBB_DEFINITIONS "")
1712+  if (MSVC AND TBB_STATIC)
1713+    set(TBB_DEFINITIONS __TBB_NO_IMPLICIT_LINKAGE)
1714+  endif ()
1715+
1716+  unset (TBB_STATIC_SUFFIX)
1717+
1718+  find_package_handle_standard_args(TBB
1719+      REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
1720+      FAIL_MESSAGE "TBB library cannot be found. Consider set TBBROOT environment variable."
1721+      HANDLE_COMPONENTS
1722+      VERSION_VAR TBB_VERSION)
1723+
1724+  ##################################
1725+  # Create targets
1726+  ##################################
1727+
1728+  if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND)
1729+    add_library(TBB::tbb UNKNOWN IMPORTED)
1730+    set_target_properties(TBB::tbb PROPERTIES
1731+          INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS}"
1732+          INTERFACE_LINK_LIBRARIES  "Threads::Threads;${CMAKE_DL_LIBS}"
1733+          INTERFACE_INCLUDE_DIRECTORIES  ${TBB_INCLUDE_DIRS}
1734+          IMPORTED_LOCATION              ${TBB_LIBRARIES})
1735+    if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG)
1736+      set_target_properties(TBB::tbb PROPERTIES
1737+          INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS};$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:${TBB_DEFINITIONS_DEBUG}>;$<$<CONFIG:Release>:${TBB_DEFINITIONS_RELEASE}>"
1738+          IMPORTED_LOCATION_DEBUG          ${TBB_LIBRARIES_DEBUG}
1739+          IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_RELEASE}
1740+          IMPORTED_LOCATION_RELEASE        ${TBB_LIBRARIES_RELEASE}
1741+          IMPORTED_LOCATION_MINSIZEREL     ${TBB_LIBRARIES_RELEASE}
1742+          )
1743+    endif()
1744+  endif()
1745+
1746+  mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)
1747+
1748+  unset(TBB_ARCHITECTURE)
1749+  unset(TBB_BUILD_TYPE)
1750+  unset(TBB_LIB_PATH_SUFFIX)
1751+  unset(TBB_DEFAULT_SEARCH_DIR)
1752+
1753+  if(TBB_DEBUG)
1754+    message(STATUS "  TBB_FOUND               = ${TBB_FOUND}")
1755+    message(STATUS "  TBB_INCLUDE_DIRS        = ${TBB_INCLUDE_DIRS}")
1756+    message(STATUS "  TBB_DEFINITIONS         = ${TBB_DEFINITIONS}")
1757+    message(STATUS "  TBB_LIBRARIES           = ${TBB_LIBRARIES}")
1758+    message(STATUS "  TBB_DEFINITIONS_DEBUG   = ${TBB_DEFINITIONS_DEBUG}")
1759+    message(STATUS "  TBB_LIBRARIES_DEBUG     = ${TBB_LIBRARIES_DEBUG}")
1760+    message(STATUS "  TBB_DEFINITIONS_RELEASE = ${TBB_DEFINITIONS_RELEASE}")
1761+    message(STATUS "  TBB_LIBRARIES_RELEASE   = ${TBB_LIBRARIES_RELEASE}")
1762+  endif()
1763+
1764 endif()
1765diff --git a/openvdb/CMakeLists.txt b/openvdb/CMakeLists.txt
1766index 89301bd..6a3c90c 100644
1767--- a/openvdb/CMakeLists.txt
1768+++ b/openvdb/CMakeLists.txt
1769@@ -78,7 +78,7 @@ else()
1770 endif()
1771
1772 find_package(TBB ${MINIMUM_TBB_VERSION} REQUIRED COMPONENTS tbb)
1773-if(${Tbb_VERSION} VERSION_LESS FUTURE_MINIMUM_TBB_VERSION)
1774+if(${TBB_VERSION} VERSION_LESS FUTURE_MINIMUM_TBB_VERSION)
1775   message(DEPRECATION "Support for TBB versions < ${FUTURE_MINIMUM_TBB_VERSION} "
1776     "is deprecated and will be removed.")
1777 endif()
1778@@ -129,10 +129,13 @@ endif()
1779 # include paths from shared installs (including houdini) may pull in the wrong
1780 # headers
1781
1782+include (CheckAtomic)
1783+
1784 set(OPENVDB_CORE_DEPENDENT_LIBS
1785   Boost::iostreams
1786   Boost::system
1787   IlmBase::Half
1788+  ${CMAKE_REQUIRED_LIBRARIES}
1789 )
1790
1791 if(USE_EXR)
1792@@ -185,11 +188,6 @@ if(WIN32)
1793   endif()
1794 endif()
1795
1796-# @todo Should be target definitions
1797-if(WIN32)
1798-  add_definitions(-D_WIN32 -DNOMINMAX -DOPENVDB_DLL)
1799-endif()
1800-
1801 ##### Core library configuration
1802
1803 set(OPENVDB_LIBRARY_SOURCE_FILES
1804@@ -374,10 +372,16 @@ set(OPENVDB_LIBRARY_UTIL_INCLUDE_FILES
1805
1806 if(OPENVDB_CORE_SHARED)
1807   add_library(openvdb_shared SHARED ${OPENVDB_LIBRARY_SOURCE_FILES})
1808+  if(WIN32)
1809+    target_compile_definitions(openvdb_shared PUBLIC OPENVDB_DLL)
1810+  endif()
1811 endif()
1812
1813 if(OPENVDB_CORE_STATIC)
1814   add_library(openvdb_static STATIC ${OPENVDB_LIBRARY_SOURCE_FILES})
1815+  if(WIN32)
1816+    target_compile_definitions(openvdb_static PUBLIC OPENVDB_STATICLIB)
1817+  endif()
1818 endif()
1819
1820 # Alias either the shared or static library to the generic OpenVDB
1821diff --git a/openvdb/Grid.cc b/openvdb/Grid.cc
1822index 0015f81..cb6084a 100644
1823--- a/openvdb/Grid.cc
1824+++ b/openvdb/Grid.cc
1825@@ -35,6 +35,9 @@
1826 #include <boost/algorithm/string/trim.hpp>
1827 #include <tbb/mutex.h>
1828
1829+// WTF??? Somehow from stdlib.h
1830+#undef min
1831+#undef max
1832
1833 namespace openvdb {
1834 OPENVDB_USE_VERSION_NAMESPACE
1835diff --git a/openvdb/PlatformConfig.h b/openvdb/PlatformConfig.h
1836index 20ad9a3..c2dd1ef 100644
1837--- a/openvdb/PlatformConfig.h
1838+++ b/openvdb/PlatformConfig.h
1839@@ -44,9 +44,12 @@
1840
1841     // By default, assume that we're dynamically linking OpenEXR, unless
1842     // OPENVDB_OPENEXR_STATICLIB is defined.
1843-    #if !defined(OPENVDB_OPENEXR_STATICLIB) && !defined(OPENEXR_DLL)
1844-        #define OPENEXR_DLL
1845-    #endif
1846+    // Meszaros Tamas: Why? OpenEXR and its imported targets have OPENEXR_DLL
1847+    // in INTERFACE_COMPILE_DEFINITIONS if build with it.
1848+    // #if !defined(OPENVDB_OPENEXR_STATICLIB) && !defined(OPENEXR_DLL)
1849+    //     #define OPENEXR_DLL
1850+    //     static_assert(false, "This is bad: OPENEXR_DLL");
1851+    // #endif
1852
1853 #endif // _WIN32
1854
1855diff --git a/openvdb/cmd/CMakeLists.txt b/openvdb/cmd/CMakeLists.txt
1856index 57fbec0..55b3850 100644
1857--- a/openvdb/cmd/CMakeLists.txt
1858+++ b/openvdb/cmd/CMakeLists.txt
1859@@ -74,8 +74,9 @@ if(WIN32)
1860   endif()
1861 endif()
1862
1863+# @todo Should be target definitions
1864 if(WIN32)
1865-  add_definitions(-D_WIN32 -DNOMINMAX -DOPENVDB_DLL)
1866+  add_definitions(-D_WIN32 -DNOMINMAX)
1867 endif()
1868
1869 # rpath handling
1870@@ -88,7 +89,6 @@ if(OPENVDB_ENABLE_RPATH)
1871     ${IlmBase_LIBRARY_DIRS}
1872     ${Log4cplus_LIBRARY_DIRS}
1873     ${Blosc_LIBRARY_DIRS}
1874-    ${Tbb_LIBRARY_DIRS}
1875   )
1876   if(OPENVDB_BUILD_CORE)
1877     list(APPEND RPATHS ${CMAKE_INSTALL_PREFIX}/lib)
1878diff --git a/openvdb/unittest/CMakeLists.txt b/openvdb/unittest/CMakeLists.txt
1879index c9e0c34..7e261c0 100644
1880--- a/openvdb/unittest/CMakeLists.txt
1881+++ b/openvdb/unittest/CMakeLists.txt
1882@@ -71,8 +71,9 @@ if(WIN32)
1883   link_directories(${Boost_LIBRARY_DIR})
1884 endif()
1885
1886+# @todo Should be target definitions
1887 if(WIN32)
1888-  add_definitions(-D_WIN32 -DNOMINMAX -DOPENVDB_DLL)
1889+  add_definitions(-D_WIN32 -DNOMINMAX)
1890 endif()
1891
1892 ##### VDB unit tests
1893diff --git a/openvdb/unittest/TestFile.cc b/openvdb/unittest/TestFile.cc
1894index df51830..0ab0c12 100644
1895--- a/openvdb/unittest/TestFile.cc
1896+++ b/openvdb/unittest/TestFile.cc
1897@@ -2573,7 +2573,7 @@ TestFile::testBlosc()
1898         outdata(new char[decompbufbytes]);
1899
1900     for (int compcode = 0; compcode <= BLOSC_ZLIB; ++compcode) {
1901-        char* compname = nullptr;
1902+        const char* compname = nullptr;
1903         if (0 > blosc_compcode_to_compname(compcode, &compname)) continue;
1904         /// @todo This changes the compressor setting globally.
1905         if (blosc_set_compressor(compname) < 0) continue;
1906--
19072.17.1
1908
1909