Skip to content

Commit

Permalink
Merge pull request #464 from maya3d/duvalb/HYDRA-444/hydra_scene_brow…
Browse files Browse the repository at this point in the history
…ser_library_build_infrastructure

HYDRA 444 - Add build infrastructure for Hydra Scene Browser
  • Loading branch information
duvalb-adsk authored and GitHub Enterprise committed Aug 8, 2023
2 parents 509d487 + 206e94b commit ce55a7e
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ option(CMAKE_WANT_MATERIALX_BUILD "Enable building with MaterialX (experimental)

set(PXR_OVERRIDE_PLUGINPATH_NAME PXR_PLUGINPATH_NAME
CACHE STRING "Name of env var USD searches to find plugins")

option(BUILD_HDSBLIB "Build Hydra Scene Browser library (hdui)." OFF)

#------------------------------------------------------------------------------
# internal flags to control build
Expand Down Expand Up @@ -167,6 +169,10 @@ endif()
#------------------------------------------------------------------------------
add_subdirectory(lib)

if(BUILD_HDSBLIB AND IS_WINDOWS)
add_subdirectory(lib/adskHydraSceneBrowser)
endif()

#------------------------------------------------------------------------------
# install
#------------------------------------------------------------------------------
Expand All @@ -176,7 +182,6 @@ else()
set(USD_INSTALL_LOCATION ${PXR_USD_LOCATION})
endif()


#------------------------------------------------------------------------------
# Maya module files
#------------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ def BuildAndInstall(context, buildArgs, stages):
else:
extraArgs.append('-DMAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG=OFF')

# HYDRA-444 build infrastructure for Hydra Scene Browser Library
if context.qtLocation:
extraArgs.append('-DQT_LOCATION="{qtLocation}"'
.format(qtLocation=context.qtLocation))

extraArgs += buildArgs
stagesArgs += stages

Expand Down Expand Up @@ -467,6 +472,10 @@ def Package(context):
parser.add_argument("--debug-python", dest="debug_python", action="store_true",
help="Define Boost Python Debug if your Python library comes with Debugging symbols (default: %(default)s).")

# HYDRA-444 build infrastructure for Hydra Scene Browser Library
parser.add_argument("--qt-location", type=str,
help="Directory where Qt is installed. Used only by the Hydra Scene Browser library build.")

parser.add_argument("--build-args", type=str, nargs="*", default=[],
help=("Comma-separated list of arguments passed into CMake when building libraries"))

Expand Down Expand Up @@ -541,6 +550,11 @@ def __init__(self, args):
# Maya Devkit Location
self.devkitLocation = (os.path.abspath(args.devkit_location)
if args.devkit_location else None)

# HYDRA-444 build infrastructure for Hydra Scene Browser Library
# Qt Location
self.qtLocation = (os.path.abspath(args.qt_location)
if args.qt_location else None)

# Log File Name
logFileName="build_log.txt"
Expand Down
155 changes: 155 additions & 0 deletions lib/adskHydraSceneBrowser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# -----------------------------------------------------------------------------
# setup Qt
# -----------------------------------------------------------------------------
if(DEFINED QT_LOCATION)
if(NOT DEFINED QT_VERSION)
set(QT_VERSION "5.12")
endif()
set(CMAKE_PREFIX_PATH "${QT_LOCATION}")
find_package(Qt5 ${QT_VERSION} COMPONENTS Core Widgets REQUIRED)
if(Qt5_FOUND)
message(STATUS "QT_LOCATION set. Building adskHydraSceneBrowser enabled.")
endif()
else()
message(STATUS "QT_LOCATION not set. Building adskHydraSceneBrowser will be disabled.")
return()
endif()

# -----------------------------------------------------------------------------
# setup adskHydraSceneBrowser library
# -----------------------------------------------------------------------------
set(TARGET_NAME adskHydraSceneBrowser)
add_library(${TARGET_NAME} SHARED api.h)

# -----------------------------------------------------------------------------
# setup sources
# -----------------------------------------------------------------------------
set(HEADERS
dataSourceTreeWidget.h
dataSourceValueTreeView.h
registeredSceneIndexChooser.h
sceneIndexDebuggerWidget.h
sceneIndexObserverLoggingTreeView.h
sceneIndexObserverLoggingWidget.h
sceneIndexTreeWidget.h
)
set(SOURCES
dataSourceTreeWidget.cpp
dataSourceValueTreeView.cpp
registeredSceneIndexChooser.cpp
sceneIndexDebuggerWidget.cpp
sceneIndexObserverLoggingTreeView.cpp
sceneIndexObserverLoggingWidget.cpp
sceneIndexTreeWidget.cpp
)

string(REGEX REPLACE "^[0-9]+\\.([0-9]+\\.[0-9]+)$" "\\1" USD_minor_patch_version ${USD_VERSION})
set(DOWNLOAD_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/src/download")
set(DLL_API_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/src/dll_api")

macro(download file)
file(DOWNLOAD
"https://raw.githubusercontent.com/PixarAnimationStudios/OpenUSD/v${USD_minor_patch_version}/extras/imaging/examples/hdui/${file}"
"${DOWNLOAD_LOCATION}/${file}")
endmacro()

# Download source files
foreach(SOURCE IN ITEMS ${SOURCES})
download(${SOURCE})
# Copy source file to dll_api directory
# Note: we intentionally copy over the sources to make the build folders easier
# to understand and the debugging process easier.
configure_file("${DOWNLOAD_LOCATION}/${SOURCE}" "${DLL_API_LOCATION}/${SOURCE}" COPYONLY)
endforeach()

foreach(HEADER IN ${HEADERS})
# Download header files
download(${HEADER})

# Add DLL import/export support for Windows
# Insert 'HDUI_API' symbols for class declarations
# Note: we assume class declarations are always followed by double colons
file(READ "${DOWNLOAD_LOCATION}/${HEADER}" FILE_CONTENTS)
string(REGEX REPLACE "class ([a-zA-Z]+[^\;]:)" "class HDUI_API \\1" FILE_CONTENTS "${FILE_CONTENTS}")

# Insert '#include <api.h>' above the first occurrence of "#include"
# Note: we assume there is always at least one include statement in header files
string(FIND "${FILE_CONTENTS}" "#include" include_pos)
string(SUBSTRING "${FILE_CONTENTS}" 0 ${include_pos} include_line)
string(SUBSTRING "${FILE_CONTENTS}" ${include_pos} -1 remaining_contents)
set(modified_contents "${include_line}\n#include <api.h>\n${remaining_contents}")

file(WRITE "${DLL_API_LOCATION}/${HEADER}" "${modified_contents}")
endforeach()

# Prepend an absolute path to the downloaded source files, located in
# the CMAKE_CURRENT_BINARY_DIR.
# Note: the sources are downloaded for PixarAnimationStudios/OpenUSD and
# are not located in this repository's folder
list(TRANSFORM SOURCES PREPEND "${DLL_API_LOCATION}/")

# Add CMAKE_CURRENT_BINARY_DIR downloaded sources to the adskHydraSceneBrowser target
target_sources(${TARGET_NAME}
PRIVATE
${SOURCES}
)

# -----------------------------------------------------------------------------
# include directories
# -----------------------------------------------------------------------------
target_include_directories(${TARGET_NAME}
PUBLIC
${PXR_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${DLL_API_LOCATION}
)

# -----------------------------------------------------------------------------
# compiler configuration
# -----------------------------------------------------------------------------
# QT_NO_KEYWORDS prevents Qt from defining the foreach, signals, slots and emit macros.
# this avoids overlap between Qt macros and boost, and enforces using Q_ macros.
set_target_properties(Qt5::Core PROPERTIES INTERFACE_COMPILE_DEFINITIONS QT_NO_KEYWORDS)

target_compile_definitions(${TARGET_NAME}
PRIVATE
HDUI_EXPORT
)
mayaUsd_compile_config(${TARGET_NAME})

# -----------------------------------------------------------------------------
# link libraries
# -----------------------------------------------------------------------------
target_link_libraries(${TARGET_NAME}
PUBLIC
usd
usdImaging
Qt5::Core
Qt5::Widgets
)

# -----------------------------------------------------------------------------
# Qt file processing (moc)
# -----------------------------------------------------------------------------
set_property(TARGET adskHydraSceneBrowser PROPERTY AUTOMOC ON)

# -----------------------------------------------------------------------------
# install
# -----------------------------------------------------------------------------
install(TARGETS ${TARGET_NAME}
LIBRARY
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
RUNTIME
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)

list(TRANSFORM HEADERS PREPEND "${DLL_API_LOCATION}/")
install(FILES ${HEADERS}
DESTINATION
${CMAKE_INSTALL_PREFIX}/include/adskHydraSceneBrowser
)

if(IS_WINDOWS)
install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}>
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib OPTIONAL)
endif()
39 changes: 39 additions & 0 deletions lib/adskHydraSceneBrowser/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2023 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if defined _WIN32 || defined __CYGWIN__

// The main export symbol used for the UI library.
#ifdef HDUI_EXPORT
#ifdef __GNUC__
#define HDUI_API __attribute__((dllexport))
#else
#define HDUI_API __declspec(dllexport)
#endif
#else
#ifdef __GNUC__
#define HDUI_API __attribute__((dllimport))
#else
#define HDUI_API __declspec(dllimport)
#endif
#endif

#else
#if __GNUC__ >= 4
#define HDUI_API __attribute__((visibility("default")))
#else
#define HDUI_API
#endif
#endif

0 comments on commit ce55a7e

Please sign in to comment.