]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: revamp on lttng support
authorKefu Chai <kchai@redhat.com>
Thu, 26 May 2016 06:32:48 +0000 (14:32 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 27 May 2016 11:54:42 +0000 (19:54 +0800)
* Findlttng-ust.cmake: detect lttng-gen-tp, and make it a required var
* Findlttng-ust.cmake: fix the detection of lttng
* src/tracing/CMakeLists.txt:
  - do not put the generated header files into ${CMAKE_SOURCE_DIR}/src/tracing,
    instead we should put the generated files into ${PROJECT_BINARY_DIR}/include.
  - do not compile the tracing library using the .c files in the repo,
    instead, we should generate them at compile time using lttng-gen-tp,
    and compile the genererated .c files.
* CMakeLists.txt: make the lttng-use package REQUIRED if WITH_LTTNG=ON
* src/CMakeLists.txt: let librados depend on librados-tp if LTTNG is
  enabled: librados includes tracing/librados.h. the same applies to
  librbd, libos and libosd. cmake could deduce the dependencies if we
  add the lttng header files under include/tracing into the
  corresponding target, as the lttng header files are already listed
  as OUTPUT and GENERATED files, but this requires us to put all the
  involved targets in the same CMakeLists.txt. in this case, three
  CMakeLists.txts are impacted. so we create a new target for each
  lttng header, and let the impacted target depend on it.

Signed-off-by: Kefu Chai <kchai@redhat.com>
CMakeLists.txt
cmake/modules/Findlttng-ust.cmake
src/CMakeLists.txt
src/librbd/CMakeLists.txt
src/tracing/CMakeLists.txt

index 159702253f615a9e1a1cd24249bbed5cef658462..9552e05fc926d437a2a54937f688e11958c0a34d 100644 (file)
@@ -332,8 +332,7 @@ 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)
-  set(WITH_LTTNG ${LTTNG_FOUND})
+  find_package(lttng-ust REQUIRED)
 endif(${WITH_LTTNG})
 
 #option for Babeltrace
index c04a474379c95d8a1b0db3d95c233c6ba93106e5..e4498e57a034ee8e4a2ecbeecb205fe360718863 100644 (file)
@@ -53,18 +53,19 @@ find_program(LTTNG_EXECUTABLE
   PATHS ${LTTNG_PATH_HINT}/bin
   NO_DEFAULT_PATH
   DOC "The LTTNG command line tool")
-find_program(LEX_PROGRAM
+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)
+                                  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)
-
index 019c40e517b71ba5ad098ce954392381f40da87c..b5a182832ebb9e9e27345c36fc681d6397d13580 100644 (file)
@@ -530,6 +530,9 @@ add_library(librados ${CEPH_SHARED} ${librados_srcs}
   $<TARGET_OBJECTS:cls_references_objs>
   $<TARGET_OBJECTS:common_util_obj>)
 add_dependencies(librados osdc)
+if(WITH_LTTNG)
+  add_dependencies(librados librados-tp)
+endif()
 # LINK_PRIVATE instead of PRIVATE is used to backward compatibility with cmake 2.8.11
 target_link_libraries(librados LINK_PRIVATE osdc osd os global common cls_lock_client
   ${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
@@ -844,6 +847,9 @@ if(WITH_SPDK)
     ${DPDK_INCLUDE_DIR}
     ${PCIACCESS_INCLUDE_DIR})
 endif(WITH_SPDK)
+if(WITH_LTTNG)
+  add_dependencies(os objectstore-tp)
+endif()
 target_link_libraries(os kv)
 
 set(cls_references_files objclass/class_api.cc)
@@ -882,6 +888,9 @@ add_library(osd_mon_objs OBJECT ${osd_mon_files})
 add_library(osd STATIC ${osd_srcs} $<TARGET_OBJECTS:osd_mon_objs>
   $<TARGET_OBJECTS:cls_references_objs> $<TARGET_OBJECTS:heap_profiler_objs>)
 target_link_libraries(osd dl leveldb ${ALLOC_LIBS})
+if(WITH_LTTNG)
+  add_dependencies(osd osd-tp)
+endif()
 
 set(ceph_osd_srcs
   ceph_osd.cc
index e75407ce031b845243639aea5da46d4bfa56bec5..67c7235c51dcfabb728be17bcf44017944620a18 100644 (file)
@@ -63,6 +63,9 @@ set(librbd_internal_srcs
 
 add_library(rbd_api STATIC librbd.cc)
 add_library(rbd_internal STATIC ${librbd_internal_srcs})
+if(WITH_LTTNG)
+  add_dependencies(rbd_internal librbd-tp)
+endif()
 
 add_library(librbd ${CEPH_SHARED}
   $<TARGET_OBJECTS:osdc_rbd_objs>
index 1305a35bcb3ab6073a66a0619b215eae3c61a8c7..da9af34a4045163f9cac3b099ff31233a26430bc 100644 (file)
@@ -1,40 +1,50 @@
-add_custom_target(lttng_gen_tp
-  ALL
-  COMMAND 
-  lttng-gen-tp tracing/librados.tp -o tracing/librados.h && 
-  lttng-gen-tp tracing/librbd.tp -o tracing/librbd.h && 
-  lttng-gen-tp tracing/objectstore.tp -o tracing/objectstore.h && 
-  lttng-gen-tp tracing/oprequest.tp -o tracing/oprequest.h &&
-  lttng-gen-tp tracing/osd.tp -o tracing/osd.h &&
-  lttng-gen-tp tracing/pg.tp -o tracing/pg.h
-  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
-  COMMENT "lttng-gen-tp generated .h files")
+# we are in "src/tracing", so create the output dir manually.
+# the source files include the tracing headers like
+# #include "tracing/oprequest.h". so better put them into
+# ${PROJECT_BINARY_DIR}/include, where acconfig.h is also located
+set(header_dir ${CMAKE_BINARY_DIR}/include/tracing)
+file(MAKE_DIRECTORY ${header_dir})
 
-add_library(libosd_tp STATIC
-  oprequest.c
-  osd.c
-  pg.c)
-target_link_libraries(libosd_tp lttng-ust dl)
-target_include_directories(libosd_tp PUBLIC ${CMAKE_SOURCE_DIR}/src/tracing)
-add_dependencies(libosd_tp lttng_gen_tp)
-set_target_properties(libosd_tp PROPERTIES OUTPUT_NAME osd_tp VERSION 1.0.0 SOVERSION 1)
+file(GLOB tps "*.tp")
+foreach(tp ${tps})
+  get_filename_component(name ${tp} NAME_WE)
+  set(header ${header_dir}/${name}.h)
+  set(src ${header_dir}/${name}.c)
+  add_custom_command(
+    OUTPUT ${header} ${src}
+    COMMAND ${LTTNG_GEN_TP} ${tp} -o tracing/${name}.h -o tracing/${name}.c
+    DEPENDS ${tp}
+    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/include
+    COMMENT "generating ${header} ${src}")
+  set_source_files_properties(${header} ${src}
+    PROPERTIES GENERATED TRUE)
+  add_custom_target(
+    ${name}-tp
+    DEPENDS ${header})
+endforeach()
 
-add_library(librados_tp STATIC librados.c)
-target_link_libraries(librados_tp lttng-ust dl)
-target_include_directories(librados_tp PUBLIC ${CMAKE_SOURCE_DIR}/src/tracing)
-add_dependencies(librados_tp lttng_gen_tp)
-set_target_properties(librados_tp PROPERTIES OUTPUT_NAME rados_tp VERSION 2.0.0 SOVERSION 2)
+function(add_tracing_library name tracings version)
+  foreach(tp_file ${tracings})
+    get_filename_component(tp ${tp_file} NAME_WE)
+    list(APPEND srcs
+      ${header_dir}/${tp}.h
+      ${header_dir}/${tp}.c)
+  endforeach()
+  add_library(${name} STATIC ${srcs})
+  target_link_libraries(${name} ${LTTNG_LIBRARIES} dl)
+  string(REGEX MATCH "^[0-9]+" soversion ${version})
+  string(REGEX REPLACE "^lib" "" output_name ${name})
+  set_target_properties(${name} PROPERTIES
+    OUTPUT_NAME ${output_name}
+    VERSION ${version}
+    SOVERSION ${soversion})
+endfunction()
 
-add_library(librbd_tp STATIC librbd.c)
-target_link_libraries(librbd_tp lttng-ust dl)
-target_include_directories(librbd_tp PUBLIC ${CMAKE_SOURCE_DIR}/src/tracing)
-add_dependencies(librbd_tp lttng_gen_tp)
-set_target_properties(librbd_tp PROPERTIES OUTPUT_NAME rbd_tp VERSION 1.0.0 SOVERSION 1)
-
-add_library(libos_tp STATIC objectstore.c)
-target_link_libraries(libos_tp lttng-ust dl)
-target_include_directories(libos_tp PUBLIC ${CMAKE_SOURCE_DIR}/src/tracing)
-add_dependencies(libos_tp lttng_gen_tp)
-set_target_properties(libos_tp PROPERTIES OUTPUT_NAME os_tp VERSION 1.0.0 SOVERSION 1)
+set(osd_traces oprequest.tp osd.tp pg.tp)
+add_tracing_library(libosd_tp "${osd_traces}" 1.0.0)
+add_tracing_library(librados_tp librados.tp 2.0.0)
+add_tracing_library(librbd_tp librbd.tp 1.0.0)
+add_tracing_library(libos_tp objectstore.tp 1.0.0)
 
 install(TARGETS librados_tp libosd_tp librbd_tp libos_tp DESTINATION lib)
+