Skip to contentSkip to conversation

KernelShark build fixes for v1.0

PATCH In review Yordan Karadzhov 3 participants 6 messages Jun 14, 2019 – Jul 8, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover KernelShark build fixes for v1.0

Patches addressing the problem of having the paths to the build directory embedded in the final binaries. The problem was reported by Troy Engel.

Changes in v2:
- In FindTraceCmd.cmake : discovering the trace-cmd executable is now a compulsory requirement.
- A new buld type called "Package" has been defined.

Yordan Karadzhov (3):
kernel-shark: Remove the "-g" compiler flag.
kernel-shark: Avoid TRACECMD_BIN_DIR being set to the build path
kernel-shark: Define a CMAKE_BUILD_TYPE "Package"

 kernel-shark/CMakeLists.txt           | 45 ++++++++++++++++++---------
 kernel-shark/README                   | 22 +++++++++----
 kernel-shark/build/FindTraceCmd.cmake | 18 ++++++-----
 kernel-shark/build/deff.h.cmake       |  2 +-
 kernel-shark/src/KsCaptureDialog.cpp  |  7 ++---
 5 files changed, 61 insertions(+), 33 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/3 kernel-shark: Remove the "-g" compiler flag.

The debug flags by design embed the build paths, but the distro package binaries should not have such paths embedded in them.

---
 kernel-shark/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/CMakeLists.txt +2 -2
index d45be20..87f33d6 100644
@@ -33,8 +33,8 @@ endif (Qt5Widgets_FOUND)
 set(LIBRARY_OUTPUT_PATH    "${KS_DIR}/lib")
 set(EXECUTABLE_OUTPUT_PATH "${KS_DIR}/bin")
 
-set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wall -g -pthread -fPIC")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -std=c++11 -pthread -fPIC")
+set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wall -pthread -fPIC")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -pthread -fPIC")
 
 if(NOT _INSTALL_PREFIX)
 	set(_INSTALL_PREFIX "/usr/local")
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/3 kernel-shark: Avoid TRACECMD_BIN_DIR being set to the build path

In reply to Yordan Karadzhov

The full path to the build directory (which is random for every user) is embedded in the final binary. This is a no-no for some Linux distros which are requiring that the finished binaries should not have such paths embedded in them.

---
 kernel-shark/build/FindTraceCmd.cmake | 18 +++++++++++-------
 kernel-shark/build/deff.h.cmake       |  2 +-
 kernel-shark/src/KsCaptureDialog.cpp  |  7 +++----
 3 files changed, 15 insertions(+), 12 deletions(-)
kernel-shark/build/FindTraceCmd.cmake +11 -7
index 8c51f11..2da4eee 100644
@@ -12,10 +12,14 @@
 # MESSAGE(" Looking for trace-cmd ...")
 
 # First search in the user provided paths.
-find_path(TRACECMD_BIN_DIR      NAMES  trace-cmd
-                                PATHS  $ENV{TRACE_CMD}/tracecmd/
-                                       ${CMAKE_SOURCE_DIR}/../tracecmd/
-                                NO_DEFAULT_PATH)
+if (CMAKE_BUILD_TYPE MATCHES Debug)
+
+  find_program(TRACECMD_EXECUTABLE   NAMES  trace-cmd
+                                     PATHS  $ENV{TRACE_CMD}/tracecmd/
+                                            ${CMAKE_SOURCE_DIR}/../tracecmd/
+                                     NO_DEFAULT_PATH)
+
+endif (CMAKE_BUILD_TYPE MATCHES Debug)
 
 find_path(TRACECMD_INCLUDE_DIR  NAMES  trace-cmd/trace-cmd.h
                                 PATHS  $ENV{TRACE_CMD}/include/
@@ -34,16 +38,16 @@ find_library(TRACEEVENT_LIBRARY NAMES  traceevent/libtraceevent.a
 
 # If not found, search in the default system paths. Note that if the previous
 # search was successful "find_path" will do nothing this time.
-find_path(TRACECMD_BIN_DIR      NAMES  trace-cmd)
+find_program(TRACECMD_EXECUTABLE   NAMES  trace-cmd)
 find_path(TRACECMD_INCLUDE_DIR  NAMES  trace-cmd/trace-cmd.h)
 find_library(TRACECMD_LIBRARY   NAMES  trace-cmd/libtracecmd.so)
 find_library(TRACEEVENT_LIBRARY NAMES  traceevent/libtraceevent.so)
 
-IF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY)
+IF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY AND TRACECMD_EXECUTABLE)
 
   SET(TRACECMD_FOUND TRUE)
 
-ENDIF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY)
+ENDIF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY AND TRACECMD_EXECUTABLE)
 
 IF (TRACECMD_FOUND)
 
kernel-shark/build/deff.h.cmake +1 -1
index efee2a1..79726ff 100644
@@ -18,7 +18,7 @@
 #cmakedefine KS_PLUGIN_INSTALL_PREFIX "@KS_PLUGIN_INSTALL_PREFIX@"
 
 /** Location of the trace-cmd executable. */
-#cmakedefine TRACECMD_BIN_DIR "@TRACECMD_BIN_DIR@"
+#cmakedefine TRACECMD_EXECUTABLE "@TRACECMD_EXECUTABLE@"
 
 /** "pkexec" executable. */
 #cmakedefine DO_AS_ROOT "@DO_AS_ROOT@"
kernel-shark/src/KsCaptureDialog.cpp +3 -4
index b107595..7f8cf64 100644
@@ -489,12 +489,11 @@ KsCaptureDialog::KsCaptureDialog(QWidget *parent)
 	connect(&_captureCtrl._closeButton,	&QPushButton::pressed,
 		this,				&KsCaptureDialog::close);
 
-	if (KsUtils::isInstalled())
-		captureExe = QString(_INSTALL_PREFIX) + QString("/bin");
+	if (!KsUtils::isInstalled())
+		captureExe = QString(_INSTALL_PREFIX) + QString("/bin/trace-cmd");
 	else
-		captureExe = TRACECMD_BIN_DIR;
+		captureExe = TRACECMD_EXECUTABLE;
 
-	captureExe += "/trace-cmd";
 	_captureProc.setProgram(captureExe);
 
 	_captureMon.connectMe(&_captureProc, &_captureCtrl);
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 3/3 kernel-shark: Define a CMAKE_BUILD_TYPE "Package"

In reply to Yordan Karadzhov

A special build type dedicated for package maintainers is added. By default this build type adds the "-O2" compiler flag. Users can chose their own compiler flags by providing the corresponding CMAKE_XXXX_FLAGS_PACKAGE Command-Line options.

If no type is specified, the build type will be "Debug".

---
 kernel-shark/CMakeLists.txt | 41 +++++++++++++++++++++++++------------
 kernel-shark/README         | 22 ++++++++++++++------
 2 files changed, 44 insertions(+), 19 deletions(-)
kernel-shark/CMakeLists.txt +28 -13
index 87f33d6..4b58b9b 100644
@@ -36,9 +36,34 @@ set(EXECUTABLE_OUTPUT_PATH "${KS_DIR}/bin")
 set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wall -pthread -fPIC")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -pthread -fPIC")
 
-if(NOT _INSTALL_PREFIX)
-	set(_INSTALL_PREFIX "/usr/local")
-endif()
+if (NOT CMAKE_BUILD_TYPE)
+    set(CMAKE_BUILD_TYPE Debug)
+endif (NOT CMAKE_BUILD_TYPE)
+
+message("\n Build type: ${CMAKE_BUILD_TYPE}")
+
+if (NOT CMAKE_C_FLAGS_PACKAGE)
+    set(CMAKE_C_FLAGS_PACKAGE "-O3")
+endif (NOT CMAKE_C_FLAGS_PACKAGE)
+
+if (NOT CMAKE_CXX_FLAGS_PACKAGE)
+    set(CMAKE_CXX_FLAGS_PACKAGE "-O3")
+endif (NOT CMAKE_CXX_FLAGS_PACKAGE)
+
+if (NOT _INSTALL_PREFIX)
+    set(_INSTALL_PREFIX "/usr/local")
+endif (NOT _INSTALL_PREFIX)
+
+if (CMAKE_BUILD_TYPE MATCHES Package)
+
+    set(CMAKE_INSTALL_RPATH "${_INSTALL_PREFIX}/lib/${KS_APP_NAME}/")
+    set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+
+else (CMAKE_BUILD_TYPE MATCHES Package)
+
+    set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+
+endif (CMAKE_BUILD_TYPE MATCHES Package)
 
 set(KS_PLUGIN_INSTALL_PREFIX ${_INSTALL_PREFIX}/lib/${KS_APP_NAME}/plugins/)
 
@@ -47,16 +72,6 @@ set(KS_ICON_FIN    KS_icon_fin.svg)
 set(KS_LOGO        KS_logo_symbol.svg)
 set(KS_LOGO_LABEL  KS_logo_horizontal.svg)
 
-if (NOT _DEBUG)
-
-	set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -O2")
-	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
-
-endif (NOT _DEBUG)
-
-SET(CMAKE_INSTALL_RPATH "${_INSTALL_PREFIX}/lib/${KS_APP_NAME}/")
-SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
-
 include_directories(${KS_DIR}/src/
                     ${KS_DIR}/build/src/
                     ${JSONC_INCLUDE_DIR}
kernel-shark/README +16 -6
index 379c390..75a0dd0 100644
@@ -38,14 +38,24 @@ the original trace-cmd end traceevent libraries.
 2.1.1 In order to create a Doxygen documentation add -D_DOXYGEN_DOC=1
 as a CMake Command-Line option.
 
-2.1.2 In order to generates complete debug information to be used by GDB add
--D_DEBUG=1 as a CMake Command-Line option.
-
-2.1.3 By default, installation prefix is "/usr/local". It can be changed using
+2.1.2 By default, installation prefix is "/usr/local". It can be changed using
 -D_INSTALL_PREFIX= as a CMake Command-Line option.
 
-Example:
-    cmake -D_DOXYGEN_DOC=1 -D_DEBUG=1 -D_INSTALL_PREFIX=/usr ../
+2.1.3 In addition to the standard CMake build types (Debug, Release,
+RelWithDebInfo, MinSizeRel) KernelShark supports a "Package" build type.
+By default this build type adds the "-O2" compiler flag. Package maintainers
+can chose their own compiler flags by providing the corresponding
+CMAKE_XXXX_FLAGS_PACKAGE Command-Line options (see the example below).
+
+Note that when built as a "Package" the RPATH-s of the executables are
+set directly to _INSTALL_PREFIX/lib/kernelshark/
+
+If no build types is specified, the type will be "Debug".
+
+Examples:
+    cmake -D_DOXYGEN_DOC=1 -D_INSTALL_PREFIX=/usr ../
+
+    cmake -DCMAKE_BUILD_TYPE=Package -DCMAKE_C_FLAGS_PACKAGE="-O3 -pedantic"  ../
 
 2.2.1 Use "make clean" if you want to delete all already compiled objects.
 
Signature · 1 line
2.20.1
#4 lore raw

Re: [PATCH v2 3/3] kernel-shark: Define a CMAKE_BUILD_TYPE "Package"

Quoted 8 lines · On Fri, 14 Jun 2019 13:26:59 +0000 Yordan Karadzhov <[email protected]>…

A special build type dedicated for package maintainers is added. By default this build type adds the "-O2" compiler flag. Users can chose their own compiler flags by providing the corresponding CMAKE_XXXX_FLAGS_PACKAGE Command-Line options.

If no type is specified, the build type will be "Debug".

Hmm, after applying this commit, I get this:

<trace-cmd.git># make install_gui
<trace-cmd.git># cd
<~/># kernelshark
kernelshark: error while loading shared libraries: libkshark-gui.so.0.9.8: cannot open shared object file: No such file or directory

-- Steve

#5 lore raw

Re: [PATCH v2 3/3] kernel-shark: Define a CMAKE_BUILD_TYPE "Package"

Quoted 10 lines · Steven Rostedt
Quoted 7 lines · On Fri, 14 Jun 2019 13:26:59 +0000 Yordan Karadzhov <[email protected]>…

A special build type dedicated for package maintainers is added. By default this build type adds the "-O2" compiler flag. Users can chose their own compiler flags by providing the corresponding CMAKE_XXXX_FLAGS_PACKAGE Command-Line options.

If no type is specified, the build type will be "Debug".

Quoted 9 lines
Quoted 1 line

Hmm, after applying this commit, I get this:

<trace-cmd.git># make install_gui
<trace-cmd.git># cd
<~/># kernelshark
kernelshark: error while loading shared libraries: libkshark-gui.so.0.9.8: cannot open shared object file: No such file or directory

Thanks!
I see my mistake. Is turns that we need to set CMAKE_INSTALL_RPATH regardless of the choice to build with or without RPATH. This is not made clear in the CMake documentation. So the line

set(CMAKE_INSTALL_RPATH "${_INSTALL_PREFIX}/lib/${KS_APP_NAME}/")

has to go outside of the IF. I will send new version of the patch.

Yordan

Quoted 2 lines

-- Steve