Building with CMake

The CMake tool is used to both to generate projects for your plug-ins and applications, and to build the plug-ins and applications from the projects it generated.

Projects are generated by calling a CMake Generator. A CMakeLists.txt file in the plug-in or application directory provides information about the libraries, files, and source needed to generate the project.

Projects are generated using

cmake -H. -B<build_directory> -G <generator>

For example:

Type of project cmake command
Visual Studio cmake -H. -Bbuild -G "Visual Studio 17 2022"
Xcode cmake -H. -Bbuild -G Xcode
Makefile for macOS or Linux cmake -H. -Bbuild -G "Unix Makefiles"

On Macs with an Apple Silicon chip, the target architecture will be arm64 by default. Similarly, on Macs with Intel chips, the target architecture will be Intel x86_64 by default.

You can optionally choose to build for both architectures using the CMAKE_OSX_ARCHITECTURES option.

For example:

Project type cmake command
Xcode cmake -H. -Bbuild -G Xcode -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
Makefile cmake -H. -Bbuild -G "Unix Makefiles" -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
Note:

Only one project is generated when you build for both arm64 and Intel x86_64.

The -B flag is used to specify the project file target directory.

For example, to generate an Xcode project in the project directory, use

cmake -H. -Bproject -G Xcode

After your project is generated, you can open the project in an IDE and build it from there, or you can use CMake with the --build option to build the plug-in or application

cmake --build <build_directory>

For example, if you generated the project to the project directory, use

cmake --build project/

Your built application or plug-in will be located in the top level of your build directory if you generated your project using Unix Makefiles. If you used the Xcode or Visual Studio 16 2019 Win64 generator, your plug-in or application will be located under the build directory's Debug subdirectory.

Note:

Plug-ins built on different platforms will have different extensions. Plug-ins built on Windows will have the mll extension. Plug-ins built on Linux will have the so extension. Plug-ins built on macOS will have the bundle extension.

Standalone applications are run directly from the command line or from Windows Explorer.

If you set MAYA_PLUG_IN_PATH path in Maya.env as described in Setting up your build environment, you can copy your plug-in to the MAYA_PLUG_IN_PATH and it will be loaded automatically into Maya. You can also choose to not place your plug-in in MAYA_PLUG_IN_PATH and instead load it manually.

Important:

Do not rebuild a plug-in that is already loaded into Maya. Unload the plug-in before you rebuild it.