1CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
2PROJECT(phosphor)
3
4INCLUDE(CTest)
5include(check_unit_test_enabled)
6
7check_unit_test_enabled(phosphor COUCHBASE_PHOSPHOR_BUILD_UNIT_TESTS)
8
9IF (${CMAKE_MAJOR_VERSION} GREATER 2)
10    CMAKE_POLICY(SET CMP0042 NEW)
11ENDIF ()
12
13IF(NOT DEFINED COUCHBASE_SERVER_BUILD)
14    INCLUDE(NonServerBuild.cmake)
15ENDIF ()
16
17INCLUDE_DIRECTORIES(BEFORE
18        ${phosphor_SOURCE_DIR}/include
19        ${phosphor_SOURCE_DIR}/src
20        ${phosphor_SOURCE_DIR}/thirdparty/dvyukov/include)
21
22SET(phosphor_HEADER_FILES
23        ${phosphor_SOURCE_DIR}/include/phosphor/category_registry.h
24        ${phosphor_SOURCE_DIR}/include/phosphor/chunk_lock.h
25        ${phosphor_SOURCE_DIR}/include/phosphor/inline_zstring.h
26        ${phosphor_SOURCE_DIR}/include/phosphor/phosphor.h
27        ${phosphor_SOURCE_DIR}/include/phosphor/phosphor-internal.h
28        ${phosphor_SOURCE_DIR}/include/phosphor/relaxed_atomic.h
29        ${phosphor_SOURCE_DIR}/include/phosphor/scoped_event_guard.h
30        ${phosphor_SOURCE_DIR}/include/phosphor/stats_callback.h
31        ${phosphor_SOURCE_DIR}/include/phosphor/trace_argument.h
32        ${phosphor_SOURCE_DIR}/include/phosphor/trace_buffer.h
33        ${phosphor_SOURCE_DIR}/include/phosphor/trace_config.h
34        ${phosphor_SOURCE_DIR}/include/phosphor/trace_context.h
35        ${phosphor_SOURCE_DIR}/include/phosphor/trace_event.h
36        ${phosphor_SOURCE_DIR}/include/phosphor/trace_log.h
37        ${phosphor_SOURCE_DIR}/include/phosphor/tracepoint_info.h
38        ${phosphor_SOURCE_DIR}/include/phosphor/platform/core.h
39        ${phosphor_SOURCE_DIR}/include/phosphor/platform/thread.h
40        ${phosphor_SOURCE_DIR}/include/phosphor/platform/visibility.h
41        ${phosphor_SOURCE_DIR}/include/phosphor/tools/export.h)
42
43SET(phosphor_SOURCE_FILES
44        ${phosphor_SOURCE_DIR}/src/category_registry.cc
45        ${phosphor_SOURCE_DIR}/src/chunk_lock.cc
46        ${phosphor_SOURCE_DIR}/src/trace_buffer.cc
47        ${phosphor_SOURCE_DIR}/src/trace_config.cc
48        ${phosphor_SOURCE_DIR}/src/trace_context.cc
49        ${phosphor_SOURCE_DIR}/src/trace_event.cc
50        ${phosphor_SOURCE_DIR}/src/trace_log.cc
51        ${phosphor_SOURCE_DIR}/src/platform/thread.cc
52        ${phosphor_SOURCE_DIR}/src/tools/export.cc
53        ${phosphor_SOURCE_DIR}/src/utils/memory.cc
54        ${phosphor_SOURCE_DIR}/src/utils/string_utils.cc)
55
56ADD_LIBRARY(phosphor SHARED
57        ${phosphor_HEADER_FILES}
58        ${phosphor_SOURCE_FILES})
59
60INSTALL(TARGETS phosphor
61        RUNTIME DESTINATION bin
62        LIBRARY DESTINATION lib
63        ARCHIVE DESTINATION lib)
64
65# To allow targets which depend on phosphor, but don't themselves
66# support running under Sanitizers (e.g. Erlang NIFs use platform
67# which uses phosphor), add a variant library 'phosphor_unsanitized'
68# which has Sanitizers disabled on it.
69IF(CB_SANITIZERS)
70  ADD_LIBRARY(phosphor_unsanitized SHARED
71    ${phosphor_HEADER_FILES}
72    ${phosphor_SOURCE_FILES})
73  REMOVE_SANITIZERS(phosphor_unsanitized)
74
75  INSTALL(TARGETS phosphor_unsanitized
76    RUNTIME DESTINATION bin
77    LIBRARY DESTINATION lib
78    ARCHIVE DESTINATION lib)
79ELSE()
80  ADD_LIBRARY(phosphor_unsanitized ALIAS phosphor)
81ENDIF()
82
83SET(PHOSPHOR_LIB phosphor)
84GET_DIRECTORY_PROPERTY(hasParent PARENT_DIRECTORY)
85IF(hasParent)
86    SET(PHOSPHOR_LIB phosphor PARENT_SCOPE)
87ENDIF()
88
89if (COUCHBASE_PHOSPHOR_BUILD_UNIT_TESTS)
90    ADD_SUBDIRECTORY(tests)
91endif(COUCHBASE_PHOSPHOR_BUILD_UNIT_TESTS)
92
93option(PHOSPHOR_BUILD_EXAMPLES "Enable building the examples" OFF)
94IF(PHOSPHOR_BUILD_EXAMPLES)
95    ADD_SUBDIRECTORY(examples)
96ENDIF ()
97
98ENABLE_CODE_COVERAGE_REPORT()
99