Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial wasm commit including pxr/base #3469

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14)

project(usd)

if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT EMSCRIPTEN)
if (WIN32)
message(FATAL_ERROR "Compiler does not support 64-bit builds. "
"If you are using Visual Studio, make sure you are in the "
Expand Down Expand Up @@ -37,6 +37,15 @@ include(CXXDefaults)
add_definitions(${_PXR_CXX_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${_PXR_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")

if(PXR_ENABLE_JS_SUPPORT)
# Add EMSCRIPTEN specific compiler flags (is this the right place)?
set(EMSCRIPTEN_COMPILE_FLAGS "-fPIC -pthread -fexceptions")
add_compile_options("SHELL:${EMSCRIPTEN_COMPILE_FLAGS}")
add_link_options("SHELL:-sSTACK_SIZE=5MB -sDEFAULT_PTHREAD_STACK_SIZE=2MB \
-sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4GB -fexceptions")
message("EMSCRIPTEN Flags enabled")
endif()

include(Public)

pxr_toplevel_prologue()
Expand Down
190 changes: 156 additions & 34 deletions build_scripts/build_usd.py

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ option(PXR_BUILD_DOCUMENTATION "Generate doxygen documentation" OFF)
option(PXR_BUILD_PYTHON_DOCUMENTATION "Generate Python documentation" OFF)
option(PXR_BUILD_HTML_DOCUMENTATION "Generate HTML documentation if PXR_BUILD_DOCUMENTATION is ON" ON)
option(PXR_ENABLE_PYTHON_SUPPORT "Enable Python based components for USD" ON)
option(PXR_ENABLE_JS_SUPPORT "Enable Javascript based components for USD" OFF)
option(PXR_ENABLE_JS_BINDINGS_SUPPORT "Enable Javascript bindings for USD" ON)
if (NOT EMSCRIPTEN)
set(PXR_ENABLE_JS_BINDINGS_SUPPORT OFF)
endif()
option(PXR_USE_PYTHON_3 "Build Python bindings for Python 3" ON)
option(PXR_USE_DEBUG_PYTHON "Build with debug python" OFF)
option(PXR_USE_BOOST_PYTHON "Use boost::python for Python bindings (deprecated)" OFF)
option(PXR_ENABLE_HDF5_SUPPORT "Enable HDF5 backend in the Alembic plugin for USD" OFF)
Expand All @@ -37,6 +43,7 @@ option(PXR_ENABLE_NAMESPACES "Enable C++ namespaces." ON)
option(PXR_PREFER_SAFETY_OVER_SPEED
"Enable certain checks designed to avoid crashes or out-of-bounds memory reads with malformed input files. These checks may negatively impact performance."
ON)
option(PXR_BUILD_PERFORMANCE "Build Performance Component." ON)

if(APPLE)
# Cross Compilation detection as defined in CMake docs
Expand Down
4 changes: 4 additions & 0 deletions cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ if((PXR_ENABLE_PYTHON_SUPPORT AND PXR_USE_BOOST_PYTHON) OR PXR_ENABLE_OPENVDB_SU
endif()
endif()

if (PXR_ENABLE_JS_BINDINGS_SUPPORT)
add_definitions(-DPXR_JS_BINDINGS_SUPPORT_ENABLED)
endif()

if(PXR_ENABLE_PYTHON_SUPPORT)
# 1--Python.
macro(setup_python_package package)
Expand Down
116 changes: 107 additions & 9 deletions cmake/macros/Private.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
# https://openusd.org/license.
#
include(Version)
include(${CMAKE_CURRENT_LIST_DIR}/pxrStaticConfig.cmake)

function(_get_all_dependencies target result)
get_target_property(dependencies ${target} INTERFACE_LINK_LIBRARIES)
# Split core libraries from non-core libraries.
_pxr_split_libraries("${dependencies}" internalDeps externalDeps)
if(NOT internalDeps)
return()
endif()

foreach(dependency IN LISTS internalDeps)
if(NOT ${dependency} IN_LIST ${result})
list(APPEND ${result} ${dependency})
_get_final_package_name("${dependency}" dependency_internal)
_get_all_dependencies(${dependency_internal} ${result})
endif()
endforeach()

# Set the result variable in the parent scope
set(${result} "${${result}}" PARENT_SCOPE)
endfunction()

# Copy headers to the build tree. Under pxr/ the include paths match the
# source tree paths but elsewhere they do not. Instead we use include
Expand Down Expand Up @@ -320,14 +341,26 @@ function(_install_resource_files NAME pluginInstallPrefix pluginToLibraryPath)
${resourceFile} ${plugInfoFile})
endif()
set(resourceFile "${plugInfoFile}")
set(EMSCRIPTEN_RESOURCE_FILE ${resourceFile})
else()
set(EMSCRIPTEN_RESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${resourceFile}")
endif()

if (PXR_ENABLE_JS_SUPPORT)
string(REGEX REPLACE "^lib\\/" "/" LOCAL_PATH "${resourcesPath}")

list(APPEND EMSCRIPTEN_RESOURCE_FILES "--preload-file ${EMSCRIPTEN_RESOURCE_FILE}@${LOCAL_PATH}/${dirPath}/${destFileName}")
endif()
install(
FILES ${resourceFile}
DESTINATION ${resourcesPath}/${dirPath}
RENAME ${destFileName}
)
endforeach()

if (PXR_ENABLE_JS_SUPPORT)
set_property(TARGET ${NAME} PROPERTY EMSCRIPTEN_RESOURCES ${EMSCRIPTEN_RESOURCE_FILES})
endif()
endfunction() # _install_resource_files

function(_install_pyside_ui_files LIBRARY_NAME)
Expand Down Expand Up @@ -805,8 +838,27 @@ endfunction()
# always want those.
#
function(_pxr_target_link_libraries NAME)
set(options
IS_STATIC_PLUGIN
)
set(oneValueArgs
)
set(multiValueArgs
)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

# Split core libraries from non-core libraries.
_pxr_split_libraries("${ARGN}" internal external)
_pxr_split_libraries("${args_UNPARSED_ARGUMENTS}" internal external)

set(NAME_INTERNAL "${NAME}")
if (args_IS_STATIC_PLUGIN)
set(NAME_INTERNAL "${NAME}_internal")
endif()

get_property(type TARGET ${NAME} PROPERTY TYPE)
if("${type}" STREQUAL "OBJECT_LIBRARY")
Expand Down Expand Up @@ -943,7 +995,9 @@ function(_pxr_target_link_libraries NAME)
list(APPEND final -WHOLEARCHIVE:$<TARGET_FILE:${lib}>)
list(APPEND final ${lib})
elseif(CMAKE_COMPILER_IS_GNUCXX)
list(APPEND final -Wl,--whole-archive ${lib} -Wl,--no-whole-archive)
list(APPEND final "$<LINK_LIBARAY:WHOLE_ARCHIVE,${lib}")
elseif(PXR_ENABLE_JS_SUPPORT)
list(APPEND final ${lib})
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
list(APPEND final -Wl,-force_load ${lib})
else()
Expand All @@ -953,7 +1007,7 @@ function(_pxr_target_link_libraries NAME)
endforeach()
set(internal ${final})
endif()
target_link_libraries(${NAME}
target_link_libraries(${NAME_INTERNAL}
${internal}
${external}
${PXR_MALLOC_LIBRARY}
Expand Down Expand Up @@ -1178,6 +1232,8 @@ function(_pxr_library NAME)
${ARGN}
)

_get_final_package_name("${NAME}" NAME_INTERNAL)

#
# Set up the target.
#
Expand Down Expand Up @@ -1253,6 +1309,19 @@ function(_pxr_library NAME)
${args_PRIVATE_HEADERS}
)

elseif(args_TYPE STREQUAL "STATIC" AND PXR_ENABLE_JS_SUPPORT)
# Building an explicitly static library.
add_library(${NAME_INTERNAL}
STATIC
${args_CPPFILES}
${args_PUBLIC_HEADERS}
${args_PRIVATE_HEADERS}
)
add_library(${NAME}
INTERFACE
)
target_link_libraries(${NAME} INTERFACE "$<LINK_LIBRARY:LOAD_PLUGIN,${NAME}_internal>")

elseif(args_TYPE STREQUAL "STATIC")
# Building an explicitly static library.
add_library(${NAME}
Expand Down Expand Up @@ -1363,16 +1432,17 @@ function(_pxr_library NAME)
# PIC is required by shared libraries. It's on for static libraries
# because we'll likely link them into a shared library.
_get_folder("" folder)
set_target_properties(${NAME}
set_target_properties(${NAME_INTERNAL}
PROPERTIES
FOLDER "${folder}"
POSITION_INDEPENDENT_CODE ON
IMPORT_PREFIX "${args_PREFIX}"
PREFIX "${args_PREFIX}"
SUFFIX "${args_SUFFIX}"
OUTPUT_NAME ${NAME}
)

target_compile_definitions(${NAME}
target_compile_definitions(${NAME_INTERNAL}
PUBLIC
${apiPublic}
PRIVATE
Expand All @@ -1395,7 +1465,7 @@ function(_pxr_library NAME)
${PXR_PREFIX}
)

target_include_directories(${NAME}
target_include_directories(${NAME_INTERNAL}
PRIVATE
"${PROJECT_BINARY_DIR}/include"
"${PROJECT_BINARY_DIR}/${PXR_INSTALL_SUBDIR}/include"
Expand All @@ -1408,7 +1478,7 @@ function(_pxr_library NAME)
# as system include directories so that compiler warnings from these
# headers are ignored, since we have no control over the contents
# of those headers.
target_include_directories(${NAME}
target_include_directories(${NAME_INTERNAL}
SYSTEM
PUBLIC
${args_INCLUDE_DIRS}
Expand All @@ -1430,15 +1500,19 @@ function(_pxr_library NAME)
endif()

# XXX -- May want some plugins to be baked into monolithic.
_pxr_target_link_libraries(${NAME} ${args_LIBRARIES})
set(ADDITIONAL_ARGS )
if(PXR_ENABLE_JS_SUPPORT)
list(APPEND ADDITIONAL_ARGS IS_STATIC_PLUGIN)
endif()
_pxr_target_link_libraries(${NAME} ${ADDITIONAL_ARGS} ${args_LIBRARIES})

# Rpath has libraries under the third party prefix and the install prefix.
# The former is for helper libraries for a third party application and
# the latter for core USD libraries.
_pxr_init_rpath(rpath "${libInstallPrefix}")
_pxr_add_rpath(rpath "${CMAKE_INSTALL_PREFIX}/${PXR_INSTALL_SUBDIR}/lib")
_pxr_add_rpath(rpath "${CMAKE_INSTALL_PREFIX}/lib")
_pxr_install_rpath(rpath ${NAME})
_pxr_install_rpath(rpath ${NAME_INTERNAL})

#
# Set up the install.
Expand Down Expand Up @@ -1482,6 +1556,14 @@ function(_pxr_library NAME)
ARCHIVE DESTINATION ${libInstallPrefix}
RUNTIME DESTINATION ${libInstallPrefix}
)
if (PXR_ENABLE_JS_SUPPORT)
install(
TARGETS ${NAME_INTERNAL}
LIBRARY DESTINATION ${libInstallPrefix}
ARCHIVE DESTINATION ${libInstallPrefix}
RUNTIME DESTINATION ${libInstallPrefix}
)
endif()
if(WIN32)
install(
FILES $<TARGET_PDB_FILE:${NAME}>
Expand Down Expand Up @@ -1513,6 +1595,15 @@ function(_pxr_library NAME)
ARCHIVE DESTINATION ${libInstallPrefix}
RUNTIME DESTINATION ${libInstallPrefix}
)
if (PXR_ENABLE_JS_SUPPORT)
install(
TARGETS ${NAME_INTERNAL}
EXPORT pxrTargets
LIBRARY DESTINATION ${libInstallPrefix}
ARCHIVE DESTINATION ${libInstallPrefix}
RUNTIME DESTINATION ${libInstallPrefix}
)
endif()
endif()

if(NOT isPlugin)
Expand All @@ -1536,3 +1627,10 @@ function(_pxr_library NAME)
endif()
endif()
endfunction() # _pxr_library

function(_get_final_package_name PXR_PACKAGE FINAL_PXR_PACKAGE)
set(${FINAL_PXR_PACKAGE} "${PXR_PACKAGE}" PARENT_SCOPE)
if(PXR_ENABLE_JS_SUPPORT)
set(${FINAL_PXR_PACKAGE} "${PXR_PACKAGE}_internal" PARENT_SCOPE)
endif ()
endfunction()
Loading