From 2ea40370a40ad7420bc98f057155ff127f00b983 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Mon, 9 Sep 2024 15:48:13 -0700 Subject: [PATCH] move to meson --- .github/workflows/main.yml | 104 +++++++++++++++++++++++++++ CMakeLists.txt | 29 -------- mayaConfigure.bat | 19 ----- meson.build | 37 ++++++++++ modules/FindMaya.cmake | 127 --------------------------------- quick_compile.bat | 25 +++++++ src/pluginMain.cpp | 3 +- src/version.h.in | 3 + subprojects/maya/meson.build | 107 +++++++++++++++++++++++++++ subprojects/maya/meson.options | 30 ++++++++ 10 files changed, 308 insertions(+), 176 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 CMakeLists.txt delete mode 100644 mayaConfigure.bat create mode 100644 meson.build delete mode 100644 modules/FindMaya.cmake create mode 100644 quick_compile.bat create mode 100644 src/version.h.in create mode 100644 subprojects/maya/meson.build create mode 100644 subprojects/maya/meson.options diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6e51d55 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,104 @@ + +name: build + +on: + push: + branches: [ master ] + tags: + - v* + pull_request: + branches: [ master ] + +# matrix: +# maya: [2024] +# os: [macos-latest, ubuntu-latest, windows-latest] +# include: +# - maya: 2024 +# update: 2 + +jobs: + compile_plugin: + strategy: + matrix: + maya: [2022, 2023, 2024, 2025] + os: [macos-13, macos-latest, ubuntu-latest, windows-latest] + include: + # Add the maya update versions here + - maya: 2022 + update: 5 + - maya: 2023 + update: 3 + - maya: 2024 + update: 2 + - maya: 2025 + update: 1 + + # cross-compiling is annoying so just fall back to macos-13 + exclude: + - os: macos-latest + maya: 2022 + - os: macos-latest + maya: 2023 + - os: macos-13 + maya: 2024 + - os: macos-13 + maya: 2025 + + fail-fast: false + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - run: git fetch --force --tags origin + + - name: Get Maya Devkit + id: get-devkit + uses: blurstudio/mayaModuleActions/getMayaDevkit@v1 + with: + maya: ${{ matrix.maya }} + update: ${{ matrix.update }} + + - name: Build + uses: blurstudio/mayaModuleActions/mesonBuild@v1 + with: + setup-args: > + -Dmaya:maya_version=${{ matrix.maya }} + -Dmaya:maya_devkit_base=${{ steps.get-devkit.outputs.devkit-path }} + --buildtype release + --backend ninja + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ runner.os }}-${{ matrix.maya }}-plugin + path: build/*.${{ steps.get-devkit.outputs.plugin-ext }} + if-no-files-found: error + + upload_release: + name: Upload release + needs: compile_plugin + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: git fetch --force --tags origin + - name: 'Get Previous tag' + id: previoustag + uses: "WyriHaximus/github-action-get-previous-tag@v1" + with: + fallback: 0.0.1 + + - name: Package + uses: blurstudio/mayaModuleActions/packageMayaModule@v1 + with: + module-name: blurNoise + folder-list: scripts icons + version: ${{ steps.previoustag.outputs.tag }} + + - name: Upload distribution + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + uses: softprops/action-gh-release@v1 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false + files: | + *.zip diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index cf68d57..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -cmake_minimum_required(VERSION 2.6) - -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/modules) - -project(blurNoise) -set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) -find_package(Maya REQUIRED) -find_package(OpenGL REQUIRED) -find_package(OpenMP REQUIRED) -set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../output/maya/${MAYA_VERSION}/blur) - - -set(SOURCE_FILES - "src/blurNoise.h" - "src/blurNoise.cpp" - "src/pluginMain.cpp" - "src/pluginMain.cpp" - "src/OpenSimplex2F.h" - "src/OpenSimplex2F.cpp" -) - -include_directories(${MAYA_INCLUDE_DIR}) -link_directories(${MAYA_LIBRARY_DIR}) -add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} ${MAYA_LIBRARIES} ${OPENGL_LIBRARY} ${OpenMP_CXX_LIBRARIES}) - -MAYA_PLUGIN(${PROJECT_NAME}) -install(TARGETS ${PROJECT_NAME} ${MAYA_TARGET_TYPE} DESTINATION plug-ins) - diff --git a/mayaConfigure.bat b/mayaConfigure.bat deleted file mode 100644 index 7ce088b..0000000 --- a/mayaConfigure.bat +++ /dev/null @@ -1,19 +0,0 @@ -setlocal - -SET MAYA_VERSION=2020 -SET BUILD=mayabuild_%MAYA_VERSION% -SET COMPILER=Visual Studio 15 2017 Win64 - -SET PFX=%~dp0 -cd %PFX% -rmdir %BUILD% /s /q -mkdir %BUILD% -cd %BUILD% - -cmake ^ - -DMAYA_VERSION=%MAYA_VERSION% ^ - -G "%COMPILER%" ..\ - -REM cmake --build . --config Debug --target INSTALL - -pause diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..6fc9add --- /dev/null +++ b/meson.build @@ -0,0 +1,37 @@ +project('blurNoise', 'cpp', default_options: ['cpp_std=c++20']) + +fs = import('fs') +maya_dep = dependency('maya') +maya_name_suffix = maya_dep.get_variable('name_suffix') +maya_version = maya_dep.get_variable('maya_version') + +if fs.is_file('src/version.h') + message('Using existing version.h') + version_h = 'src/version.h' +else + git = find_program('git', native: true, required: true) + version_h = vcs_tag( + command: [git, 'describe', '--tags', '--match', 'v[0-9]*', '--dirty=+'], + fallback: 'v0.0.1', + input: 'src/version.h.in', + output: 'version.h', + ) +endif + +source_files = files([ + 'src/OpenSimplex2F.cpp', + 'src/blurNoise.cpp', + 'src/pluginMain.cpp', +]) + +outlib = shared_library( + meson.project_name(), + source_files + version_h, + install: true, + install_dir : meson.global_source_root() / 'output_Maya' + maya_version, + include_directories : include_directories(['src']), + dependencies : maya_dep, + name_prefix : '', + name_suffix : maya_name_suffix, +) + diff --git a/modules/FindMaya.cmake b/modules/FindMaya.cmake deleted file mode 100644 index 77e4016..0000000 --- a/modules/FindMaya.cmake +++ /dev/null @@ -1,127 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2015 Chad Vernon -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -# - Maya finder module -# -# Variables that will be defined: -# MAYA_FOUND Defined if a Maya installation has been detected -# MAYA_EXECUTABLE Path to Maya's executable -# MAYA__FOUND Defined if has been found -# MAYA__LIBRARY Path to library -# MAYA_INCLUDE_DIR Path to the devkit's include directories -# MAYA_LIBRARIES All the Maya libraries -# - -# Set a default Maya version if not specified -if(NOT DEFINED MAYA_VERSION) - set(MAYA_VERSION 2016 CACHE STRING "Maya version") -endif() - -# OS Specific environment setup -set(MAYA_COMPILE_DEFINITIONS "REQUIRE_IOSTREAM;_BOOL") -set(MAYA_INSTALL_BASE_SUFFIX "") -set(MAYA_INC_SUFFIX "include") -set(MAYA_LIB_SUFFIX "lib") -set(MAYA_BIN_SUFFIX "bin") -set(MAYA_TARGET_TYPE LIBRARY) -if(WIN32) - # Windows - set(MAYA_INSTALL_BASE_DEFAULT "C:/Program Files/Autodesk") - set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};NT_PLUGIN") - set(OPENMAYA OpenMaya.lib) - set(MAYA_PLUGIN_EXTENSION ".mll") - set(MAYA_TARGET_TYPE RUNTIME) -elseif(APPLE) - # Apple - set(MAYA_INSTALL_BASE_DEFAULT /Applications/Autodesk) - set(MAYA_INC_SUFFIX "devkit/include") - set(MAYA_LIB_SUFFIX "Maya.app/Contents/MacOS") - set(MAYA_BIN_SUFFIX "Maya.app/Contents/bin/") - set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};OSMac_") - set(OPENMAYA libOpenMaya.dylib) - set(MAYA_PLUGIN_EXTENSION ".bundle") -else() - # Linux - set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};LINUX") - set(MAYA_INSTALL_BASE_DEFAULT /usr/autodesk) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") - if(MAYA_VERSION LESS 2016) - SET(MAYA_INSTALL_BASE_SUFFIX -x64) - endif() - set(OPENMAYA libOpenMaya.so) - set(MAYA_PLUGIN_EXTENSION ".so") -endif() - -set(MAYA_INSTALL_BASE_PATH ${MAYA_INSTALL_BASE_DEFAULT} CACHE STRING - "Root path containing your maya installations, e.g. /usr/autodesk or /Applications/Autodesk/") - -set(MAYA_LOCATION ${MAYA_INSTALL_BASE_PATH}/Maya${MAYA_VERSION}${MAYA_INSTALL_BASE_SUFFIX}) - -# Maya library directory -find_path(MAYA_LIBRARY_DIR ${OPENMAYA} - PATHS - ${MAYA_LOCATION} - $ENV{MAYA_LOCATION} - PATH_SUFFIXES - "${MAYA_LIB_SUFFIX}/" - DOC "Maya library path" -) - -# Maya include directory -find_path(MAYA_INCLUDE_DIR maya/MFn.h - PATHS - ${MAYA_LOCATION} - $ENV{MAYA_LOCATION} - PATH_SUFFIXES - "${MAYA_INC_SUFFIX}/" - DOC "Maya include path" -) - -# Maya libraries -set(_MAYA_LIBRARIES OpenMaya OpenMayaAnim OpenMayaFX OpenMayaRender OpenMayaUI Foundation clew) -foreach(MAYA_LIB ${_MAYA_LIBRARIES}) - find_library(MAYA_${MAYA_LIB}_LIBRARY NAMES ${MAYA_LIB} PATHS ${MAYA_LIBRARY_DIR} - NO_DEFAULT_PATH) - if (MAYA_${MAYA_LIB}_LIBRARY) - set(MAYA_LIBRARIES ${MAYA_LIBRARIES} ${MAYA_${MAYA_LIB}_LIBRARY}) - endif() -endforeach() - -if (APPLE AND ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - # Clang and Maya needs to use libstdc++ - set(MAYA_CXX_FLAGS "-std=c++0x -stdlib=libstdc++") -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Maya DEFAULT_MSG MAYA_INCLUDE_DIR MAYA_LIBRARIES) - -function(MAYA_PLUGIN _target) - if (WIN32) - set_target_properties(${_target} PROPERTIES - LINK_FLAGS "/export:initializePlugin /export:uninitializePlugin" - ) - endif() - set_target_properties(${_target} PROPERTIES - COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS}" - PREFIX "" - SUFFIX ${MAYA_PLUGIN_EXTENSION}) -endfunction() diff --git a/quick_compile.bat b/quick_compile.bat new file mode 100644 index 0000000..77eb18e --- /dev/null +++ b/quick_compile.bat @@ -0,0 +1,25 @@ +setlocal + +SET MAYA_VERSION=2024 +REM "vs" "ninja" +REM use VS for the debugger, otherwise use NINJA +REM Until I figure out how to debug using nvim +SET BACKEND=vs +REM "debug" "debugoptimized" "release" +SET BUILDTYPE=debug +SET BUILDDIR=mayabuild_%BUILDTYPE%_%MAYA_VERSION%_%BACKEND% + +if not exist %BUILDDIR%\ ( + meson setup %BUILDDIR% ^ + -Dmaya:maya_version=%MAYA_VERSION% ^ + -Dmaya:maya_link_qt=true ^ + --buildtype %BUILDTYPE% ^ + --backend %BACKEND% --vsenv +) + +if exist %BUILDDIR%\ ( + meson compile -C %BUILDDIR% + meson install -C %BUILDDIR% +) + +pause diff --git a/src/pluginMain.cpp b/src/pluginMain.cpp index e14d1ac..b977a66 100644 --- a/src/pluginMain.cpp +++ b/src/pluginMain.cpp @@ -1,10 +1,11 @@ #include #include #include "blurNoise.h" +#include "version.h" MStatus initializePlugin(MObject obj) { MStatus result; - MFnPlugin plugin(obj, "Blur Studio", "1.0", "Any"); + MFnPlugin plugin(obj, "Blur Studio", VERSION_STRING, "Any"); result = plugin.registerNode( DEFORMER_NAME, blurNoise::id, diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..b7f88a8 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,3 @@ +#pragma once +#define VERSION_STRING "@VCS_TAG@" + diff --git a/subprojects/maya/meson.build b/subprojects/maya/meson.build new file mode 100644 index 0000000..43caa6f --- /dev/null +++ b/subprojects/maya/meson.build @@ -0,0 +1,107 @@ +project('maya', 'cpp') + +maya_version = get_option('maya_version') +maya_devkit_base = get_option('maya_devkit_base') +maya_link_qt = get_option('maya_link_qt') +maya_qt_extra_includes = get_option('maya_qt_extra_includes') + +os_name = build_machine.system() + +maya_inc_suffix = 'include' +maya_lib_suffix = 'lib' + +maya_compile_args = ['-DREQUIRE_IOSTREAM', '-D_BOOL'] +maya_link_args = [] + +if os_name == 'windows' + maya_install_base = 'c:/Program Files/Autodesk' + maya_plugin_ext = 'mll' + maya_compile_args += ['-DNT_PLUGIN'] + maya_link_args = ['/export:initializePlugin', '/export:uninitializePlugin'] +elif os_name == 'darwin' + maya_install_base = '/Applications/Autodesk' + maya_plugin_ext = 'bundle' + if maya_devkit_base == '' + maya_lib_suffix = 'Maya.app/Contents/MacOS' + maya_bin_suffix = 'Maya.app/Contents/bin' + endif + maya_compile_args += ['-DOSMac_'] + if meson.get_compiler('cpp').get_id() == 'clang' + maya_compile_args += ['--std', 'c++17', '--stdlib', 'libc++'] + maya_compile_args += ['-arch', 'x86_64'] + maya_link_args += ['-arch', 'x86_64'] + if maya_version.version_compare('>=2024') + # build both the arm and x86 plugins when compiling for mac + maya_compile_args += ['-arch', 'arm64'] + maya_link_args += ['-arch', 'arm64'] + else + endif + endif + + # ignore this warning that comes from maya's headers + maya_compile_args += ['-Wno-inconsistent-missing-override'] +elif os_name == 'linux' + maya_install_base = '/usr/autodesk' + maya_plugin_ext = 'so' + maya_compile_args += ['-DLINUX', '-fPIC'] +else + error('Incompatible operating system') +endif +maya_install_path = maya_install_base / ('Maya' + maya_version) + +if maya_devkit_base != '' + message('Using Maya Devkit:', maya_devkit_base) + maya_install_path = maya_devkit_base +endif + +maya_inc_dir = maya_install_path / maya_inc_suffix +message('Searching Maya Include directory:', maya_inc_dir) +maya_inc = include_directories(maya_inc_dir) + +maya_lib_dir = maya_install_path / maya_lib_suffix +message('Searching Maya lib directory:', maya_lib_dir) + +# Get all the maya libraries +cmplr = meson.get_compiler('cpp') +maya_libs = [ + cmplr.find_library('Foundation', dirs : maya_lib_dir), + cmplr.find_library('OpenMaya', dirs : maya_lib_dir), + cmplr.find_library('OpenMayaAnim', dirs : maya_lib_dir), + cmplr.find_library('OpenMayaFX', dirs : maya_lib_dir), + cmplr.find_library('OpenMayaRender', dirs : maya_lib_dir), + cmplr.find_library('OpenMayaUI', dirs : maya_lib_dir), + cmplr.find_library('clew', dirs : maya_lib_dir), +] + +# Link to maya's qt libs if required +# This doesn't do MOC stuff ... yet +if maya_link_qt + fs = import('fs') + if not fs.is_dir(maya_inc_dir / 'QtCore') + error( + 'Could not find Maya QT headers with `maya_link_qt` defined\n', + 'You probably need to unzip `include/qt_*-include.zip`\n', + 'Checking in folder: ', maya_inc_dir, + ) + endif + + maya_qt_lib_names = ['Qt5Core', 'Qt5Gui', 'Qt5Widgets'] + if maya_qt_extra_includes != '' + maya_qt_lib_names += maya_qt_extra_includes.split(';') + endif + + foreach lib_name : maya_qt_lib_names + maya_libs += cmplr.find_library(lib_name, dirs : maya_lib_dir) + endforeach +endif + +maya_dep = declare_dependency( + dependencies : maya_libs, + include_directories : maya_inc, + variables : {'name_suffix' : maya_plugin_ext, 'maya_version' : maya_version}, + compile_args : maya_compile_args, + link_args : maya_link_args, + +) + +meson.override_dependency('maya', maya_dep) diff --git a/subprojects/maya/meson.options b/subprojects/maya/meson.options new file mode 100644 index 0000000..c28e358 --- /dev/null +++ b/subprojects/maya/meson.options @@ -0,0 +1,30 @@ +option( + 'maya_version', + type : 'string', + value : '2024', + description : 'The version of Maya to compile for', + yield : true, +) + +option( + 'maya_devkit_base', + type : 'string', + description : 'Optional path to the maya devkit', + yield : true, +) + +option( + 'maya_link_qt', + type : 'boolean', + description : 'Whether to link to the Qt libraries that maya provides in their devkit/install', + value: false, + yield : true, +) + +option( + 'maya_qt_extra_includes', + type : 'string', + description : 'Any qt headers other than QtCore, QtGui, or QtWidgets that you need to include, separated by semicolons', + value: '', + yield : true, +)