@@ -530,7 +530,7 @@ There are four ways to link USD controlled by the following options:
530530| ---------------------- | --------- | ----------------------------------------- |
531531| BUILD_SHARED_LIBS | ` ON ` | Build shared or static libraries |
532532| PXR_BUILD_MONOLITHIC | ` OFF ` | Build single or several libraries |
533- | PXR_MONOLITHIC_IMPORT | | CMake file defining usd_ms import library |
533+ | PXR_MONOLITHIC_IMPORT | | CMake file defining usd_m import library |
534534
535535##### Shared Libraries
536536
@@ -568,25 +568,41 @@ cmake -DBUILD_SHARED_LIBS=OFF ...
568568##### Internal Monolithic Library
569569
570570This mode builds the core libraries (i.e. everything under ` pxr/ ` ) into a
571- single archive library, ' usd_m', and from that it builds a single shared
572- library, 'usd_ms'. It builds plugins outside of ` pxr/ ` and Python modules
573- as usual except they link against 'usd_ms ' instead of the individual
574- libraries of the default mode. Plugins inside of ` pxr/ ` are compiled into
575- 'usd_m' and 'usd_ms' . plugInfo.json files under ` pxr/ ` refer to 'usd_ms '.
571+ single library, ` usd_m ` . The monolithic library will be static or shared based
572+ on the value of ` BUILD_SHARED_LIBS ` . It builds plugins outside of ` pxr/ `
573+ and Python modules as usual except they link against 'usd_m ' instead of the
574+ individual libraries of the default mode. Plugins inside of ` pxr/ ` are compiled
575+ into 'usd_m'. plugInfo.json files under ` pxr/ ` refer to 'usd_m '.
576576
577577This mode is useful to reduce the number of installed files and simplify
578578linking against USD.
579579
580580| Option Name | Value |
581581| ---------------------- | ---------- |
582- | BUILD_SHARED_LIBS | _ Don't care _ |
582+ | BUILD_SHARED_LIBS | ` ON ` / ` OFF ` |
583583| PXR_BUILD_MONOLITHIC | ` ON ` |
584584| PXR_MONOLITHIC_IMPORT | |
585585
586586``` bash
587- cmake -DPXR_BUILD_MONOLITHIC=ON ...
587+ # Configuring to build a monolithic shared USD library
588+ cmake -DPXR_BUILD_MONOLITHIC=ON -DBUILD_SHARED_LIBS=ON ...
589+
590+ # Configuring to build a monolithic static USD library
591+ cmake -DPXR_BUILD_MONOLITHIC=ON -DBUILD_SHARED_LIBS=OFF ...
588592```
589593
594+ > [ !NOTE]
595+ > For historical consistency, the output filename of the USD shared monolithic
596+ > library is ` usd_ms ` while the static monolithic library is named ` usd_m ` . In
597+ > both cases the CMake target is ` usd_m ` .
598+
599+ > [ !WARNING]
600+ > Due to the need to link to the static monolithic library with the
601+ > ` WHOLE_ARCHIVE ` option (see [ Linking Whole Archives] ( #linking-whole-archives ) ),
602+ > consumers should be aware that resulting executables and shared libraries will
603+ > be quite large as they are effectively bringing in every object file from USD.
604+
605+
590606##### External Monolithic Library
591607
592608This mode is similar to the
@@ -604,7 +620,7 @@ significantly more complicated and are described below.
604620To build in this mode:
605621
6066221 . Choose a path where the import file will be. You'll be creating a cmake
607- file with ` add_library(usd_ms SHARED IMPORTED) ` and one or more ` set_property `
623+ file with ` add_library(usd_m SHARED IMPORTED) ` and one or more ` set_property `
608624calls. The file doesn't need to exist. If it does exist it should be empty
609625or valid cmake code.
6106261 . Configure the build in the usual way but with ` PXR_BUILD_MONOLITHIC=ON `
@@ -620,22 +636,22 @@ for more details.
6206361 . Edit the import file to describe your library. Your cmake build may
621637be able to generate the file directly via ` export() ` . The USD build
622638will include this file and having done so must be able to link against
623- your library by adding 'usd_ms ' as a target link library. The file
639+ your library by adding 'usd_m ' as a target link library. The file
624640should look something like this:
625641 ```cmake
626- add_library(usd_ms SHARED IMPORTED)
627- set_property(TARGET usd_ms PROPERTY IMPORTED_LOCATION ...)
642+ add_library(usd_m SHARED IMPORTED)
643+ set_property(TARGET usd_m PROPERTY IMPORTED_LOCATION ...)
628644 # The following is necessary on Windows.
629- #set_property(TARGET usd_ms PROPERTY IMPORTED_IMPLIB ...)
630- set_property(TARGET usd_ms PROPERTY INTERFACE_COMPILE_DEFINITIONS ...)
631- set_property(TARGET usd_ms PROPERTY INTERFACE_INCLUDE_DIRECTORIES ...)
632- set_property(TARGET usd_ms PROPERTY INTERFACE_LINK_LIBRARIES ...)
645+ #set_property(TARGET usd_m PROPERTY IMPORTED_IMPLIB ...)
646+ set_property(TARGET usd_m PROPERTY INTERFACE_COMPILE_DEFINITIONS ...)
647+ set_property(TARGET usd_m PROPERTY INTERFACE_INCLUDE_DIRECTORIES ...)
648+ set_property(TARGET usd_m PROPERTY INTERFACE_LINK_LIBRARIES ...)
633649 ```
6346501 . Complete the USD build by building the usual way, either with the
635651default target or the 'install' target.
636652
637653Two notes:
638- 1 . Your library does ** not** need to be named usd_ms . That's simply the
654+ 1 . Your library does ** not** need to be named usd_m . That's simply the
639655name given to it by the import file. The IMPORTED_LOCATION has the real
640656name and path to your library.
6416571 . USD currently only supports installations where your library is in
@@ -654,26 +670,14 @@ link would not include them. The side effects will not occur and USD
654670will not work.
655671
656672To include everything you need to tell the linker to include the whole
657- archive. That's platform dependent and you'll want code something like
658- this:
673+ archive. The exact link flags to achieve this are platform-dependent
674+ but CMake 3.24 and above support the following platform-agnostic generator
675+ expression:
659676
660677``` cmake
661- if(MSVC)
662- target_link_libraries(mylib -WHOLEARCHIVE:$<TARGET_FILE:usd_m> usd_m)
663- elseif(CMAKE_COMPILER_IS_GNUCXX)
664- target_link_libraries(mylib -Wl,--whole-archive usd_m -Wl,--no-whole-archive)
665- elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
666- target_link_libraries(mylib -Wl,-force_load usd_m)
667- endif()
678+ target_link_libraries(mylib "$<LINK_LIBRARY:WHOLE_ARCHIVE,usd_m>")
668679```
669680
670- On Windows cmake cannot recognize 'usd_m' as a library when appended to
671- -WHOLEARCHIVE: because it's not a word to itself so we use TARGET_FILE
672- to get the path to the library. We also link 'usd_m' separately so cmake
673- will add usd_m's interface link libraries, etc. This second instance
674- doesn't increase the resulting file size because all symbols will be
675- found in the first (-WHOLEARCHIVE) instance.
676-
677681###### Avoiding linking statically to Python
678682
679683The default build with python support will link to the python static lib for
0 commit comments