From 570517b89fb6cba80f99109ae0bad2abdd039e3e Mon Sep 17 00:00:00 2001 From: indigo Date: Sun, 24 Sep 2023 21:17:31 +0800 Subject: [PATCH] + Add build script for windows --- CMakeLists.txt | 2 +- README.md | 8 ++++ make.bat | 93 ++++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 8 ++-- 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 make.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bfe781..29d0abc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ project(CgMeshInfo) cmake_minimum_required(VERSION 3.12) -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) add_subdirectory(src) \ No newline at end of file diff --git a/README.md b/README.md index 6f12c84..2dd5538 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,12 @@ cmds.meshInfo(vtxHash=True, uvHash=True, ptHash=True, noIntermediate # Mesh info file exported : C:/Temp/mesh_info.json # ``` +## How to build in windows +### Requirement +* Visual Studio 2012 or Build Tool C++ 2012 or higher + +open command shell (**CMD**), change dir into repository directory, then run the follow command +```shell +make.bat 2020 +``` diff --git a/make.bat b/make.bat new file mode 100644 index 0000000..d1371d4 --- /dev/null +++ b/make.bat @@ -0,0 +1,93 @@ +@echo off +:: +:: Usage : +:: make.bat [maya_version] +:: +:: Example : +:: Build plugin for maya version 2020 +:: > make.bat 2020 +:: +:: ------------------------------------- +setlocal EnableDelayedExpansion + +set maya_ver=%1 +set maya_install_base=C:\aw + +if "%1" == "" ( + echo "Maya version is not specify. exit." + goto end +) + +if "%2" NEQ "" ( + set maya_install_base=%2 +) + +cd %~dp0 +set current=%cd% +set is_build_tool=0 +if not defined VisualStudioVersion ( + + echo "VisualStudioVersion is not set, setup %maya_ver% compiler..." + + if %maya_ver% LSS 2020 ( + set compiler_ver=9.0 + if %maya_ver% LEQ 2014 set compiler_ver=10.0 + if %maya_ver% GEQ 2015 set compiler_ver=11.0 + if %maya_ver% GEQ 2018 set compiler_ver=14.0 + set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio !compiler_ver!\VC\vcvarsall.bat" x86_amd64 + ) + + if %maya_ver% GEQ 2020 ( + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio 2017\WDExpress\VC\Auxiliary\Build\vcvarsall.bat" ( + set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio 2017\WDExpress\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 + set compiler_ver=15.0 + ) + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" ( + set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" + ) + ) + + set VisualStudioVersion=!compiler_ver! + + if not exist !compiler_bat! ( + echo "Can\'t find !compiler_bat!" + goto end + ) + echo !compiler_bat! + call !compiler_bat! +) + +if not defined VisualStudioVersion ( + echo "VisualStudioVersion is not set correct." + goto end +) + +IF %VisualStudioVersion% == 11.0 set vc_config=Visual Studio 11 2012 Win64 +IF %VisualStudioVersion% == 12.0 set vc_config=Visual Studio 12 2013 Win64 +IF %VisualStudioVersion% == 14.0 set vc_config=Visual Studio 14 2015 Win64 +IF %VisualStudioVersion% == 15.0 set vc_config=Visual Studio 15 2017 Win64 + +set install_dir=%current%\install + +if exist build ^ +rmdir build /S/Q + +if not exist build ^ +mkdir build + +cd build + +cmake -G "%vc_config%"^ + -DCMAKE_INSTALL_PREFIX=%install_dir%^ + -DMAYA_INSTALL_BASE_PATH="%maya_install_base%"^ + -DMAYA_VERSION=%maya_ver%^ + .. + +:build +cmake --build . --target install --config Release -- /maxcpucount:8 + +:end +cd %current% + +endlocal + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b3c7a9..c847e90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,18 +5,20 @@ set(SRC_FILES "sha1.hpp" "json.hpp") -# find_package(Maya REQUIRED) +find_package(Maya REQUIRED) add_definitions(-D_CRT_SECURE_NO_WARNINGS) include_directories( -"C:/aw/Maya2020/include" + ${MAYA_INCLUDE_DIR} ) link_directories( -"C:/aw/Maya2020/lib" + ${MAYA_LIBRARY_DIR} ) link_libraries(Foundation OpenMaya OpenMayaAnim OpenMayaUI OpenMayaFX OpenMayaRender) add_library(${PROJECT_NAME} SHARED ${SRC_FILES}) set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".mll") # Suffix + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "plug-ins/${MAYA_VERSION}")