linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH v7 05/32] kernel-shark: Define build target for JSONC
Date: Fri, 11 Dec 2020 16:44:44 +0200	[thread overview]
Message-ID: <20201211144511.575346-6-y.karadz@gmail.com> (raw)
In-Reply-To: <20201211144511.575346-1-y.karadz@gmail.com>

Having the JSONC libs as a target simplifies the build/linking of
the KernelShark libraries and executables because all necessary
information, like include paths, compiler flags and library names
can be retriever directly from the target.

The patch also adds to FindJSONC.cmake the standard module
documentation header.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 CMakeLists.txt        |  4 +--
 build/FindJSONC.cmake | 70 +++++++++++++++++++++++++++++++++----------
 src/CMakeLists.txt    |  2 +-
 3 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 007f46a..a66050f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,8 +26,7 @@ include(${KS_DIR}/build/FindTraceCmd.cmake)
 set(CMAKE_MODULE_PATH "${KS_DIR}/build")
 find_package(TraceEvent REQUIRED)
 find_package(TraceFS    REQUIRED)
-
-include(${KS_DIR}/build/FindJSONC.cmake)
+find_package(JSONC      REQUIRED)
 
 find_package(Doxygen)
 
@@ -84,7 +83,6 @@ endif (CMAKE_BUILD_TYPE MATCHES Package)
 
 include_directories(${KS_DIR}/src/
                     ${KS_DIR}/build/src/
-                    ${JSONC_INCLUDE_DIR}
                     ${TRACECMD_INCLUDE_DIR})
 
 message("")
diff --git a/build/FindJSONC.cmake b/build/FindJSONC.cmake
index 3bae20f..2d0d41f 100644
--- a/build/FindJSONC.cmake
+++ b/build/FindJSONC.cmake
@@ -1,13 +1,44 @@
-# - Try to find json-c
-# https://cmake.org/Wiki/CMake:How_To_Find_Libraries
-# Once done this will define
-#  JSONC_FOUND - System has json-c
-#  JSONC_INCLUDE_DIRS - The json-c include directories
-#  JSONC_LIBRARIES - The libraries needed to use json-c
-#  JSONC_DEFINITIONS - Compiler switches required for using json-c
-
-find_package(PkgConfig)
+
+#[=======================================================================[.rst:
+FindJSONC
+-------
+
+Finds the traceevent library.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module defines the :prop_tgt:`IMPORTED` targets:
+
+``jsonc::jsonc``
+ Defined if the system has json-c.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+``JSONC_FOUND``
+  True if the system has the json-c library.
+``JSONC_VERSION``
+  The version of the json-c library which was found.
+``JSONC_INCLUDE_DIRS``
+  Include directories needed to use json-c.
+``JSONC_LIBRARIES``
+  Libraries needed to link to json-c.
+
+Cache Variables
+^^^^^^^^^^^^^^^
+
+``JSONC_INCLUDE_DIR``
+  The directory containing ``json.h``.
+``JSONC_LIBRARY``
+  The path to the traceevent library.
+
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
 pkg_check_modules(PC_JSONC QUIET json-c)
+
+set(JSONC_VERSION     ${PC_JSONC_VERSION})
 set(JSONC_DEFINITIONS ${PC_JSONC_CFLAGS_OTHER})
 
 find_path(JSONC_INCLUDE_DIR json.h
@@ -20,19 +51,28 @@ find_library(JSONC_LIBRARY NAMES json-c libjson-c
 find_library(JSONC_LIBRARY NAMES json-c libjson-c
              HINTS ${PC_JSON-C_LIBDIR} ${PC_JSON-C_LIBRARY_DIRS})
 
+mark_as_advanced(JSONC_INCLUDE_DIR JSONC_LIBRARY)
+
 include(FindPackageHandleStandardArgs)
 # handle the QUIETLY and REQUIRED arguments and set JSONC_FOUND to TRUE
 # if all listed variables are TRUE
 find_package_handle_standard_args(JSONC DEFAULT_MSG
                                   JSONC_LIBRARY JSONC_INCLUDE_DIR)
 
-if (NOT JSONC_FOUND)
+if(JSONC_FOUND)
 
-  message(FATAL_ERROR "Json-C is Required!\n")
+  set(JSONC_LIBRARIES    ${JSONC_LIBRARY})
+  set(JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIR})
 
-endif (NOT JSONC_FOUND)
+  if(NOT TARGET jsonc::jsonc)
+    add_library(jsonc::jsonc UNKNOWN IMPORTED)
 
-mark_as_advanced(JSONC_INCLUDE_DIR JSONC_LIBRARY)
+    set_target_properties(jsonc::jsonc
+                          PROPERTIES
+                            INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIRS}"
+                            INTERFACE_COMPILE_DEFINITIONS "${JSONC_DEFINITIONS}"
+                            IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+                            IMPORTED_LOCATION "${JSONC_LIBRARIES}")
+  endif()
 
-set(JSONC_LIBRARIES    ${JSONC_LIBRARY})
-set(JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIR})
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7474e9d..213ce87 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,7 +10,7 @@ add_library(kshark SHARED libkshark.c
 target_link_libraries(kshark ${TRACECMD_LIBRARY}
                              trace::fs
                              trace::event
-                             ${JSONC_LIBRARY}
+                             jsonc::jsonc
                              ${CMAKE_DL_LIBS})
 
 set_target_properties(kshark  PROPERTIES SUFFIX	".so.${KS_VERSION_STRING}")
-- 
2.25.1


  parent reply	other threads:[~2020-12-11 15:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 14:44 [PATCH v7 00/32] Start KernelShark v2 transformation Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 01/32] kernel-shark: Add license information Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 02/32] kernel-shark: Change the CMake minimum version required Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 03/32] kernel-shark: Use libtraceevent and libtracefs Yordan Karadzhov (VMware)
2020-12-11 19:38   ` Steven Rostedt
2020-12-11 14:44 ` [PATCH v7 04/32] kernel-shark: Update README Yordan Karadzhov (VMware)
2020-12-11 14:44 ` Yordan Karadzhov (VMware) [this message]
2020-12-11 14:44 ` [PATCH v7 06/32] kernel-shark: Use only signed types in kshark_entry Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 07/32] kernel-shark: Add stream_id to kshark_entry Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 08/32] kernel-shark: Introduce libkshark-hash Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 09/32] kernel-shark: Introduce Data streams Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 10/32] kernel-shark: Rename static methods in libkshark Yordan Karadzhov (VMware)
2020-12-11 14:44 ` [PATCH v7 11/32] kernel-shark: Add basic methods for Data streams Yordan Karadzhov (VMware)
2020-12-11 15:07 [PATCH v7 00/32] Start KernelShark v2 transformation Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 05/32] kernel-shark: Define build target for JSONC Yordan Karadzhov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211144511.575346-6-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).