@@ -151,6 +151,7 @@ include(CompileOptions)
151151include (LanguageStandards)
152152include (TestTargets)
153153include (ListTargets)
154+ include (CheckCXXSourceCompiles)
154155
155156cmake_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