From ca39d4064579c92789c636d520f4c67006a01c45 Mon Sep 17 00:00:00 2001 From: Luca Scheller Date: Sat, 23 Sep 2023 15:20:59 +0200 Subject: [PATCH] Add windows compat imports --- .github/scripts/houdini_build.bat | 5 +++ .github/workflows/build_houdini.yml | 5 ++- CMakeLists.txt | 59 ++++++++++++++++++------- build.bat | 13 ++++++ src/FileResolver/CMakeLists.txt | 41 +++++++---------- src/FileResolver/resolverContext.cpp | 1 + src/FileResolver/resolverContext.h | 2 + src/FileResolver/wrapResolverTokens.cpp | 1 + src/PythonResolver/CMakeLists.txt | 20 ++++++--- 9 files changed, 98 insertions(+), 49 deletions(-) create mode 100644 .github/scripts/houdini_build.bat create mode 100644 build.bat diff --git a/.github/scripts/houdini_build.bat b/.github/scripts/houdini_build.bat new file mode 100644 index 0000000..983bacf --- /dev/null +++ b/.github/scripts/houdini_build.bat @@ -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 \ No newline at end of file diff --git a/.github/workflows/build_houdini.yml b/.github/workflows/build_houdini.yml index ebacd88..6960e7a 100644 --- a/.github/workflows/build_houdini.yml +++ b/.github/workflows/build_houdini.yml @@ -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 \ No newline at end of file + python3 .github/scripts/houdini.py --install + - name: Build USD File Resolver + run: | + .\.github\scripts\houdini_build.bat fileResolver \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1625418..723be07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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) @@ -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 ### @@ -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 @@ -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") \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..8746700 --- /dev/null +++ b/build.bat @@ -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 \ No newline at end of file diff --git a/src/FileResolver/CMakeLists.txt b/src/FileResolver/CMakeLists.txt index cc15425..143cd3a 100644 --- a/src/FileResolver/CMakeLists.txt +++ b/src/FileResolver/CMakeLists.txt @@ -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 ## @@ -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} @@ -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} @@ -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 @@ -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) +) \ No newline at end of file diff --git a/src/FileResolver/resolverContext.cpp b/src/FileResolver/resolverContext.cpp index ce4f19d..dfddcee 100644 --- a/src/FileResolver/resolverContext.cpp +++ b/src/FileResolver/resolverContext.cpp @@ -2,6 +2,7 @@ #define DEFINE_STRING(string) CONVERT_STRING(string) #include +#include #include "pxr/pxr.h" #include "pxr/base/tf/getenv.h" diff --git a/src/FileResolver/resolverContext.h b/src/FileResolver/resolverContext.h index 6b5f3d1..d1ca21e 100644 --- a/src/FileResolver/resolverContext.h +++ b/src/FileResolver/resolverContext.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "pxr/pxr.h" #include "pxr/usd/ar/defineResolverContext.h" @@ -36,6 +37,7 @@ class FileResolverContext { public: // Constructors + AR_FILERESOLVER_API FileResolverContext(); AR_FILERESOLVER_API FileResolverContext(const FileResolverContext& ctx); diff --git a/src/FileResolver/wrapResolverTokens.cpp b/src/FileResolver/wrapResolverTokens.cpp index 3c79b7b..6935fa1 100644 --- a/src/FileResolver/wrapResolverTokens.cpp +++ b/src/FileResolver/wrapResolverTokens.cpp @@ -1,3 +1,4 @@ +#include #include "boost_include_wrapper.h" #include BOOST_INCLUDE(python/class.hpp) diff --git a/src/PythonResolver/CMakeLists.txt b/src/PythonResolver/CMakeLists.txt index ce4189e..1a52d01 100644 --- a/src/PythonResolver/CMakeLists.txt +++ b/src/PythonResolver/CMakeLists.txt @@ -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 ## @@ -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} @@ -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} @@ -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 @@ -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 ### +) \ No newline at end of file