2020-04-27 06:50:23 +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)
|
|
|
|
set(NPCOMP_PYEXT_LINK_MODE SHARED)
|
|
|
|
set(NPCOMP_PYEXT_LIBADD ${PYTHON_LIBRARIES})
|
|
|
|
|
2020-06-19 14:28:30 +08:00
|
|
|
if(NPCOMP_ENABLE_IREE)
|
|
|
|
list(APPEND NPCOMP_PYEXT_LIBADD NPCOMPBackendIREEPythonModule)
|
|
|
|
endif()
|
|
|
|
|
2020-04-27 06:50:23 +08:00
|
|
|
# TODO(laurenzo): Add a config setting to control this.
|
|
|
|
# set(NPCOMP_PYEXT_LINK_MODE MODULE)
|
|
|
|
# set(NPCOMP_PYEXT_LIBADD "")
|
|
|
|
|
|
|
|
# When building the extension, distinguish between those sources that use
|
|
|
|
# pybind (and need rtti/exceptions) and those that only use LLVM/MLIR.
|
|
|
|
# Some of the low-level components do not support mixing RTTI modes and are
|
|
|
|
# compiled separately for now.
|
|
|
|
set(extension_target NPCOMPNativePyExt)
|
2020-06-04 14:58:58 +08:00
|
|
|
set(extension_llvm_sources
|
|
|
|
)
|
|
|
|
set(extension_pybind_sources
|
2020-05-07 13:44:12 +08:00
|
|
|
NpcompModule.cpp
|
2020-04-27 06:50:23 +08:00
|
|
|
)
|
|
|
|
set_source_files_properties(
|
|
|
|
${extension_pybind_sources}
|
2020-06-19 09:02:39 +08:00
|
|
|
PROPERTIES COMPILE_FLAGS
|
2020-04-27 06:50:23 +08:00
|
|
|
"-frtti -fexceptions")
|
2020-06-19 09:02:39 +08:00
|
|
|
add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE}
|
2020-04-27 06:50:23 +08:00
|
|
|
${extension_pybind_sources}
|
2020-06-04 14:58:58 +08:00
|
|
|
${extension_llvm_sources}
|
2020-04-27 06:50:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
set_target_properties(${extension_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
2020-05-07 13:44:12 +08:00
|
|
|
set_target_properties(${extension_target} PROPERTIES OUTPUT_NAME _npcomp)
|
2020-06-19 09:02:39 +08:00
|
|
|
set_target_properties(${extension_target} PROPERTIES PREFIX
|
2020-04-27 06:50:23 +08:00
|
|
|
"${PYTHON_MODULE_PREFIX}")
|
2020-06-19 09:02:39 +08:00
|
|
|
set_target_properties(${extension_target} PROPERTIES SUFFIX
|
|
|
|
"${PYTHON_MODULE_EXTENSION}")
|
2020-04-27 06:50:23 +08:00
|
|
|
|
|
|
|
# pybind requires binding code to be compiled with -fvisibility=hidden
|
|
|
|
# Better code can be generated if the entire project compiles that way, but
|
|
|
|
# that is not enforced here. Instead, include a linker script that explicitly
|
|
|
|
# hides anything but the PyInit_* symbols, allowing gc to take place.
|
|
|
|
# TODO(laurenzo): Windows needs a .def file and different flags.
|
|
|
|
set_target_properties(${extension_target} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
|
|
|
|
set_target_properties(${extension_target} PROPERTIES LINK_FLAGS
|
|
|
|
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/unix_version.script")
|
|
|
|
|
|
|
|
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
|
|
|
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
|
|
|
|
2020-05-01 07:00:00 +08:00
|
|
|
# llvm_update_compile_flags(${extension_target})
|
2020-06-19 09:02:39 +08:00
|
|
|
target_link_libraries(${extension_target}
|
2020-04-27 06:50:23 +08:00
|
|
|
PRIVATE
|
|
|
|
${dialect_libs}
|
|
|
|
${conversion_libs}
|
2020-06-12 08:47:14 +08:00
|
|
|
NPCOMPInitAll
|
2020-06-19 09:02:39 +08:00
|
|
|
NPCOMPPythonCommon
|
2020-06-09 08:52:07 +08:00
|
|
|
|
2020-04-27 08:20:58 +08:00
|
|
|
# Upstream depends
|
2020-04-27 06:50:23 +08:00
|
|
|
LLVMSupport
|
|
|
|
MLIRAffineToStandard
|
|
|
|
MLIRAffineTransforms
|
|
|
|
MLIRDialect
|
|
|
|
MLIREDSC
|
|
|
|
MLIREDSCInterface
|
|
|
|
MLIRIR
|
2020-05-22 04:09:06 +08:00
|
|
|
MLIRSCFToStandard
|
2020-04-27 06:50:23 +08:00
|
|
|
MLIRLLVMIR
|
|
|
|
MLIRPass
|
|
|
|
MLIRTargetLLVMIR
|
|
|
|
MLIRTransforms
|
|
|
|
|
|
|
|
${NPCOMP_PYEXT_LIBADD}
|
|
|
|
)
|