Skip to content

Commit 6a720c2

Browse files
committed
enable c++20
1 parent 436d339 commit 6a720c2

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

LanguageStandards.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ function(swift_set_language_standards)
5454
set(x_CXX 14)
5555
endif()
5656

57+
if (x_CXX)
58+
message(STATUS "C++ STANDARD: ${x_CXX}")
59+
endif()
5760
set(C_EXTENSIONS ON)
5861

5962
if(NOT x_C_EXTENSIONS_ON)
6063
set(C_EXTENSIONS OFF)
6164
endif()
6265

66+
message(STATUS "UNPARSED ARGS: ${x_UNPARSED_ARGUMENTS}")
6367
set_target_properties(${x_UNPARSED_ARGUMENTS}
6468
PROPERTIES
6569
C_STANDARD ${x_C}

SwiftTargets.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ include(CompileOptions)
151151
include(LanguageStandards)
152152
include(TestTargets)
153153
include(ListTargets)
154+
include(CheckCXXSourceCompiles)
154155

155156
cmake_policy(SET CMP0007 NEW) # new behaviour list command no longer ignores empty elements
156157

@@ -247,10 +248,40 @@ function(swift_add_target target type)
247248
list(APPEND compile_options_args REMOVE ${x_REMOVE_COMPILE_OPTIONS})
248249
endif()
249250

251+
set(extra_definitions)
250252
if (x_C_STANDARD)
251253
list(APPEND language_standards_args C ${x_C_STANDARD})
252254
endif()
253255
if (x_CXX_STANDARD)
256+
if (${x_CXX_STANDARD} STREQUAL "20")
257+
# check if the compiler supports memory_resource
258+
set(CMAKE_REQUIRED_FLAGS "-std=c++20")
259+
check_cxx_source_compiles("
260+
#include <memory_resource>
261+
int main() {
262+
return 0;
263+
}
264+
" memory_resource)
265+
if (NOT memory_resource)
266+
list(APPEND extra_definitions "SWIFTNAV_EXPERIMENTAL_MEMORY_RESOURCE")
267+
endif()
268+
check_cxx_source_compiles("
269+
#include <iostream>
270+
int a =
271+
#ifdef _LIBCPP_VERSION
272+
1;
273+
#else
274+
kdfasfdl
275+
#endif
276+
int main() {
277+
return 0;
278+
}
279+
" libcxx)
280+
if (libcxx)
281+
list(APPEND extra_definitions "_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES")
282+
endif()
283+
endif()
284+
message(STATUS "DA LANG ${x_CXX_STANDARD}")
254285
list(APPEND language_standards_args CXX ${x_CXX_STANDARD})
255286
endif()
256287

@@ -351,6 +382,7 @@ function(swift_add_target target type)
351382
swift_set_language_standards(${target} ${language_standards_args})
352383
target_code_coverage(${target} NO_RUN)
353384

385+
target_compile_definitions(${target} PRIVATE ${extra_definitions})
354386
if (NOT x_SKIP_COMPILE_OPTIONS)
355387
swift_set_compile_options(${target} ${compile_options_args} EXTRA_FLAGS ${extra_flags})
356388
endif()

0 commit comments

Comments
 (0)