Skip to content

pxrConfig.cmake: propagate dependencies OpenGL and X11#3648

Draft
qbisi wants to merge 1 commit intoPixarAnimationStudios:devfrom
qbisi:fixCmake
Draft

pxrConfig.cmake: propagate dependencies OpenGL and X11#3648
qbisi wants to merge 1 commit intoPixarAnimationStudios:devfrom
qbisi:fixCmake

Conversation

@qbisi
Copy link

@qbisi qbisi commented May 25, 2025

Description of Change(s)

This patch fix generated prxConfig.cmake when PXR_ENABLE_MATERIALX_SUPPORT is set to ON.

The target MaterialXRenderGlsl defined in materiax that openusd link to require additional target OpenGL::GL X11::X11 X11::Xt.
see https://github.com/AcademySoftwareFoundation/MaterialX/blob/97505091af01390b888905237ff6aef432bff2dc/source/MaterialXRenderGlsl/CMakeLists.txt#L84-L86.

This patch should work on nixpkgs when i am trying to build f3d with vtk-9.4.2 and openusd support.

Link to proposal (if applicable)

Fixes Issue(s)

Checklist

@jesschimein
Copy link
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
Author

qbisi commented May 27, 2025

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

@spiffmon
Copy link
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
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
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
Author

qbisi commented May 27, 2025

@spiffmon
Copy link
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants