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

Commit 4cb0a28

Browse files
Merge pull request #1058 from lukaszstolarczuk/cmake-fixes
CMake fixes
2 parents 78b9a3c + cf64ba0 commit 4cb0a28

9 files changed

Lines changed: 123 additions & 105 deletions

File tree

.github/workflows/gha.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ jobs:
150150
-DCMAKE_TOOLCHAIN_FILE="${env:CMAKE_TOOLCHAIN_FILE}"
151151
-DCMAKE_INSTALL_PREFIX="${env:CMAKE_INSTALL_PREFIX}"
152152
-DTESTS_USE_FORCED_PMEM=ON
153+
-DTESTS_USE_VALGRIND=OFF
153154
-DTESTS_TBB=ON
154155
-DDEVELOPER_MODE=ON
155156
-DCXX_STANDARD="${{ matrix.CXX_STANDARD }}"

CMakeLists.txt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Copyright 2018-2021, Intel Corporation
33

44
cmake_minimum_required(VERSION 3.3)
5+
56
project(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})
2022
endif()
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
3126
set(CXX_STANDARD_REQUIRED ON)
32-
33-
set(CXX_STANDARD 14 CACHE STRING "C++ language standard")
3427
set(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
4430
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
4531
set(predefined_build_types
@@ -48,9 +34,9 @@ set(predefined_build_types
4834
RelWithDebInfo
4935
MinSizeRel)
5036
if(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}")
5440
else()
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()
6046
endif()
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+
6252
set(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)
110112
include(CheckCXXCompilerFlag)
111113
include(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

117121
if(WIN32)
118122
# Required for MSVC to correctly define __cplusplus
@@ -123,20 +127,16 @@ if(NOT WIN32)
123127
find_package(PkgConfig QUIET)
124128
endif()
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
133131
if(PKG_CONFIG_FOUND)
134132
pkg_check_modules(VALGRIND QUIET valgrind)
135133
else()
136134
find_package(VALGRIND QUIET)
137135
endif()
138136

139137
if(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.")
150154
endif()
151155

152156
# Find Clang
@@ -314,7 +318,7 @@ endif()
314318
if(BUILD_EXAMPLES AND NO_GCC_VARIADIC_TEMPLATE_BUG)
315319
add_subdirectory(examples)
316320
elseif(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")
318322
endif()
319323

320324
if(NOT "${CPACK_GENERATOR}" STREQUAL "")

cmake/functions.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Copyright 2018-2021, Intel Corporation
33

44
#
5-
# functions.cmake - helper functions for CMakeLists.txt
5+
# functions.cmake - helper functions for top-level CMakeLists.txt
66
#
77

8+
# join all ${VALUES} into an ${OUT} string, split with custom ${SEP}arator
89
function(join SEP OUT VALUES)
910
string(REPLACE ";" "${SEP}" JOIN_TMP "${VALUES}")
1011
set(${OUT} "${JOIN_TMP}" PARENT_SCOPE)

cmake/packages.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
string(TOUPPER "${CPACK_GENERATOR}" CPACK_GENERATOR)
99

1010
if(NOT ("${CPACK_GENERATOR}" STREQUAL "DEB" OR
11-
"${CPACK_GENERATOR}" STREQUAL "RPM"))
11+
"${CPACK_GENERATOR}" STREQUAL "RPM"))
1212
message(FATAL_ERROR "Wrong CPACK_GENERATOR value, valid generators are: DEB, RPM")
1313
endif()
1414

1515
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
16-
set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for tmp")
16+
set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for temporary package")
1717
set(CPACK_COMPONENTS_ALL_IN_ONE)
1818

1919
# Filter out some of directories from %dir section, which are expected

cmake/tbb.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright 2017-2021, Intel Corporation
33

4+
set(TBB_DIR "" CACHE PATH "dir with TBBConfig.cmake, to be set if using custom TBB installation")
45
message(STATUS "Checking for module 'tbb'")
56

67
# TBB was found without pkg-config:

examples/CMakeLists.txt

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright 2018-2021, Intel Corporation
33

4+
#
5+
# examples/CMakeLists.txt - CMake file for building all examples along with
6+
# the current libpmemobj-cpp sources, for verification purposes.
7+
# To build an example as a standalone application (with libpmemobj-cpp
8+
# from the system) see a CMake file in any of the subdirectories.
9+
#
10+
add_custom_target(examples)
11+
12+
# ----------------------------------------------------------------- #
13+
## Setup examples
14+
# ----------------------------------------------------------------- #
415
if(MSVC_VERSION)
516
add_flag(-W2)
617
add_flag("-D_FORTIFY_SOURCE=2" RELEASE)
@@ -30,11 +41,10 @@ if(COVERAGE)
3041
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage")
3142
endif()
3243

33-
add_custom_target(examples)
34-
3544
include_directories(${LIBPMEMOBJ_INCLUDE_DIRS} .)
3645
link_directories(${LIBPMEMOBJ_LIBRARY_DIRS})
3746

47+
# Add developer checks
3848
add_cppstyle(examples-common ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
3949
add_check_whitespace(examples-common ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
4050

@@ -101,14 +111,7 @@ add_check_whitespace(examples-inline_string ${CMAKE_CURRENT_SOURCE_DIR}/inline_s
101111
add_cppstyle(examples-radix_tree ${CMAKE_CURRENT_SOURCE_DIR}/radix_tree/*.*pp)
102112
add_check_whitespace(examples-radix_tree ${CMAKE_CURRENT_SOURCE_DIR}/radix_tree/*.*)
103113

104-
function(add_example name)
105-
set(srcs ${ARGN})
106-
prepend(srcs ${CMAKE_CURRENT_SOURCE_DIR} ${srcs})
107-
add_executable(example-${name} ${srcs})
108-
target_link_libraries(example-${name} ${LIBPMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
109-
add_dependencies(examples example-${name})
110-
endfunction()
111-
114+
# Find required packages for examples
112115
if(PKG_CONFIG_FOUND)
113116
pkg_check_modules(CURSES QUIET ncurses)
114117
else()
@@ -126,6 +129,17 @@ else()
126129
set(SFML_LIBRARIES sfml-graphics sfml-window sfml-system)
127130
endif()
128131

132+
function(add_example name)
133+
set(srcs ${ARGN})
134+
prepend(srcs ${CMAKE_CURRENT_SOURCE_DIR} ${srcs})
135+
add_executable(example-${name} ${srcs})
136+
target_link_libraries(example-${name} ${LIBPMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
137+
add_dependencies(examples example-${name})
138+
endfunction()
139+
140+
# ----------------------------------------------------------------- #
141+
## Add examples (some under the 'if', required for specific example)
142+
# ----------------------------------------------------------------- #
129143
if(TEST_ARRAY)
130144
add_example(queue queue/queue.cpp)
131145
endif()

tests/CMakeLists.txt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ include(ctest_helpers.cmake)
88
# ----------------------------------------------------------------- #
99
add_custom_target(tests)
1010

11-
# Try to find it for some tests using TBB
12-
include(tbb)
13-
1411
# Add checks when DEVELOPER_MODE is ON
1512
add_cppstyle(tests-common ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp
1613
${CMAKE_CURRENT_SOURCE_DIR}/*.c
@@ -78,9 +75,11 @@ if(COVERAGE)
7875
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage")
7976
endif()
8077

81-
# Prepare additional libraries/executables and finding required packages
78+
# Prepare additional libraries/executables and find packages required for tests
8279
find_packages()
83-
find_gdb()
80+
81+
# Try to find it for some tests using TBB
82+
include(tbb)
8483

8584
add_library(test_backtrace STATIC test_backtrace.c)
8685
if(LIBUNWIND_FOUND)
@@ -107,6 +106,10 @@ if(NOT GDB_FOUND)
107106
message(WARNING "GDB was not found - skipping some tests. To fix, make sure `gdb` command is OS-wide accessible.")
108107
endif()
109108

109+
if(NOT PMREORDER_SUPPORTED)
110+
message(WARNING "Skipping pmreorder tests because of no pmreorder support")
111+
endif()
112+
110113
# ----------------------------------------------------------------- #
111114
## Tests
112115
# ----------------------------------------------------------------- #
@@ -134,7 +137,6 @@ if(BUILD_EXAMPLES AND NO_GCC_VARIADIC_TEMPLATE_BUG)
134137
add_test_generic(NAME ex-pman CASE 0 TRACERS none SCRIPT ex-pman/ex-pman_0.cmake)
135138
endif()
136139
elseif(BUILD_EXAMPLES)
137-
message(WARNING "Skipping examples tests because of gcc variadic template bug")
138140
skip_test("examples_tests" "SKIPPED_BECAUSE_OF_GCC_VARIADIC_TEMPLATE_BUG")
139141
endif()
140142

@@ -345,8 +347,6 @@ if(TEST_ARRAY)
345347
build_test(array_slice_pmreorder array/array_slice_pmreorder.cpp)
346348
add_test_generic(NAME array_slice_pmreorder CASE 0 TRACERS none SCRIPT array/array_slice_pmreorder_0.cmake)
347349
add_test_generic(NAME array_slice_pmreorder CASE 1 TRACERS none SCRIPT array/array_slice_pmreorder_1.cmake)
348-
else()
349-
message(WARNING "Skipping pmreorder tests because of no pmreorder support")
350350
endif()
351351
endif()
352352
################################################################################
@@ -647,8 +647,6 @@ if(TEST_CONCURRENT_HASHMAP)
647647
add_test_generic(NAME ${TEST} CASE ${case} TRACERS none)
648648
endforeach()
649649
endif()
650-
else()
651-
message(WARNING "Skipping pmreorder tests because of no pmreorder support")
652650
endif()
653651
endif()
654652
################################################################################
@@ -953,11 +951,7 @@ if(TEST_CONCURRENT_MAP)
953951
configure_file("${CMAKE_SCRIPT}.cmake.in" "${CMAKE_SCRIPT}_${case}.cmake" @ONLY)
954952
add_test_generic(NAME ${TEST} CASE ${case} TRACERS none)
955953
endforeach()
956-
else()
957-
message(WARNING "Skipping concurrent_map_pmreorder_break_insert test because GDB was not found")
958954
endif()
959-
else()
960-
message(WARNING "Skipping pmreorder tests because of no pmreorder support")
961955
endif()
962956
endif()
963957
################################################################################

0 commit comments

Comments
 (0)