how to compile USD_TmpArResolver example using cmake?

   2478   3   2
User Avatar
Member
15 posts
Joined: Nov. 2022
Offline
Hi,
I have been struggling to get any asset resolver compiled and working in houdini using cmake. I can compile it fine but then it never loads to houdini. The same source compiled with hcustom works perfectly fine.
What I did is I printed the flags that hcustom uses and replicated them in cmake. The resulting dll is smaller and not working. Does anyone know what is needed in cmake to get an asset resolver working in houdni usd? Why do I want cmake? Because my project is going to be more complicated than the one file example that ships with houdini and as far as I know hcustom can only compile plugins that are single source file.

I'm using houdni 19.5.368 on windows 10 (yeah windows, that's the catch ;-))

any tips welcome. I'm slowly running out of ideas. The compiler and windows sdk are the same using hcustom and cmake so there must be something missing in my cmake. most likely I'm not linking something since the compilation is successful.

the dll compiled with cmake errors with:
'Failed to load plugin 'arTmp': The specified module could not be found.
when I try to load the plugin with the following python:
from pxr import Usd,Plug,Ar   
Plug.Registry().GetPluginWithName('arTmp').Load()


here is my cmake:
# Specify the minimum required version of CMake to build the project.
cmake_minimum_required( VERSION 3.6 )
project( My_HDK_Project )

set(USDPLUGIN_NAME USD_TmpArResolver)


set(HROOT "$ENV{HOUDINI_INSTALLATION_ROOT_PATH}")

list( APPEND CMAKE_PREFIX_PATH "${HROOT}/toolkit/cmake" )

set(USD_ROOT ${HROOT})
set(PXR_LIB_DIR ${HROOT}/custom/houdini/dsolib)

set(PXR_INCLUDE_DIR ${HROOT}/toolkit/include)
set(PYTHON_ROOT ${HROOT}/python39)
set(PYTHON_INCLUDE_DIR ${HROOT}/python39/include)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHBOOST_ALL_NO_LIB -D_GLIBCXX_USE_CXX11_ABI=0 -nologo -TP -Zc:forScope -Zc:rvalueCast -Zc:inline- -Zc:strictStrings -std:c++17 -Zc:referenceBinding -Zc:ternary -Zc:throwingNew -permissive- -Zc:__cplusplus -DAMD64 -DSIZEOF_VOID_P=8 -DI386 -DWIN32 -DSWAP_BITFIELDS -D_WIN32_WINNT=0x0600 -DNOMINMAX -DSTRICT -DWIN32_LEAN_AND_MEAN -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DSESI_LITTLE_ENDIAN -DHBOOST_ALL_NO_LIB -DEIGEN_MALLOC_ALREADY_ALIGNED=0 -DFBX_ENABLED=1 -DOPENCL_ENABLED=1 -DOPENVDB_ENABLED=1 -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS=1 -wd4384 -wd4355 -w14996 -O2 -DNDEBUG -DUSE_PYTHON3=1 -MD -EHsc -GR -bigobj  -DMAKING_DSO -LD")
set(BOOST_DIR ${HROOT}/toolkit/include/hboost)


set(PYTHON_LIBRARY "${PXR_LIB_DIR}/hboost_python39-mt-x64.lib")

set(PXR_LIB_PREFIX "libpxr_")
set(PXR_LIBRARIES "${PXR_LIB_DIR}/${PXR_LIB_PREFIX}arch.lib"
                  "${PXR_LIB_DIR}/${PXR_LIB_PREFIX}tf.lib"
                  "${PXR_LIB_DIR}/${PXR_LIB_PREFIX}gf.lib"
                  "${PXR_LIB_DIR}/${PXR_LIB_PREFIX}js.lib"
                  "${PXR_LIB_DIR}/${PXR_LIB_PREFIX}vt.lib"
                  "${PXR_LIB_DIR}/${PXR_LIB_PREFIX}ar.lib")


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DAMD64 -DSIZEOF_VOID_P=8 -DI386 -DWIN32 -DSWAP_BITFIELDS -D_WIN32_WINNT=0x0600 -DNOMINMAX -DSTRICT -DWIN32_LEAN_AND_MEAN -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DSESI_LITTLE_ENDIAN -DHBOOST_ALL_NO_LIB -DEIGEN_MALLOC_ALREADY_ALIGNED=0 -DFBX_ENABLED=1 -DOPENCL_ENABLED=1 -DOPENVDB_ENABLED=1 -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS=1 -DUSE_PYTHON3=1")          
       

set(DEPLOY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deploy/arTmp")
SET(CMAKE_INSTALL_PREFIX "${DEPLOY_DIR}/" CACHE PATH "Default install dir " FORCE)

# Locate Houdini's libraries and header files.
# Registers an imported library target named 'Houdini'.
# find_package( Houdini REQUIRED )
# Add a library with two source files.

# include_directories(${PXR_INCLUDE_DIR})
# link_directories(${PXR_LIB_DIR})

add_library( ${USDPLUGIN_NAME} SHARED
    USD_TmpArResolver.C
    USD_TmpArResolver.h
)

# add_compile_definitions(BOOST_ALL_NO_LIB=1)
# add_compile_definitions(HBOOST_ALL_NO_LIB=1)

target_link_directories(${USDPLUGIN_NAME} PUBLIC
    ${PYTHON_ROOT}/libs
    ${PXR_LIB_DIR}
    # ${USD_ROOT}/bin
)

target_include_directories(${USDPLUGIN_NAME}
    PUBLIC
    # ${BOOST_DIR}
    ${PXR_INCLUDE_DIR}
    ${PYTHON_INCLUDE_DIR}
)

target_link_libraries(${USDPLUGIN_NAME}
    ${PXR_LIB_DIR}/*.a
    ${PXR_LIB_DIR}/*.lib
    
    # ${PXR_LIBRARIES}
    # ${PYTHON_LIBRARY}
)

install(
    TARGETS ${USDPLUGIN_NAME}
    RUNTIME DESTINATION lib
)


# Link against the Houdini libraries, and add required include directories and compile definitions.
# target_link_libraries( ${library_name} Houdini )
# Configure several common target properties, such as its output directory.
# houdini_configure_target( ${library_name} )
User Avatar
Member
15 posts
Joined: Nov. 2022
Offline
If anyone is struggling with the same issue there were two things that were breaking the plugin in my case.

  1. vcpkg. if you have it on your system vs will use it even if it is not on the path anywhere. this means you may link your plugin to a different python that is specified in the cmake.
    to disable it run this in the shell:
    vcpkg integrate remove
  2. -Zc:inline- missing flag for the compiler. There is a bug in vs2019 and this is enabled by default. it has to be disabled to get usd properly linked. more about it here: https://github.com/PixarAnimationStudios/USD/issues/1279 [github.com]
User Avatar
Member
2 posts
Joined: Feb. 2023
Offline
pawel-fin
If anyone is struggling with the same issue there were two things that were breaking the plugin in my case.

  1. vcpkg. if you have it on your system vs will use it even if it is not on the path anywhere. this means you may link your plugin to a different python that is specified in the cmake.
    to disable it run this in the shell:
    vcpkg integrate remove
  2. -Zc:inline- missing flag for the compiler. There is a bug in vs2019 and this is enabled by default. it has to be disabled to get usd properly linked. more about it here: https://github.com/PixarAnimationStudios/USD/issues/1279 [github.com]

Hello, can I ask you where you used that Zc:inline option exactly? Thank you.
User Avatar
Member
15 posts
Joined: Nov. 2022
Offline
I added it to cmakeLists.txt to compiler flags

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Zc:inline- -DAMD64 -DSIZEOF_VOID_P=8 -DI386 -DWIN32 -DSWAP_BITFIELDS -D_WIN32_WINNT=0x0600 -DNOMINMAX -DSTRICT -DWIN32_LEAN_AND_MEAN -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DSESI_LITTLE_ENDIAN -DHBOOST_ALL_NO_LIB -DEIGEN_MALLOC_ALREADY_ALIGNED=0 -DFBX_ENABLED=1 -DOPENCL_ENABLED=1 -DOPENVDB_ENABLED=1 -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS=1 -DUSE_PYTHON3=1")          
  • Quick Links