@@ -148,16 +148,6 @@ set(ESICppRuntimeHeaders
148148set (ESICppRuntimeBackendHeaders
149149 ${CMAKE_CURRENT_SOURCE_DIR} /cpp/include /esi/backends/Trace.h
150150)
151- set (ESIPythonRuntimeSources
152- python/esiaccel/__init__.py
153- python/esiaccel/accelerator.py
154- python/esiaccel/codegen.py
155- python/esiaccel/types.py
156- python/esiaccel/utils.py
157- python/esiaccel/cosim/questa.py
158- python/esiaccel/cosim/simulator.py
159- python/esiaccel/cosim/verilator.py
160- )
161151
162152IF (MSVC )
163153 # ESI runtime requires exceptions. Purge any exception-related flags from
@@ -273,150 +263,8 @@ target_link_libraries(esitester PRIVATE
273263)
274264add_dependencies (ESIRuntime esitester)
275265
276- ##===----------------------------------------------------------------------===//
277- ## Python bindings for the ESI runtime.
278- ##===----------------------------------------------------------------------===//
279-
280- # Pybind11 is used to wrap the ESICppRuntime APIs.
281- find_package (Python3 COMPONENTS Interpreter Development)
282- if (Python3_FOUND)
283- IF (MSVC )
284- # Work around an issue with pybind11 and cmake incompatibility on Windows in debug mode.
285- set_target_properties (Python3::Module PROPERTIES
286- MAP_IMPORTED_CONFIG_DEBUG ";RELEASE" )
287- ENDIF (MSVC )
288-
289- if (pybind11_DIR)
290- message (STATUS "Using explicit pybind11 cmake directory: ${pybind11_DIR} (-Dpybind11_DIR to change)" )
291- else ()
292- message (STATUS "Checking for pybind11 in python path..." )
293- execute_process (
294- COMMAND "${Python3_EXECUTABLE} "
295- -c "import pybind11;print(pybind11.get_cmake_dir(), end='')"
296- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
297- RESULT_VARIABLE STATUS
298- OUTPUT_VARIABLE PACKAGE_DIR
299- ERROR_QUIET)
300- if (NOT STATUS EQUAL "0" )
301- message (FATAL_ERROR "pybind11 not found (install via 'pip install pybind11' or set pybind11_DIR)" )
302- endif ()
303- message (STATUS "found (${PACKAGE_DIR} )" )
304- set (pybind11_DIR "${PACKAGE_DIR} " )
305- endif ()
306-
307- # Now, find pybind11.
308- find_package (pybind11 CONFIG)
309- if (NOT pybind11_FOUND)
310- message (STATUS "Could not find pybind11. Disabling Python API." )
311- if (WHEEL_BUILD)
312- message (FATAL_ERROR "pybind11 is required for a wheel build." )
313- endif ()
314- else ()
315- # Compile Pybind11 module and copy to the correct python directory.
316- pybind11_add_module(esiCppAccel
317- ${CMAKE_CURRENT_SOURCE_DIR} /python/esiaccel/esiCppAccel.cpp)
318- target_link_libraries (esiCppAccel PRIVATE ESICppRuntime)
319- set_target_properties (esiCppAccel PROPERTIES
320- LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /python/esiaccel"
321- )
322-
323- # Check for stubgen and generate stubs if available.
324- find_program (STUBGEN pybind11-stubgen)
325- if ("${STUBGEN} " STREQUAL "STUBGEN-NOTFOUND" )
326- message (STATUS "pybind11_stubgen not found. Skipping stub generation." )
327- else ()
328- if (WIN32 )
329- # I just wasted all day trying to figure out the DLL search path on
330- # Windows both locally and in the runner. I'm done. Windows wheels
331- # won't have a stub until somebody else figures this out.
332- # TODO: have the patience to make this work.
333- message (WARNING "pybind11-stubgen is not supported on Windows." )
334- else ()
335- set (stubgen_python_path "$ENV{PYTHONPATH} :${CMAKE_CURRENT_BINARY_DIR} /python" )
336- add_custom_command (
337- TARGET esiCppAccel
338- POST_BUILD
339- COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH="${stubgen_python_path} "
340- ${STUBGEN}
341- -o "${CMAKE_CURRENT_BINARY_DIR} /python/esiaccel"
342- esiaccel.esiCppAccel
343- )
344- endif ()
345- endif ()
346-
347- if (WHEEL_BUILD)
348- if ("${STUBGEN} " STREQUAL "STUBGEN-NOTFOUND" )
349- message (FATAL_ERROR "pybind11_stubgen is required for a wheel build." )
350- endif ()
351- set_target_properties (esiCppAccel PROPERTIES
352- INSTALL_RPATH "$ORIGIN/lib" )
353- else ()
354- set_target_properties (esiCppAccel PROPERTIES
355- INSTALL_RPATH "$ORIGIN/../../lib" )
356- endif ()
357- set_target_properties (esiCppAccel PROPERTIES
358- INSTALL_RPATH_USE_LINK_PATH FALSE )
359-
360- if (WHEEL_BUILD)
361- install (TARGETS esiCppAccel
362- DESTINATION .
363- COMPONENT ESIRuntime
364- )
365- else ()
366- install (TARGETS esiCppAccel
367- DESTINATION python/esiaccel
368- COMPONENT ESIRuntime
369- )
370- endif ()
371- install (RUNTIME_DEPENDENCY_SET ESICppRuntime_RUNTIME_DEPS
372- DESTINATION ${ESIRT_INSTALL_LIBDIR}
373- PRE_EXCLUDE_REGEXES .*
374- COMPONENT ESIRuntime
375- )
376-
377- foreach (pysrc ${ESIPythonRuntimeSources} )
378- # Copy each of the Python sources to the build dir.
379- add_custom_command (
380- OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${pysrc}
381- COMMAND ${CMAKE_COMMAND} -E copy
382- ${CMAKE_CURRENT_SOURCE_DIR} /${pysrc}
383- ${CMAKE_CURRENT_BINARY_DIR} /${pysrc}
384- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /${pysrc}
385- )
386-
387- # Specify the install location for the Python sources.
388- get_filename_component (DEST ${pysrc} DIRECTORY )
389- # If we're building a wheel, we need to install to the root directory.
390- if (WHEEL_BUILD)
391- cmake_path(GET DEST PARENT_PATH DEST)
392- cmake_path(GET DEST PARENT_PATH DEST)
393- if (DEST STREQUAL "" )
394- set (DEST "." )
395- endif ()
396- endif ()
397-
398- install (FILES ${pysrc}
399- DESTINATION ${DEST}
400- COMPONENT ESIRuntime)
401- endforeach ()
402-
403- # Custom target for the Python runtime just aggregates the python sources
404- # and Pybind11 module.
405- add_custom_target (ESIPythonRuntime
406- DEPENDS
407- ${ESIPythonRuntimeSources}
408- esiCppAccel
409- )
410-
411- add_dependencies (ESIRuntime ESIPythonRuntime)
412-
413- endif ()
414- else () # Python not found.
415- if (WHEEL_BUILD)
416- message (FATAL_ERROR "python-dev is required for a wheel build." )
417- endif ()
418- endif ()
419-
266+ # Add the Python bindings.
267+ add_subdirectory (python)
420268
421269##===----------------------------------------------------------------------===//
422270## Backends are loaded dynamically as plugins.
0 commit comments