Skip to content

Commit be3cf23

Browse files
authored
Merge pull request #167 from PatKamin/update-build-reqs
Update C++17 requirement cases
2 parents aff94a2 + 965008f commit be3cf23

File tree

5 files changed

+59
-35
lines changed

5 files changed

+59
-35
lines changed

.github/workflows/pr_push.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ jobs:
1111
name: Fast build
1212
strategy:
1313
matrix:
14-
os: [ubuntu-latest, windows-latest]
14+
os: [ubuntu-latest]
15+
nproc: ['$(nproc)']
16+
pool_scalable: ['ON']
17+
disjoint: ['ON', 'OFF']
18+
jemalloc: ['ON']
1519
include:
16-
- os: ubuntu-latest
17-
nproc: $(nproc)
18-
pool_scalable: 'ON'
19-
jemalloc: 'ON'
2020
- os: windows-latest
2121
nproc: $Env:NUMBER_OF_PROCESSORS
2222
pool_scalable: 'OFF'
23+
disjoint: 'OFF'
2324
jemalloc: 'OFF'
2425
runs-on: ${{matrix.os}}
2526

@@ -42,8 +43,9 @@ jobs:
4243
-DUMF_DEVELOPER_MODE=ON
4344
-DUMF_ENABLE_POOL_TRACKING=ON
4445
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=${{matrix.pool_scalable}}
45-
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
46+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=${{matrix.disjoint}}
4647
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{matrix.jemalloc}}
48+
-DUMF_BUILD_TESTS=OFF
4749
4850
- name: Build
4951
run: >

CMakeLists.txt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
6-
project(unified-memory-framework VERSION 0.1.0)
7-
8-
set(CMAKE_CXX_STANDARD 17)
9-
set(CMAKE_CXX_STANDARD_REQUIRED YES)
10-
11-
include(CTest)
12-
include(CMakePackageConfigHelpers)
13-
include(GNUInstallDirs)
14-
15-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
16-
include(helpers)
6+
project(unified-memory-framework VERSION 0.1.0 LANGUAGES C)
177

188
# Build Options
199
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
@@ -31,6 +21,28 @@ option(USE_UBSAN "Enable UndefinedBehaviorSanitizer checks" OFF)
3121
option(USE_TSAN "Enable ThreadSanitizer checks" OFF)
3222
option(USE_MSAN "Enable MemorySanitizer checks" OFF)
3323

24+
# For using the options listed in the OPTIONS_REQUIRING_CXX variable
25+
# a C++17 compiler is required. Moreover, if these options are not set,
26+
# CMake will set up a strict C build, without C++ support.
27+
set(OPTIONS_REQUIRING_CXX
28+
"UMF_BUILD_TESTS"
29+
"UMF_BUILD_LIBUMF_POOL_DISJOINT")
30+
foreach(option_name ${OPTIONS_REQUIRING_CXX})
31+
if(${option_name})
32+
enable_language(CXX)
33+
set(CMAKE_CXX_STANDARD 17)
34+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
35+
break()
36+
endif()
37+
endforeach()
38+
39+
include(CTest)
40+
include(CMakePackageConfigHelpers)
41+
include(GNUInstallDirs)
42+
43+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
44+
include(helpers)
45+
3446
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
3547
set(LINUX TRUE)
3648
set(OS_NAME "linux")

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option has to be turned `ON` to build this
7272
### Requirements
7373

7474
Required packages:
75-
- C++ compiler with C++17 support
75+
- C compiler
7676
- [CMake](https://cmake.org/) >= 3.14.0
7777

7878
For development and contributions:
7979
- clang-format-15.0 (can be installed with `python -m pip install clang-format==15.0.7`)
8080

81+
For building tests and Disjoint Pool:
82+
- C++ compiler with C++17 support
83+
8184
### Benchmark
8285

8386
A simple micro benchmark based on [ubench](https://github.com/sheredom/ubench.h).

cmake/helpers.cmake

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,34 +133,40 @@ macro(add_sanitizer_flag flag)
133133
set(check_name "HAS_MSAN")
134134
endif()
135135

136-
# Check C and CXX compilers for given sanitizer flag.
136+
# Check C and CXX compilers for a given sanitizer flag.
137137
check_c_compiler_flag("${SANITIZER_FLAG}" "C_${check_name}")
138-
check_cxx_compiler_flag("${SANITIZER_FLAG}" "CXX_${check_name}")
139-
if (NOT ${C_${check_name}} OR NOT ${CXX_${check_name}})
140-
message(FATAL_ERROR "${flag} sanitizer is not supported (either by C or CXX compiler)")
138+
if (NOT C_${check_name})
139+
message(FATAL_ERROR "sanitizer '${flag}' is not supported by the C compiler)")
141140
endif()
141+
if (CMAKE_CXX_COMPILE_FEATURES)
142+
check_cxx_compiler_flag("${SANITIZER_FLAG}" "CXX_${check_name}")
143+
if (NOT CXX_${check_name})
144+
message(FATAL_ERROR "sanitizer '${flag}' is not supported by the CXX compiler)")
145+
endif()
146+
endif()
147+
148+
add_compile_options("${SANITIZER_FLAG}")
142149

143150
# Check C and CXX compilers for sanitizer arguments.
144-
if (${SANITIZER_ARGS})
151+
if (SANITIZER_ARGS)
145152
check_c_compiler_flag("${SANITIZER_ARGS}" "C_HAS_SAN_ARGS")
146-
check_cxx_compiler_flag("${SANITIZER_ARGS}" "CXX_HAS_SAN_ARGS")
147-
148-
if (NOT ${C_HAS_SAN_ARGS} OR NOT ${CXX_HAS_SAN_ARGS})
149-
message(FATAL_ERROR "sanitizer argument ${SANITIZER_ARGS} is not supported (either by C or CXX compiler)")
153+
if (NOT C_HAS_SAN_ARGS)
154+
message(FATAL_ERROR "sanitizer argument '${SANITIZER_ARGS}' is not supported by the C compiler)")
155+
endif()
156+
if (CMAKE_CXX_COMPILE_FEATURES)
157+
check_cxx_compiler_flag("${SANITIZER_ARGS}" "CXX_HAS_SAN_ARGS")
158+
if (NOT CXX_HAS_SAN_ARGS)
159+
message(FATAL_ERROR "sanitizer argument '${SANITIZER_ARGS}' is not supported by the CXX compiler)")
160+
endif()
150161
endif()
151162

152-
set(SANITIZER_OPTION "${SANITIZER_FLAG} ${SANITIZER_ARGS}")
153-
else()
154-
# No sanitizer argument was set. For now, that's the case for MSVC.
155-
set(SANITIZER_OPTION "${SANITIZER_FLAG}")
163+
add_compile_options("${SANITIZER_ARGS}")
156164
endif()
157165

158-
add_compile_options("${SANITIZER_OPTION}")
159-
160166
# Clang/gcc needs the flag added to the linker. The Microsoft LINK linker doesn't recognize
161167
# sanitizer flags and will give a LNK4044 warning.
162168
if (NOT MSVC)
163-
add_link_options("${SANITIZER_OPTION}")
169+
add_link_options("${SANITIZER_FLAG}")
164170
endif()
165171

166172
set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})

test/test_base_alloc_linear.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static void *start_routine(void *arg) {
2929
long TID = syscall(SYS_gettid);
3030

3131
for (int i = 0; i < ITERATIONS; i++) {
32-
buffer[i].size = (rand() * MAX_ALLOCATION_SIZE) / RAND_MAX;
32+
buffer[i].size =
33+
(size_t)((rand() / (double)RAND_MAX) * MAX_ALLOCATION_SIZE);
3334
buffer[i].ptr = umf_ba_linear_alloc(pool, buffer[i].size);
3435
UT_ASSERTne(buffer[i].ptr, NULL);
3536
memset(buffer[i].ptr, (i + TID) & 0xFF, buffer[i].size);

0 commit comments

Comments
 (0)