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 structure:

  1. The minimum version of CMake required.

    cmake_minimum_required(VERSION 2.8)
  2. The project name.

    set(PROJECT_NAME <projectName>)
    

    For example, the project name section of the circleNode CMakeLists.txt file looks like this:

    set(PROJECT_NAME circleNode)
  3. The path to the pluginEntry.cmake file. This line is identical in all CMakeLists.txt files.

    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
  4. A list of required resource files.

    If your project uses more than one resource file, separate each file with a space.

    set(RESOURCES_FILES myResource.xpm)
  5. If your project also requires mel files, list these in the MEL_FILES section.

    If your project uses more than one mel file, separate each file with a space:

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

    For example, the circleNode sample includes a mel file, and has this line in its CMakeLists.txt file:

    set(MEL_FILES 
        circleNode.mel)
  6. 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, the circleNode SOURCE_FILES variable is defined as follows:

    set(SOURCE_FILES
        circleNode.cpp
        ${MEL_FILES}
        )
  7. A list of required devkit libraries.

If the project needs more than one library, separate each library with a space.

Consult the C++ API reference to determine which libraries you need.

For example, `circleNode` requires only the OpenMaya and Foundation libraries:

    set(LIBRARIES
    OpenMaya Foundation
    )

A list of required 3rd party packages included using find_package() .

find_package() uses Find<PackageName>.cmake files to include packages in the build. These files are located under $DEVKIT_LOCATION/cmake/modules/ on Linux and MacOS, and under %DEVKIT_LOCATION%\cmake\modules on Windows. To add a package, call find_package(PackageName). For example, to add the Alembic package, make sure that FindAlembic.cmake exists under the modules directory, then write the following in your CMakeLists.txt file:

find_packaged(Alembic)

For convenience, the devkit includes macros for commonly-used packages. The macros are of the form find_<packageName> and are called by putting each macro for each package on its own line. For example, to add the zlib and alembic packages, you would add the following two lines to your CMakeLists.txt file:

find_zlib()
find_alembic()

Macros are available for the following packages:

If your project requires a package that is not in this list, you will need to create a cmake find script for it, then call it with the find_package() command. Use the cmake find scripts in the modules directory as a guide.

  • Finally, the build function.

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