Vincent Touache - Character TD
/tutos/19_compile_devkit_plugins/content.php
data=================:ArrayCompile maya example plugins

Table of Contents

  1. Context
  2. TL;DR
  3. What you'll need
    1. Cmake
    2. Devkit
  4. Let's compile
    1. Get dat devkit
    2. Environment variables
    3. Compilation
  5. Frequent errors
    1. Project name
    2. Adding libraries



Context

Every now and then, I need to play around with Maya example plugins, from the devkit. And it's always the same problem, I have to remember how they structure them. It's not a big deal, but enough for me to make myself a reminder on how to do it (and make it public on this website, because why not ;)

TL;DR

What you'll need

Before you start compiling, you'll need a few things

Cmake

I'm not going to explain the details of Cmake here, all you need to know is that cmake is kind of a script language that helps you generate Makefiles (necessary to compile plugins) in a more flexible way, regardless of your environment. This is - as far as I know - widely used, can be fired up from command line or gui, and is dope! Since Maya is also using CMake, you'll need to download cmake on their website

Devkit

Since a few versions, the Maya plugins don't ship with Maya anymore. You will have to download the devkit from Autodesk website. Make sure you download the one specific to your installation of maya

Let's compile

Get dat devkit

Extract your devkit archive directly under your Maya2024 install file. The structure should look something like:

  path/to/your/maya/install/devkit/
  |__ devkit
      |__ README_DEVKIT_MOVED.txt
      |__ devkitBase
          |__ cmake
          |__ devkit
              |__ Alembic
              |__ animEngine
              |__ ...
              |__ plug-ins
              |__ ...
          |__ include
          |__ lib
          |__ mkspecs
          |__ Autodesk_EULA.pdf

Environment variables

Every folder comes with their own CMakeLists.txt file, which is where the instructions for CMake are.

The goal is to tell CMake: "ok, for this plugin, read the associated CMakeLists.text file to generate a "build" folder that will contain all instructions for my compilation. Once done, go ahead and compile, using the said "build" folder".

If you open a CMakeLists.txt file, you will see a line that looks like

  include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
That means CMakeLists.text needs a file named "pluginEntry.cmake". You can check directly in your devkit path, it should be here. This file is responsible for finding all the dependencies you'll need to compile (opengl, maya libs, etc)

Problem: what is $ENV{DEVKIT_LOCATION} ? In CMake language, that's how you query an environment variable. So we're gonna need to populate that env variable, to let cmake know where is our devkit (think of it as a variable, just like in python or mel, but for your operating system).

Windows

Unix (mac OS / Linux)

This is much easier than on Windows. In your ~/.bash-profile file (or ~/.zshrc file or whatever prefs file you have), you just need to add:

  export DEVKIT_LOCATION=path/to/your/devkit
Then save your file and open a new terminal. To check if it worked, you can run printenv in a new terminal window. If you want this change to be temporary, do it in your current terminal session instead of doing it in your .bashrc file

Compilation

Next step, open a command line / terminal and go to your devkit folder (cd path/to/your/devkit/plug-ins/folder-of-the-plugin-you-want-to-compile). You want to be in the same folder where the CMakeLists.text file is. For instance, ...\devkitBase\devkit\plug-ins\footPrintNode_GeometryOverride

Here, run the command

  cmake -B build
This will create all the data needed to compile, and put it under a folder named build, in the current directory.
Info If you're not sure whether you have cmake installed and valid, try cmake --help and see if it returns you something
Once cmake -B build has been launched successfully and you have that build folder, you can run
  cmake --build build
Info the first build is the argument name, the second build is because you named your folder build in the previous command.
Note that it will pick the default compiler, which may not be the one you want. I can't give you a precise answer as to which compiler you want, because it depends on your environment. If you run cmake --help, you will see a list of compilers available on your machine. The one with a * next to it is the default one. If you want to use a different one, you can do
  cmake --build -G "another compiler"
On windows, you will usually use Visual Studio 17 2022 or another flavor of visual studio (which does NOT mean you compile via Visual Studio gui, which got me confused when I was learning that!), and on mac OS I usually go with Unix Makefiles.

Once done, your plugin *.mll (windows) / *.bundle (mac os) / *.so (linux) will be created directly under your build file. Make sure to check your terminal window before you close it, as it will give you the absolute path to your compiled plugin

Voila, you have your plugin compiled

Frequent errors

Project name

If you get the following error:

  CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  
  The top-level CMakeLists.txt file must
  contain a literal, direct call to the 
  project() command.  Add a line of code 
  such as

    project(ProjectName)

  near the top of the file, 
  but after cmake_minimum_required().

  CMake is pretending there is a 
  "project(Project)" command on 
  the first line.

The cmake files provided with maya are pretty old, and CMake changed a bit in the past 10 years. Now, it requires to specify the project name using the syntax suggested by the error. So nothing really complicated here, you just need to add a line in your CMakeLists.txt, preferably close to the top of your file, with project(your_project_name). That's it.

Adding libraries

Especially when you compile custom locators or plugins which draw in the viewport, you sometimes need some external libraries like GLEW. Keep an eye on what the build step prints out to make sure it found everything. But if you're missing something, you can include the right library (provided that it's installed on your machine, of course...) using the following syntax:

list(APPEND CMAKE_PREFIX_PATH "C:/path_to/glew")