--- CMakeLists.txt.orig	2018-12-15 16:05:53.000000000 -0700
+++ CMakeLists.txt	2018-12-29 16:20:36.000000000 -0700
@@ -30,32 +30,7 @@
     "MinSizeRel" "RelWithDebInfo")
 endif()
 
-if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/openexr/OpenEXR")
-  message(FATAL_ERROR "The OpenEXR submodule directory is missing! "
-    "You probably did not clone the project with --recursive. It is possible to recover "
-    "by running \"git submodule update --init --recursive\"")
-endif()
-
-if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/glog/cmake")
-  message(FATAL_ERROR "The glog submodule directory is missing! "
-    "You probably did not clone the project with --recursive, or you first checked out "
-    "pbrt before it was added. It is possible to recover by running "
-    "\"git submodule update --init --recursive\"")
-endif()
-
-if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/ptex/src")
-  message(FATAL_ERROR "The ptex submodule directory is missing! "
-    "You probably did not clone the project with --recursive, or you first checked out "
-    "pbrt before it was added. It is possible to recover by running "
-    "\"git submodule update --init --recursive\"")
-endif()
-
-if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/zlib/doc")
-  message(FATAL_ERROR "The zlib submodule directory is missing! "
-    "You probably did not clone the project with --recursive, or you first checked out "
-    "pbrt before it was added. It is possible to recover by running "
-    "\"git submodule update --init --recursive\"")
-endif()
+find_package(PkgConfig REQUIRED)
 
 FIND_PACKAGE ( Sanitizers )
 FIND_PACKAGE ( Threads )
@@ -72,7 +47,7 @@
 IF(CMAKE_COMPILER_IS_GNUCXX)
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-conversion-null")
-ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
 ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
@@ -307,61 +282,25 @@
 ###########################################################################
 # OpenEXR
 
-SET(ILMBASE_NAMESPACE_VERSIONING OFF CACHE BOOL " " FORCE)
-SET(OPENEXR_NAMESPACE_VERSIONING OFF CACHE BOOL " " FORCE)
-SET(OPENEXR_BUILD_SHARED_LIBS    OFF CACHE BOOL " " FORCE)
-SET(ILMBASE_BUILD_SHARED_LIBS    OFF CACHE BOOL " " FORCE)
-
-ADD_SUBDIRECTORY(src/ext/openexr)
-
-SET_PROPERTY(TARGET IexMath eLut toFloat b44ExpLogTable dwaLookups IlmThread Half Iex Imath IlmImf PROPERTY FOLDER "ext")
+pkg_check_modules(OPENEXR REQUIRED OpenEXR)
 
 INCLUDE_DIRECTORIES (
-  src/ext/openexr/IlmBase/Imath
-  src/ext/openexr/IlmBase/Half
-  src/ext/openexr/IlmBase/Iex
-  src/ext/openexr/OpenEXR/IlmImf
-  ${CMAKE_BINARY_DIR}/src/ext/openexr/IlmBase/config
-  ${CMAKE_BINARY_DIR}/src/ext/openexr/OpenEXR/config
+  ${OPENEXR_INCLUDE_DIRS}
 )
-IF(WIN32)
-  SET(OPENEXR_LIBS IlmImf Imath Half ${ZLIB_LIBRARY})
-ELSE()
-  SET(OPENEXR_LIBS IlmImf Imath Half)
-ENDIF()
 
 ###########################################################################
 # glog
 
-SET(WITH_GFLAGS OFF CACHE BOOL "Use gflags")
-SET(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE)
-IF(WIN32)
-  ADD_DEFINITIONS( -D GOOGLE_GLOG_DLL_DECL= )
-ENDIF()
-ADD_SUBDIRECTORY(src/ext/glog)
-SET_PROPERTY(TARGET glog logging_unittest demangle_unittest utilities_unittest stl_logging_unittest PROPERTY FOLDER "ext")
+pkg_check_modules(GLOG REQUIRED libglog)
 INCLUDE_DIRECTORIES (
-  src/ext/glog/src
-  ${CMAKE_BINARY_DIR}/src/ext/glog
+  ${GLOG_INCLUDE_DIRS}
 )
 
 ###########################################################################
 # ptex
 
-# work around https://github.com/wdas/ptex/issues/28
-IF ( CMAKE_BUILD_TYPE )
-  STRING ( TOLOWER ${CMAKE_BUILD_TYPE} LOWER_BUILD_TYPE )
-  SET ( ENV{FLAVOR} ${LOWER_BUILD_TYPE} )
-ENDIF ()
-SET(PTEX_BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE)
-
-SET(CMAKE_MACOSX_RPATH 1)
-IF ( WIN32 )
-  ADD_DEFINITIONS ( /D PTEX_STATIC)
-ENDIF ()
-ADD_SUBDIRECTORY(src/ext/ptex)
-SET_PROPERTY(TARGET Ptex_static ptxinfo halftest ftest rtest wtest PROPERTY FOLDER "ext")
-INCLUDE_DIRECTORIES ( src/ext/ptex/src/ptex )
+find_package(PTex REQUIRED)
+INCLUDE_DIRECTORIES ( ${Ptex_INCLUDE_DIRS} )
 
 ###########################################################################
 # On to pbrt...
@@ -483,13 +422,15 @@
 ###########################################################################
 # pbrt libraries and executables
 
-ADD_LIBRARY ( pbrt STATIC
+ADD_LIBRARY ( pbrt SHARED
   ${PBRT_YACC_LEX_SOURCE}
   ${PBRT_CORE_SOURCE}
   ${PBRT_CORE_HEADERS}
   ${PBRT_SOURCE}
   )
 ADD_SANITIZERS ( pbrt )
+TARGET_LINK_LIBRARIES ( pbrt ${OPENEXR_LIBRARIES} glog Ptex )
+set_target_properties( pbrt PROPERTIES VERSION 3 SOVERSION 3 )
 
 # A non-exhaustive but pretty representative set..
 # Note that we work-around shoddy c++11 support in MSVC2013
@@ -512,9 +453,9 @@
 SET(ALL_PBRT_LIBS
   pbrt
   ${CMAKE_THREAD_LIBS_INIT}
-  ${OPENEXR_LIBS}
+  ${OPENEXR_LIBRARIES}
   glog
-  Ptex_static
+  Ptex
   ${ZLIB_LIBRARY}
 )