1f1603f8cSMark NunbergFIND_PROGRAM(DTRACE dtrace)
2f1603f8cSMark NunbergIF(DTRACE)
3f1603f8cSMark Nunberg    SET(LCB_DTRACE_HEADER "${LCB_GENSRCDIR}/probes.h")
42a07f70bSMark Nunberg    SET(LCB_DTRACE_SRC "${PROJECT_SOURCE_DIR}/src/probes.d")
5f1603f8cSMark Nunberg
6f1603f8cSMark Nunberg    # Generate probes.h
7d7a144f8SMark Nunberg    EXECUTE_PROCESS(COMMAND ${DTRACE} -C -h -s ${LCB_DTRACE_SRC} -o ${LCB_DTRACE_HEADER}
8d7a144f8SMark Nunberg        RESULT_VARIABLE _rv)
9d7a144f8SMark Nunberg    IF(NOT ${_rv} EQUAL 0)
10d7a144f8SMark Nunberg        MESSAGE(WARNING "Could not execute DTrace. DTrace support will be disabled!")
11d7a144f8SMark Nunberg        RETURN()
12d7a144f8SMark Nunberg    ENDIF()
13f1603f8cSMark Nunberg
147dc493a4SSergey Avseyev    # Fix probes.h on FreeBSD
157dc493a4SSergey Avseyev    IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
167dc493a4SSergey Avseyev        FIND_PROGRAM(SED sed)
177dc493a4SSergey Avseyev        EXECUTE_PROCESS(COMMAND ${SED} -i.tmp "s/, *char \\*/, const char \\*/g" ${LCB_DTRACE_HEADER}
187dc493a4SSergey Avseyev            RESULT_VARIABLE _rv)
197dc493a4SSergey Avseyev        IF(NOT ${_rv} EQUAL 0)
207dc493a4SSergey Avseyev            MESSAGE(WARNING "Could not execute sed to update dtrace-generated header. DTrace support will be disabled!")
217dc493a4SSergey Avseyev            RETURN()
227dc493a4SSergey Avseyev        ENDIF()
237dc493a4SSergey Avseyev    ENDIF()
247dc493a4SSergey Avseyev
25d7a144f8SMark Nunberg    ADD_DEFINITIONS(-DHAVE_DTRACE)
26f1603f8cSMark Nunberg    IF(NOT APPLE)
27f1603f8cSMark Nunberg        SET(LCB_DTRACE_OBJECT "${LCB_GENSRCDIR}/probes.o")
28728ef344SSergey Avseyev        IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
294fda7574SSergey Avseyev            SET(LCB_DTRACE_OPTIONS "-k")
30728ef344SSergey Avseyev        ENDIF()
31f1603f8cSMark Nunberg        # Generate probes.o
32d7a144f8SMark Nunberg        IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
3311e5515bSMark Nunberg            SET(LCB_DTRACE_INSTRO ON)
3411e5515bSMark Nunberg            UNSET(LCB_DTRACE_OBJECT)
3511e5515bSMark Nunberg        ELSE()
3611e5515bSMark Nunberg            ADD_CUSTOM_COMMAND(OUTPUT ${LCB_DTRACE_OBJECT}
3711e5515bSMark Nunberg                DEPENDS ${LCB_DTRACE_SRC}
384fda7574SSergey Avseyev                COMMAND ${DTRACE} -C -G ${LCB_DTRACE_OPTIONS} -s ${LCB_DTRACE_SRC} -o ${LCB_DTRACE_OBJECT})
3911e5515bSMark Nunberg        ENDIF()
40f1603f8cSMark Nunberg    ENDIF()
41b68c7c8dSSergey Avseyev
42b68c7c8dSSergey Avseyev    FIND_PROGRAM(STAP stap)
43b68c7c8dSSergey Avseyev    IF(STAP)
44c3b9f31cSSergey Avseyev      SET(LCB_TAPSET_ROOT ${CMAKE_INSTALL_PREFIX}/share/systemtap/tapset)
45b68c7c8dSSergey Avseyev      CONFIGURE_FILE(
46b68c7c8dSSergey Avseyev        ${PROJECT_SOURCE_DIR}/cmake/libcouchbase.stp.in
47b68c7c8dSSergey Avseyev        ${LCB_GENSRCDIR}/libcouchbase.so.${LCB_SONAME_FULL}.stp)
48b68c7c8dSSergey Avseyev      INSTALL(
49b68c7c8dSSergey Avseyev        FILES ${LCB_GENSRCDIR}/libcouchbase.so.${LCB_SONAME_FULL}.stp
50b68c7c8dSSergey Avseyev        DESTINATION ${LCB_TAPSET_ROOT})
51b68c7c8dSSergey Avseyev    ENDIF()
52f1603f8cSMark NunbergENDIF()
53