Skip to content

pxrConfig.cmake: request MaterialX RenderGlsl component#3648

Open
qbisi wants to merge 1 commit into
PixarAnimationStudios:devfrom
qbisi:fixCmake
Open

pxrConfig.cmake: request MaterialX RenderGlsl component#3648
qbisi wants to merge 1 commit into
PixarAnimationStudios:devfrom
qbisi:fixCmake

Conversation

@qbisi
Copy link
Copy Markdown

@qbisi qbisi commented May 25, 2025

Description of Change(s)

When MaterialX support is enabled, OpenUSD now first asks MaterialX for the RenderGlsl CMake package component:

find_package(MaterialX QUIET COMPONENTS RenderGlsl)

OpenUSD links MaterialX render targets such as MaterialXRenderGlsl, and MaterialX 1.39.5 teaches its package config to propagate the dependencies needed by that component. This lets MaterialX own its OpenGL/X11 dependency propagation instead of OpenUSD spelling those dependencies out directly.

For compatibility with MaterialX versions before 1.39.5, which do not support package components, the lookup falls back to the previous plain MaterialX package lookup. The fallback can be removed later if OpenUSD raises its minimum supported MaterialX version to 1.39.5 or newer.

The generated pxrConfig.cmake uses the same lookup pattern so downstream projects that consume OpenUSD also get the MaterialX component dependency handling when available.

Related MaterialX fix: AcademySoftwareFoundation/MaterialX#2752

Link to proposal (if applicable)

Fixes Issue(s)

Checklist

@jesschimein
Copy link
Copy Markdown
Collaborator

Filed as internal issue #USD-11039

❗ Please make sure that a signed CLA has been submitted!

(This is an automated message. See here for more information.)

@qbisi
Copy link
Copy Markdown
Author

qbisi commented May 27, 2025

You can fix this problem(if it is) yourself. I contribute my code for free.

@spiffmon
Copy link
Copy Markdown
Member

Hi @qbisi , we don't believe these changes should be necessary, as those dependencies should get picked up transitively from the MaterialX CMake config shipping with MaterialX. Can you provide more context on

  • How you are trying to build OpenUSD
  • What errors you are getting, and from where?

@qbisi
Copy link
Copy Markdown
Author

qbisi commented May 27, 2025

  1. How you are trying to build OpenUSD: i use the prebuilt binary in nixpkgs
  2. What errors you are getting, and from where? I tried to build f3d with OpenUSD/vtk-9.4.2, the cmake build system raise error like
  The link interface of target "usd_ms" contains:

    OpenGL::GL

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

I am not sure if downstream MaterialX should declare dependency of opengl and x11 in their materiaxconfig.cmake module, as not all targets listed in materiaxtarget.cmake link to opengl/x11.
I have also contact the upsteam developer of f3d, they think it's not their job to declare dependency of opengl/x11.

Here is the contents of MateriaXTargets.cmake in nixpkgs

# Generated by CMake

if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8)
   message(FATAL_ERROR "CMake >= 2.8.12 required")
endif()
if(CMAKE_VERSION VERSION_LESS "2.8.12")
   message(FATAL_ERROR "CMake >= 2.8.12 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.8.12...3.29)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_cmake_targets_defined "")
set(_cmake_targets_not_defined "")
set(_cmake_expected_targets "")
foreach(_cmake_expected_target IN ITEMS MaterialXCore MaterialXFormat MaterialXGenShader MaterialXGenGlsl MaterialXGenOsl MaterialXGenMdl MaterialXGenMsl MaterialXRender MaterialXRenderHw MaterialXRenderGlsl MaterialXRenderOsl)
  list(APPEND _cmake_expected_targets "${_cmake_expected_target}")
  if(TARGET "${_cmake_expected_target}")
    list(APPEND _cmake_targets_defined "${_cmake_expected_target}")
  else()
    list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}")
  endif()
endforeach()
unset(_cmake_expected_target)
if(_cmake_targets_defined STREQUAL _cmake_expected_targets)
  unset(_cmake_targets_defined)
  unset(_cmake_targets_not_defined)
  unset(_cmake_expected_targets)
  unset(CMAKE_IMPORT_FILE_VERSION)
  cmake_policy(POP)
  return()
endif()
if(NOT _cmake_targets_defined STREQUAL "")
  string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}")
  string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}")
  message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n")
endif()
unset(_cmake_targets_defined)
unset(_cmake_targets_not_defined)
unset(_cmake_expected_targets)


# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

# Create imported target MaterialXCore
add_library(MaterialXCore STATIC IMPORTED)

set_target_properties(MaterialXCore PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "dl"
)

# Create imported target MaterialXFormat
add_library(MaterialXFormat STATIC IMPORTED)

set_target_properties(MaterialXFormat PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXCore;dl"
)

# Create imported target MaterialXGenShader
add_library(MaterialXGenShader STATIC IMPORTED)

set_target_properties(MaterialXGenShader PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXCore;MaterialXFormat;dl"
)

# Create imported target MaterialXGenGlsl
add_library(MaterialXGenGlsl STATIC IMPORTED)

set_target_properties(MaterialXGenGlsl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXGenShader;MaterialXCore;dl"
)

# Create imported target MaterialXGenOsl
add_library(MaterialXGenOsl STATIC IMPORTED)

set_target_properties(MaterialXGenOsl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXGenShader;MaterialXCore;dl"
)

# Create imported target MaterialXGenMdl
add_library(MaterialXGenMdl STATIC IMPORTED)

set_target_properties(MaterialXGenMdl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXGenShader;MaterialXCore;dl"
)

# Create imported target MaterialXGenMsl
add_library(MaterialXGenMsl STATIC IMPORTED)

set_target_properties(MaterialXGenMsl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXGenShader;MaterialXCore;dl"
)

# Create imported target MaterialXRender
add_library(MaterialXRender STATIC IMPORTED)

set_target_properties(MaterialXRender PROPERTIES
  INTERFACE_LINK_LIBRARIES "MaterialXGenShader;dl;/nix/store/1hb1gdhnvc2ca70kjvz1hcq6jfzix43k-openimageio-2.5.17.0/lib/libOpenImageIO.so;/nix/store/1hb1gdhnvc2ca70kjvz1hcq6jfzix43k-openimageio-2.5.17.0/lib/libOpenImageIO_Util.so"
)

# Create imported target MaterialXRenderHw
add_library(MaterialXRenderHw STATIC IMPORTED)

set_target_properties(MaterialXRenderHw PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXRender;dl;X11::X11;X11::Xt"
)

# Create imported target MaterialXRenderGlsl
add_library(MaterialXRenderGlsl STATIC IMPORTED)

set_target_properties(MaterialXRenderGlsl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXRenderHw;MaterialXGenGlsl;dl;OpenGL::GL;X11::X11;X11::Xt"
)

# Create imported target MaterialXRenderOsl
add_library(MaterialXRenderOsl STATIC IMPORTED)

set_target_properties(MaterialXRenderOsl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "MaterialXRender;dl"
)

# Load information for each installed configuration.
file(GLOB _cmake_config_files "${CMAKE_CURRENT_LIST_DIR}/MaterialXTargets-*.cmake")
foreach(_cmake_config_file IN LISTS _cmake_config_files)
  include("${_cmake_config_file}")
endforeach()
unset(_cmake_config_file)
unset(_cmake_config_files)

# Cleanup temporary variables.
set(_IMPORT_PREFIX)

# Loop over all imported files and verify that they actually exist
foreach(_cmake_target IN LISTS _cmake_import_check_targets)
  if(CMAKE_VERSION VERSION_LESS "3.28"
      OR NOT DEFINED _cmake_import_check_xcframework_for_${_cmake_target}
      OR NOT IS_DIRECTORY "${_cmake_import_check_xcframework_for_${_cmake_target}}")
    foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}")
      if(NOT EXISTS "${_cmake_file}")
        message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file
   \"${_cmake_file}\"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   \"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
      endif()
    endforeach()
  endif()
  unset(_cmake_file)
  unset("_cmake_import_check_files_for_${_cmake_target}")
endforeach()
unset(_cmake_target)
unset(_cmake_import_check_targets)

# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)

@spiffmon
Copy link
Copy Markdown
Member

OK, unless other folks see something, I suspect that, since the MaterialX package will build fine on its own, and using OpenUSD's build_usd.py to build USD with MaterialX also works fine (we've not had this error before), that this may be an issue with the nix configuration for OpenUSD. We are unfortunately not able to help or support nix or other external package management systems.

@qbisi
Copy link
Copy Markdown
Author

qbisi commented May 27, 2025

@spiffmon
Copy link
Copy Markdown
Member

@qbisi , we are hoping the workaround in archlinux would be sufficient, and we're very wary of adding an X11 dependency, which we also think should not be required. Can you tell us what happens for you if you just add the OpenGL dependency, and amend your PR?

Also, we really do need a CLA if you want the PR and its commit to go into the repo. Otherwise, we can make the fix independently.

@qbisi
Copy link
Copy Markdown
Author

qbisi commented May 28, 2025

If you do propogate dependency opengl, then i can build f3d with vtk-9.4.2( which no longer require opengl in version >9.3) and openusd support. This is a block for me to update vtk from 9.2.6 to 9.4.2 in nixpkgs.

For the dependency x11, i catch this dep by analyzing the src code in materiax. Since most downstream project that make use of openusd/materialx will mostly require the x11 dependency themself. This interior propagated dependency of x11 may not be catched/reported by downstream project. Also, i am not sure if materiax should declare find_dependency(X11) itself.

Finally, this pr is more than a issue to pull request, you can fix the problem youself, i am satisfied with either propagating dependency opengl or both of opengl and x11.

@qbisi qbisi marked this pull request as draft June 14, 2025 00:18
@FlorianZ FlorianZ moved this to On Deck in Public Backlog Jan 8, 2026
@abbec
Copy link
Copy Markdown

abbec commented May 25, 2026

The reason this happens is that every build in Nix is hermetic, which means that any dependencies needed for the build must to be declared, i.e. nothing can "leak" in. So in the case of MaterialX for example, that uses X11 and GL headers in their public header files, they need to propagate those dependencies up.

When constructing this build without Nix, you would essentially make sure X11 and GL dev files (headers and libs) are installed. This will result in the MaterialX build working but it will also have the side effect of any downstream dependency working without declaring that dependency because X11 and GL headers+libs happen to be installed.

The correct way to handle this is that any external dependencies that are exposed (used in public headers) need to be declared as "PUBLIC" dependencies (link type) in CMake and then declared (with find_dependency) in the Cmake config shipped with the lib. Another instance of this problem can be seen here: #3441 for TBB and OpenSubdiv.

That said, I do think this specific issue is fixed in MaterialX.

@qbisi
Copy link
Copy Markdown
Author

qbisi commented May 26, 2026

This should be fixed in AcademySoftwareFoundation/MaterialX#2752. I am waiting for the new release of materialX 1.39.5 , downstream openusd can now declare the usage of component MaterialXRenderHw when finding materialX (this component require extra opengl inputs, note not all downstream project use MaterialXRenderHw hence i make it optional).

@qbisi qbisi changed the title pxrConfig.cmake: propagate dependencies OpenGL and X11 pxrConfig.cmake: request MaterialX RenderGlsl component May 26, 2026
@qbisi qbisi marked this pull request as ready for review May 27, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: On Deck

Development

Successfully merging this pull request may close these issues.

5 participants