Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit c8742a3

Browse files
Merge pull request #999 from lukaszstolarczuk/update-cmake
Update CMake and package's version in name
2 parents 3b4b00d + b7dc434 commit c8742a3

File tree

4 files changed

+86
-32
lines changed

4 files changed

+86
-32
lines changed

CMakeLists.txt

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
cmake_minimum_required(VERSION 3.3)
55
project(libpmemobj-cpp C CXX)
66

7+
# ----------------------------------------------------------------- #
78
## Set required and useful variables
9+
# ----------------------------------------------------------------- #
810
set(VERSION_MAJOR 1)
911
set(VERSION_MINOR 11)
1012
set(VERSION_PATCH 0)
@@ -18,25 +20,6 @@ if(VERSION_PRERELEASE)
1820
set(VERSION ${VERSION}-${VERSION_PRERELEASE})
1921
endif()
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-
4023
set(LIBPMEMOBJ_REQUIRED_VERSION 1.9)
4124
set(LIBPMEM_REQUIRED_VERSION 1.7)
4225
# Only pmreorder in ver. >= 1.9 guarantees reliable output
@@ -62,7 +45,9 @@ endif()
6245

6346
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
6447

48+
# ----------------------------------------------------------------- #
6549
## CMake build options
50+
# ----------------------------------------------------------------- #
6651
option(BUILD_EXAMPLES "build examples" ON)
6752
option(BUILD_TESTS "build tests" ON)
6853
option(BUILD_DOC "build documentation" ON)
@@ -97,15 +82,21 @@ option(TEST_CONCURRENT_MAP "enable testing of pmem::obj::experimental::concurren
9782
option(TEST_SELF_RELATIVE_POINTER "enable testing of pmem::obj::experimental::self_relative_ptr" ON)
9883
option(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+
# ----------------------------------------------------------------- #
10189
include(FindPerl)
10290
include(FindThreads)
10391
include(CMakeDependentOption)
10492
include(CMakePackageConfigHelpers)
10593
include(CheckCXXSourceCompiles)
10694
include(CheckCXXCompilerFlag)
10795
include(GNUInstallDirs)
96+
10897
include(${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
111102
add_flag("/Zc:__cplusplus")
@@ -140,31 +131,33 @@ if(VALGRIND_FOUND)
140131
endif()
141132
endif()
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
149135
find_program(CLANG NAMES clang)
150136
if(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()
156138
else()
157139
message(STATUS "clang not found")
158140
endif()
159141

160142
if(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()
168161
endif()
169162

170163
add_custom_target(checkers ALL)
@@ -234,7 +227,9 @@ add_check_whitespace(include-experimental ${CMAKE_CURRENT_SOURCE_DIR}/include/li
234227
add_check_whitespace(cmake-main ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
235228
add_check_whitespace(cmake-helpers ${CMAKE_CURRENT_SOURCE_DIR}/cmake/*.cmake)
236229

230+
# ----------------------------------------------------------------- #
237231
## Configure make install/uninstall and packages
232+
# ----------------------------------------------------------------- #
238233
configure_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.
283278
include(${CMAKE_SOURCE_DIR}/cmake/check_compiling_issues.cmake)
284279

285-
280+
# ----------------------------------------------------------------- #
286281
## Add/include sub-directories if build options enabled them
282+
# ----------------------------------------------------------------- #
287283
if(BUILD_TESTS)
288284
if(TEST_DIR)
289285
enable_testing()

cmake/functions.cmake

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,56 @@ function(find_pmemcheck)
162162
message(WARNING "Valgrind pmemcheck NOT found. Pmemcheck tests will not be performed.")
163163
endif()
164164
endfunction()
165+
166+
# src version shows the current version, as reported by git describe
167+
# unless git is not available, then it's set to the recently released VERSION
168+
function(set_source_ver SRCVERSION)
169+
# if there's version file commited, use it
170+
if(EXISTS "${CMAKE_SOURCE_DIR}/.version")
171+
file(STRINGS ${CMAKE_SOURCE_DIR}/.version FILE_VERSION)
172+
set(SRCVERSION ${FILE_VERSION} PARENT_SCOPE)
173+
return()
174+
endif()
175+
176+
# otherwise take it from git
177+
execute_process(COMMAND git describe
178+
OUTPUT_VARIABLE GIT_VERSION
179+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
180+
OUTPUT_STRIP_TRAILING_WHITESPACE
181+
ERROR_QUIET)
182+
if(GIT_VERSION)
183+
# 1.5-rc1-19-gb8f78a329 -> 1.5-rc1.git19.gb8f78a329
184+
string(REGEX MATCHALL
185+
"([0-9.]*)-rc([0-9]*)-([0-9]*)-([0-9a-g]*)"
186+
MATCHES
187+
${GIT_VERSION})
188+
if(MATCHES)
189+
set(SRCVERSION
190+
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}.git${CMAKE_MATCH_3}.${CMAKE_MATCH_4}"
191+
PARENT_SCOPE)
192+
return()
193+
endif()
194+
195+
# 1.5-19-gb8f78a329 -> 1.5-git19.gb8f78a329
196+
string(REGEX MATCHALL
197+
"([0-9.]*)-([0-9]*)-([0-9a-g]*)"
198+
MATCHES
199+
${GIT_VERSION})
200+
if(MATCHES)
201+
set(SRCVERSION
202+
"${CMAKE_MATCH_1}-git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
203+
PARENT_SCOPE)
204+
return()
205+
endif()
206+
else()
207+
execute_process(COMMAND git log -1 --format=%h
208+
OUTPUT_VARIABLE GIT_COMMIT
209+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
210+
OUTPUT_STRIP_TRAILING_WHITESPACE)
211+
set(SRCVERSION ${GIT_COMMIT} PARENT_SCOPE)
212+
return()
213+
endif()
214+
215+
# last chance: use version set up in the top-level CMake
216+
set(SRCVERSION ${VERSION} PARENT_SCOPE)
217+
endfunction()

cmake/packages.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
2929
${CPACK_PACKAGING_INSTALL_PREFIX}/share/doc)
3030

3131
set(CPACK_PACKAGE_NAME "libpmemobj++")
32-
set(CPACK_PACKAGE_VERSION ${VERSION})
32+
set(CPACK_PACKAGE_VERSION ${SRCVERSION}) # use the most accurate version (not ${VERSION})
3333
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
3434
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
35+
#set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
3536
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "c++ bindings to libpmemobj")
3637
set(CPACK_PACKAGE_VENDOR "Intel")
3738

tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
include(ctest_helpers.cmake)
55

6+
# ----------------------------------------------------------------- #
67
## Setup
8+
# ----------------------------------------------------------------- #
79
add_custom_target(tests)
810

911
# Try to find it for some tests using TBB
@@ -87,7 +89,9 @@ add_library(valgrind_internal STATIC valgrind_internal.cpp)
8789
add_executable(check_is_pmem check_is_pmem/check_is_pmem.cpp)
8890
target_link_libraries(check_is_pmem ${LIBPMEM_LIBRARIES})
8991

92+
# ----------------------------------------------------------------- #
9093
## Tests
94+
# ----------------------------------------------------------------- #
9195
# tests using examples
9296
function(build_example_queue)
9397
add_executable(ex-queue ../examples/queue/queue.cpp)

0 commit comments

Comments
 (0)