Search code examples
visual-studiovisual-c++buildusdzusd

How to build USD library for Win32 and distribute it along with exe


So I need to support .usd/.usda/.usdc for my renderer application, and I need to distribute the resulting project .exe and usd .libs/.dlls to our users on install. How do I build the library in a way that I can distribute? If I can't distribute it due to how the library is structured, how do I have the user install the needed dependencies automatically?

I was able to get oneTBB I believe (as TBB is a dependency of the library, but I don't know if USD can use it, here is how I compiled it)

::Issue this creates a .dll, would have been nice to have a static lib for not needed function culling
download: https://github.com/oneapi-src/oneTBB
extract: oneTBB-master folder
copy: include folder to destination (/I.\include in cl command when compiling)
open: cmd inside oneTBB-master folder (TIP: if you type cmd and hit enter in the folder path in the top it opens cmd there)
run: mkdir build && cd build
::if you want HWLOC then you need to rebuild with TBB bindings (for OpenMPI, I believe, but we don't currently use)
run: cmake .. -G "Visual Studio 15 2017 Win64" -DTBB_TEST=OFF -DCMAKE_CXX_STANDARD=17  -DCMAKE_BUILD_TYPE=Release
run: cmake --build . --config Release
run: cd msvc_19.16_cxx17_64_md_release
copy: tbb12.dll to destination
copy: tbb12.lib to destination (link against this)
:: don't think we need tbbmalloc.dll/tbbmalloc_proxy.dll and tbbmalloc.lib/tbbmalloc_proxy.lib

I tested TBB by compiling on the command line with a simple test program and build script like

@echo off
if not defined DevEnvDir (
    call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
)

set FILES=MinimalTBB.cpp

set LIBS=kernel32.lib user32.lib gdi32.lib
set DLLLIBS=tbb12.lib 
:: tbbmalloc.lib tbbmalloc_proxy.lib

cl /nologo /W3 /Z7 /GS- /DEBUG:none /Gs999999 /MT /EHsc /O2  %FILES% -FeMinimalTBB.exe %LIBS% /I.\include /link %DLLLIBS% /incremental:no /opt:icf /opt:ref /subsystem:console

But then I need to do Boost.

And then I would love to do something like:

download: https://github.com/PixarAnimationStudios/USD
extract: USD-release folder
open: cmd inside USD-release folder
run: mkdir build && cd build
run: cmake .. -G "Visual Studio 15 2017 Win64" -DBUILD_SHARED_LIBS=ON -DPXR_BUILD_MONOLITHIC=OFF -DPXR_BUILD_IMAGING=OFF -DPXR_BUILD_USDVIEW=OFF -DPXR_ENABLE_PYTHON_SUPPORT=OFF -DPXR_BUILD_DOCUMENTATION=OFF -DPXR_BUILD_TESTS=OFF -DPXR_VALIDATE_GENERATED_CODE=OFF -DPXR_BUILD_PRMAN_PLUGIN=OFF -DPXR_BUILD_ALEMBIC_PLUGIN=OFF -DPXR_BUILD_DRACO_PLUGIN=OFF -DPXR_ENABLE_MATERIALX_SUPPORT=OFF -DCMAKE_BUILD_TYPE=Release
run: cmake --build . --config Release

to get .dll which i will distribute along with the .exe and then just link against the .lib in my project without the user installing anything

As an aside: I saw nVidia has a precompiled version too, I tried compiling with it, but it threw a bunch of python36.dll missing errors, when I am not even using python (only c++).


Solution

  • I found a ok solution from compiling from the command line, there is probably a much better way to do this, but to get it going here is what I did

    The following wastes lots of memory on ur build machine, lots of files that don't need to be there, so go through and remove them:

    1. download: lastest repo to C:\USD and create a USD-install folder inside of it
    2. run: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat"
    3. run: py C:\USD\build_scripts\build_usd.py C:\USD\USD-install --no-docs --no-embree --no-python --no-debug-python --no-draco --no-prman --no-materialx --no-alembic --no-hdf5 --no-opencolorio --no-openimageio --no-usdview --no-openvdb --no-ptex --no-imaging
    4. I am compiling a windows program from the command line, so I created a new cpp project, but since we are compiling inside of our program we do not worry about this step
    5. copied over the C:\USD\USD-install\bin, C:\USD\USD-install\include, and C:\USD\USD-install\lib folder to place of build. (copied .\include has to be included in include path)
    6. moved tbb.dll, usd_ar.dll, usd_arch.dll, usd_gf.dll, usd_js.dll, usd_js.dll, usd_kind.dll, usd_pcp.dll, usd_plug.dll, usd_sdf.dll, usd_tf.dll, usd_trace.dll, usd_usd.dll, usd_vt.dll, and usd_work.dll all from lib folder to the level where my .exe will be generated and run from
    7. In usd/pcp/types.h on line 119 change the numeric_limits<size_t>::max() to SIZE_MAX and in base/gf/ilmbase_halfLimits.h comment out the min and max functions on line 66 and 67
    8. I then linked against lib/tbb.lib lib/usd_tf.lib lib/usd_sdf.lib lib/usd_vt.lib lib/usd_usd.lib
    9. Create a resources folder at level of .exe and copy C:\USD\USD-install\plugin\usd\plugInfo.json to resources folder
    10. In lib copy over C:\USD\USD-install\lib\usd up to the .exe level
    11. distribute .exe, .dll's, and resources folder