The CMakeLists.txt File

The CMake tool is used to generate projects for your plug-ins and applications.

The CMakeLists.txt file in the plug-in or application directory contains information about the libraries, source files, and build functions needed to generated a project. It must be located at the top level of your plug-in or application directory, along with your source code and any mel scripts that will be packaged with your plug-in.

This page will walk you through the different parts of a CMakeLists.txt file.

Note: You can use the CMakeLists.txt files in the devkit samples as starting points for creating your own.

The CMakeLists.txt file has the following elements:

  1. The minimum version of CMake required

    cmake_minimum_required(VERSION 2.8)
  2. The path to the pluginEntry.cmake file. This path will be identical for all CMakeLists.txt files you use with the Maya devkit

    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    

    For example:

    cmake_minimum_required(VERSION 2.8)
    
     include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
  3. The project name

    set(PROJECT_NAME <projectName>)
    

    For example:

    cmake_minimum_required(VERSION 2.8)
    
     include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    set(PROJECT_NAME exampleNode)
  4. A list of required resource files, if needed. If your project uses more than one resource file, separate each file with a space

    ```sh cmake_minimum_required(VERSION 2.8)

    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)

    set(PROJECT_NAME exampleNode)

set(RESOURCES_FILES myResource.xpm) ```

  1. A list of mel files, if needed. If your project uses more than one mel file, separate each file with a space

    set(MEL_FILES 
        <melFileName1> <melFileName2> <melFileName3>)
    

    For example:

    cmake_minimum_required(VERSION 2.8)
    
    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    set(PROJECT_NAME exampleNode)
    
    set(RESOURCES_FILES myResource.xpm)
    
    set(MEL_FILES 
        exampleNode.mel)
  2. A list of source files, including the mel and resource files, if used. If your project uses more than one source file, separate each file with a space

    set(SOURCE_FILES
        <sourceFileName1> <sourceFileName2> <sourceFileName3>
            ${MEL_FILES}
            ${RESOURCE_FILES})
    

    For example:

    cmake_minimum_required(VERSION 2.8)
    
    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    set(PROJECT_NAME exampleNode)
    
    set(RESOURCES_FILES myResource.xpm)
    
    set(MEL_FILES 
        exampleNode.mel)
    
    set(SOURCE_FILES
            exampleNode.cpp
            ${MEL_FILES}
        )
  3. A list of required devkit libraries. Separate the list of libraries with a space

    Important: All plug-ins and applications must include the OpenMaya and Foundation libraries.

    set(LIBRARIES
        OpenMaya Foundation <additionalLibrary1> <additionalLibrary2>
        )
    

    For example:

    cmake_minimum_required(VERSION 2.8)
    
    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    set(PROJECT_NAME exampleNode)
    
    set(RESOURCES_FILES myResource.xpm)
    
    set(MEL_FILES 
        exampleNode.mel)
    
    set(SOURCE_FILES
            exampleNode.cpp
            ${MEL_FILES}
        )
    
    set(LIBRARIES
        OpenMaya Foundation
        )
  4. A list of required 3rd party packages added using the find_<package_name> macros or the find_package() call.

    find_package(MtoA)
    find_alembic()
    

    For example:

      cmake_minimum_required(VERSION 2.8)
    
     include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    set(PROJECT_NAME exampleNode)
    
    set(RESOURCES_FILES myResource.xpm)
    
    set(MEL_FILES 
        exampleNode.mel)
    
    set(SOURCE_FILES
            exampleNode.cpp
            ${MEL_FILES}
        )
    
    set(LIBRARIES
        OpenMaya Foundation
        )
    
    find_package(MtoA)
    find_alembic()
  5. Finally, the build function.

    If you are creating a plug-in, add build_plugin(). If you are creating a standalone application, add build_application().

    cmake_minimum_required(VERSION 2.8)
    
    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    set(PROJECT_NAME exampleNode)
    
    set(RESOURCES_FILES myResource.xpm)
    
    set(MEL_FILES 
        exampleNode.mel)
    
    set(SOURCE_FILES
            exampleNode.cpp
            ${MEL_FILES}
        )
    
    set(LIBRARIES
        OpenMaya Foundation
        )
    
    find_package(MtoA)
    find_alembic()
    build_plugin()