Tuesday, March 14, 2017

Maya C++ Plugin Environment on Mac OSX

This is just a quick guide for all the Mac users out there that are trying to build Maya plugins in C++.

I learned a lot about CMake and compiling for maya from Chad Vernon's series, if you have a bit of time on your hands, I definitely recommend going through this as it will be very detailed.

For this example I also used Chad Vernon's BlendNode that he was so nice to share.

What we want to end up with basically being able to press Ctrl+B in Sublime Text and having the plugin built and copied into the maya folder so all we have to do is fire it up in maya.

The first thing is to install cmake. Once you have done that, you need to create a good file structure.

Mine looks like this

    • __MODULES
      • build (folder where the binaries will end up after compiling)
      • __MAKE.sh (the file to run for building the makefile) 
      • __BUILD.sh (the file we use to compile the plugin and copy to the maya dir)
      • CMakeLists.txt (cmake settings file)
      • src (the folder containing our .cpp and .h files
        • plugin.cpp
        • plugin.h
        • CMakeLists.txt (more cmake settings)
      • etc...

Download the FindMaya.cmake file and place it in the right folder. Next up we place the .cpp and .h in the src subdirectory. Once we have that in place, lets create the CMakeLists.txt.

The CMakeList in the root directory of the project will look like this:
The one in the subdirectory "src" will look like this. Just be sure to change the filenames in the first two lines to yours

Ok now we add the two bash scripts:

You can now double click __MAKE.sh which will create the build for you and will hopefully look like this.

You can now compile by double clicking __BUILD.sh or you can setup a simple build script for SublimeText.

In Sublime go to Tools -> Build System and New Build System.
This will open a new file. The build command we will create will basically just walk up one folder from where its run and run the __BUILD.sh.

Paste this into the file, save it and close it

Great, now simply go to your .cpp file in sublime and hit ctrl+B, it should compile and copy the plugin into your maya directory.

GG! Now fire up maya and load the plugin!

1 comment: