Skip to content

Commit

Permalink
adding pre and post build script execution
Browse files Browse the repository at this point in the history
  • Loading branch information
scottenglert committed Apr 1, 2022
1 parent ed93cbe commit cfe5616
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1,159 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ set(CMAKE_CONFIGURATION_TYPES "Debug" "Release")
set(Maya_DIR "${PROJECT_SOURCE_DIR}/cmake")

find_package(Maya REQUIRED)

add_subdirectory(pybind11)

add_custom_target(BuildMFnTypes ALL python ./scripts/mfn.py parse ${MAYA_DEVKIT_ROOT}
BYPRODUCTS ./src/MFn.Types.inl
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
add_library(${PROJECT_NAME} SHARED ${CMDC_SOURCES})
add_dependencies(${PROJECT_NAME} BuildMFnTypes)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND python ./mfn.py clear -
BYPRODUCTS ./src/MFn.Types.inl
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/scripts"
)
pybind11_extension(${PROJECT_NAME})

if (APPLE)
Expand Down
16 changes: 15 additions & 1 deletion cmake/MayaConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ if (WIN32)

elseif (APPLE)
set(PYTHON_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/os/mac/${PYBIND11_PYTHON_VERSION}/include")
set(PYTHON_LIB "${PROJECT_SOURCE_DIR}/os/mac/${PYBIND11_PYTHON_VERSION}/lib/libpython${PYBIND11_PYTHON_VERSION}.dylib")
if (${PYBIND11_PYTHON_VERSION} EQUAL "2.7")
set(PYTHON_LIB "${PROJECT_SOURCE_DIR}/os/mac/${PYBIND11_PYTHON_VERSION}/lib/libpython${PYBIND11_PYTHON_VERSION}.dylib")
else()
set(PYTHON_LIB "${PROJECT_SOURCE_DIR}/os/mac/${PYBIND11_PYTHON_VERSION}/lib/libpython${PYBIND11_PYTHON_VERSION}m.dylib")
endif()
else()
set(PYTHON_INCLUDE_DIR "${MAYA_DEVKIT_ROOT}/include/Python")
if (${PYBIND11_PYTHON_VERSION} EQUAL "2.7")
Expand All @@ -22,6 +26,9 @@ else()
endif()
endif()

message("Python library set to: ${PYTHON_LIB}")
message("Python include set to: ${PYTHON_INCLUDE_DIR}")

add_library(Maya::Foundation SHARED IMPORTED)
add_library(Maya::OpenMaya SHARED IMPORTED)
add_library(Maya::OpenMayaRender SHARED IMPORTED)
Expand Down Expand Up @@ -71,6 +78,7 @@ elseif(APPLE)
set_target_properties(Python::Lib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIR}
IMPORTED_LOCATION ${PYTHON_LIB}
IMPORTED_SONAME "libpython${PYBIND11_PYTHON_VERSION}m.dylib"
)

set_target_properties(Maya::Foundation PROPERTIES
Expand Down Expand Up @@ -109,6 +117,12 @@ elseif(APPLE)
IMPORTED_SONAME "libOpenMayaFX.dylib"
)
else()
set_target_properties(Python::Lib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIR}
IMPORTED_LOCATION ${PYTHON_LIB}
IMPORTED_SONAME "libpython${PYBIND11_PYTHON_VERSION}m.so"
)

set_target_properties(Maya::Foundation PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${MAYA_INCLUDE_DIR}
IMPORTED_LOCATION "${MAYA_LIB_DIR}/libFoundation.so"
Expand Down
13 changes: 7 additions & 6 deletions scripts/mfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@

def main(*argv):
"""Parse the MFn header file to generate an array of MFn::Type names."""

cmd, = (argv or [None])
cmd, devkit_path = (argv or [None, None])

mfn_inl_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'src', 'MFn.Types.inl')

if cmd == 'parse':
_parse(mfn_inl_path)
_parse(mfn_inl_path, devkit_path)
elif cmd == 'clear':
_clear(mfn_inl_path)

return 0


def _clear(mfn_inl_path):
print('Clearing MFn.Types.inl...')
with open(mfn_inl_path, 'w') as fp:
fp.write('// Auto-generated by /Scripts/mfn.py at build type\n')
fp.write('// Auto-generated by /Scripts/mfn.py at build time\n')


def _parse(mfn_inl_path):
mfn_header = os.path.join(os.environ['DEVKIT_LOCATION'], 'include', 'maya', 'MFn.h')
def _parse(mfn_inl_path, devkit_path):
print('Parsing MFn.h to MFn.Types.inl...')
mfn_header = os.path.join(devkit_path, 'include', 'maya', 'MFn.h')

with open(mfn_header, 'r') as fp:
lines = fp.readlines()
Expand Down
Loading

0 comments on commit cfe5616

Please sign in to comment.