Skip to content

Commit 2d8bf99

Browse files
authored
CMake use mono (USDU-160) (#241)
Fixes USD.NET OSX issues Building USD.NET with custom Mono is now available but optional. Default is still to use the version provided by Unity
1 parent 5d3f585 commit 2d8bf99

File tree

17 files changed

+92
-309
lines changed

17 files changed

+92
-309
lines changed

CMakeLists.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ project(usd-unity-sdk)
1515
set(BUILD_USD_NET FALSE CACHE BOOL "Build USD.NET.dll and USD.NET.Unity.dll")
1616
set(BUILD_USDCS TRUE CACHE BOOL "Build USD C# bindings")
1717
set(BUILD_TESTS FALSE CACHE BOOL "Build USD.NET tests")
18+
set(PYTHON_VERSION "3.6" CACHE STRING "Python version to use")
19+
set(USE_CUSTOM_MONO FALSE CACHE BOOL "Use a standalon version of mono. If false, use the Mono version provided by Unity.")
1820

1921
message("${PXR_USD_LOCATION_PYTHON_BUILD}")
2022
if (NOT PXR_USD_LOCATION_PYTHON_BUILD)
@@ -25,10 +27,16 @@ set(USD_PKG_DIR ${CMAKE_SOURCE_DIR}/package/com.unity.formats.usd)
2527
set(USD_PLUGINS_DIR ${USD_PKG_DIR}/Runtime/Plugins)
2628

2729
find_package(USD REQUIRED)
28-
find_package(PythonInterp 3.6 REQUIRED COMPONENTS Interpreter)
30+
find_package(PythonInterp ${PYTHON_VERSION} REQUIRED COMPONENTS Interpreter)
2931
message("Python exec ${Python3_FOUND} ${Python3_EXECUTABLE} ${Python3_INTERPRETER_ID}")
30-
if (BUILD_USD_NET)
31-
find_package(Unity REQUIRED)
32+
33+
if (BUILD_USD_NET OR BUILD_TESTS)
34+
if (USE_CUSTOM_MONO)
35+
# Unity Mono is currently 5.11 (custom) so standalonee mono should be close
36+
find_package(Mono REQUIRED)
37+
else ()
38+
find_package(Unity REQUIRED)
39+
endif()
3240
endif()
3341

3442
add_subdirectory(src)

bin/add_MonoPInvokeCallback_attribute.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"CreateString("]
2424

2525
def decorate(line):
26-
print("decorating: {0}".format(line))
2726
leading_spaces = len(line) - len(line.lstrip(' '))
2827
decorated = ["{0}{1}".format(" "*leading_spaces, d) for d in DECORATORS]
2928
decorated.append(line)
@@ -36,12 +35,14 @@ def main():
3635
cwd = os.path.abspath(os.path.dirname(__file__))
3736
filein_path = os.path.join(cwd, build_path, "UsdCsPINVOKE.cs")
3837
fileout_path = os.path.join(cwd, build_path, "UsdCsPINVOKE.cs.out")
38+
prev_line = ""
3939
with open(filein_path, "r") as filein, open(fileout_path, "w") as fileout:
4040
for line in filein:
41-
if any(methods in line for methods in METHODS_TO_DECORATE):
41+
if DECORATORS[1] not in prev_line and any(methods in line for methods in METHODS_TO_DECORATE):
4242
fileout.write(decorate(line))
4343
else:
4444
fileout.write(line)
45+
prev_line = line
4546
os.replace(fileout_path, filein_path)
4647

4748
if __name__ == "__main__":

bin/build.py

100644100755
+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python -B
1+
#!/usr/bin/env python3 -B
22
from builtins import FileNotFoundError
33

44
import logging
@@ -78,11 +78,13 @@ def download_usd_binaries(usd_version, python_version=PYTHON_VERSION, output_dir
7878
parser.add_argument("--download", dest="download_usd_binaries", action="store_true", default=False,
7979
help="Download USD binaries from Unity's Stevedore internal repository. "
8080
"Refer to BUILDING.md for command used to build the libraries")
81-
parser.add_argument("--target", dest="cmake_target", action="store_const", const="clean", default="install",
81+
parser.add_argument("--clean", dest="cmake_target", action="store_const", const="clean", default="install",
8282
help="Call cmake with the clean target.")
83-
parser.add_argument("--component", dest="component", choices=["usdcs", "usdnet"], default="usdcs")
83+
parser.add_argument("--component", dest="component", choices=["usdcs", "usdnet", "tests"], default="usdcs")
8484
parser.add_argument("-v", "--verbose", action="store_true", default=False,
8585
help="Set the CMake verbose flag.")
86+
parser.add_argument("--use_custom_mono", action="store_true", default=False,
87+
help="Use a custom mono version. Default is to use the mono compiler provided by Unity.")
8688

8789
args = parser.parse_args()
8890

@@ -118,6 +120,8 @@ def download_usd_binaries(usd_version, python_version=PYTHON_VERSION, output_dir
118120
build_dir += "_usdcs"
119121
elif args.component == "usdnet":
120122
build_dir += "_usdnet"
123+
elif args.component == "tests":
124+
build_dir += "_tests"
121125
if not os.path.exists(build_dir):
122126
os.mkdir(build_dir)
123127

@@ -127,13 +131,16 @@ def download_usd_binaries(usd_version, python_version=PYTHON_VERSION, output_dir
127131
"-DUNITY_VERSION={} ",
128132
"-DBUILD_USDCS={} ",
129133
"-DBUILD_USD_NET={} ",
134+
"-DBUILD_TESTS={} ",
130135
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
131-
"-DCMAKE_MODULE_PATH=./cmake/modules "]).format(build_dir, usd_no_python_dir_path,
136+
"-DCMAKE_MODULE_PATH=./cmake/modules",
137+
"-DUSE_CUSTOM_MONO={} "]).format(build_dir, usd_no_python_dir_path,
132138
usd_python_dir_path,
133139
args.unity_version,
134140
args.component == "usdcs",
135141
args.component == "usdnet",
136-
args.unity_version)
142+
args.component == "tests",
143+
args.use_custom_mono)
137144

138145
if args.verbose:
139146
cmake_cmd += "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON "

cmake/ilm_static_lib.patch

-103
This file was deleted.

cmake/install_usd_bindings.cmake

+1-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ FILE(GLOB usd_kind ${CMAKE_BINARY_DIR}/generated/Kind*.cs)
4646
FILE(INSTALL ${usd_kind} DESTINATION ${CMAKE_SOURCE_DIR}/../src/USD.NET/generated/pxr/usd/kind)
4747
LIST(APPEND SWIG_FILES pxr/usd/kind/*.cs)
4848

49-
FILE(GLOB usd__ndr ${CMAKE_BINARY_DIR}/generated/_Ndr*.cs)
50-
FILE(INSTALL ${usd__ndr} DESTINATION ${CMAKE_SOURCE_DIR}/../src/USD.NET/generated/pxr/usd/ndr)
51-
LIST(APPEND SWIG_FILES pxr/usd/ndr/*.cs)
52-
53-
FILE(GLOB usd_ndr ${CMAKE_BINARY_DIR}/generated/ndr*.cs)
49+
FILE(GLOB usd_ndr ${CMAKE_BINARY_DIR}/generated/Ndr*.cs)
5450
FILE(INSTALL ${usd_ndr} DESTINATION ${CMAKE_SOURCE_DIR}/../src/USD.NET/generated/pxr/usd/ndr)
5551
LIST(APPEND SWIG_FILES pxr/usd/ndr/*.cs)
5652

0 commit comments

Comments
 (0)