1FIND_PROGRAM(DTRACE dtrace)
2IF(DTRACE)
3    SET(LCB_DTRACE_HEADER "${LCB_GENSRCDIR}/probes.h")
4    SET(LCB_DTRACE_SRC "${PROJECT_SOURCE_DIR}/src/probes.d")
5
6    # Generate probes.h
7    EXECUTE_PROCESS(COMMAND ${DTRACE} -C -h -s ${LCB_DTRACE_SRC} -o ${LCB_DTRACE_HEADER}
8        RESULT_VARIABLE _rv)
9    IF(NOT ${_rv} EQUAL 0)
10        MESSAGE(WARNING "Could not execute DTrace. DTrace support will be disabled!")
11        RETURN()
12    ENDIF()
13
14    # Fix probes.h on FreeBSD
15    IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
16        FIND_PROGRAM(SED sed)
17        EXECUTE_PROCESS(COMMAND ${SED} -i.tmp "s/, *char \\*/, const char \\*/g" ${LCB_DTRACE_HEADER}
18            RESULT_VARIABLE _rv)
19        IF(NOT ${_rv} EQUAL 0)
20            MESSAGE(WARNING "Could not execute sed to update dtrace-generated header. DTrace support will be disabled!")
21            RETURN()
22        ENDIF()
23    ENDIF()
24
25    ADD_DEFINITIONS(-DHAVE_DTRACE)
26    IF(NOT APPLE)
27        SET(LCB_DTRACE_OBJECT "${LCB_GENSRCDIR}/probes.o")
28        IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
29            SET(LCB_DTRACE_OPTIONS "-k")
30        ENDIF()
31        # Generate probes.o
32        IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
33            SET(LCB_DTRACE_INSTRO ON)
34            UNSET(LCB_DTRACE_OBJECT)
35        ELSE()
36            ADD_CUSTOM_COMMAND(OUTPUT ${LCB_DTRACE_OBJECT}
37                DEPENDS ${LCB_DTRACE_SRC}
38                COMMAND ${DTRACE} -C -G ${LCB_DTRACE_OPTIONS} -s ${LCB_DTRACE_SRC} -o ${LCB_DTRACE_OBJECT})
39        ENDIF()
40    ENDIF()
41
42    FIND_PROGRAM(STAP stap)
43    IF(STAP)
44      SET(LCB_TAPSET_ROOT ${CMAKE_INSTALL_PREFIX}/share/systemtap/tapset)
45      CONFIGURE_FILE(
46        ${PROJECT_SOURCE_DIR}/cmake/libcouchbase.stp.in
47        ${LCB_GENSRCDIR}/libcouchbase.so.${LCB_SONAME_FULL}.stp)
48      INSTALL(
49        FILES ${LCB_GENSRCDIR}/libcouchbase.so.${LCB_SONAME_FULL}.stp
50        DESTINATION ${LCB_TAPSET_ROOT})
51    ENDIF()
52ENDIF()
53