News Overview SceneEngine Downloads VideoTutorials Main Page SourceForge Get Involved Bookmark and Share

How To Build Maya Plug-ins using CMake

This How To explains how to generate the project files for a Maya plug-in for Windows. This How To has been tested with Maya 2010 in Windows 7 32 Bits and building the plug-in with Visual Studio 2005.

About CMake

CMake is a cross-platform system for build automation. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice. (source: Wikipedia > CMake)

Download CMake

The code folder

CMake needs to be run once for each Visual Studio Version/Platform (Visual Studio 2005 32 Bits, Visual Studio 2005 64 Bits, Visual Studio 2008 32 Bits and Visual Studio 2008 32 Bits). For each version of Visual Studio only the projects compatible with that IDE will be built.

Create a new folder and add a code sub folder on it.

/MayaPlugin/
/MayaPlugin/code

In the folder /MayaPlugin/code create these files:

/MayaPlugin/code/CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

PROJECT( CMakeMaya )

SET ( MAYA_2010_PLUGIN_NAME "CMakeMaya" )

SET ( MAYA_2010_HEADERS_DIR "C:/Program Files (x86)/Autodesk/Maya2010/include" )
SET ( MAYA_2010_LIBRARY_DIR "C:/Program Files (x86)/Autodesk/Maya2010/lib" )

SET ( SOURCE_FILES "pluginMaya.cpp" )

INCLUDE_DIRECTORIES ( ${PUBLIC_INCLUDE_DIRS} ${MAYA_2010_HEADERS_DIR} )
LINK_DIRECTORIES ( ${PUBLIC_LIBRARY_DIRS} ${MAYA_2010_LIBRARY_DIR} )

SET( LIBRARIES "Foundation.lib" "OpenMaya.lib" )

SET ( SCENG_MAYA_2010_DEFINITIONS "_AFXDLL,_MBCS,NT_PLUGIN,REQUIRE_IOSTREAM" )

# /export:initializePlugin /export:uninitializePlugin

ADD_LIBRARY ( ${MAYA_2010_PLUGIN_NAME} SHARED ${SOURCE_FILES} )
TARGET_LINK_LIBRARIES( ${MAYA_2010_PLUGIN_NAME} ${LIBRARIES} )

SET_TARGET_PROPERTIES( ${MAYA_2010_PLUGIN_NAME} PROPERTIES COMPILE_DEFINITIONS ${SCENG_MAYA_2010_DEFINITIONS} )
SET_TARGET_PROPERTIES( ${MAYA_2010_PLUGIN_NAME} PROPERTIES OUTPUT_NAME "CMakeMaya" )
SET_TARGET_PROPERTIES( ${MAYA_2010_PLUGIN_NAME} PROPERTIES SUFFIX ".mll" )
SET_TARGET_PROPERTIES( ${MAYA_2010_PLUGIN_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1 )

SET_TARGET_PROPERTIES( ${MAYA_2010_PLUGIN_NAME} PROPERTIES LINK_FLAGS "/export:initializePlugin /export:uninitializePlugin" )

SET ( LOCAL_WARNING_FLAGS /W3 )
SET ( LOCAL_RTTI_FLAGS /GR )

/MayaPlugin/code/MayaPlugin.cpp

//
// Copyright (C) You 
// 
// File: pluginMain.cpp
//
// Author: Maya Plug-in Wizard 2.0
//
 
#include <maya/MFnPlugin.h>
 
MStatus initializePlugin( MObject obj )
//
//	Description:
//		this method is called when the plug-in is loaded into Maya.  It 
//		registers all of the services that this plug-in provides with 
//		Maya.
//
//	Arguments:
//		obj - a handle to the plug-in object (use MFnPlugin to access it)
//
{ 
	MStatus   status;
	MFnPlugin plugin( obj, "CMakeMaya", "2010", "Any");
 
	// Add plug-in feature registration here
	//
 
	return status;
}
 
MStatus uninitializePlugin( MObject obj )
//
//	Description:
//		this method is called when the plug-in is unloaded from Maya. It 
//		deregisters all of the services that it was providing.
//
//	Arguments:
//		obj - a handle to the plug-in object (use MFnPlugin to access it)
//
{
	MStatus   status;
	MFnPlugin plugin( obj );
 
	// Add plug-in feature deregistration here
	//
 
	return status;
}

In CMake, set the source code directory: /MayaPlugin/code

This CMake script generates out-of-source files, so set the build directory to:

/MayaPlugin/build

or something more specific, like Visual Studio Version and Platform:

/MayaPlugin/build_msvc80_32

Hit Configure and then Generate.

In Visual Studio open the CMakeMaya project located in /MayaPlugin/build_msvc80_32 and build it.

Views