forked from wetadigital/USDPluginExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSDPluginTools.cmake
863 lines (735 loc) · 23.6 KB
/
USDPluginTools.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
# ============================================================================
# Public-facing convenience functions & macros for building USD plugin(s).
# ============================================================================
# To gain access to standard install directory variables such as CMAKE_INSTALL_LIBDIR.
include(GNUInstallDirs)
# Exposed USD variable(s) for installation.
# XXX: We can hide these if we provide a more convenient way to install the
# root plugInfo.json(s) and __init__.py files.
set(USD_PLUGIN_DIR "plugin")
set(USD_PYTHON_DIR "python")
set(USD_PLUG_INFO_RESOURCES_DIR "resources")
set(USD_PLUG_INFO_ROOT_DIR "usd")
#
# Public entry point for building a C++ based USD shared library.
#
function(usd_library NAME)
set(options)
set(oneValueArgs
)
set(multiValueArgs
PUBLIC_HEADERS_INSTALL_PREFIX
PUBLIC_HEADERS
PUBLIC_CLASSES
CPPFILES
LIBRARIES
INCLUDE_DIRS
RESOURCE_FILES
PYTHON_INSTALL_PREFIX
PYTHON_FILES
PYTHON_CPPFILES
PYMODULE_CPPFILES
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
_usd_cpp_library(${NAME}
TYPE
SHARED
PUBLIC_HEADERS_INSTALL_PREFIX
${args_PUBLIC_HEADERS_INSTALL_PREFIX}
PUBLIC_HEADERS
${args_PUBLIC_HEADERS}
PUBLIC_CLASSES
${args_PUBLIC_CLASSES}
CPPFILES
${args_CPPFILES}
LIBRARIES
${args_LIBRARIES}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
PYTHON_CPPFILES
${args_PYTHON_CPPFILES}
)
_usd_install_resource_files(${NAME}
TYPE
SHARED
RESOURCE_FILES
${args_RESOURCE_FILES}
)
if (ENABLE_PYTHON_SUPPORT)
_usd_python_module(${NAME}
PYTHON_INSTALL_PREFIX
${args_PYTHON_INSTALL_PREFIX}
LIBRARIES
${args_LIBRARIES}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
PYMODULE_CPPFILES
${args_PYMODULE_CPPFILES}
PYTHON_FILES
${args_PYTHON_FILES}
)
endif()
endfunction()
#
# Public entry point for building a C++ based USD plugin.
#
function(usd_plugin NAME)
set(options)
set(oneValueArgs
)
set(multiValueArgs
CPPFILES
LIBRARIES
INCLUDE_DIRS
RESOURCE_FILES
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
_usd_cpp_library(${NAME}
TYPE
"PLUGIN"
PUBLIC_HEADERS_INSTALL_PREFIX
${args_PUBLIC_HEADERS_INSTALL_PREFIX}
PUBLIC_HEADERS
${args_PUBLIC_HEADERS}
PUBLIC_CLASSES
${args_PUBLIC_CLASSES}
CPPFILES
${args_CPPFILES}
LIBRARIES
${args_LIBRARIES}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
)
_usd_install_resource_files(${NAME}
TYPE
"PLUGIN"
RESOURCE_FILES
${args_RESOURCE_FILES}
)
endfunction()
# Public entry point for building python-and-resource-files only library.
# This was _specifically_ exposed to produce plugins for usdview, but can be useful
# for deploying python plugins in general that adhere to the installation structure
# prescribed by USDPluginTools.
#
function(usd_python_library NAME)
set(options)
set(oneValueArgs
)
set(multiValueArgs
PYTHON_INSTALL_PREFIX
PYTHON_FILES
RESOURCE_FILES
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
if (ENABLE_PYTHON_SUPPORT)
_usd_python_module(${NAME}
PYTHON_INSTALL_PREFIX
${args_PYTHON_INSTALL_PREFIX}
PYTHON_FILES
${args_PYTHON_FILES}
)
_usd_install_resource_files(${NAME}
TYPE
SHARED
RESOURCE_FILES
${args_RESOURCE_FILES}
)
endif()
endfunction()
# Adds a USD-based C++ executable application.
function(usd_executable EXECUTABLE_NAME)
set(options)
set(oneValueArgs
)
set(multiValueArgs
CPPFILES
LIBRARIES
INCLUDE_DIRS
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
# Define a new executable.
add_executable(${EXECUTABLE_NAME}
${args_CPPFILES}
)
# Apply properties.
_usd_target_properties(${EXECUTABLE_NAME}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
LIBRARIES
${args_LIBRARIES}
)
# Install built executable.
install(
TARGETS ${EXECUTABLE_NAME}
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endfunction() # usd_executable
# Adds a USD-based cpp test which is executed by CTest.
function(usd_test TEST_TARGET)
if (NOT BUILD_TESTING)
return()
endif()
set(options)
set(oneValueArgs
)
set(multiValueArgs
CPPFILES
LIBRARIES
INCLUDE_DIRS
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
# Define a new executable.
add_executable(${TEST_TARGET}
${args_CPPFILES}
)
# Apply properties.
_usd_target_properties(${TEST_TARGET}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
LIBRARIES
${args_LIBRARIES}
)
# Add the test target.
add_test(
NAME ${TEST_TARGET}
COMMAND $<TARGET_FILE:${TEST_TARGET}>
)
# Set-up runtime environment variables for the test.
_usd_set_test_properties(${TEST_TARGET} OFF)
endfunction()
# Adds a USD-based python test which is executed by CTest.
# The python file is simply executed by the python interpreter
# with no special arguments.
function(usd_python_test TEST_TARGET PYTHON_FILE)
if (NOT ENABLE_PYTHON_SUPPORT)
message(STATUS "ENABLE_PYTHON_SUPPORT is OFF, skipping python test: ${TEST_PREFIX} ${PYTHON_FILE}")
return()
endif()
if (NOT BUILD_TESTING)
return()
endif()
# Add a new test target.
add_test(
NAME ${TEST_TARGET}
COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Set-up runtime environment variables for the test.
_usd_set_test_properties(${TEST_TARGET} ON)
endfunction()
#
# Internal function for building a USD-based C++ library.
#
function(_usd_cpp_library NAME)
set(options)
set(oneValueArgs
TYPE
)
set(multiValueArgs
PUBLIC_HEADERS_INSTALL_PREFIX
PUBLIC_HEADERS
PUBLIC_CLASSES
CPPFILES
LIBRARIES
INCLUDE_DIRS
PYTHON_CPPFILES
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
#
# Resolve build variables.
#
# Check desired library type is supported.
if (NOT args_TYPE STREQUAL "PLUGIN" AND NOT args_TYPE STREQUAL "SHARED")
message(FATAL_ERROR
"Building library type '${args_TYPE}' not supported.")
endif()
# Plugins do not provide public headers (nor public classes).
if (args_TYPE STREQUAL "PLUGIN" AND (args_PUBLIC_HEADERS OR args_PUBLIC_CLASSES))
message(FATAL_ERROR
"'${args_TYPE}' library type does not support public headers nor classes.")
endif()
# Does not make sense to build a companion python module for a "plugin".
if (args_TYPE STREQUAL "PLUGIN" AND args_PYMODULE_CPPFILES)
message(FATAL_ERROR
"'${args_TYPE}' library type does not support associated python module.")
endif()
# Expand class names to .cpp & .h files.
foreach(className ${args_PUBLIC_CLASSES})
list(APPEND args_CPPFILES ${className}.cpp)
list(APPEND args_PUBLIC_HEADERS ${className}.h)
endforeach()
# If python support is enabled, then merge PYTHON_CPPFILES into CPPFILES.
if (ENABLE_PYTHON_SUPPORT)
if (args_PYTHON_CPPFILES)
list(APPEND args_CPPFILES ${args_PYTHON_CPPFILES})
endif()
endif()
# Determine public header install location.
if (args_PUBLIC_HEADERS_INSTALL_PREFIX)
set(PUBLIC_HEADERS_INSTALL_PREFIX ${args_PUBLIC_HEADERS_INSTALL_PREFIX}/${NAME})
else()
set(PUBLIC_HEADERS_INSTALL_PREFIX ${NAME})
endif()
# Copy public headers into build tree.
file(
COPY ${args_PUBLIC_HEADERS}
DESTINATION ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/${PUBLIC_HEADERS_INSTALL_PREFIX}
)
# Install public headers.
install(
FILES ${args_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PUBLIC_HEADERS_INSTALL_PREFIX}
)
# Convert "PLUGIN" into "MODULE".
# (MODULE is CMake terminology for a dynamic lib only intended to be dlopen'ed at runtime).
if (args_TYPE STREQUAL "PLUGIN")
set(LIBRARY_TYPE "MODULE")
else()
set(LIBRARY_TYPE ${args_TYPE})
endif()
# Add a new library target.
add_library(${NAME}
${LIBRARY_TYPE}
)
# Add sources for building the target.
target_sources(${NAME}
PRIVATE
${args_CPPFILES}
${args_PUBLIC_HEADERS}
)
# Apply common compiler properties, and include path properties.
_usd_target_properties(${NAME}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
LIBRARIES
${args_LIBRARIES}
)
_usd_compute_library_install_and_file_prefix(${args_TYPE}
LIBRARY_INSTALL_PREFIX
LIBRARY_FILE_PREFIX
)
if (args_TYPE STREQUAL "PLUGIN")
# Install the plugin.
# We do not need to export the target because plugins are _not_
# meant to be built against.
install(
TARGETS ${NAME}
LIBRARY DESTINATION ${LIBRARY_INSTALL_PREFIX}
)
else()
# Setup SOVERSION & VERSION properties to create
# NAMELINK, SONAME, and actual library with full version suffix.
set_target_properties(${NAME}
PROPERTIES
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
VERSION ${CMAKE_PROJECT_VERSION}
)
# Install the library and export it as an public target.
install(
TARGETS ${NAME}
EXPORT ${CMAKE_PROJECT_NAME}-targets
LIBRARY DESTINATION ${LIBRARY_INSTALL_PREFIX}
RUNTIME DESTINATION ${LIBRARY_INSTALL_PREFIX}
)
endif()
# Mirror installation structure in PROJECT_BINARY_DIR - for running tests against.
if (BUILD_TESTING)
add_custom_command(
TARGET ${NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:${NAME}> ${PROJECT_BINARY_DIR}/${LIBRARY_INSTALL_PREFIX}/$<TARGET_FILE_NAME:${NAME}>
)
endif()
# Update the target properties.
set_target_properties(${NAME}
PROPERTIES
PREFIX "${LIBRARY_FILE_PREFIX}"
)
endfunction() # _usd_cpp_library
#
# Internal function for build a C++ python module with python files.
#
function(_usd_python_module NAME)
set(options)
set(oneValueArgs
TYPE
)
set(multiValueArgs
LIBRARIES
INCLUDE_DIRS
PYTHON_INSTALL_PREFIX
PYTHON_FILES
PYMODULE_CPPFILES
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
# Public module name (example: UsdTri)
_usd_get_python_module_name(${NAME} PYTHON_MODULE_NAME)
# Construct the installation prefix for the python modules & files.
if (args_PYTHON_INSTALL_PREFIX)
set(PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_LIBDIR}/${USD_PYTHON_DIR}/${args_PYTHON_INSTALL_PREFIX}/${PYTHON_MODULE_NAME})
else()
set(PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_LIBDIR}/${USD_PYTHON_DIR}/${PYTHON_MODULE_NAME})
endif()
#
# Python module / bindings.
#
if (args_PYMODULE_CPPFILES)
# Target name.
set(PYLIB_NAME "_${NAME}")
# Add a library target.
add_library(${PYLIB_NAME}
MODULE
)
# Add sources for building the target.
target_sources(${PYLIB_NAME}
PRIVATE
${args_PYMODULE_CPPFILES}
)
# Lose the library prefix.
if (MSVC)
set_target_properties(${PYLIB_NAME}
PROPERTIES
PREFIX ""
SUFFIX ".pyd"
)
else()
set_target_properties(${PYLIB_NAME}
PROPERTIES
PREFIX ""
)
endif()
# Apply common compilation properties, and include path properties.
_usd_target_properties(${PYLIB_NAME}
INCLUDE_DIRS
${args_INCLUDE_DIRS}
DEFINES
MFB_PACKAGE_NAME=${NAME}
MFB_ALT_PACKAGE_NAME=${NAME}
MFB_PACKAGE_MODULE=${PYTHON_MODULE_NAME}
LIBRARIES
${args_LIBRARIES}
${NAME}
)
# Mirror installation structure in PROJECT_BINARY_DIR - for running tests against.
if (BUILD_TESTING)
add_custom_command(
TARGET ${PYLIB_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:${PYLIB_NAME}> ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/$<TARGET_FILE_NAME:${PYLIB_NAME}>
)
endif()
# Install python module library.
install(
TARGETS
${PYLIB_NAME}
RENAME
${PYLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION
${PYTHON_INSTALL_PREFIX}
)
endif()
#
# Install python files.
#
if (args_PYTHON_FILES)
# If tests are enabled - copy these files into project binary dir
# _mirroring_ the install structure, such that we can run tests against
# them.
if (BUILD_TESTING)
foreach(pythonFile ${args_PYTHON_FILES})
file(
COPY ${CMAKE_CURRENT_SOURCE_DIR}/${pythonFile}
DESTINATION ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}
)
endforeach()
endif()
# Install python files.
install(
FILES
${args_PYTHON_FILES}
DESTINATION
${PYTHON_INSTALL_PREFIX}
)
endif()
endfunction() # _usd_python_module
#
# Internal function for installing resource files (plugInfo, etc).
#
function(_usd_install_resource_files NAME)
set(options)
set(oneValueArgs
TYPE
)
set(multiValueArgs
RESOURCE_FILES
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
_usd_compute_library_install_and_file_prefix(${args_TYPE}
LIBRARY_INSTALL_PREFIX
LIBRARY_FILE_PREFIX
)
if (args_TYPE STREQUAL "PLUGIN")
set(LIBRARY_FILE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX})
else()
set(LIBRARY_FILE_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
# Compose the full name of the library.
# This will be used when performing variable substition on the plugInfo.json resource file.
set(LIBRARY_FILE_NAME ${LIBRARY_FILE_PREFIX}${NAME}${LIBRARY_FILE_SUFFIX})
# Plugin resources will be installed as a 'usd' subdir under the library install location.
set(RESOURCES_INSTALL_PREFIX ${LIBRARY_INSTALL_PREFIX}/${USD_PLUG_INFO_ROOT_DIR})
foreach(resourceFile ${args_RESOURCE_FILES})
# Apply string substitution to plugInfo.json, copy to binary dir.
if (${resourceFile} STREQUAL "plugInfo.json")
file(RELATIVE_PATH
RESOURCE_TO_LIBRARY_PATH
${CMAKE_INSTALL_PREFIX}/${RESOURCES_INSTALL_PREFIX}/${NAME}
${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_PREFIX}/${LIBRARY_FILE_NAME})
_usd_plug_info_subst(${NAME} ${RESOURCE_TO_LIBRARY_PATH} ${resourceFile})
# Update resourceFile var to path of substituted file.
set(resourceFile "${CMAKE_CURRENT_BINARY_DIR}/${resourceFile}")
endif()
# Install into project binary dir (for tests)
if (BUILD_TESTING)
file(
COPY ${resourceFile}
DESTINATION ${PROJECT_BINARY_DIR}/${RESOURCES_INSTALL_PREFIX}/${NAME}/${USD_PLUG_INFO_RESOURCES_DIR}
)
endif()
# Install resource file.
install(
FILES
${resourceFile}
DESTINATION
${RESOURCES_INSTALL_PREFIX}/${NAME}/${USD_PLUG_INFO_RESOURCES_DIR}
)
endforeach()
endfunction() # _usd_install_resource_files
# Internal utility for differentiating between "shared library" vs "plugin".
#
# Outputs:
# LIBRARY_INSTALL_PREFIX: The sub-directory under installation root where the
# shared library will be deployed.
# LIBRARY_FILE_PREFIX: The filename prefix of the shared library. ("lib" on Linux)
function(_usd_compute_library_install_and_file_prefix
TYPE
LIBRARY_INSTALL_PREFIX
LIBRARY_FILE_PREFIX
)
if (TYPE STREQUAL "PLUGIN")
set(${LIBRARY_INSTALL_PREFIX} ${USD_PLUGIN_DIR} PARENT_SCOPE)
set(${LIBRARY_FILE_PREFIX} "" PARENT_SCOPE)
else()
set(${LIBRARY_INSTALL_PREFIX} ${CMAKE_INSTALL_LIBDIR} PARENT_SCOPE)
set(${LIBRARY_FILE_PREFIX} ${CMAKE_SHARED_LIBRARY_PREFIX} PARENT_SCOPE)
endif()
endfunction()
# Converts a library name, such as _tf.so to the internal module name given
# our naming conventions, e.g. Tf
function(_usd_get_python_module_name
LIBRARY_FILENAME
MODULE_NAME
)
# Library names are either something like tf.so for shared libraries
# or _tf.pyd/_tf_d.pyd for Python module libraries.
# We want to strip off the leading "_" and the trailing "_d".
set(LIBNAME ${LIBRARY_FILENAME})
string(REGEX REPLACE "^_" "" LIBNAME ${LIBNAME})
string(SUBSTRING ${LIBNAME} 0 1 LIBNAME_FL)
string(TOUPPER ${LIBNAME_FL} LIBNAME_FL)
string(SUBSTRING ${LIBNAME} 1 -1 LIBNAME_SUFFIX)
set(${MODULE_NAME}
"${LIBNAME_FL}${LIBNAME_SUFFIX}"
PARENT_SCOPE
)
endfunction() # _usd_get_python_module_name
# Performs variable substitution in a plugInfo.json file.
function(_usd_plug_info_subst
LIBRARY_TARGET
RESOURCE_TO_LIBRARY_PATH
PLUG_INFO_PATH
)
set(PLUG_INFO_ROOT "..")
set(PLUG_INFO_LIBRARY_PATH ${RESOURCE_TO_LIBRARY_PATH})
set(PLUG_INFO_RESOURCE_PATH ${USD_PLUG_INFO_RESOURCES_DIR})
configure_file(
${PLUG_INFO_PATH}
${CMAKE_CURRENT_BINARY_DIR}/${PLUG_INFO_PATH}
)
endfunction() # _usd_plug_info_subst
# Common target-specific properties to apply to library targets.
function(_usd_target_properties
TARGET_NAME
)
set(options)
set(oneValueArgs)
set(multiValueArgs
INCLUDE_DIRS
DEFINES
LIBRARIES
)
cmake_parse_arguments(
args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
# Add additional platform-speific compile definitions
set (platform_definitions)
if (MSVC)
# Depending on which parts of USD the project uses, additional definitions for windows may need
# to be added. A explicit list of MSVC definitions USD builds with can be found in the USD source at:
# cmake/defaults/CXXDefaults.cmake
# cmake/defaults/msvcdefaults.cmake
list(APPEND platform_definitions NOMINMAX)
endif()
target_compile_definitions(${TARGET_NAME}
PRIVATE
${args_DEFINES}
${platform_definitions}
)
target_compile_features(${TARGET_NAME}
PRIVATE
cxx_std_14
)
# Exported include paths for this target.
target_include_directories(${TARGET_NAME}
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# Project includes for building against.
target_include_directories(${TARGET_NAME}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}>
)
# Setup include path for binary dir.
# We set external includes as SYSTEM so that their warnings are muted.
set(_INCLUDE_DIRS "")
list(APPEND _INCLUDE_DIRS ${args_INCLUDE_DIRS} ${USD_INCLUDE_DIR} ${TBB_INCLUDE_DIRS})
if (ENABLE_PYTHON_SUPPORT)
list(APPEND _INCLUDE_DIRS ${PYTHON_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
endif()
target_include_directories(${TARGET_NAME}
SYSTEM
PRIVATE
${_INCLUDE_DIRS}
)
# Set-up library search path.
target_link_directories(${TARGET_NAME}
PRIVATE
${USD_LIBRARY_DIR}
)
# Link to libraries.
set(_LINK_LIBRARIES "")
list(APPEND _LINK_LIBRARIES ${args_LIBRARIES} ${TBB_LIBRARIES})
if (ENABLE_PYTHON_SUPPORT)
list(APPEND _LINK_LIBRARIES ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES})
endif()
target_link_libraries(${TARGET_NAME}
PRIVATE
${_LINK_LIBRARIES}
)
endfunction() # _usd_target_properties
# Set-up runtime environment variables for the test.
# When USE_PYTHONPATH is one, will include project python libraries
function(_usd_set_test_properties
TARGET_NAME
USE_PYTHONPATH
)
# The paths refer to the build tree (which mirrors the final installation).
# The first path for an env var needs the 'VARNAME=' prepended.
# On windows, calls to "$ENV{}" must be sanitized to replace back slashes with forward slashes
# Env vars after the first must be prepended with a double escaped semicolon to be recognized.
set(TEST_ENV_VARS "")
# Building the PXR_PLUGINPATH_NAME environment variable
set(TEST_PXR_PLUGINPATH_NAME "$ENV{PXR_PLUGINPATH_NAME}")
if (MSVC)
string(REGEX REPLACE "\\\\" "/" TEST_PXR_PLUGINPATH_NAME "${TEST_PXR_PLUGINPATH_NAME}")
endif()
string(PREPEND TEST_PXR_PLUGINPATH_NAME "PXR_PLUGINPATH_NAME=")
list(APPEND TEST_PXR_PLUGINPATH_NAME
"${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/${USD_PLUG_INFO_ROOT_DIR}"
"${PROJECT_BINARY_DIR}/${USD_PLUGIN_DIR}/${USD_PLUG_INFO_ROOT_DIR}"
)
list(APPEND TEST_ENV_VARS "${TEST_PXR_PLUGINPATH_NAME}")
# Building the PYTHONPATH environment variable
if (USE_PYTHONPATH)
set(TEST_PYTHON_PATH "$ENV{PYTHONPATH}")
if (MSVC)
string(REGEX REPLACE "\\\\" "/" TEST_PYTHON_PATH "${TEST_PYTHON_PATH}")
endif()
string(PREPEND TEST_PYTHON_PATH "PYTHONPATH=")
string(PREPEND TEST_PYTHON_PATH "\\;")
list(APPEND TEST_PYTHON_PATH
"${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/python"
"${USD_ROOT}/${CMAKE_INSTALL_LIBDIR}/python"
)
list(APPEND TEST_ENV_VARS "${TEST_PYTHON_PATH}")
endif()
# Add MSVC-required paths
if (MSVC)
# Building the PATH environment variable
set(TEST_PATH "$ENV{PATH}")
string(REGEX REPLACE "\\\\" "/" TEST_PATH "${TEST_PATH}")
string(PREPEND TEST_PATH "PATH=")
string(PREPEND TEST_PATH "\\;")
list(APPEND TEST_PATH
"${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
"${USD_ROOT}/${CMAKE_INSTALL_LIBDIR}"
"${USD_ROOT}/${CMAKE_INSTALL_BINDIR}"
)
list(APPEND TEST_ENV_VARS "${TEST_PATH}")
endif()
if (MSVC)
list(JOIN TEST_ENV_VARS "\\;" TEST_ENV_VARS)
else()
list(JOIN TEST_ENV_VARS ":" TEST_ENV_VARS)
endif()
set_tests_properties(${TARGET_NAME}
PROPERTIES
ENVIRONMENT
"${TEST_ENV_VARS}"
)
endfunction() # _usd_set_test_properties