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

Commit

Permalink
Merge pull request #999 from lukaszstolarczuk/update-cmake
Browse files Browse the repository at this point in the history
Update CMake and package's version in name
  • Loading branch information
lukaszstolarczuk authored Dec 23, 2020
2 parents 3b4b00d + b7dc434 commit c8742a3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 32 deletions.
58 changes: 27 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
cmake_minimum_required(VERSION 3.3)
project(libpmemobj-cpp C CXX)

# ----------------------------------------------------------------- #
## Set required and useful variables
# ----------------------------------------------------------------- #
set(VERSION_MAJOR 1)
set(VERSION_MINOR 11)
set(VERSION_PATCH 0)
Expand All @@ -18,25 +20,6 @@ if(VERSION_PRERELEASE)
set(VERSION ${VERSION}-${VERSION_PRERELEASE})
endif()

# Set ${SRCVERSION}
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND git describe
OUTPUT_VARIABLE SRCVERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(NOT SRCVERSION)
execute_process(COMMAND git log -1 --format=%h
OUTPUT_VARIABLE SRCVERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
elseif(EXISTS "${CMAKE_SOURCE_DIR}/.version")
file(STRINGS ${CMAKE_SOURCE_DIR}/.version SRCVERSION)
else()
set(SRCVERSION ${VERSION})
endif()

set(LIBPMEMOBJ_REQUIRED_VERSION 1.9)
set(LIBPMEM_REQUIRED_VERSION 1.7)
# Only pmreorder in ver. >= 1.9 guarantees reliable output
Expand All @@ -62,7 +45,9 @@ endif()

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

# ----------------------------------------------------------------- #
## CMake build options
# ----------------------------------------------------------------- #
option(BUILD_EXAMPLES "build examples" ON)
option(BUILD_TESTS "build tests" ON)
option(BUILD_DOC "build documentation" ON)
Expand Down Expand Up @@ -97,15 +82,21 @@ option(TEST_CONCURRENT_MAP "enable testing of pmem::obj::experimental::concurren
option(TEST_SELF_RELATIVE_POINTER "enable testing of pmem::obj::experimental::self_relative_ptr" ON)
option(TEST_RADIX_TREE "enable testing of pmem::obj::experimental::radix_tree" ON)

## Setup environment, find packages, set compiler's flags, add additional custom targets
# ----------------------------------------------------------------- #
## Setup environment, find packages, set compiler's flags,
## add additional custom targets, ...
# ----------------------------------------------------------------- #
include(FindPerl)
include(FindThreads)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)
include(GNUInstallDirs)

include(${CMAKE_SOURCE_DIR}/cmake/functions.cmake)
# set SRCVERSION, it's more accurate and "current" than VERSION
set_source_ver(SRCVERSION)

# Required for MSVC to correctly define __cplusplus
add_flag("/Zc:__cplusplus")
Expand Down Expand Up @@ -140,31 +131,33 @@ if(VALGRIND_FOUND)
endif()
endif()

# XXX: move under if(BUILD_TESTS)
# Some tests and examples require clang >= 8.0
# because of the following bug:
# https://bugs.llvm.org/show_bug.cgi?id=28280
# which is fixed in clang v8.0.
set(CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG "8.0")
# Find Clang
find_program(CLANG NAMES clang)
if(CLANG)
get_program_version_major_minor(${CLANG} CLANG_VERSION)
message(STATUS "Found clang: ${CLANG} (version: ${CLANG_VERSION})")
if(CLANG_VERSION VERSION_LESS CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG)
set(CLANG_DESTRUCTOR_REFERENCE_BUG_PRESENT 1)
endif()
else()
message(STATUS "clang not found")
endif()

if(BUILD_TESTS OR BUILD_EXAMPLES OR BUILD_BENCHMARKS)
# Find libpmem and libpmemobj (PMDK libraries)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBPMEMOBJ REQUIRED libpmemobj>=${LIBPMEMOBJ_REQUIRED_VERSION})
pkg_check_modules(LIBPMEM REQUIRED libpmem>=${LIBPMEM_REQUIRED_VERSION})
else()
find_package(LIBPMEMOBJ REQUIRED ${LIBPMEMOBJ_REQUIRED_VERSION})
find_package(LIBPMEM REQUIRED ${LIBPMEM_REQUIRED_VERSION})
endif()

# Some tests and examples require clang >= 8.0, because of the bug
# (https://bugs.llvm.org/show_bug.cgi?id=28280), which is fixed in clang v8.0.
set(CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG "8.0")
if(CLANG)
get_program_version_major_minor(${CLANG} CLANG_VERSION)
if(CLANG_VERSION VERSION_LESS CLANG_REQUIRED_BY_DESTRUCTOR_REFERENCE_BUG)
set(CLANG_DESTRUCTOR_REFERENCE_BUG_PRESENT 1)
endif()
endif()
endif()

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

# ----------------------------------------------------------------- #
## Configure make install/uninstall and packages
# ----------------------------------------------------------------- #
configure_file(${CMAKE_SOURCE_DIR}/cmake/version.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/version.hpp @ONLY)

Expand Down Expand Up @@ -282,8 +277,9 @@ include_directories(include)
# all packages are found and all paths/variables are set.
include(${CMAKE_SOURCE_DIR}/cmake/check_compiling_issues.cmake)


# ----------------------------------------------------------------- #
## Add/include sub-directories if build options enabled them
# ----------------------------------------------------------------- #
if(BUILD_TESTS)
if(TEST_DIR)
enable_testing()
Expand Down
53 changes: 53 additions & 0 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,56 @@ function(find_pmemcheck)
message(WARNING "Valgrind pmemcheck NOT found. Pmemcheck tests will not be performed.")
endif()
endfunction()

# src version shows the current version, as reported by git describe
# unless git is not available, then it's set to the recently released VERSION
function(set_source_ver SRCVERSION)
# if there's version file commited, use it
if(EXISTS "${CMAKE_SOURCE_DIR}/.version")
file(STRINGS ${CMAKE_SOURCE_DIR}/.version FILE_VERSION)
set(SRCVERSION ${FILE_VERSION} PARENT_SCOPE)
return()
endif()

# otherwise take it from git
execute_process(COMMAND git describe
OUTPUT_VARIABLE GIT_VERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(GIT_VERSION)
# 1.5-rc1-19-gb8f78a329 -> 1.5-rc1.git19.gb8f78a329
string(REGEX MATCHALL
"([0-9.]*)-rc([0-9]*)-([0-9]*)-([0-9a-g]*)"
MATCHES
${GIT_VERSION})
if(MATCHES)
set(SRCVERSION
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}.git${CMAKE_MATCH_3}.${CMAKE_MATCH_4}"
PARENT_SCOPE)
return()
endif()

# 1.5-19-gb8f78a329 -> 1.5-git19.gb8f78a329
string(REGEX MATCHALL
"([0-9.]*)-([0-9]*)-([0-9a-g]*)"
MATCHES
${GIT_VERSION})
if(MATCHES)
set(SRCVERSION
"${CMAKE_MATCH_1}-git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
PARENT_SCOPE)
return()
endif()
else()
execute_process(COMMAND git log -1 --format=%h
OUTPUT_VARIABLE GIT_COMMIT
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(SRCVERSION ${GIT_COMMIT} PARENT_SCOPE)
return()
endif()

# last chance: use version set up in the top-level CMake
set(SRCVERSION ${VERSION} PARENT_SCOPE)
endfunction()
3 changes: 2 additions & 1 deletion cmake/packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
${CPACK_PACKAGING_INSTALL_PREFIX}/share/doc)

set(CPACK_PACKAGE_NAME "libpmemobj++")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_VERSION ${SRCVERSION}) # use the most accurate version (not ${VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
#set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "c++ bindings to libpmemobj")
set(CPACK_PACKAGE_VENDOR "Intel")

Expand Down
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

include(ctest_helpers.cmake)

# ----------------------------------------------------------------- #
## Setup
# ----------------------------------------------------------------- #
add_custom_target(tests)

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

# ----------------------------------------------------------------- #
## Tests
# ----------------------------------------------------------------- #
# tests using examples
function(build_example_queue)
add_executable(ex-queue ../examples/queue/queue.cpp)
Expand Down

0 comments on commit c8742a3

Please sign in to comment.