diff mbox series

[v2,15/27] kernel-shark: Search for font with Cmake at pre-build

Message ID 20210211103205.418588-16-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit 30331ea648348adaad4b44a899907e335ff71d79
Headers show
Series Complete the KernelShark v2 transformation | expand

Commit Message

Yordan Karadzhov Feb. 11, 2021, 10:31 a.m. UTC
Being able to load the Truetype font is compulsory for the functioning
of the visualization, hence the font must be considered as critical
external dependency. Add a search for the font file next to the search
of the other third party dependencies and have this file added as
definition in the Cmake-generated header file. This way we do not need
to search for the font every time when we open KernelShark.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 .github/workflows/main.yml |  1 +
 CMakeLists.txt             | 14 ++++++++++++++
 README                     |  1 +
 build/deff.h.cmake         |  3 +++
 examples/CMakeLists.txt    |  4 ++--
 src/CMakeLists.txt         |  4 ++--
 tests/CMakeLists.txt       | 22 +++++++++++++---------
 tests/libkshark-tests.cpp  |  9 +++++++++
 8 files changed, 45 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2cce624..4125354 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -19,6 +19,7 @@  jobs:
         sudo apt-get update
         sudo apt-get install build-essential git cmake libjson-c-dev -y
         sudo apt-get install freeglut3-dev libxmu-dev libxi-dev -y
+        sudo apt-get install fonts-freefont-ttf
         sudo apt-get install qtbase5-dev libboost-all-dev -y
         git clone https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
         cd libtraceevent
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b9b947e..8ca33fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,6 +49,20 @@  set(OpenGL_GL_PREFERENCE LEGACY)
 find_package(OpenGL)
 find_package(GLUT)
 
+set(KS_FONT FreeSans)
+execute_process(COMMAND  bash "-c" "fc-list '${KS_FONT}' |grep ${KS_FONT}.ttf | cut -d':' -f 1 -z"
+                OUTPUT_VARIABLE TT_FONT_FILE)
+
+if (TT_FONT_FILE)
+
+  message(STATUS "Found font: ${TT_FONT_FILE}")
+
+else (TT_FONT_FILE)
+
+  message(WARNING "\nCould not find font ${KS_FONT}!\n")
+
+endif (TT_FONT_FILE)
+
 find_package(Qt5Widgets 5.7.1)
 find_package(Qt5Network)
 if (Qt5Widgets_FOUND)
diff --git a/README b/README
index d7efd96..a7e66df 100644
--- a/README
+++ b/README
@@ -12,6 +12,7 @@  KernelShark has the following external dependencies:
 1. In order to install the packages on Ubuntu do the following:
     sudo apt-get install build-essential git cmake libjson-c-dev -y
     sudo apt-get install freeglut3-dev libxmu-dev libxi-dev -y
+    sudo apt-get install fonts-freefont-ttf
     sudo apt-get install qtbase5-dev -y
 
 1.1 I you want to be able to generate Doxygen documentation:
diff --git a/build/deff.h.cmake b/build/deff.h.cmake
index 423a2fd..06cbf16 100644
--- a/build/deff.h.cmake
+++ b/build/deff.h.cmake
@@ -26,6 +26,9 @@ 
 /** GLUT has been found. */
 #cmakedefine GLUT_FOUND
 
+/** Truetype font file. */
+#cmakedefine TT_FONT_FILE "@TT_FONT_FILE@"
+
 /** Qt - old version detected. */
 #cmakedefine QT_VERSION_LESS_5_11
 
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index e6af5f2..bc17635 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -24,7 +24,7 @@  message(STATUS "dataplot")
 add_executable(dplot          dataplot.cpp)
 target_link_libraries(dplot   kshark-plot)
 
-if (Qt5Widgets_FOUND)
+if (Qt5Widgets_FOUND AND TT_FONT_FILE)
 
     message(STATUS "widgetdemo")
     add_executable(widgetdemo          widgetdemo.cpp)
@@ -34,4 +34,4 @@  if (Qt5Widgets_FOUND)
     add_executable(cmd_split           cmd_split.cpp)
     target_link_libraries(cmd_split    kshark-gui)
 
-endif (Qt5Widgets_FOUND)
+endif (Qt5Widgets_FOUND AND TT_FONT_FILE)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 140fed8..6c02d82 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -63,7 +63,7 @@  if (OPENGL_FOUND)
 
 endif (OPENGL_FOUND)
 
-if (Qt5Widgets_FOUND AND Qt5Network_FOUND)
+if (Qt5Widgets_FOUND AND Qt5Network_FOUND AND TT_FONT_FILE)
 
     message(STATUS "libkshark-gui")
     set (ks-guiLib_hdr  KsUtils.hpp
@@ -134,7 +134,7 @@  if (Qt5Widgets_FOUND AND Qt5Network_FOUND)
             DESTINATION ${_INSTALL_PREFIX}/bin/
                 COMPONENT                 kernelshark)
 
-endif (Qt5Widgets_FOUND AND Qt5Network_FOUND)
+endif (Qt5Widgets_FOUND AND Qt5Network_FOUND AND TT_FONT_FILE)
 
 add_subdirectory(plugins)
 set(PLUGINS ${PLUGINS} PARENT_SCOPE)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 28f711b..1814c72 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -38,13 +38,17 @@  add_test(NAME              "libkshark_tests"
          COMMAND           ${KS_TEST_DIR}/kshark-tests --log_format=HRF
          WORKING_DIRECTORY ${KS_TEST_DIR})
 
-add_executable(kshark-gui-tests          libkshark-gui-tests.cpp)
-target_include_directories(kshark-gui-tests PRIVATE ${Boost_INCLUDE_DIRS})
-target_compile_definitions(kshark-gui-tests PRIVATE "BOOST_TEST_DYN_LINK=1")
-target_link_libraries(kshark-gui-tests   kshark-gui
-                                     ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+if (Qt5Widgets_FOUND AND TT_FONT_FILE)
 
-message(STATUS "libkshark-gui_tests")
-add_test(NAME              "libkshark-gui_tests"
-         COMMAND           ${KS_TEST_DIR}/kshark-gui-tests --log_format=HRF
-         WORKING_DIRECTORY ${KS_TEST_DIR})
+    add_executable(kshark-gui-tests          libkshark-gui-tests.cpp)
+    target_include_directories(kshark-gui-tests PRIVATE ${Boost_INCLUDE_DIRS})
+    target_compile_definitions(kshark-gui-tests PRIVATE "BOOST_TEST_DYN_LINK=1")
+    target_link_libraries(kshark-gui-tests   kshark-gui
+                          ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+
+    message(STATUS "libkshark-gui_tests")
+    add_test(NAME              "libkshark-gui_tests"
+             COMMAND           ${KS_TEST_DIR}/kshark-gui-tests --log_format=HRF
+             WORKING_DIRECTORY ${KS_TEST_DIR})
+
+endif (Qt5Widgets_FOUND AND TT_FONT_FILE)
diff --git a/tests/libkshark-tests.cpp b/tests/libkshark-tests.cpp
index a22c1e5..5f7c88a 100644
--- a/tests/libkshark-tests.cpp
+++ b/tests/libkshark-tests.cpp
@@ -435,3 +435,12 @@  BOOST_AUTO_TEST_CASE(readout_plugins)
 
 	kshark_free(kshark_ctx);
 }
+
+BOOST_AUTO_TEST_CASE(check_font_found)
+{
+#ifdef TT_FONT_FILE
+BOOST_REQUIRE(true);
+#else
+BOOST_REQUIRE(false);
+#endif
+}