2020-07-11 13:45:30 +08:00
|
|
|
################################################################################
|
|
|
|
# Resources that must be packaged into the python tree
|
|
|
|
################################################################################
|
|
|
|
|
2020-08-07 14:51:05 +08:00
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/npcomp/compiler/backend/refjit_resources")
|
2020-07-11 13:45:30 +08:00
|
|
|
add_custom_target(NPCOMPPythonResources)
|
|
|
|
add_custom_command(
|
2020-08-07 14:51:05 +08:00
|
|
|
TARGET NPCOMPPythonResources
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
2020-07-11 13:45:30 +08:00
|
|
|
# TODO: Make the runtime library work for windows.
|
2020-12-28 17:30:45 +08:00
|
|
|
${CMAKE_BINARY_DIR}/lib/libNPCOMPCompilerRuntimeShlib${CMAKE_SHARED_LIBRARY_SUFFIX}
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/npcomp/compiler/generic/backend/libNPCOMPCompilerRuntimeShlib${CMAKE_SHARED_LIBRARY_SUFFIX}
|
2020-07-11 13:45:30 +08:00
|
|
|
)
|
|
|
|
add_dependencies(NPCOMPPythonResources
|
|
|
|
NPCOMPCompilerRuntimeShlib
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-27 06:50:23 +08:00
|
|
|
################################################################################
|
|
|
|
# Manage python source files
|
|
|
|
################################################################################
|
2020-10-13 12:39:48 +08:00
|
|
|
npcomp_python_create_symlinks(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
2020-08-04 08:46:34 +08:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Native extensions
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Normally on unix-like platforms, extensions are built as "MODULE" libraries
|
|
|
|
# and do not explicitly link to the python shared object. This allows for
|
|
|
|
# come greater deployment flexibility since the extension will bind to
|
|
|
|
# symbols in the python interpreter on load. However, it also keeps the
|
|
|
|
# linker from erroring on undefined symbols, leaving this to (usually obtuse)
|
|
|
|
# runtime errors. Building in "SHARED" mode with an explicit link to the
|
|
|
|
# python libraries allows us to build with the expectation of no undefined
|
|
|
|
# symbols, which is better for development.
|
|
|
|
# TODO(laurenzo): Windows requires linking against the PYTHON_LIBRARIES
|
|
|
|
# TODO(laurenzo): OSX requires allowing undefined (-undefined dynamic_lookup)
|
2020-08-05 08:10:14 +08:00
|
|
|
if(NPCOMP_PYTHON_BINDINGS_VERSION_LOCKED)
|
|
|
|
set(NPCOMP_PYEXT_LINK_MODE SHARED)
|
2020-11-18 08:04:14 +08:00
|
|
|
set(NPCOMP_PYEXT_LIBADD ${Python3_LIBRARIES})
|
2020-08-05 08:10:14 +08:00
|
|
|
else()
|
|
|
|
set(NPCOMP_PYEXT_LINK_MODE MODULE)
|
|
|
|
set(NPCOMP_PYEXT_LIBADD)
|
|
|
|
endif()
|
2020-08-04 08:46:34 +08:00
|
|
|
|
|
|
|
if(NPCOMP_ENABLE_REFJIT)
|
|
|
|
list(APPEND NPCOMP_PYEXT_LIBADD
|
|
|
|
NPCOMPBackendRefJITPythonModule
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-10-09 09:29:59 +08:00
|
|
|
add_library(NPCOMPNativePyExt ${NPCOMP_PYEXT_LINK_MODE}
|
2020-08-04 08:46:34 +08:00
|
|
|
NpcompModule.cpp
|
|
|
|
)
|
|
|
|
|
2020-10-09 09:29:59 +08:00
|
|
|
set_target_properties(NPCOMPNativePyExt PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
2020-08-04 08:46:34 +08:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
2020-10-09 09:29:59 +08:00
|
|
|
set_target_properties(NPCOMPNativePyExt PROPERTIES OUTPUT_NAME _npcomp)
|
|
|
|
set_target_properties(NPCOMPNativePyExt PROPERTIES PREFIX
|
2020-08-04 08:46:34 +08:00
|
|
|
"${PYTHON_MODULE_PREFIX}")
|
2020-10-09 09:29:59 +08:00
|
|
|
set_target_properties(NPCOMPNativePyExt PROPERTIES SUFFIX
|
2020-08-04 08:46:34 +08:00
|
|
|
"${PYTHON_MODULE_EXTENSION}")
|
|
|
|
|
|
|
|
# pybind requires binding code to be compiled with -fvisibility=hidden
|
|
|
|
# Better code can be generated if the entire project compiles that way, but
|
2020-10-09 09:29:59 +08:00
|
|
|
# that is not enforced here.
|
|
|
|
set_target_properties(NPCOMPNativePyExt PROPERTIES CXX_VISIBILITY_PRESET "hidden")
|
2020-08-04 08:46:34 +08:00
|
|
|
|
|
|
|
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
|
|
|
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
|
|
|
|
2020-10-09 09:29:59 +08:00
|
|
|
target_link_libraries(NPCOMPNativePyExt
|
2020-08-04 08:46:34 +08:00
|
|
|
PRIVATE
|
2020-10-09 09:29:59 +08:00
|
|
|
# Transitive dep on the shared library links most things from there.
|
|
|
|
NPCOMP
|
2020-08-04 08:46:34 +08:00
|
|
|
|
2020-10-09 09:29:59 +08:00
|
|
|
NPCOMPInitAll
|
2020-08-04 08:46:34 +08:00
|
|
|
${NPCOMP_PYEXT_LIBADD}
|
2020-11-14 10:06:59 +08:00
|
|
|
)
|
2020-10-09 09:29:59 +08:00
|
|
|
npcomp_python_target_compile_options(NPCOMPNativePyExt)
|
2020-08-06 05:49:18 +08:00
|
|
|
|
2020-10-09 09:29:59 +08:00
|
|
|
mlir_check_all_link_libraries(NPCOMPNativePyExt)
|
2020-12-30 05:22:18 +08:00
|
|
|
|
|
|
|
# Order dependent: Built artifacts add dependencies to the above targets.
|
|
|
|
add_subdirectory(npcomp/dialects)
|