forked from sfu-dis/pmwcas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
159 lines (129 loc) · 5.13 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
cmake_minimum_required (VERSION 3.12)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.")
endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
project(pmwcas)
include(FetchContent)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long -pedantic -fPIC -march=native")
if (CMAKE_BUILD_TYPE EQUAL "Release")
message("-- Release mode, all optimizations enabled")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Ofast")
endif ()
FUNCTION(PMWCAS_DEFINE_ENV)
# Set backend to PMDK by default to build persistent version
set(PMEM_BACKEND "PMDK" CACHE STRING "Persistent memory backend type")
string(TOUPPER ${PMEM_BACKEND} PMEM_BACKEND)
# Both volatile and persistent versions are supported, by setting PMEM_BACKEND to:
# PMDK : use PMDK for persistence
# EMU : use simple shared memory for emulating persistent memory. This
# should only be used for experimental and profiling purpose. No real
# persistence is guaranteed.
# VOLATILE: turn off persistence and build a volatile version, no persistence
# whatsoever. Equivalent to the original MwCAS operation.
#
# If persistent memory support is turned on, in the code we define both PMEM and
# the corresponding macro for the backend. Code that is agnostic to the backend
# is wrapped by PMEM; code that is specific to the backend is wrapped around by
# PMEMEMU (for using emulation) or PMDK (for using PMDK).
if(${PMEM_BACKEND} STREQUAL "PMDK")
add_definitions(-DPMEM)
add_definitions(-DPMDK)
message(STATUS "Persistence support: PMDK")
elseif(${PMEM_BACKEND} STREQUAL "EMU")
add_definitions(-DPMEM)
add_definitions(-DPMEMEMU)
message(STATUS "Persistence support: PMDK")
message(STATUS "Persistence support: emulation")
elseif(${PMEM_BACKEND} STREQUAL "VOLATILE")
message(STATUS "Persistence support: off")
else()
message(FATAL_ERROR "Unsupported persistent memory backend: ${PMEM_BACKEND}")
endif()
# Descriptor capacity - default four words max
set(DESC_CAP "4" CACHE STRING "Descriptor capacity")
add_definitions(-DDESC_CAP=${DESC_CAP})
message(STATUS "Descirptor capacity: ${DESC_CAP}")
ENDFUNCTION()
# The PMWCAS_DEFINE_ENV is used for libraries depend on it to properly setup compile definitions.
PMWCAS_DEFINE_ENV()
# Turn off RTM by default - only allowed when persistence is turned off (i.e.,
# PMEM_BACKEND == VOLATILE
option(WITH_RTM "Use RTM for installing descriptors" OFF)
if(WITH_RTM)
add_definitions(-DRTM)
message("-- RTM configured")
endif()
##################### PMDK ####################
if(${PMEM_BACKEND} STREQUAL "PMDK")
set(PMDK_LIB_PATH "/usr/local/lib" CACHE STRING "PMDK lib install path")
add_library(pmemobj SHARED IMPORTED)
set_property(TARGET pmemobj PROPERTY IMPORTED_LOCATION ${PMDK_LIB_PATH}/libpmemobj.so)
endif()
##############################################
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/src)
# Google Test
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
)
FetchContent_GetProperties(googletest)
if (NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif ()
include(GoogleTest)
# Google Log
FetchContent_Declare(
glog
GIT_REPOSITORY https://github.com/google/glog.git
GIT_TAG v0.4.0
)
FetchContent_GetProperties(glog)
if (NOT glog_POPULATED)
FetchContent_Populate(glog)
set(WITH_GFLAGS OFF CACHE BOOL "we don't want gflags")
add_subdirectory(${glog_SOURCE_DIR} ${glog_BINARY_DIR})
endif()
# Set the list of libraries that make up the pmwcas stack
set (PMWCAS_LINK_LIBS
glog::glog
)
# Set the list of libraries that use pmwcas
set (PMWCAS_APPS_LINK_LIBS
pmwcas
glog::glog
gtest_main
)
set(LINUX_ENVIRONMENT_SOURCES
src/environment/environment_linux.cc
)
# Set the link libraries to for test compilation
set (PMWCAS_TEST_LINK_LIBS ${PMWCAS_LINK_LIBS} "-lpthread -lnuma -fPIC")
# Set the link libraries to for benchmark binary compilation
set (PMWCAS_BENCHMARK_LINK_LIBS ${PMWCAS_BENCHMARK_LINK_LIBS} gflags::gflags "-fPIC -lpthread -lnuma")
enable_testing()
#Function to automate building test binaries with appropriate environment sources
FUNCTION(ADD_PMWCAS_TEST TEST_NAME)
add_executable(${TEST_NAME} ${TEST_NAME}.cc ${PROJECT_SOURCE_DIR}/${LINUX_ENVIRONMENT_SOURCES})
target_link_libraries(${TEST_NAME} ${PMWCAS_TEST_LINK_LIBS} ${PMWCAS_APPS_LINK_LIBS})
gtest_add_tests(TARGET ${TEST_NAME})
ENDFUNCTION()
# Build each subdirectory
add_subdirectory(src/util)
add_subdirectory(src/environment)
add_subdirectory(src/common)
add_subdirectory(src/mwcas)
# Generate a shared library for applications to link
set_property(GLOBAL APPEND PROPERTY PMWCAS_SRC ${LINUX_ENVIRONMENT_SOURCES})
get_property(PMWCAS_SRC GLOBAL PROPERTY PMWCAS_SRC)
add_library(pmwcas SHARED ${PMWCAS_SRC})
if(${PMEM_BACKEND} STREQUAL "PMDK")
set (PMWCAS_LINK_LIBS
${PMWCAS_LINK_LIBS}
pmemobj
)
endif()
target_link_libraries(pmwcas PUBLIC ${PMWCAS_LINK_LIBS})