|
| 1 | +# Copyright 2017 Chad Vernon |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| 4 | +# associated documentation files (the "Software"), to deal in the Software without restriction, |
| 5 | +# including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 6 | +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 7 | +# furnished to do so, subject to the following conditions: |
| 8 | +# |
| 9 | +# The above copyright notice and this permission notice shall be included in all copies or |
| 10 | +# substantial portions of the Software. |
| 11 | +# |
| 12 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| 13 | +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 14 | +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 15 | +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 16 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 17 | + |
| 18 | +#.rst: |
| 19 | +# FindMaya |
| 20 | +# -------- |
| 21 | +# |
| 22 | +# Find Maya headers and libraries. |
| 23 | +# |
| 24 | +# Imported targets |
| 25 | +# ^^^^^^^^^^^^^^^^ |
| 26 | +# |
| 27 | +# This module defines the following :prop_tgt:`IMPORTED` target: |
| 28 | +# |
| 29 | +# ``Maya::Maya`` |
| 30 | +# The Maya libraries, if found. |
| 31 | +# |
| 32 | +# Result variables |
| 33 | +# ^^^^^^^^^^^^^^^^ |
| 34 | +# |
| 35 | +# This module will set the following variables in your project: |
| 36 | +# |
| 37 | +# ``Maya_FOUND`` |
| 38 | +# Defined if a Maya installation has been detected |
| 39 | +# ``MAYA_INCLUDE_DIR`` |
| 40 | +# Where to find the headers (maya/MFn.h) |
| 41 | +# ``MAYA_LIBRARIES`` |
| 42 | +# All the Maya libraries. |
| 43 | +# |
| 44 | + |
| 45 | +# Set a default Maya version if not specified |
| 46 | +if(NOT DEFINED MAYA_VERSION) |
| 47 | + set(MAYA_VERSION 2018 CACHE STRING "Maya version") |
| 48 | +endif() |
| 49 | + |
| 50 | +# OS Specific environment setup |
| 51 | +set(MAYA_COMPILE_DEFINITIONS "REQUIRE_IOSTREAM;_BOOL") |
| 52 | +set(MAYA_INSTALL_BASE_SUFFIX "") |
| 53 | +set(MAYA_TARGET_TYPE LIBRARY) |
| 54 | +if(WIN32) |
| 55 | + # Windows |
| 56 | + set(MAYA_INSTALL_BASE_DEFAULT "C:/Program Files/Autodesk") |
| 57 | + set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};NT_PLUGIN") |
| 58 | + set(MAYA_PLUGIN_EXTENSION ".mll") |
| 59 | + set(MAYA_TARGET_TYPE RUNTIME) |
| 60 | +elseif(APPLE) |
| 61 | + # Apple |
| 62 | + set(MAYA_INSTALL_BASE_DEFAULT /Applications/Autodesk) |
| 63 | + set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};OSMac_") |
| 64 | + set(MAYA_PLUGIN_EXTENSION ".bundle") |
| 65 | +else() |
| 66 | + # Linux |
| 67 | + set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};LINUX") |
| 68 | + set(MAYA_INSTALL_BASE_DEFAULT /usr/autodesk) |
| 69 | + if(MAYA_VERSION LESS 2016) |
| 70 | + # Pre Maya 2016 on Linux |
| 71 | + set(MAYA_INSTALL_BASE_SUFFIX -x64) |
| 72 | + endif() |
| 73 | + set(MAYA_PLUGIN_EXTENSION ".so") |
| 74 | +endif() |
| 75 | + |
| 76 | +set(MAYA_INSTALL_BASE_PATH ${MAYA_INSTALL_BASE_DEFAULT} CACHE STRING |
| 77 | + "Root path containing your maya installations, e.g. /usr/autodesk or /Applications/Autodesk/") |
| 78 | + |
| 79 | +set(MAYA_LOCATION ${MAYA_INSTALL_BASE_PATH}/maya${MAYA_VERSION}${MAYA_INSTALL_BASE_SUFFIX}) |
| 80 | + |
| 81 | +# Maya include directory |
| 82 | +find_path(MAYA_INCLUDE_DIR maya/MFn.h |
| 83 | + PATHS |
| 84 | + ${MAYA_LOCATION} |
| 85 | + $ENV{MAYA_LOCATION} |
| 86 | + PATH_SUFFIXES |
| 87 | + "include/" |
| 88 | + "devkit/include/" |
| 89 | +) |
| 90 | + |
| 91 | +find_library(MAYA_LIBRARY |
| 92 | + NAMES |
| 93 | + OpenMaya |
| 94 | + PATHS |
| 95 | + ${MAYA_LOCATION} |
| 96 | + $ENV{MAYA_LOCATION} |
| 97 | + PATH_SUFFIXES |
| 98 | + "lib/" |
| 99 | + "Maya.app/Contents/MacOS/" |
| 100 | + NO_DEFAULT_PATH |
| 101 | +) |
| 102 | +set(MAYA_LIBRARIES "${MAYA_LIBRARY}") |
| 103 | + |
| 104 | +include(FindPackageHandleStandardArgs) |
| 105 | +find_package_handle_standard_args(Maya |
| 106 | + REQUIRED_VARS MAYA_INCLUDE_DIR MAYA_LIBRARY) |
| 107 | +mark_as_advanced(MAYA_INCLUDE_DIR MAYA_LIBRARY) |
| 108 | + |
| 109 | +if (NOT TARGET Maya::Maya) |
| 110 | + add_library(Maya::Maya UNKNOWN IMPORTED) |
| 111 | + set_target_properties(Maya::Maya PROPERTIES |
| 112 | + INTERFACE_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS}" |
| 113 | + INTERFACE_INCLUDE_DIRECTORIES "${MAYA_INCLUDE_DIR}" |
| 114 | + IMPORTED_LOCATION "${MAYA_LIBRARY}") |
| 115 | + |
| 116 | + if (APPLE AND ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND MAYA_VERSION LESS 2017) |
| 117 | + # Clang and Maya 2016 and older needs to use libstdc++ |
| 118 | + set_target_properties(Maya::Maya PROPERTIES |
| 119 | + INTERFACE_COMPILE_OPTIONS "-std=c++0x;-stdlib=libstdc++") |
| 120 | + endif () |
| 121 | +endif() |
| 122 | + |
| 123 | +# Add the other Maya libraries into the main Maya::Maya library |
| 124 | +set(_MAYA_LIBRARIES OpenMayaAnim OpenMayaFX OpenMayaRender OpenMayaUI Foundation clew) |
| 125 | +foreach(MAYA_LIB ${_MAYA_LIBRARIES}) |
| 126 | + find_library(MAYA_${MAYA_LIB}_LIBRARY |
| 127 | + NAMES |
| 128 | + ${MAYA_LIB} |
| 129 | + PATHS |
| 130 | + ${MAYA_LOCATION} |
| 131 | + $ENV{MAYA_LOCATION} |
| 132 | + PATH_SUFFIXES |
| 133 | + "lib/" |
| 134 | + "Maya.app/Contents/MacOS/" |
| 135 | + NO_DEFAULT_PATH) |
| 136 | + mark_as_advanced(MAYA_${MAYA_LIB}_LIBRARY) |
| 137 | + if (MAYA_${MAYA_LIB}_LIBRARY) |
| 138 | + add_library(Maya::${MAYA_LIB} UNKNOWN IMPORTED) |
| 139 | + set_target_properties(Maya::${MAYA_LIB} PROPERTIES |
| 140 | + IMPORTED_LOCATION "${MAYA_${MAYA_LIB}_LIBRARY}") |
| 141 | + set_property(TARGET Maya::Maya APPEND PROPERTY |
| 142 | + INTERFACE_LINK_LIBRARIES Maya::${MAYA_LIB}) |
| 143 | + set(MAYA_LIBRARIES ${MAYA_LIBRARIES} "${MAYA_${MAYA_LIB}_LIBRARY}") |
| 144 | + endif() |
| 145 | +endforeach() |
| 146 | + |
| 147 | +function(MAYA_PLUGIN _target) |
| 148 | + if (WIN32) |
| 149 | + set_target_properties(${_target} PROPERTIES |
| 150 | + LINK_FLAGS "/export:initializePlugin /export:uninitializePlugin") |
| 151 | + endif() |
| 152 | + set_target_properties(${_target} PROPERTIES |
| 153 | + PREFIX "" |
| 154 | + SUFFIX ${MAYA_PLUGIN_EXTENSION}) |
| 155 | +endfunction() |
0 commit comments