diff mbox series

[RFC,v2,2/6] kernel-shark: Prepare for building the NumPy interface

Message ID 20190405101411.25466-3-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series NumPy Interface for KernelShark | expand

Commit Message

Yordan Karadzhov April 5, 2019, 10:14 a.m. UTC
This patch prepares the Cmake build infrastructure for the
introduction of a the NumPy interface.

We add building of a static version of the C API library to be used by
the interface. The NumPy interface itself will be added in the following
patches.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/CMakeLists.txt        |  3 +++
 kernel-shark/README                | 12 ++++++++--
 kernel-shark/build/FindNumPy.cmake | 35 ++++++++++++++++++++++++++++
 kernel-shark/src/CMakeLists.txt    | 37 ++++++++++++++++++++++--------
 4 files changed, 76 insertions(+), 11 deletions(-)
 create mode 100644 kernel-shark/build/FindNumPy.cmake
diff mbox series

Patch

diff --git a/kernel-shark/CMakeLists.txt b/kernel-shark/CMakeLists.txt
index e0778ba..c6a4abf 100644
--- a/kernel-shark/CMakeLists.txt
+++ b/kernel-shark/CMakeLists.txt
@@ -34,6 +34,9 @@  if (Qt5Widgets_FOUND)
 
 endif (Qt5Widgets_FOUND)
 
+find_package(PythonLibs)
+include(${KS_DIR}/build/FindNumPy.cmake)
+
 set(LIBRARY_OUTPUT_PATH    "${KS_DIR}/lib")
 set(EXECUTABLE_OUTPUT_PATH "${KS_DIR}/bin")
 
diff --git a/kernel-shark/README b/kernel-shark/README
index b238d3f..a75b08b 100644
--- a/kernel-shark/README
+++ b/kernel-shark/README
@@ -12,7 +12,11 @@  KernelShark has the following external dependencies:
     sudo apt-get install freeglut3-dev libxmu-dev libxi-dev -y
     sudo apt-get install qtbase5-dev -y
 
-1.1 I you want to be able to generate Doxygen documentation:
+1.1 I you want to be able to use the NumPu Interface of KernelShark:
+    sudo apt-get install libpython3-dev cython3 -y
+    sudo apt-get install python3-numpy python3-matplotlib -y
+
+1.2 I you want to be able to generate Doxygen documentation:
     sudo apt-get install graphviz doxygen-gui -y
 
 
@@ -21,7 +25,11 @@  KernelShark has the following external dependencies:
     dnf install freeglut-devel redhat-rpm-config -y
     dnf install qt5-qtbase-devel -y
 
-2.1 I you want to be able to generate Doxygen documentation:
+2.1 I you want to be able to use the NumPu Interface of KernelShark:
+    dnf install python3-devel python-Cython -y
+    dnf install python-numpy python3-matplotlib -y
+
+2.2 I you want to be able to generate Doxygen documentation:
     dnf install graphviz doxygen -y
 
 
diff --git a/kernel-shark/build/FindNumPy.cmake b/kernel-shark/build/FindNumPy.cmake
new file mode 100644
index 0000000..b23440c
--- /dev/null
+++ b/kernel-shark/build/FindNumPy.cmake
@@ -0,0 +1,35 @@ 
+execute_process(COMMAND python -c "import Cython; print(Cython.__version__)"
+                RESULT_VARIABLE CYTHON_RES
+                OUTPUT_VARIABLE CYTHON_VERSION
+                ERROR_VARIABLE CYTHON_ERR
+                OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+IF (CYTHON_RES MATCHES 0)
+
+  SET(CYTHON_FOUND TRUE)
+  message(STATUS "Found Cython:  (version: ${CYTHON_VERSION})")
+
+ELSE (CYTHON_RES MATCHES 0)
+
+  SET(CYTHON_FOUND FALSE)
+  message(STATUS "\nCould not find CYTHON:  ${CYTHON_ERR}\n")
+
+ENDIF (CYTHON_RES MATCHES 0)
+
+execute_process(COMMAND python -c "import numpy; print(numpy.__version__)"
+                RESULT_VARIABLE NP_RES
+                OUTPUT_VARIABLE NUMPY_VERSION
+                ERROR_VARIABLE NP_ERR
+                OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+IF (NP_RES MATCHES 0)
+
+  SET(NUMPY_FOUND TRUE)
+  message(STATUS "Found NumPy:  (version: ${NUMPY_VERSION})")
+
+ELSE (NP_RES MATCHES 0)
+
+  SET(NUMPY_FOUND FALSE)
+  message(STATUS "\nCould not find NumPy:  ${NP_ERR}\n")
+
+ENDIF (NP_RES MATCHES 0)
diff --git a/kernel-shark/src/CMakeLists.txt b/kernel-shark/src/CMakeLists.txt
index b7dbd7e..b9a05e1 100644
--- a/kernel-shark/src/CMakeLists.txt
+++ b/kernel-shark/src/CMakeLists.txt
@@ -1,16 +1,21 @@ 
 message("\n src ...")
 
 message(STATUS "libkshark")
-add_library(kshark SHARED libkshark.c
-                          libkshark-model.c
-                          libkshark-plugin.c
-                          libkshark-configio.c
-                          libkshark-collection.c)
 
-target_link_libraries(kshark ${CMAKE_DL_LIBS}
-                             ${JSONC_LIBRARY}
-                             ${TRACEEVENT_LIBRARY}
-                             ${TRACECMD_LIBRARY})
+set(LIBKSHARK_SOURCE libkshark.c
+                     libkshark-model.c
+                     libkshark-plugin.c
+                     libkshark-configio.c
+                     libkshark-collection.c)
+
+set(LIBKSHARK_LINK_LIBS ${CMAKE_DL_LIBS}
+                        ${JSONC_LIBRARY}
+                        ${TRACEEVENT_LIBRARY}
+                        ${TRACECMD_LIBRARY})
+
+add_library(kshark SHARED ${LIBKSHARK_SOURCE})
+
+target_link_libraries(kshark ${LIBKSHARK_LINK_LIBS})
 
 set_target_properties(kshark  PROPERTIES SUFFIX	".so.${KS_VERSION_STRING}")
 
@@ -28,6 +33,20 @@  if (OPENGL_FOUND AND GLUT_FOUND)
 
 endif (OPENGL_FOUND AND GLUT_FOUND)
 
+if (PYTHONLIBS_FOUND AND CYTHON_FOUND AND NUMPY_FOUND)
+
+    message(STATUS "kshark_wrapper")
+
+    add_library(kshark-static STATIC ${LIBKSHARK_SOURCE})
+
+    target_compile_options(kshark-static PUBLIC "-fPIC")
+
+    set_target_properties(kshark-static PROPERTIES OUTPUT_NAME kshark)
+
+    target_link_libraries(kshark-static ${LIBKSHARK_LINK_LIBS})
+
+endif (PYTHONLIBS_FOUND AND CYTHON_FOUND AND NUMPY_FOUND)
+
 if (Qt5Widgets_FOUND AND Qt5Network_FOUND)
 
     message(STATUS "libkshark-gui")