@@ -14,14 +14,71 @@ target_include_directories(coconext PUBLIC
1414target_compile_features (coconext PUBLIC cxx_std_20 )
1515set_target_properties (coconext PROPERTIES POSITION_INDEPENDENT_CODE TRUE )
1616
17- # On macOS the install name is @rpath-relative so a preloaded image
18- # satisfies the dependency by install-name match rather than by search path.
19- # Looks like RPATH, is actually not.
17+ # Needed for MacOS.
2018set_target_properties (coconext PROPERTIES
2119 MACOSX_RPATH TRUE
2220 INSTALL_NAME_DIR "@rpath" )
2321
24- install (TARGETS coconext
22+ # -- libgpi --------------------------------------------------------------------
23+ #
24+ # This is some CMake to pull in libgpi since cocotb doesn't provide a CMake
25+ # package yet.
26+
27+ # Use cocotb_tools.config to get libgpi binary dir and include dir
28+ execute_process (
29+ COMMAND ${Python_EXECUTABLE} -c
30+ "from cocotb_tools.config import libs_dir, share_dir; print(libs_dir); print(share_dir / 'include')"
31+ OUTPUT_VARIABLE _coconext_cocotb_paths
32+ OUTPUT_STRIP_TRAILING_WHITESPACE
33+ COMMAND_ERROR_IS_FATAL ANY )
34+ string (REPLACE "\n " ";" _coconext_cocotb_paths "${_coconext_cocotb_paths} " )
35+ list (GET _coconext_cocotb_paths 0 COCOTB_LIBS_DIR)
36+ list (GET _coconext_cocotb_paths 1 COCOTB_INCLUDE_DIR)
37+
38+ # Create a CMake target for libgpi. cocotb installs libgpi as .so on every platform except Windows (including MacOS).
39+ if (WIN32 )
40+ set (_coconext_libgpi_suffix ".dll" )
41+ else ()
42+ set (_coconext_libgpi_suffix ".so" )
43+ endif ()
44+ add_library (cocotb_gpi SHARED IMPORTED )
45+ set_target_properties (cocotb_gpi PROPERTIES
46+ IMPORTED_LOCATION "${COCOTB_LIBS_DIR} /libgpi${_coconext_libgpi_suffix} "
47+ INTERFACE_INCLUDE_DIRECTORIES "${COCOTB_INCLUDE_DIR} " )
48+
49+ # -- libcoconext_gpi -----------------------------------------------------------
50+ #
51+ # For parts of the library that have a dependency on libgpi and a running
52+ # simulation, e.g. handles and GPI triggers.
53+
54+ add_library (coconext_gpi SHARED
55+ src/sim_objects.cpp
56+ )
57+ set_target_properties (coconext_gpi PROPERTIES POSITION_INDEPENDENT_CODE TRUE )
58+ target_link_libraries (coconext_gpi
59+ PRIVATE
60+ cocotb_gpi
61+ PUBLIC
62+ coconext )
63+
64+ # Needed for MacOS.
65+ set_target_properties (coconext_gpi PROPERTIES
66+ MACOSX_RPATH TRUE
67+ INSTALL_NAME_DIR "@rpath" )
68+
69+ # RPATH to the current dir to pick up libcoconext.
70+ if (APPLE )
71+ set (_coconext_origin "@loader_path" )
72+ else ()
73+ set (_coconext_origin "$ORIGIN" )
74+ endif ()
75+ set_target_properties (coconext_gpi PROPERTIES
76+ INSTALL_RPATH "${_coconext_origin} "
77+ BUILD_RPATH "${_coconext_origin} " )
78+
79+ # -- install -------------------------------------------------------------------
80+
81+ install (TARGETS coconext coconext_gpi
2582 EXPORT coconextTargets
2683 LIBRARY DESTINATION coconext/lib
2784 RUNTIME DESTINATION coconext/lib
0 commit comments