44cmake_minimum_required (VERSION 3.3)
55project (libpmemobj-cpp C CXX)
66
7+ # ----------------------------------------------------------------- #
78## Set required and useful variables
9+ # ----------------------------------------------------------------- #
810set (VERSION_MAJOR 1)
911set (VERSION_MINOR 11)
1012set (VERSION_PATCH 0)
@@ -18,25 +20,6 @@ if(VERSION_PRERELEASE)
1820 set (VERSION ${VERSION} -${VERSION_PRERELEASE} )
1921endif ()
2022
21- # Set ${SRCVERSION}
22- if (EXISTS "${CMAKE_SOURCE_DIR} /.git" )
23- execute_process (COMMAND git describe
24- OUTPUT_VARIABLE SRCVERSION
25- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
26- OUTPUT_STRIP_TRAILING_WHITESPACE
27- ERROR_QUIET)
28- if (NOT SRCVERSION)
29- execute_process (COMMAND git log -1 --format=%h
30- OUTPUT_VARIABLE SRCVERSION
31- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
32- OUTPUT_STRIP_TRAILING_WHITESPACE)
33- endif ()
34- elseif (EXISTS "${CMAKE_SOURCE_DIR} /.version" )
35- file (STRINGS ${CMAKE_SOURCE_DIR} /.version SRCVERSION)
36- else ()
37- set (SRCVERSION ${VERSION} )
38- endif ()
39-
4023set (LIBPMEMOBJ_REQUIRED_VERSION 1.9)
4124set (LIBPMEM_REQUIRED_VERSION 1.7)
4225# Only pmreorder in ver. >= 1.9 guarantees reliable output
@@ -62,7 +45,9 @@ endif()
6245
6346set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR} /cmake)
6447
48+ # ----------------------------------------------------------------- #
6549## CMake build options
50+ # ----------------------------------------------------------------- #
6651option (BUILD_EXAMPLES "build examples" ON )
6752option (BUILD_TESTS "build tests" ON )
6853option (BUILD_DOC "build documentation" ON )
@@ -97,15 +82,21 @@ option(TEST_CONCURRENT_MAP "enable testing of pmem::obj::experimental::concurren
9782option (TEST_SELF_RELATIVE_POINTER "enable testing of pmem::obj::experimental::self_relative_ptr" ON )
9883option (TEST_RADIX_TREE "enable testing of pmem::obj::experimental::radix_tree" ON )
9984
100- ## Setup environment, find packages, set compiler's flags, add additional custom targets
85+ # ----------------------------------------------------------------- #
86+ ## Setup environment, find packages, set compiler's flags,
87+ ## add additional custom targets, ...
88+ # ----------------------------------------------------------------- #
10189include (FindPerl)
10290include (FindThreads)
10391include (CMakeDependentOption)
10492include (CMakePackageConfigHelpers)
10593include (CheckCXXSourceCompiles)
10694include (CheckCXXCompilerFlag)
10795include (GNUInstallDirs)
96+
10897include (${CMAKE_SOURCE_DIR} /cmake/functions.cmake)
98+ # set SRCVERSION, it's more accurate and "current" than VERSION
99+ set_source_ver(SRCVERSION)
109100
110101# Required for MSVC to correctly define __cplusplus
111102add_flag("/Zc:__cplusplus" )
@@ -140,31 +131,33 @@ if(VALGRIND_FOUND)
140131 endif ()
141132endif ()
142133
143- # XXX: move under if(BUILD_TESTS)
144- # Some tests and examples require clang >= 8.0
145- # because of the following bug:
146- # https://bugs.llvm.org/show_bug.cgi?id=28280
147- # which is fixed in clang v8.0.
148- set (CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG "8.0" )
134+ # Find Clang
149135find_program (CLANG NAMES clang)
150136if (CLANG)
151- get_program_version_major_minor(${CLANG} CLANG_VERSION)
152137 message (STATUS "Found clang: ${CLANG} (version: ${CLANG_VERSION} )" )
153- if (CLANG_VERSION VERSION_LESS CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG)
154- set (CLANG_DESTRUCTOR_REFERENCE_BUG_PRESENT 1)
155- endif ()
156138else ()
157139 message (STATUS "clang not found" )
158140endif ()
159141
160142if (BUILD_TESTS OR BUILD_EXAMPLES OR BUILD_BENCHMARKS)
143+ # Find libpmem and libpmemobj (PMDK libraries)
161144 if (PKG_CONFIG_FOUND)
162145 pkg_check_modules(LIBPMEMOBJ REQUIRED libpmemobj>=${LIBPMEMOBJ_REQUIRED_VERSION} )
163146 pkg_check_modules(LIBPMEM REQUIRED libpmem>=${LIBPMEM_REQUIRED_VERSION} )
164147 else ()
165148 find_package (LIBPMEMOBJ REQUIRED ${LIBPMEMOBJ_REQUIRED_VERSION} )
166149 find_package (LIBPMEM REQUIRED ${LIBPMEM_REQUIRED_VERSION} )
167150 endif ()
151+
152+ # Some tests and examples require clang >= 8.0, because of the bug
153+ # (https://bugs.llvm.org/show_bug.cgi?id=28280), which is fixed in clang v8.0.
154+ set (CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG "8.0" )
155+ if (CLANG)
156+ get_program_version_major_minor(${CLANG} CLANG_VERSION)
157+ if (CLANG_VERSION VERSION_LESS CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG)
158+ set (CLANG_DESTRUCTOR_REFERENCE_BUG_PRESENT 1)
159+ endif ()
160+ endif ()
168161endif ()
169162
170163add_custom_target (checkers ALL )
@@ -234,7 +227,9 @@ add_check_whitespace(include-experimental ${CMAKE_CURRENT_SOURCE_DIR}/include/li
234227add_check_whitespace(cmake-main ${CMAKE_CURRENT_SOURCE_DIR} /CMakeLists.txt)
235228add_check_whitespace(cmake-helpers ${CMAKE_CURRENT_SOURCE_DIR} /cmake/*.cmake)
236229
230+ # ----------------------------------------------------------------- #
237231## Configure make install/uninstall and packages
232+ # ----------------------------------------------------------------- #
238233configure_file (${CMAKE_SOURCE_DIR} /cmake/version .hpp.in
239234 ${CMAKE_CURRENT_BINARY_DIR} /version .hpp @ONLY)
240235
@@ -282,8 +277,9 @@ include_directories(include)
282277# all packages are found and all paths/variables are set.
283278include (${CMAKE_SOURCE_DIR} /cmake/check_compiling_issues.cmake)
284279
285-
280+ # ----------------------------------------------------------------- #
286281## Add/include sub-directories if build options enabled them
282+ # ----------------------------------------------------------------- #
287283if (BUILD_TESTS)
288284 if (TEST_DIR)
289285 enable_testing ()
0 commit comments