message: Allow building against an external NanoGUI installation
diff: +option(MATERIALX_NANOGUI_EXTERNAL "Build aginst an external install of NanoGUI (NANOGUI_ROOT may also need to be set)" OFF)
  +
  +if (MATERIALX_NANOGUI_EXTERNAL)
  + find_path(NANOGUI_INCLUDE_DIRS
  + NAMES
  + nanogui/nanogui.h
  + HINTS
  + "${NANOGUI_ROOT}/include"
  + "$ENV{NANOGUI_ROOT}/include")
  + find_library(NANOGUI_LIBRARIES
  + NAMES
  + nanogui
  + HINTS
  + "${NANOGUI_ROOT}/lib"
  + "$ENV{NANOGUI_ROOT}/lib"
  + "${NANOGUI_ROOT}/lib64"
  + "$ENV{NANOGUI_ROOT}/lib64")
  +
  + if (NOT NANOGUI_INCLUDE_DIRS OR NOT NANOGUI_LIBRARIES)
  + message(FATAL_ERROR "Could not find external NanoGUI installation, is NANOGUI_ROOT set?")
  + endif()
  +else()
  if (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/NanoGUI/ext/glfw/src")
  message(FATAL_ERROR "Building the MaterialX viewer requires the NanoGUI submodule "
  "to be present. Update your repository by calling the following:\n"
  "git submodule update --init --recursive")
  endif()
  -file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
  -file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
  -
  set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE)
  set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE)
  set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
  @@ -28,9 +47,16 @@ endif()
  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/NanoGUI external/NanoGUI)
  set_property(TARGET nanogui nanogui-obj glfw glfw_objects PROPERTY FOLDER "External")
  + set(NANOGUI_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../;${CMAKE_CURRENT_SOURCE_DIR}/NanoGUI/include")
  + set(NANOGUI_LIBRARIES "nanogui")
  +
  # Restore warnings for MaterialXView
  set(CMAKE_C_FLAGS ${PREV_CMAKE_C_FLAGS})
  set(CMAKE_CXX_FLAGS ${PREV_CMAKE_CXX_FLAGS})
  +endif()
  +
  +file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
  +file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
  add_definitions(${NANOGUI_EXTRA_DEFS})
  @@ -41,14 +67,13 @@ target_link_libraries(
  MaterialXFormat
  MaterialXGenGlsl
  MaterialXRenderGlsl
  - nanogui
  + ${NANOGUI_LIBRARIES}
  ${NANOGUI_EXTRA_LIBS})
  target_include_directories(
  MaterialXView
  PRIVATE
  - ${CMAKE_CURRENT_SOURCE_DIR}/../
  - ${CMAKE_CURRENT_SOURCE_DIR}/NanoGUI/include
  + ${NANOGUI_INCLUDE_DIRS}
  ${NANOGUI_EXTRA_INCS})
  if(MATERIALX_BUILD_OIIO AND OPENIMAGEIO_ROOT_DIR)
  