|
| 1 | +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") |
| 2 | +load("@rules_cc//cc:defs.bzl", "cc_test") |
| 3 | +load("@rules_cc//cc:defs.bzl", "cc_binary") |
| 4 | +load("@rules_license//rules:license.bzl", "license") |
| 5 | +load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") |
| 6 | + |
| 7 | +package( |
| 8 | + default_applicable_licenses = [":license"], |
| 9 | + default_visibility = ["//visibility:public"], |
| 10 | +) |
| 11 | + |
| 12 | +exports_files(["LICENSE.txt"]) |
| 13 | + |
| 14 | +# Note: OpenUSD uses a derivative of the Apache 2.0 license called the |
| 15 | +# Tomorrow Open Source Technology License 1.0. |
| 16 | +license( |
| 17 | + name = "license", |
| 18 | + package_name = "openusd", |
| 19 | + license_kinds = [ |
| 20 | + ], |
| 21 | + license_text = ":LICENSE.txt", |
| 22 | +) |
| 23 | + |
| 24 | +filegroup( |
| 25 | + name = "all_srcs", |
| 26 | + srcs = glob([ |
| 27 | + "CMakeLists.txt", |
| 28 | + "pxr/**", |
| 29 | + "cmake/**", |
| 30 | + "extras/**", |
| 31 | + "docs/**", |
| 32 | + "third_party/**" |
| 33 | + ], exclude=[ |
| 34 | + "bazel*/**", |
| 35 | + "BUILD", |
| 36 | + "BUILD.bazel", |
| 37 | + "MODULE.bazel" |
| 38 | + ]), |
| 39 | + visibility = ["//visibility:public"], |
| 40 | +) |
| 41 | + |
| 42 | +# Build OpenUSD as a monolithic static library. This is the simplest option for linking |
| 43 | +# but note it does not allow USD plugins or Python modules. This is because it would result in duplicate |
| 44 | +# symbol definitions for libusd symbols (statically linked into the main exec and also linked into the dynamic libs). |
| 45 | +# |
| 46 | +# Also note: We must specify the alwayslink=True so that dependents link in all symbols from the archive. This is |
| 47 | +# a stated requirement in BUILDING.md. If not specified, OpenUSD will not initialize properly and you will encounter |
| 48 | +# segfaults when using certain objects. |
| 49 | +# |
| 50 | +# See BUILDING.md in the OpenUSD repo for details. |
| 51 | +# |
| 52 | +cmake( |
| 53 | + name = "openusd", |
| 54 | + cache_entries = { |
| 55 | + "BUILD_SHARED_LIBS": "OFF", |
| 56 | + "PXR_BUILD_MONOLITHIC": "ON", |
| 57 | + "PXR_PREFER_SAFETY_OVER_SPEED": "ON", |
| 58 | + "PXR_FIND_TBB_IN_CONFIG": "OFF", |
| 59 | + "TBB_USE_DEBUG_BUILD": "OFF", |
| 60 | + "PXR_ENABLE_PYTHON_SUPPORT": "OFF", |
| 61 | + "PXR_ENABLE_GL_SUPPORT": "OFF", |
| 62 | + "PXR_ENABLE_METAL_SUPPORT": "OFF", |
| 63 | + "PXR_BUILD_DOCUMENTATION": "OFF", |
| 64 | + "PXR_BUILD_HTML_DOCUMENTATION": "OFF", |
| 65 | + "PXR_BUILD_PYTHON_DOCUMENTATION": "OFF", |
| 66 | + "PXR_BUILD_TESTS": "OFF", |
| 67 | + "PXR_BUILD_EXAMPLES": "OFF", |
| 68 | + "PXR_BUILD_TUTORIALS": "OFF", |
| 69 | + "PXR_BUILD_USD_TOOLS": "OFF", |
| 70 | + "PXR_BUILD_USD_VALIDATION": "OFF", |
| 71 | + "PXR_BUILD_IMAGING": "OFF", |
| 72 | + "PXR_BUILD_USD_IMAGING": "OFF", |
| 73 | + "PXR_BUILD_USDVIEW": "OFF", |
| 74 | + "PXR_BUILD_ALEMBIC_PLUGIN": "OFF", |
| 75 | + "PXR_BUILD_DRACO_PLUGIN": "OFF", |
| 76 | + "PXR_ENABLE_MATERIALX_SUPPORT": "OFF", |
| 77 | + "PXR_BUILD_MAYAPY_TESTS": "OFF", |
| 78 | + "PXR_BUILD_ANIMX_TESTS": "OFF", |
| 79 | + "Boost_NO_SYSTEM_PATHS": "ON", |
| 80 | + }, |
| 81 | + env = { |
| 82 | + "CMAKE_BUILD_TYPE": "Release", |
| 83 | + "CMAKE_BUILD_PARALLEL_LEVEL": "4", |
| 84 | + }, |
| 85 | + alwayslink = True, |
| 86 | + out_static_libs = [ |
| 87 | + # This is name of the monolithic static lib. |
| 88 | + "libusd_m.a", |
| 89 | + ], |
| 90 | + out_data_dirs = [ |
| 91 | + "lib/usd" |
| 92 | + ], |
| 93 | + lib_source = ":all_srcs", |
| 94 | + deps = [ |
| 95 | + "@onetbb//:tbb", |
| 96 | + ], |
| 97 | +) |
| 98 | + |
| 99 | +# As part of the cmake build, OpenUSD installs a directory of plugin file resources (many plugInfo.json files) |
| 100 | +# to openusd/lib/usd. On program startup, OpenUSD expects these plugin files to be in a usd/ dir directly next |
| 101 | +# to the executable or .so library. It will throw an exception and crash if they are not found. |
| 102 | +# We use the 'copy_to_directory' helper to copy them out of 'openusd/lib/usd' to just 'usd' so that they |
| 103 | +# are at the right path. |
| 104 | +copy_to_directory( |
| 105 | + name = "plugin_files", |
| 106 | + srcs = [":openusd"], |
| 107 | + out = "usd", |
| 108 | + replace_prefixes = { |
| 109 | + "openusd/lib/usd": "", |
| 110 | + } |
| 111 | +) |
| 112 | + |
| 113 | +cc_test( |
| 114 | + name = "test_main", |
| 115 | + srcs = ["test_main.cpp"], |
| 116 | + deps = [ |
| 117 | + ":openusd", |
| 118 | + "@bazel_tools//tools/cpp/runfiles", |
| 119 | + ], |
| 120 | + data = [ |
| 121 | + ":plugin_files", |
| 122 | + ] |
| 123 | +) |
| 124 | + |
0 commit comments