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

How To Build 3ds Max Plug-ins using CMake

This How To explains how to generate the project files for a 3ds Max plug-in for Windows. This How To has been tested with 3ds Max 2008 built with Visual Studio 2005, and 3ds Max 2010 built with Visual Studio 2008, both in 32 and 64 bits platforms.

The sample project builds a 3ds max utility that does nothing. Download it here.

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.

/MaxPlugin/
/MaxPlugin/code

Copy to that folder all the cpp, h, def and rc files from your project (Or from the sample project).

The CMake script file. CMakeLists.txt

In the folder /MaxPlugin/code create this file:

/MaxPlugin/code/CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

PROJECT( MaxUtility )

# 3 d s   m a x

# 3ds Max 9    | MAXSDK9  | Visual Studio 8.0 | 32 Bits | 64 Bits 
# 3ds Max 2008 | MAXSDK10 | Visual Studio 8.0 | 32 Bits | 64 Bits 
# 3ds Max 2009 | MAXSDK11 | Visual Studio 8.0 | 32 Bits | 64 Bits 
# 3ds Max 2010 | MAXSDK12 | Visual Studio 9.0 | 32 Bits | 64 Bits 
# 3ds Max 2011 | MAXSDK13 | Visual Studio 9.0 | 32 Bits | 64 Bits 
                                                      
# Define the Project Name.
#  Projects that are built with the same IDE (ie. Visual Studio 2005) will be
#  added to the same Solution. For this reason all project need to have 
#  unique names.

SET ( PROJECT_NAME_MAX_6  "UtilityMax6" )
SET ( PROJECT_NAME_MAX_9  "UtilityMax9" )
SET ( PROJECT_NAME_MAX_10 "UtilityMax2008" )
SET ( PROJECT_NAME_MAX_11 "UtilityMax2008" )
SET ( PROJECT_NAME_MAX_12 "UtilityMax2010" )

# Define the header libraries for each SDK

SET ( MAXSDK6_HEADERS_DIR  "c:/Libraries/maxsdk/6/include" )
SET ( MAXSDK9_HEADERS_DIR  "c:/Libraries/maxsdk/9/include" )
SET ( MAXSDK10_HEADERS_DIR "c:/Libraries/maxsdk/10/include" )
SET ( MAXSDK11_HEADERS_DIR "c:/Libraries/maxsdk/11/include" )
SET ( MAXSDK12_HEADERS_DIR "c:/Libraries/maxsdk/12/include" )

# Define the library files for each SDK, and platform. 64 bits lib path will replace
# 32 bits lib path.

# 32 BITS 

SET ( MAXSDK6_LIBRARY_DIR  "c:/Libraries/maxsdk/6/lib" )
SET ( MAXSDK9_LIBRARY_DIR  "c:/Libraries/maxsdk/9/lib" )
SET ( MAXSDK10_LIBRARY_DIR "c:/Libraries/maxsdk/10/lib" )
SET ( MAXSDK11_LIBRARY_DIR "c:/Libraries/maxsdk/11/lib" )
SET ( MAXSDK12_LIBRARY_DIR "c:/Libraries/maxsdk/12/lib" )

SET ( PROGRAM_FILES "c:\\Program Files (x86)" )

IF ( CMAKE_CL_64 ) # 64 BITS

	SET ( MAXSDK9_LIBRARY_DIR  "c:/Libraries/maxsdk/9/x64/lib" )
	SET ( MAXSDK10_LIBRARY_DIR "c:/Libraries/maxsdk/10/x64/lib" )
	SET ( MAXSDK11_LIBRARY_DIR "c:/Libraries/maxsdk/11/x64/lib" )
	SET ( MAXSDK12_LIBRARY_DIR "c:/Libraries/maxsdk/12/x64/lib" )

	SET ( PROGRAM_FILES "c:\\Program Files" )

ENDIF ()

# Add the source files.

SET ( SOURCE_FILES
	"dll.cpp"
	"utility.cpp"
)

# Add the header files.

SET ( HEADER_FILES
	"utility.h"
)

# Add the resource and definition file.

SET ( RESOURCE_FILES
  "utility.rc"
  "utility.def"
)

# Define the max libraries.

SET( MAX_LIBS  "mnmath.lib"
			   "poly.lib"
			   "paramblk2.lib"
			   "core.lib"
			   "geom.lib"
			   "mesh.lib"
			   "maxutil.lib"
			   "bmm.lib"
			   "maxscrpt.lib"
			   "comctl32.lib"
)


IF ( MSVC80 )

	#######################################################
	# P L U G I N   F O R   3 D S M A X   9               #
	#######################################################
	
	INCLUDE_DIRECTORIES ( ${MAXSDK9_HEADERS_DIR} )
	LINK_DIRECTORIES ( ${MAXSDK9_LIBRARY_DIR} )

	ADD_LIBRARY ( ${PROJECT_NAME_MAX_9} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} )
	TARGET_LINK_LIBRARIES( ${PROJECT_NAME_MAX_9} ${MAX_LIBS} )

	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_9} PROPERTIES OUTPUT_NAME "Max9/Utility" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_9} PROPERTIES SUFFIX ".dlu" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_9} PROPERTIES CLEAN_DIRECT_OUTPUT 1 )

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

	#######################################################
	# P L U G I N   F O R   3 D S M A X   2 0 0 8         #
	#######################################################
	
	INCLUDE_DIRECTORIES ( ${MAXSDK10_HEADERS_DIR} )
	LINK_DIRECTORIES ( ${MAXSDK10_LIBRARY_DIR} )

	ADD_LIBRARY ( ${PROJECT_NAME_MAX_10} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} )
	TARGET_LINK_LIBRARIES( ${PROJECT_NAME_MAX_10} ${MAX_LIBS} )

	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_10} PROPERTIES OUTPUT_NAME "Max2008/Utility" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_10} PROPERTIES SUFFIX ".dlu" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_10} PROPERTIES CLEAN_DIRECT_OUTPUT 1 )

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

IF ( MSVC90 )

	#######################################################
	# P L U G I N   F O R   3 D S M A X   2 0 1 0         #
	#######################################################
	
	INCLUDE_DIRECTORIES ( ${MAXSDK12_HEADERS_DIR} )
	LINK_DIRECTORIES ( ${MAXSDK12_LIBRARY_DIR} )
	
	ADD_LIBRARY ( ${PROJECT_NAME_MAX_12} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} )
	TARGET_LINK_LIBRARIES( ${PROJECT_NAME_MAX_12} ${MAX_LIBS} )

	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_12} PROPERTIES OUTPUT_NAME "Max2010/Utility" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_12} PROPERTIES SUFFIX ".dlu" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_12} PROPERTIES CLEAN_DIRECT_OUTPUT 1 )	

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

	ADD_CUSTOM_COMMAND( TARGET ${PROJECT_NAME_MAX_12} POST_BUILD COMMAND copy $(ConfigurationName)\\Max2010\\Utility.dlu "${PROGRAM_FILES}\\Autodesk\\3ds Max 2010\\plugins" )

	#######################################################
	# P L U G I N   F O R   3 D S M A X   2 0 1 1         #
	#######################################################
	
	INCLUDE_DIRECTORIES ( ${MAXSDK13_HEADERS_DIR} )
	LINK_DIRECTORIES ( ${MAXSDK13_LIBRARY_DIR} )
	
	ADD_LIBRARY ( ${PROJECT_NAME_MAX_13} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} )
	TARGET_LINK_LIBRARIES( ${PROJECT_NAME_MAX_13} ${MAX_LIBS} )

	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_13} PROPERTIES OUTPUT_NAME "Max2011/Utility" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_13} PROPERTIES SUFFIX ".dlu" )
	SET_TARGET_PROPERTIES( ${PROJECT_NAME_MAX_13} PROPERTIES CLEAN_DIRECT_OUTPUT 1 )	

	SET ( LOCAL_WARNING_FLAGS /W3 )
	SET ( LOCAL_RTTI_FLAGS /GR )
	
	ADD_CUSTOM_COMMAND( TARGET ${PROJECT_NAME_MAX_13} POST_BUILD COMMAND copy $(ConfigurationName)\\Max2011\\Utility.dlu "${PROGRAM_FILES}\\Autodesk\\3ds Max 2011\\plugins" )
	
ENDIF ( MSVC90 )

Define the Source files, Header files and Resource files. Add or remove max libraries as needed. Save CMakeLists.txt.

This CMake script generates out-of-source files, so you'll need to set the build directory to a name that reminds you of the Visual Studio Version and Platform that builds the plug-in, like build_msvc80_32 or build_msvc90_62

Building for Visual Studio 2005 32 Bits

Open CMake 2.6 or higher.

Set the source code directory: /MaxPlugin/code

Set the build directory: /MaxPlugin/build_msvc80_32

Go to File > Delete Cache, to ensure that CMake flushes the last project configuration and asks for a new generator (IDE or Compiler).

Hit Configure. A 'Specify the generator for this project dialog box should be promted, select Visual Studio 8 2005 from the list.

When Configure finishes (you might need to hit is twice), hit Generate.

Open Visual Studio 2005, and load the solution \CMakeMax\build_msvc80_32\MaxUtility.sln.

If the Solution contains more than one plug-in version of max, all versions will be built.

Note: The first time I build the solution, I get an ilk error, probably because the source code of the plug-in for Max 9 and Max 2008 is the same. A second hit to Build > Build Solution returns no errors.

Building for Visual Studio 2005 64 Bits

Repeat the above steps, but set the build folder to /MaxPlugin/build_msvc80_64, and the generator to Visual Studio 8 2005 Win64. You will need to go to File > Delete Cache to get a new generator prompt on Configure.

Building for Visual Studio 2008 32 Bits

Set build folder to /MaxPlugin/build_msvc90_32 and generator to Visual Studio 9 2005.

Building for Visual Studio 2008 64 Bits

Set build folder to /MaxPlugin/build_msvc90_64 and generator to Visual Studio 9 2005 Win64.

Modifying the Project

From now on, instead of editing the Solution or Project properties, or adding files to the project, edit the CMakeLists.txt file and the changes will be applied to all versions of max.

Views