ValidShape/cmake/modules/FindMaya.cmake

184 lines
4.9 KiB
CMake

# FindMaya.cmake - CMake module for finding Autodesk Maya SDK
# This module provides functions to find Maya include directories and libraries
#[=======================================================================[
FindMaya
--------
This module finds the Maya SDK installation and provides variables
and functions for building Maya plugins.
Imported Targets
^^^^^^^^^^^^^^^^
This module does not define any library targets.
Result Variables
^^^^^^^^^^^^^^^
This module defines the following variables:
::
MAYA_FOUND - True if Maya SDK was found
MAYA_INCLUDE_DIR - Maya include directories
MAYA_LIBRARIES - Maya libraries to link against
MAYA_VERSION - The version of Maya found (e.g., 2023)
MAYA_LOCATION - The root Maya installation directory
MAYA_BIN_DIR - Maya bin directory
MAYA_LIB_DIR - Maya lib directory
MAYA_PLUGINS_DIR - Maya plugins directory
Hints
^^^^^
The user may set the following variables to help this module find what
they want:
::
MAYA_VERSION - Specify a specific Maya version to search for
(e.g., 2022, 2023, 2024, 2025, 2026)
MAYA_LOCATION - Specify the root Maya installation directory
(e.g., C:/Program Files/Autodesk/Maya2023)
#]=======================================================================]
# Check if already found
if(MAYA_FOUND AND MAYA_INCLUDE_DIR)
return()
endif()
# Default Maya version if not specified
if(NOT DEFINED MAYA_VERSION)
set(MAYA_VERSION 2023)
endif()
# List of supported Maya versions
set(_MAYA_SUPPORTED_VERSIONS "2026;2025;2024;2023;2022")
# Check if the specified Maya version is supported
if(NOT MAYA_VERSION IN_LIST _MAYA_SUPPORTED_VERSIONS)
message(WARNING "Maya version ${MAYA_VERSION} is not in the supported list: ${_MAYA_SUPPORTED_VERSIONS}")
endif()
# Search paths
set(_MAYA_SEARCH_PATHS)
# Add user-specified MAYA_LOCATION
if(MAYA_LOCATION)
list(APPEND _MAYA_SEARCH_PATHS "${MAYA_LOCATION}")
endif()
if(ENV{MAYA_LOCATION})
list(APPEND _MAYA_SEARCH_PATHS "$ENV{MAYA_LOCATION}")
endif()
message(STATUS ${_MAYA_SEARCH_PATHS})
# Add environment variable paths
foreach(_env_var IN ITEMS MAYA_LOCATION MAYA_SDK_DIR MAYA_SDK_ROOT)
if(NOT "${${_env_var}}" STREQUAL "")
list(APPEND _MAYA_SEARCH_PATHS "${${_env_var}}")
endif()
endforeach()
# Add Program Files paths for all supported versions
#foreach(_version IN ITEMS 2026 2025 2024 2023 2022)
# list(APPEND _MAYA_SEARCH_PATHS "C:/Program Files/Autodesk/Maya${_version}")
#endforeach()
# Find Maya include directory
find_path(MAYA_INCLUDE_DIR
NAMES maya/MFn.h mapi_ui_control.h
HINTS ${_MAYA_SEARCH_PATHS}
PATH_SUFFIXES include
)
# Find Maya library directory
find_path(MAYA_LIB_DIR
NAMES OpenMaya.lib
HINTS ${_MAYA_SEARCH_PATHS}
PATH_SUFFIXES lib
)
# Find Maya bin directory
find_path(MAYA_BIN_DIR
NAMES maya.exe
HINTS ${_MAYA_SEARCH_PATHS}
PATH_SUFFIXES bin
)
# Extract Maya version from include path if not specified
if(MAYA_INCLUDE_DIR AND NOT MAYA_VERSION)
foreach(_version IN ITEMS 2026 2025 2024 2023 2022)
if(MAYA_INCLUDE_DIR MATCHES "Maya${_version}")
set(MAYA_VERSION ${_version})
break()
endif()
endforeach()
endif()
# Find Maya libraries
set(_MAYA_REQUIRED_LIBS
OpenMaya
Foundation
)
set(_MAYA_OPTIONAL_LIBS
OpenMayaUI
OpenMayaAnim
OpenMayaRender
)
set(MAYA_LIBRARIES)
foreach(_lib IN ITEMS ${_MAYA_REQUIRED_LIBS})
find_library(_MAYA_LIB_${_lib}
NAMES "${_lib}.lib"
HINTS ${MAYA_LIB_DIR}
NO_DEFAULT_PATH
)
if(_MAYA_LIB_${_lib})
list(APPEND MAYA_LIBRARIES "${_MAYA_LIB_${_lib}}")
else()
message(FATAL_ERROR "Could not find required Maya library: ${_lib}.lib")
endif()
endforeach()
foreach(_lib IN ITEMS ${_MAYA_OPTIONAL_LIBS})
find_library(_MAYA_LIB_${_lib}
NAMES "${_lib}.lib"
HINTS ${MAYA_LIB_DIR}
NO_DEFAULT_PATH
)
if(_MAYA_LIB_${_lib})
list(APPEND MAYA_LIBRARIES "${_MAYA_LIB_${_lib}}")
endif()
endforeach()
# Get Maya root directory from include path
get_filename_component(MAYA_LOCATION "${MAYA_INCLUDE_DIR}" DIRECTORY)
get_filename_component(MAYA_LOCATION "${MAYA_LOCATION}" DIRECTORY)
# Set plugins directory
set(MAYA_PLUGINS_DIR "${MAYA_LOCATION}/plug-ins")
# Handle success/failure
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Maya
REQUIRED_VARS
MAYA_INCLUDE_DIR
MAYA_LIB_DIR
MAYA_LIBRARIES
VERSION_VAR MAYA_VERSION
)
# Print configuration info
if(MAYA_FOUND)
message(STATUS "Maya SDK found:")
message(STATUS " Version: ${MAYA_VERSION}")
message(STATUS " Location: ${MAYA_LOCATION}")
message(STATUS " Include: ${MAYA_INCLUDE_DIR}")
message(STATUS " Library: ${MAYA_LIB_DIR}")
endif()
# Mark as found
mark_as_advanced(MAYA_INCLUDE_DIR MAYA_LIB_DIR MAYA_BIN_DIR)