summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake-modules.7.rst1
-rw-r--r--Help/module/FindLTTngUST.rst1
-rw-r--r--Help/release/dev/add-FindLTTngUST.rst5
-rw-r--r--Modules/FindLTTngUST.cmake111
-rw-r--r--Tests/CMakeLists.txt4
-rw-r--r--Tests/CMakeOnly/AllFindModules/CMakeLists.txt2
-rw-r--r--Tests/FindLTTngUST/CMakeLists.txt10
-rw-r--r--Tests/FindLTTngUST/Test/CMakeLists.txt18
-rw-r--r--Tests/FindLTTngUST/Test/main.c31
9 files changed, 182 insertions, 1 deletions
diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index 10f05df..62910cf 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -135,6 +135,7 @@ All Modules
/module/FindLibLZMA
/module/FindLibXml2
/module/FindLibXslt
+ /module/FindLTTngUST
/module/FindLua50
/module/FindLua51
/module/FindLua
diff --git a/Help/module/FindLTTngUST.rst b/Help/module/FindLTTngUST.rst
new file mode 100644
index 0000000..a775462
--- /dev/null
+++ b/Help/module/FindLTTngUST.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLTTngUST.cmake
diff --git a/Help/release/dev/add-FindLTTngUST.rst b/Help/release/dev/add-FindLTTngUST.rst
new file mode 100644
index 0000000..a156cc8
--- /dev/null
+++ b/Help/release/dev/add-FindLTTngUST.rst
@@ -0,0 +1,5 @@
+add-FindLTTngUST
+----------------
+
+* The :module:`FindLTTngUST` module was introduced to find the LTTng-UST
+ library.
diff --git a/Modules/FindLTTngUST.cmake b/Modules/FindLTTngUST.cmake
new file mode 100644
index 0000000..e3220ac
--- /dev/null
+++ b/Modules/FindLTTngUST.cmake
@@ -0,0 +1,111 @@
+#.rst:
+# FindLTTngUST
+# ------------
+#
+# This module finds the `LTTng-UST <http://lttng.org/>`__ library.
+#
+# Imported target
+# ^^^^^^^^^^^^^^^
+#
+# This module defines the following :prop_tgt:`IMPORTED` target:
+#
+# ``LTTng::UST``
+# The LTTng-UST library, if found
+#
+# Result variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module sets the following
+#
+# ``LTTNGUST_FOUND``
+# ``TRUE`` if system has LTTng-UST
+# ``LTTNGUST_INCLUDE_DIRS``
+# The LTTng-UST include directories
+# ``LTTNGUST_LIBRARIES``
+# The libraries needed to use LTTng-UST
+# ``LTTNGUST_VERSION_STRING``
+# The LTTng-UST version
+# ``LTTNGUST_HAS_TRACEF``
+# ``TRUE`` if the ``tracef()`` API is available in the system's LTTng-UST
+# ``LTTNGUST_HAS_TRACELOG``
+# ``TRUE`` if the ``tracelog()`` API is available in the system's LTTng-UST
+
+#=============================================================================
+# Copyright 2016 Kitware, Inc.
+# Copyright 2016 Philippe Proulx <pproulx@efficios.com>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+find_path(LTTNGUST_INCLUDE_DIRS NAMES lttng/tracepoint.h)
+find_library(LTTNGUST_LIBRARIES NAMES lttng-ust)
+
+if(LTTNGUST_INCLUDE_DIRS AND LTTNGUST_LIBRARIES)
+ # find tracef() and tracelog() support
+ set(LTTNGUST_HAS_TRACEF 0)
+ set(LTTNGUST_HAS_TRACELOG 0)
+
+ if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracef.h")
+ set(LTTNGUST_HAS_TRACEF TRUE)
+ endif()
+
+ if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracelog.h")
+ set(LTTNGUST_HAS_TRACELOG TRUE)
+ endif()
+
+ # get version
+ set(lttngust_version_file "${LTTNGUST_INCLUDE_DIRS}/lttng/ust-version.h")
+
+ if(EXISTS "${lttngust_version_file}")
+ file(STRINGS "${lttngust_version_file}" lttngust_version_major_string
+ REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MAJOR_VERSION[\t ]+[0-9]+[\t ]*$")
+ file(STRINGS "${lttngust_version_file}" lttngust_version_minor_string
+ REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MINOR_VERSION[\t ]+[0-9]+[\t ]*$")
+ file(STRINGS "${lttngust_version_file}" lttngust_version_patch_string
+ REGEX "^[\t ]*#define[\t ]+LTTNG_UST_PATCHLEVEL_VERSION[\t ]+[0-9]+[\t ]*$")
+ string(REGEX REPLACE ".*([0-9]+).*" "\\1"
+ lttngust_v_major "${lttngust_version_major_string}")
+ string(REGEX REPLACE ".*([0-9]+).*" "\\1"
+ lttngust_v_minor "${lttngust_version_minor_string}")
+ string(REGEX REPLACE ".*([0-9]+).*" "\\1"
+ lttngust_v_patch "${lttngust_version_patch_string}")
+ set(LTTNGUST_VERSION_STRING
+ "${lttngust_v_major}.${lttngust_v_minor}.${lttngust_v_patch}")
+ unset(lttngust_version_major_string)
+ unset(lttngust_version_minor_string)
+ unset(lttngust_version_patch_string)
+ unset(lttngust_v_major)
+ unset(lttngust_v_minor)
+ unset(lttngust_v_patch)
+ endif()
+
+ unset(lttngust_version_file)
+
+ if(NOT TARGET LTTng::UST)
+ add_library(LTTng::UST UNKNOWN IMPORTED)
+ set_target_properties(LTTng::UST PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${LTTNGUST_INCLUDE_DIRS}"
+ INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${LTTNGUST_LIBRARIES}")
+ endif()
+
+ # add libdl to required libraries
+ set(LTTNGUST_LIBRARIES ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS})
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set LTTNGUST_FOUND to
+# TRUE if all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(LTTngUST FOUND_VAR LTTNGUST_FOUND
+ REQUIRED_VARS LTTNGUST_LIBRARIES
+ LTTNGUST_INCLUDE_DIRS
+ VERSION_VAR LTTNGUST_VERSION_STRING)
+mark_as_advanced(LTTNGUST_LIBRARIES LTTNGUST_INCLUDE_DIRS)
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index ba493cb..c7d2138 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1371,6 +1371,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindJsonCpp)
endif()
+ if(CMake_TEST_FindLTTngUST)
+ add_subdirectory(FindLTTngUST)
+ endif()
+
if(CMake_TEST_FindOpenSSL)
add_subdirectory(FindOpenSSL)
endif()
diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
index 0aad161..1f39052 100644
--- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
+++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
@@ -81,7 +81,7 @@ endmacro()
# reported.
foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HG
- HSPELL ICOTOOL JASPER LIBLZMA LIBXML2 LIBXSLT PERL PKG_CONFIG
+ HSPELL ICOTOOL JASPER LIBLZMA LIBXML2 LIBXSLT LTTNGUST PERL PKG_CONFIG
PostgreSQL TIFF ZLIB)
check_version_string(${VTEST} ${VTEST}_VERSION_STRING)
endforeach()
diff --git a/Tests/FindLTTngUST/CMakeLists.txt b/Tests/FindLTTngUST/CMakeLists.txt
new file mode 100644
index 0000000..c9c471d
--- /dev/null
+++ b/Tests/FindLTTngUST/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindLTTngUST.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindLTTngUST/Test"
+ "${CMake_BINARY_DIR}/Tests/FindLTTngUST/Test"
+ ${build_generator_args}
+ --build-project TestFindLTTngUST
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindLTTngUST/Test/CMakeLists.txt b/Tests/FindLTTngUST/Test/CMakeLists.txt
new file mode 100644
index 0000000..e5bd9f3
--- /dev/null
+++ b/Tests/FindLTTngUST/Test/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.5)
+project(TestFindLTTngUST C)
+include(CTest)
+
+find_package(LTTngUST REQUIRED)
+
+add_definitions(-DCMAKE_EXPECTED_LTTNGUST_VERSION="${LTTNGUST_VERSION_STRING}")
+add_definitions(-DCMAKE_LTTNGUST_HAS_TRACEF="${LTTNGUST_HAS_TRACEF}")
+add_definitions(-DCMAKE_LTTNGUST_HAS_TRACELOG="${LTTNGUST_HAS_TRACELOG}")
+
+add_executable(test_tgt main.c)
+target_link_libraries(test_tgt LTTng::UST)
+add_test(NAME test_tgt COMMAND test_tgt)
+
+add_executable(test_var main.c)
+target_include_directories(test_var PRIVATE ${LTTNGUST_INCLUDE_DIRS})
+target_link_libraries(test_var PRIVATE ${LTTNGUST_LIBRARIES})
+add_test(NAME test_var COMMAND test_var)
diff --git a/Tests/FindLTTngUST/Test/main.c b/Tests/FindLTTngUST/Test/main.c
new file mode 100644
index 0000000..ac775a0
--- /dev/null
+++ b/Tests/FindLTTngUST/Test/main.c
@@ -0,0 +1,31 @@
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <lttng/ust-version.h>
+
+#ifdef CMAKE_LTTNGUST_HAS_TRACEF
+#include <lttng/tracef.h>
+#endif
+
+#ifdef CMAKE_LTTNGUST_HAS_TRACELOG
+#include <lttng/tracelog.h>
+#endif
+
+int main(void)
+{
+ char lttng_version_string[16];
+
+ snprintf(lttng_version_string, 16, "%u.%u.%u", LTTNG_UST_MAJOR_VERSION,
+ LTTNG_UST_MINOR_VERSION, LTTNG_UST_PATCHLEVEL_VERSION);
+ assert(!strcmp(lttng_version_string, CMAKE_EXPECTED_LTTNGUST_VERSION));
+
+#ifdef CMAKE_LTTNGUST_HAS_TRACEF
+ tracef("calling tracef()! %d %s", -23, CMAKE_EXPECTED_LTTNGUST_VERSION);
+#endif
+
+#ifdef CMAKE_LTTNGUST_HAS_TRACELOG
+ tracelog(TRACE_WARNING, "calling tracelog()! %d", 17);
+#endif
+
+ return 0;
+}