Skip to content

Commit 3285a5b

Browse files
committed
Require a C++ compiler only when needed
Co-authored-by: [email protected]
1 parent 6515575 commit 3285a5b

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
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")

cmake/helpers.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,19 @@ macro(add_sanitizer_flag flag)
135135

136136
# Check C and CXX compilers for given sanitizer flag.
137137
check_c_compiler_flag("${SANITIZER_FLAG}" "C_${check_name}")
138-
check_cxx_compiler_flag("${SANITIZER_FLAG}" "CXX_${check_name}")
138+
if (CMAKE_CXX_COMPILE_FEATURES)
139+
check_cxx_compiler_flag("${SANITIZER_FLAG}" "CXX_${check_name}")
140+
endif()
139141
if (NOT ${C_${check_name}} OR NOT ${CXX_${check_name}})
140142
message(FATAL_ERROR "${flag} sanitizer is not supported (either by C or CXX compiler)")
141143
endif()
142144

143145
# Check C and CXX compilers for sanitizer arguments.
144146
if (${SANITIZER_ARGS})
145147
check_c_compiler_flag("${SANITIZER_ARGS}" "C_HAS_SAN_ARGS")
146-
check_cxx_compiler_flag("${SANITIZER_ARGS}" "CXX_HAS_SAN_ARGS")
147-
148+
if (CMAKE_CXX_COMPILE_FEATURES)
149+
check_cxx_compiler_flag("${SANITIZER_ARGS}" "CXX_HAS_SAN_ARGS")
150+
endif()
148151
if (NOT ${C_HAS_SAN_ARGS} OR NOT ${CXX_HAS_SAN_ARGS})
149152
message(FATAL_ERROR "sanitizer argument ${SANITIZER_ARGS} is not supported (either by C or CXX compiler)")
150153
endif()

0 commit comments

Comments
 (0)