Skip to content

Commit

Permalink
Add preliminary Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
mati-nvidia committed Dec 20, 2023
1 parent d4a903e commit 706c87d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 66 deletions.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ set(CMAKE_CXX_STANDARD "${cxx_std}" CACHE STRING "Default C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (MSVC)
# Make sure WinDef.h does not define min and max macros which
# will conflict with std::min() and std::max().
add_compile_definitions("NOMINMAX")

# From OpenUSD/cmake/defaults/msvcdefaults.cmake
#
# The /Zc:inline option strips out the "arch_ctor_<name>" symbols used for
# library initialization by ARCH_CONSTRUCTOR starting in Visual Studio 2019,
# causing release builds to fail. Disable the option for this and later
# versions.
#
# For more details, see:
# https://developercommunity.visualstudio.com/content/problem/914943/zcinline-removes-extern-symbols-inside-anonymous-n.html
if (MSVC_VERSION GREATER_EQUAL 1920)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:inline-")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:inline")
endif()
endif()

option(BUILD_TESTS "Build tests" ON)
option(BUILD_DOCS "Build documentation" ON)
option(BUILD_PYTHON_BINDINGS "Build Python Bindings" ON)
Expand Down
12 changes: 12 additions & 0 deletions cmake/modules/FindTBB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ find_path(
include
)

find_path(
TBB_LIB_DIR
tbb.lib
PATH_SUFFIXES
lib
)


mark_as_advanced(TBB_INCLUDE_DIR)

if(TBB_INCLUDE_DIR AND EXISTS "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h")
Expand Down Expand Up @@ -56,4 +64,8 @@ find_package_handle_standard_args(
if (TBB_FOUND AND NOT TARGET TBB::tbb)
add_library(TBB::tbb INTERFACE IMPORTED)
target_include_directories(TBB::tbb INTERFACE "${TBB_INCLUDE_DIR}")
if(TBB_LIB_DIR)
target_link_libraries(TBB::tbb INTERFACE "${TBB_LIB_DIR}/tbb.lib")
endif()

endif()
8 changes: 8 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ set_target_properties(pyUnf
LIBRARY_OUTPUT_DIRECTORY unf
)

if(WIN32)
# Python modules must be suffixed with .pyd on Windows.
set_target_properties(pyUnf
PROPERTIES
SUFFIX ".pyd"
)
endif()

target_compile_definitions(
pyUnf
PRIVATE
Expand Down
4 changes: 1 addition & 3 deletions src/python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# :coding: utf-8

from pxr import Tf
from . import _unf # pylint:disable=import-error

Tf.PrepareModule(_unf, locals())
Tf.PreparePythonModule()
del Tf
11 changes: 7 additions & 4 deletions src/python/wrapNotice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ using namespace unf::UnfNotice;

PXR_NAMESPACE_USING_DIRECTIVE

namespace {

TF_INSTANTIATE_NOTICE_WRAPPER(StageNotice, TfNotice);
TF_INSTANTIATE_NOTICE_WRAPPER(StageContentsChanged, StageNotice);
TF_INSTANTIATE_NOTICE_WRAPPER(ObjectsChanged, StageNotice);
TF_INSTANTIATE_NOTICE_WRAPPER(StageEditTargetChanged, StageNotice);
TF_INSTANTIATE_NOTICE_WRAPPER(LayerMutingChanged, StageNotice);

} // anonymous namespace

// Dummy class to reproduce namespace in Python.
class PythonUnfNotice {
};
class PythonUnfNotice {};

void wrapNotice()
{
Expand Down Expand Up @@ -95,13 +98,13 @@ void wrapNotice()

.def(
"HasChangedFields",
(bool (ObjectsChanged::*)(const SdfPath&) const)
(bool(ObjectsChanged::*)(const SdfPath&) const)
& ObjectsChanged::HasChangedFields,
"Indicate whether any changed fields affected the path")

.def(
"HasChangedFields",
(bool (ObjectsChanged::*)(const UsdObject&) const)
(bool(ObjectsChanged::*)(const UsdObject&) const)
& ObjectsChanged::HasChangedFields,
"Indicate whether any changed fields affected the object");

Expand Down
9 changes: 9 additions & 0 deletions src/unf/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef UNF_API_H
#define UNF_API_H

#include "pxr/base/arch/export.h"

#define UNF_API ARCH_EXPORT
#define UNF_LOCAL ARCH_HIDDEN

#endif
33 changes: 17 additions & 16 deletions src/unf/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/// \file unf/broker.h

#include "unf/api.h"
#include "unf/capturePredicate.h"
#include "unf/notice.h"

Expand Down Expand Up @@ -49,23 +50,23 @@ class Broker : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
///
/// If a broker has already been created from this \p stage, it will be
/// returned. Otherwise, a new one will be created and returned.
static BrokerPtr Create(const PXR_NS::UsdStageWeakPtr& stage);
UNF_API static BrokerPtr Create(const PXR_NS::UsdStageWeakPtr& stage);

virtual ~Broker() = default;
UNF_API virtual ~Broker() = default;

/// Remove default copy constructor.
Broker(const Broker&) = delete;
UNF_API Broker(const Broker&) = delete;

/// Remove default assignment operator.
Broker& operator=(const Broker&) = delete;
UNF_API Broker& operator=(const Broker&) = delete;

/// Return Usd Stage associated with the broker.
const PXR_NS::UsdStageWeakPtr GetStage() const { return _stage; }
UNF_API const PXR_NS::UsdStageWeakPtr GetStage() const { return _stage; }

/// \brief
/// Indicate whether a notice transaction has been started.
/// \sa BeginTransaction
bool IsInTransaction();
UNF_API bool IsInTransaction();

/// \brief
/// Start a notice transaction.
Expand All @@ -85,7 +86,7 @@ class Broker : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
///
/// \sa EndTransaction
/// \sa NoticeTransaction
void BeginTransaction(
UNF_API void BeginTransaction(
CapturePredicate predicate = CapturePredicate::Default());

/// \brief
Expand All @@ -107,7 +108,7 @@ class Broker : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
///
/// \sa EndTransaction
/// \sa NoticeTransaction
void BeginTransaction(const CapturePredicateFunc&);
UNF_API void BeginTransaction(const CapturePredicateFunc&);

/// \brief
/// Stop a notice transaction.
Expand All @@ -122,42 +123,42 @@ class Broker : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
///
/// \sa BeginTransaction
/// \sa NoticeTransaction
void EndTransaction();
UNF_API void EndTransaction();

/// \brief
/// Create and send a UnfNotice::StageNotice notice via the broker.
///
/// \note
/// The associated stage will be used as sender.
template <class UnfNotice, class... Args>
void Send(Args&&... args);
UNF_API void Send(Args&&... args);

/// \brief
/// Send a UnfNotice::StageNotice notice via the broker.
///
/// \note
/// The associated stage will be used as sender.
void Send(const UnfNotice::StageNoticeRefPtr&);
UNF_API void Send(const UnfNotice::StageNoticeRefPtr&);

/// Return dispatcher reference associated with \p identifier.
DispatcherPtr& GetDispatcher(std::string identifier);
UNF_API DispatcherPtr& GetDispatcher(std::string identifier);

/// \brief
/// Create and register a new dispatcher.
///
/// This will call the Dispatcher::Register method.
template <class T>
void AddDispatcher();
UNF_API void AddDispatcher();

/// \brief
/// Un-register broker.
///
/// \warning
/// The broker is not safe to use after this call.
void Reset();
UNF_API void Reset();

/// Un-register all brokers.
static void ResetAll();
UNF_API static void ResetAll();

private:
Broker(const PXR_NS::UsdStageWeakPtr&);
Expand All @@ -169,7 +170,7 @@ class Broker : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
void _DiscoverDispatchers();

/// Register dispacther within broker by its identifier.
void _Add(const DispatcherPtr&);
UNF_API void _Add(const DispatcherPtr&);

/// Create and register dispacther within broker without running the
/// Dispatcher::Register method.
Expand Down
9 changes: 5 additions & 4 deletions src/unf/capturePredicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/// \file unf/capturePredicate.h

#include "unf/api.h"
#include "unf/notice.h"

#include <functional>
Expand Down Expand Up @@ -38,16 +39,16 @@ class CapturePredicate {
/// return (n.GetTypeId() != typeid(Foo).name());
/// });
/// \endcode
CapturePredicate(const CapturePredicateFunc&);
UNF_API CapturePredicate(const CapturePredicateFunc&);

/// Invoke boolean predicate on UnfNotice::StageNotice \p notice.
bool operator()(const UnfNotice::StageNotice&) const;
UNF_API bool operator()(const UnfNotice::StageNotice&) const;

/// Create a predicate which return true for each notice type.
static CapturePredicate Default();
UNF_API static CapturePredicate Default();

/// Create a predicate which return false for each notice type.
static CapturePredicate BlockAll();
UNF_API static CapturePredicate BlockAll();

private:
CapturePredicateFunc _function = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions src/unf/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace unf {
class Dispatcher : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
public:
/// Revoke all registered listeners on destruction.
virtual ~Dispatcher() { Revoke(); };
UNF_API virtual ~Dispatcher() { Revoke(); };

/// \brief
/// Get unique string identifier
Expand All @@ -32,17 +32,17 @@ class Dispatcher : public PXR_NS::TfRefBase, public PXR_NS::TfWeakBase {
///
/// \sa
/// Broker::GetDispatcher
virtual std::string GetIdentifier() const = 0;
UNF_API virtual std::string GetIdentifier() const = 0;

/// Register listeners to PXR_NS::TfNotice derived notices.
virtual void Register() = 0;
UNF_API virtual void Register() = 0;

/// Revoke all registered listeners.
virtual void Revoke();
UNF_API virtual void Revoke();

protected:
/// Create a dispatcher targeting a Broker.
Dispatcher(const BrokerWeakPtr&);
UNF_API Dispatcher(const BrokerWeakPtr&);

/// \brief
/// Convenient templated method to register a listener for incoming
Expand Down
Loading

0 comments on commit 706c87d

Please sign in to comment.