22# Copyright 2018-2021, Intel Corporation
33
44cmake_minimum_required (VERSION 3.3 )
5+
56project (libpmemobj-cpp C CXX )
7+ set (LIBPMEMOBJCPP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
68
79# ----------------------------------------------------------------- #
810## Set required and useful variables
@@ -19,27 +21,11 @@ if(VERSION_PRERELEASE)
1921 set (VERSION ${VERSION} -${VERSION_PRERELEASE} )
2022endif ()
2123
22- set (LIBPMEMOBJCPP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
23- set (LIBPMEMOBJ_REQUIRED_VERSION 1.9)
24- set (LIBPMEM_REQUIRED_VERSION 1.7)
25- # Only pmreorder in ver. >= 1.9 guarantees reliable output
26- set (PMREORDER_REQUIRED_VERSION 1.9)
27-
28- set (CMAKE_DISABLE_IN_SOURCE_BUILD ON )
24+ set (CXX_STANDARD 14 CACHE STRING "C++ language standard" )
2925
30- # Treat CMAKE_CXX_STANDARD as a requirement
3126set (CXX_STANDARD_REQUIRED ON )
32-
33- set (CXX_STANDARD 14 CACHE STRING "C++ language standard" )
3427set (CMAKE_CXX_STANDARD ${CXX_STANDARD} )
3528
36- # Do not treat include directories from the interfaces
37- # of consumed Imported Targets as SYSTEM by default.
38- set (CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
39-
40- set (TEST_DIR ${CMAKE_CURRENT_BINARY_DIR} /test CACHE STRING "working directory for tests" )
41- message (STATUS "TEST_DIR set to: \" ${TEST_DIR} \" " )
42-
4329# Specify and print the build type
4430set (DEFAULT_BUILD_TYPE "RelWithDebInfo" )
4531set (predefined_build_types
@@ -48,9 +34,9 @@ set(predefined_build_types
4834 RelWithDebInfo
4935 MinSizeRel)
5036if (NOT CMAKE_BUILD_TYPE )
51- message ( STATUS " CMAKE_BUILD_TYPE not set, setting the default one: ${DEFAULT_BUILD_TYPE} " )
52- set ( CMAKE_BUILD_TYPE " ${DEFAULT_BUILD_TYPE} "
53- CACHE STRING "choose the type of build ( ${predefined_build_types} )" FORCE STRINGS )
37+ set ( CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE}
38+ CACHE STRING "choose the type of build ( ${predefined_build_types} )" FORCE )
39+ message ( STATUS "CMAKE_BUILD_TYPE not set, setting the default one: ${CMAKE_BUILD_TYPE} " )
5440else ()
5541 message (STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} " )
5642 if (NOT CMAKE_BUILD_TYPE IN_LIST predefined_build_types)
@@ -59,7 +45,23 @@ else()
5945 endif ()
6046endif ()
6147
48+ include (${LIBPMEMOBJCPP_ROOT_DIR} /cmake/functions.cmake )
49+ # set SRCVERSION, it's more accurate and "current" than VERSION
50+ set_source_ver (SRCVERSION )
51+
6252set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LIBPMEMOBJCPP_ROOT_DIR} /cmake)
53+ set (CMAKE_DISABLE_IN_SOURCE_BUILD ON )
54+ set (LIBPMEMOBJ_REQUIRED_VERSION 1.9)
55+ set (LIBPMEM_REQUIRED_VERSION 1.7)
56+ # Only pmreorder in ver. >= 1.9 guarantees reliable output
57+ set (PMREORDER_REQUIRED_VERSION 1.9)
58+
59+ set (TEST_DIR ${CMAKE_CURRENT_BINARY_DIR} /test CACHE STRING "working directory for tests" )
60+ message (STATUS "TEST_DIR set to: \" ${TEST_DIR} \" " )
61+
62+ # Do not treat include directories from the interfaces
63+ # of consumed Imported Targets as SYSTEM by default.
64+ set (CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
6365
6466# ----------------------------------------------------------------- #
6567## CMake build options
@@ -110,9 +112,11 @@ include(CheckCXXSourceCompiles)
110112include (CheckCXXCompilerFlag )
111113include (GNUInstallDirs )
112114
113- include (${LIBPMEMOBJCPP_ROOT_DIR} /cmake/functions.cmake )
114- # set SRCVERSION, it's more accurate and "current" than VERSION
115- set_source_ver (SRCVERSION )
115+ # Configure the ccache as compiler launcher
116+ find_program (CCACHE_FOUND ccache )
117+ if (USE_CCACHE AND CCACHE_FOUND)
118+ set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache )
119+ endif ()
116120
117121if (WIN32 )
118122 # Required for MSVC to correctly define __cplusplus
@@ -123,20 +127,16 @@ if(NOT WIN32)
123127 find_package (PkgConfig QUIET )
124128endif ()
125129
126- # Configure the ccache as compiler launcher
127- find_program (CCACHE_FOUND ccache )
128- if (USE_CCACHE AND CCACHE_FOUND)
129- set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache )
130- endif ()
131-
132- # Find Valgrind
130+ # Finds valgrind and checks for pmemcheck's availability
133131if (PKG_CONFIG_FOUND)
134132 pkg_check_modules (VALGRIND QUIET valgrind )
135133else ()
136134 find_package (VALGRIND QUIET )
137135endif ()
138136
139137if (VALGRIND_FOUND)
138+ message (STATUS "Found Valgrind in '${VALGRIND_LIBRARY_DIRS} ' (version: ${VALGRIND_VERSION} )" )
139+
140140 add_flag (-DLIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED=1 )
141141 add_flag (-DLIBPMEMOBJ_CPP_VG_DRD_ENABLED=1 )
142142 add_flag (-DLIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED=1 )
@@ -147,6 +147,10 @@ if(VALGRIND_FOUND)
147147 if (VALGRIND_PMEMCHECK_FOUND)
148148 add_flag (-DLIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED=1 )
149149 endif ()
150+ elseif (NOT VALGRIND_FOUND AND TESTS_USE_VALGRIND)
151+ message (FATAL_ERROR "Valgrind not found, but flag TESTS_USE_VALGRIND was set." )
152+ elseif (NOT VALGRIND_FOUND)
153+ message (WARNING "Valgrind not found. Valgrind tests will not be performed." )
150154endif ()
151155
152156# Find Clang
@@ -314,7 +318,7 @@ endif()
314318if (BUILD_EXAMPLES AND NO_GCC_VARIADIC_TEMPLATE_BUG)
315319 add_subdirectory (examples )
316320elseif (BUILD_EXAMPLES)
317- message (WARNING "Skipping building of examples because of compiler issue " )
321+ message (WARNING "Skipping building of examples because of gcc variadic template bug " )
318322endif ()
319323
320324if (NOT "${CPACK_GENERATOR} " STREQUAL "" )
0 commit comments