Skip to content

Commit

Permalink
Add windows compat imports
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScheller committed Sep 23, 2023
1 parent 570e95b commit ca39d40
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .github/scripts/houdini_build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set HFS=C:\Program Files\Side Effects Software\Houdini
set RESOLVER_NAME=%1
cmake . -B build -G "Visual Studio 16 2019" -A x64 -T v142
cmake --build build --clean-first --config Release
cmake --install build
5 changes: 4 additions & 1 deletion .github/workflows/build_houdini.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ jobs:
SIDEFX_CLIENT_ID: '${{ secrets.SIDEFX_CLIENT_ID }}'
SIDEFX_CLIENT_SECRET_KEY: '${{ secrets.SIDEFX_CLIENT_SECRET_KEY }}'
run: |
python3 .github/scripts/houdini.py --install
python3 .github/scripts/houdini.py --install
- name: Build USD File Resolver
run: |
.\.github\scripts\houdini_build.bat fileResolver
59 changes: 42 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(AR_ENV_SEARCH_REGEX_FORMAT "AR_SEARCH_REGEX_FORMAT")

# File Resolver
option(AR_FILERESOLVER_BUILD "Build the FileResolver" OFF)
if($ENV{RESOLVER_NAME} STREQUAL "fileResolver")
if("$ENV{RESOLVER_NAME}" STREQUAL "fileResolver")
set(AR_FILERESOLVER_BUILD ON)
endif()
set(AR_FILERESOLVER_USD_PLUGIN_NAME fileResolver)
Expand All @@ -21,7 +21,7 @@ set(AR_FILERESOLVER_TARGET_PYTHON _${AR_FILERESOLVER_TARGET_LIB})
set(AR_FILERESOLVER_INSTALL_PREFIX ${AR_PROJECT_NAME}/${AR_FILERESOLVER_USD_PLUGIN_NAME})
# Python Resolver
option(AR_PYTHONRESOLVER_BUILD "Build the PythonResolver" OFF)
if($ENV{RESOLVER_NAME} STREQUAL "pythonResolver")
if("$ENV{RESOLVER_NAME}" STREQUAL "pythonResolver")
set(AR_PYTHONRESOLVER_BUILD ON)
endif()
set(AR_PYTHONRESOLVER_USD_PLUGIN_NAME pythonResolver)
Expand All @@ -34,7 +34,7 @@ set(AR_PYTHONRESOLVER_TARGET_PYTHON _${AR_PYTHONRESOLVER_TARGET_LIB})
set(AR_PYTHONRESOLVER_INSTALL_PREFIX ${AR_PROJECT_NAME}/${AR_PYTHONRESOLVER_USD_PLUGIN_NAME})
# Hybrid Resolver
option(AR_HYBRIDRESOLVER_BUILD "Build the HybridResolver" OFF)
if($ENV{RESOLVER_NAME} STREQUAL "hybridResolver")
if("$ENV{RESOLVER_NAME}" STREQUAL "hybridResolver")
set(AR_HYBRIDRESOLVER_BUILD ON)
endif()
set(AR_HYBRIDRESOLVER_USD_PLUGIN_NAME hybridResolver)
Expand All @@ -49,24 +49,43 @@ set(AR_HYBRIDRESOLVER_ENV_CONTEXT_BYPASS "AR_ENV_CONTEXT_BYPASS")
set(AR_HYBRIDRESOLVER_ENV_CONTEXT_DIRTY "AR_ENV_CONTEXT_DIRTY")

# Arch
set(AR_ARCH_LIB_SUFFIX so)
if (WIN32)
set(AR_ARCH_LIB_SUFFIX "dll")
else()
set(AR_ARCH_LIB_SUFFIX "so")
endif()
# Houdini
set(AR_HOUDINI_ROOT $ENV{HFS})
set(AR_HOUDINI_LIB_DIR ${AR_HOUDINI_ROOT}/dsolib)
set(AR_HOUDINI_LIB_DIR ${AR_HOUDINI_ROOT}/custom/houdini/dsolib)
set(AR_HOUDINI_INCLUDE_DIR ${AR_HOUDINI_ROOT}/toolkit/include)
# Usd
set(AR_PXR_LIB_DIR ${AR_HOUDINI_ROOT}/dsolib)
set(AR_PXR_LIB_PREFIX "pxr_")
if (WIN32)
set(AR_PXR_LIB_DIR ${AR_HOUDINI_ROOT}/custom/houdini/dsolib)
set(AR_PXR_LIB_PREFIX "libpxr_")
else()
set(AR_PXR_LIB_DIR ${AR_HOUDINI_ROOT}/dsolib)
set(AR_PXR_LIB_PREFIX "pxr_")
endif()

set(AR_PXR_INCLUDE_DIR ${AR_HOUDINI_INCLUDE_DIR})
# Python
set(AR_PYTHON_LIB_DIR ${AR_HOUDINI_ROOT}/python/lib)
set(AR_PYTHON_LIB python3.9)
set(AR_PYTHON_LIB_NUMBER python39)
set(AR_PYTHON_LIB_SITEPACKAGES ${AR_PYTHON_LIB_DIR}/${AR_PYTHON_LIB}/site-packages)
if (WIN32)
set(AR_PYTHON_LIB_DIR ${AR_HOUDINI_ROOT}/${AR_PYTHON_LIB_NUMBER}/libs)
set(AR_PYTHON_LIB_SITEPACKAGES ${AR_HOUDINI_ROOT}/${AR_PYTHON_LIB_NUMBER}/lib/site-packages)
else()
set(AR_PYTHON_LIB_DIR ${AR_HOUDINI_ROOT}/python/lib)
set(AR_PYTHON_LIB_SITEPACKAGES ${AR_PYTHON_LIB_DIR}/${AR_PYTHON_LIB}/site-packages)
endif()
set(AR_PYTHON_INCLUDE_DIR ${AR_HOUDINI_INCLUDE_DIR}/${AR_PYTHON_LIB})
# Boost
set(AR_BOOST_NAMESPACE hboost)
set(AR_BOOST_PYTHON_LIB ${AR_BOOST_NAMESPACE}_${AR_PYTHON_LIB_NUMBER})
if (WIN32)
set(AR_BOOST_PYTHON_LIB ${AR_BOOST_NAMESPACE}_${AR_PYTHON_LIB_NUMBER}-mt-x64)
else()
set(AR_BOOST_PYTHON_LIB ${AR_BOOST_NAMESPACE}_${AR_PYTHON_LIB_NUMBER})
endif()
set(AR_BOOST_INCLUDE_DIR ${AR_HOUDINI_INCLUDE_DIR}/${AR_BOOST_NAMESPACE})

### Init ###
Expand All @@ -77,9 +96,16 @@ project(${AR_PROJECT_NAME} VERSION 1.0.0 LANGUAGES CXX)
set(BUILD_SHARED_LIBS ON)
# Preprocessor Defines (Same as #define)
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 HBOOST_ALL_NO_LIB BOOST_ALL_NO_LIB)
# This is the same as set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHBOOST_ALL_NO_LIB -D_GLIBCXX_USE_CXX11_ABI=0")
if (WIN32)
add_compile_definitions(NOMINMAX)
endif()
# Compiler Options
add_compile_options(-fPIC -Wno-deprecated -Wno-deprecated-declarations -Wno-changes-meaning) # -Zc:inline-
# This is the same as set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHBOOST_ALL_NO_LIB -D_GLIBCXX_USE_CXX11_ABI=0")
if (WIN32)
add_compile_options(/Zc:inline- /w)
else()
add_compile_options(-fPIC -Wno-deprecated -Wno-deprecated-declarations -Wno-changes-meaning)
endif()

### Packages ###
# Defaults
Expand Down Expand Up @@ -111,10 +137,9 @@ endif()
# Status
message(STATUS "--- Usd Resolver Instructions Start ---")
message(NOTICE "To use the compiled files, set the following environment variables:")
message(NOTICE "export PATH=${REPO_ROOT}/dist/${RESOLVER_NAME}/bin:${HFS}/python/bin:${PATH}")
message(NOTICE "export PATH=${REPO_ROOT}/dist/${RESOLVER_NAME}/bin:$ENV{HFS}/python/bin:${PATH}")
message(NOTICE "export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib/python:${AR_PYTHON_LIB_SITEPACKAGES}:$PYTHONPATH")
message(NOTICE "export PXR_PLUGINPATH_NAME=${CMAKE_INSTALL_PREFIX}/resources:$PXR_PLUGINPATH_NAME")
message(NOTICE "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${HFS}/python/lib:${HFS}/dsolib:$LD_LIBRARY_PATH")
message(NOTICE "To test if it worked (Only supported for the 'FileResolver'), run:\nexport ${AR_SEARCH_PATHS}=/some/search/pathA:/some/search/pathB\n${CMAKE_INSTALL_PREFIX}/bin/testResolve")
message(STATUS "--- Usd Resolver Instructions End ---\n")

message(NOTICE "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$ENV{HFS}/python/lib:$ENV{HFS}/dsolib:$LD_LIBRARY_PATH")
message(NOTICE "To test if it worked (Only supported for the 'FileResolver'), run:\nexport $ENV{AR_SEARCH_PATHS}=/some/search/pathA:/some/search/pathB\n${CMAKE_INSTALL_PREFIX}/bin/testResolve")
message(STATUS "--- Usd Resolver Instructions End ---\n")
13 changes: 13 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
REM Clear current session log
cls
REM Source setup
REM if [ ! $REPO_SOURCED ]
REM then
REM source setup.sh
REM fi
REM Clear existing build data and invoke cmake
rmdir /S /Q build
rmdir /S /Q dist
cmake . -B build -G "Visual Studio 16 2019" -A x64 -T v142
cmake --build build --clean-first --config Release
cmake --install build
41 changes: 16 additions & 25 deletions src/FileResolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist/${AR_FILERESOLVER_USD_PLUGIN_
# This is a hacky way of preprocessing the class name to a custom name.
# It is not advised to do this in a production setup! (https://stackoverflow.com/questions/20979584)
# add_compile_definitions(FileResolver=${AR_FILERESOLVER_USD_CXX_CLASS_NAME})
if (WIN32)
add_compile_definitions(AR_FILERESOLVER_EXPORTS)
endif()

### Targets ###
## Target library > FILERESOLVER ##
Expand All @@ -24,6 +27,7 @@ target_link_libraries(${AR_FILERESOLVER_TARGET_LIB}
${AR_PXR_LIB_PREFIX}vt
${AR_PXR_LIB_PREFIX}ar
${AR_PXR_LIB_PREFIX}sdf
${AR_BOOST_PYTHON_LIB}
)
# Headers
target_include_directories(${AR_FILERESOLVER_TARGET_LIB}
Expand Down Expand Up @@ -52,12 +56,14 @@ install(TARGETS ${AR_FILERESOLVER_TARGET_LIB} RUNTIME DESTINATION lib)
## Target library > FILERESOLVER Python ##
add_library(${AR_FILERESOLVER_TARGET_PYTHON}
SHARED
module.cpp
moduleDeps.cpp
resolverTokens.cpp
wrapResolver.cpp
wrapResolverContext.cpp
wrapResolverTokens.cpp
module.cpp
moduleDeps.cpp
)
add_dependencies(${AR_FILERESOLVER_TARGET_PYTHON} ${AR_FILERESOLVER_TARGET_LIB})
set_boost_namespace(${AR_FILERESOLVER_TARGET_PYTHON})
# Libs
target_link_libraries(${AR_FILERESOLVER_TARGET_PYTHON}
Expand All @@ -74,6 +80,9 @@ target_include_directories(${AR_FILERESOLVER_TARGET_PYTHON}
# Props
# Remove default "lib" prefix
set_target_properties(${AR_FILERESOLVER_TARGET_PYTHON} PROPERTIES PREFIX "")
if (WIN32)
set_target_properties(${AR_FILERESOLVER_TARGET_PYTHON} PROPERTIES SUFFIX ".pyd")
endif()
# Preprocessor Defines (Same as #define)
target_compile_definitions(${AR_FILERESOLVER_TARGET_PYTHON}
PRIVATE
Expand All @@ -87,29 +96,11 @@ target_compile_definitions(${AR_FILERESOLVER_TARGET_PYTHON}
AR_FILERESOLVER_USD_PYTHON_MODULE_FULLNAME=${AR_FILERESOLVER_USD_PYTHON_MODULE_FULLNAME}
)
# Install
install (FILES __init__.py DESTINATION lib/python/${AR_RESOLVER_USD_PYTHON_MODULE_NAME}/${AR_FILERESOLVER_USD_PYTHON_MODULE_NAME})
install (
FILES __init__.py
DESTINATION lib/python/${AR_RESOLVER_USD_PYTHON_MODULE_NAME}/${AR_FILERESOLVER_USD_PYTHON_MODULE_NAME}
)
install(
TARGETS ${AR_FILERESOLVER_TARGET_PYTHON}
DESTINATION lib/python/${AR_RESOLVER_USD_PYTHON_MODULE_NAME}/${AR_FILERESOLVER_USD_PYTHON_MODULE_NAME}
)

## Target Executable > testResolve ##
add_executable(testResolve testResolve.cpp)
# Libs
target_link_libraries(testResolve
PUBLIC
${AR_PYTHON_LIB}
${AR_BOOST_PYTHON_LIB}
${AR_PXR_LIB_PREFIX}arch
${AR_PXR_LIB_PREFIX}tf
${AR_PXR_LIB_PREFIX}gf
${AR_PXR_LIB_PREFIX}vt
${AR_PXR_LIB_PREFIX}ar
${AR_PXR_LIB_PREFIX}sdf
)
# Headers
target_include_directories(testResolve PUBLIC ${AR_PYTHON_INCLUDE_DIR} ${AR_PXR_INCLUDE_DIR})
# Props
set_target_properties(testResolve PROPERTIES PREFIX "")
# Install
install(TARGETS testResolve DESTINATION bin)
)
1 change: 1 addition & 0 deletions src/FileResolver/resolverContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DEFINE_STRING(string) CONVERT_STRING(string)

#include <iostream>
#include <vector>

#include "pxr/pxr.h"
#include "pxr/base/tf/getenv.h"
Expand Down
2 changes: 2 additions & 0 deletions src/FileResolver/resolverContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <memory>
#include <regex>
#include <string>
#include <map>

#include "pxr/pxr.h"
#include "pxr/usd/ar/defineResolverContext.h"
Expand Down Expand Up @@ -36,6 +37,7 @@ class FileResolverContext
{
public:
// Constructors
AR_FILERESOLVER_API
FileResolverContext();
AR_FILERESOLVER_API
FileResolverContext(const FileResolverContext& ctx);
Expand Down
1 change: 1 addition & 0 deletions src/FileResolver/wrapResolverTokens.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <string>
#include "boost_include_wrapper.h"
#include BOOST_INCLUDE(python/class.hpp)

Expand Down
20 changes: 14 additions & 6 deletions src/PythonResolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist/${AR_PYTHONRESOLVER_USD_PLUGI
# This is a hacky way of preprocessing the class name to a custom name.
# It is not advised to do this in a production setup! (https://stackoverflow.com/questions/20979584)
# add_compile_definitions(PythonResolver=${AR_PYTHONRESOLVER_USD_CXX_CLASS_NAME})
if (WIN32)
add_compile_definitions(AR_PYTHONRESOLVER_EXPORTS)
endif()

### Targets ###
## Target library > PYTHONRESOLVER ##
Expand All @@ -21,9 +24,9 @@ target_link_libraries(${AR_PYTHONRESOLVER_TARGET_LIB}
${AR_PXR_LIB_PREFIX}arch
${AR_PXR_LIB_PREFIX}tf
${AR_PXR_LIB_PREFIX}gf
${AR_PXR_LIB_PREFIX}js
${AR_PXR_LIB_PREFIX}vt
${AR_PXR_LIB_PREFIX}ar
${AR_BOOST_PYTHON_LIB}
)
# Headers
target_include_directories(${AR_PYTHONRESOLVER_TARGET_LIB}
Expand Down Expand Up @@ -53,12 +56,16 @@ install(TARGETS ${AR_PYTHONRESOLVER_TARGET_LIB} RUNTIME DESTINATION lib)
## Target library > PYTHONRESOLVER Python ##
add_library(${AR_PYTHONRESOLVER_TARGET_PYTHON}
SHARED
module.cpp
moduleDeps.cpp
resolverTokens.cpp
resolverContext.cpp
wrapResolver.cpp
wrapResolverContext.cpp
wrapResolverTokens.cpp
module.cpp
moduleDeps.cpp

)
add_dependencies(${AR_PYTHONRESOLVER_TARGET_PYTHON} ${AR_PYTHONRESOLVER_TARGET_LIB})
set_boost_namespace(${AR_PYTHONRESOLVER_TARGET_PYTHON})
# Libs
target_link_libraries(${AR_PYTHONRESOLVER_TARGET_PYTHON}
Expand All @@ -75,6 +82,9 @@ target_include_directories(${AR_PYTHONRESOLVER_TARGET_PYTHON}
# Props
# Remove default "lib" prefix
set_target_properties(${AR_PYTHONRESOLVER_TARGET_PYTHON} PROPERTIES PREFIX "")
if (WIN32)
set_target_properties(${AR_PYTHONRESOLVER_TARGET_PYTHON} PROPERTIES SUFFIX ".pyd")
endif()
# Preprocessor Defines (Same as #define)
target_compile_definitions(${AR_PYTHONRESOLVER_TARGET_PYTHON}
PRIVATE
Expand All @@ -100,6 +110,4 @@ install (
install(
TARGETS ${AR_PYTHONRESOLVER_TARGET_PYTHON}
DESTINATION lib/python/${AR_RESOLVER_USD_PYTHON_MODULE_NAME}/${AR_PYTHONRESOLVER_USD_PYTHON_MODULE_NAME}
)

### Status ###
)

0 comments on commit ca39d40

Please sign in to comment.