From: Kefu Chai Date: Tue, 30 Aug 2016 05:33:24 +0000 (+0800) Subject: cmake: replace Findlttng-ust.cmake with FindLTTngUST.cmake X-Git-Tag: v11.0.1~358^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2ed44f993f7b33f683d1cf7ef3592b13e25f7129;p=ceph.git cmake: replace Findlttng-ust.cmake with FindLTTngUST.cmake find_package(lttng-ust REQUIRED) fails to find the lttng library without this change. because find_path(LTTNG_LIBRARY_DIR ...) does not search in the default library paths. and the second mode of FIND_PACKAGE_HANDLE_STANDARD_ARGS() does not stop the cmake with a fatal message, even some of the required vars are missing. so use the implemetantion from cmake upstream. Signed-off-by: Kefu Chai --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 29b7549f66585..7f861b057a59e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,7 +348,12 @@ find_package(ZLIB REQUIRED) #currently off by default because lttng-gen-tp run unconditionally and forces a rebuild option(WITH_LTTNG "LTTng tracing is enabled" OFF) if(${WITH_LTTNG}) - find_package(lttng-ust REQUIRED) + find_package(LTTngUST REQUIRED) + find_program(LTTNG_GEN_TP + lttng-gen-tp) + if(NOT LTTNG_GEN_TP) + message(FATAL_ERROR "Can't find lttng-gen-tp.") + endif() endif(${WITH_LTTNG}) #option for Babeltrace diff --git a/cmake/modules/FindLTTngUST.cmake b/cmake/modules/FindLTTngUST.cmake new file mode 100644 index 0000000000000..ac8f14c645c58 --- /dev/null +++ b/cmake/modules/FindLTTngUST.cmake @@ -0,0 +1,111 @@ +#.rst: +# FindLTTngUST +# ------------ +# +# This module finds the `LTTng-UST `__ 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 +# +# 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(FindPackageHandleStandardArgs) +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/cmake/modules/Findlttng-ust.cmake b/cmake/modules/Findlttng-ust.cmake deleted file mode 100644 index e4498e57a034e..0000000000000 --- a/cmake/modules/Findlttng-ust.cmake +++ /dev/null @@ -1,71 +0,0 @@ -# - Find LTTng -# Find the Linux Trace Toolkit - next generation with associated includes path. -# See http://lttng.org/ -# -# This module accepts the following optional variables: -# LTTNG_PATH_HINT = A hint on LTTNG install path. -# -# This module defines the following variables: -# LTTNG_FOUND = Was LTTng found or not? -# LTTNG_EXECUTABLE = The path to lttng command -# LTTNG_LIBRARIES = The list of libraries to link to when using LTTng -# LTTNG_INCLUDE_DIR = The path to LTTng include directory -# -# On can set LTTNG_PATH_HINT before using find_package(LTTng) and the -# module with use the PATH as a hint to find LTTng. -# -# The hint can be given on the command line too: -# cmake -DLTTNG_PATH_HINT=/DATA/ERIC/LTTng /path/to/source - -if(LTTNG_PATH_HINT) - message(STATUS "FindLTTng: using PATH HINT: ${LTTNG_PATH_HINT}") -else() - set(LTTNG_PATH_HINT) -endif() - -#One can add his/her own builtin PATH. -#FILE(TO_CMAKE_PATH "/DATA/ERIC/LTTng" MYPATH) -#list(APPEND LTTNG_PATH_HINT ${MYPATH}) - -find_path(LTTNG_INCLUDE_DIR - NAMES lttng/tracepoint.h - PATHS ${LTTNG_PATH_HINT} - PATH_SUFFIXES include - DOC "The LTTng include headers") - -find_path(LTTNG_LIBRARY_DIR - NAMES liblttng-ust.so - PATHS ${LTTNG_PATH_HINT} - PATH_SUFFIXES lib lib64 - DOC "The LTTng libraries") - -find_library(LTTNG_UST_LIBRARY lttng-ust PATHS ${LTTNG_LIBRARY_DIR}) -find_library(URCU_LIBRARY urcu-bp PATHS ${LTTNG_LIBRARY_DIR}) -find_library(UUID_LIBRARY uuid) - -set(LTTNG_LIBRARIES ${LTTNG_UST_LIBRARY} ${URCU_LIBRARY} ${UUID_LIBRARY}) - -message(STATUS "Looking for lttng executable...") -set(LTTNG_NAMES "lttng;lttng-ctl") -# FIND_PROGRAM twice using NO_DEFAULT_PATH on first shot -find_program(LTTNG_EXECUTABLE - NAMES ${LTTNG_NAMES} - PATHS ${LTTNG_PATH_HINT}/bin - NO_DEFAULT_PATH - DOC "The LTTNG command line tool") -find_program(LTTNG_EXECUTABLE - NAMES ${LTTNG_NAMES} - PATHS ${LTTNG_PATH_HINT}/bin - DOC "The LTTNG command line tool") -find_program(LTTNG_GEN_TP NAMES lttng-gen-tp - DOC "The lttng-gen-tp command line tool") - -# handle the QUIETLY and REQUIRED arguments and set PRELUDE_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LTTNG - REQUIRED_VARS LTTNG_INCLUDE_DIR LTTNG_LIBRARY_DIR LTTNG_GEN_TP) -# VERSION FPHSA options not handled by CMake version < 2.8.2) -# VERSION_VAR) -mark_as_advanced(LTTNG_INCLUDE_DIR) -mark_as_advanced(LTTNG_LIBRARY_DIR) diff --git a/debian/copyright b/debian/copyright index db2fafaaa6335..c4c4a3b679ced 100644 --- a/debian/copyright +++ b/debian/copyright @@ -7,6 +7,12 @@ Files: * Copyright: (c) 2004-2010 by Sage Weil License: LGPL2.1 (see COPYING-LGPL2.1) +Files: cmake/modules/FindLTTngUST.cmake +Copyright: + Copyright 2016 Kitware, Inc. + Copyright 2016 Philippe Proulx +License: BSD 3-clause + Files: doc/* Copyright: (c) 2010-2012 New Dream Network and contributors License: Creative Commons Attribution-ShareAlike (CC BY-SA) diff --git a/src/tracing/CMakeLists.txt b/src/tracing/CMakeLists.txt index 7d0749d9ee1f7..9b21a092a05b0 100644 --- a/src/tracing/CMakeLists.txt +++ b/src/tracing/CMakeLists.txt @@ -30,7 +30,7 @@ function(add_tracing_library name tracings version) ${header_dir}/${tp}.c) endforeach() add_library(${name} SHARED ${srcs}) - target_link_libraries(${name} ${LTTNG_LIBRARIES} ${CMAKE_DL_LIBS}) + target_link_libraries(${name} ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS}) string(REGEX MATCH "^[0-9]+" soversion ${version}) set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}