comparison m4/acinclude.m4 @ 33393:f3ffee7cf478 stable

build: Run test for polymorphic allocators if possible. * m4/acinclude.m4 (OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR): On macOS, we need to run an executable to check if polymorphic allocators are actually working. Do that on all platforms (if possible). Fall back to a compilation-only test when cross-compiling. See: https://octave.discourse.group/t/5481/33
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 13 Apr 2024 14:22:19 +0200
parents 0d1a3c2ad9c6
children ee94862503e2 f428a432ed4f
comparison
equal deleted inserted replaced
33391:0d1a3c2ad9c6 33393:f3ffee7cf478
198 dnl 198 dnl
199 AC_DEFUN([OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR], [ 199 AC_DEFUN([OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR], [
200 AC_CACHE_CHECK([whether std::pmr::polymorphic_allocator is available], 200 AC_CACHE_CHECK([whether std::pmr::polymorphic_allocator is available],
201 [octave_cv_std_pmr_polymorphic_allocator], 201 [octave_cv_std_pmr_polymorphic_allocator],
202 [AC_LANG_PUSH(C++) 202 [AC_LANG_PUSH(C++)
203 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
204 #include <cstdlib>
205 #include <memory_resource>
206 #include <vector>
207 class mx_memory_resource : public std::pmr::memory_resource
208 {
209 private:
210 void * do_allocate (std::size_t bytes, size_t /*alignment*/)
211 {
212 void *ptr = std::malloc (bytes);
213 if (! ptr)
214 throw std::bad_alloc ();
215 return ptr;
216 }
217 void do_deallocate (void* ptr, std::size_t /*bytes*/,
218 std::size_t /*alignment*/)
219 {
220 std::free (ptr);
221 }
222 bool do_is_equal (const std::pmr::memory_resource& other) const noexcept
223 {
224 return this == dynamic_cast<const mx_memory_resource *> (&other);
225 return true;
226 }
227 };
228 mx_memory_resource the_mx_memory_resource;
229 ]], [[
230 std::pmr::vector<int> my_int_vec { &the_mx_memory_resource };
231 ]])],
232 octave_cv_std_pmr_polymorphic_allocator=yes,
233 octave_cv_std_pmr_polymorphic_allocator=no,
234 [## On macOS, we need to run an executable to check if polymorphic
235 ## allocators are working.
236 ## When cross-compiling to that target, the following test might succeed
237 ## even if polymorphic allocators are not actually implemented. In that
238 ## case, users would need to manually configure with
239 ## `--disable-std-pmr-polymorphic-allocator`.
240 ## When cross-compiling to any other target, the following test should be
241 ## giving accurate results.
242
243 ## FIXME: Is there a way to not repeat the same code from above?
203 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 244 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
204 #include <cstdlib> 245 #include <cstdlib>
205 #include <memory_resource> 246 #include <memory_resource>
206 #include <vector> 247 #include <vector>
207 class mx_memory_resource : public std::pmr::memory_resource 248 class mx_memory_resource : public std::pmr::memory_resource
228 mx_memory_resource the_mx_memory_resource; 269 mx_memory_resource the_mx_memory_resource;
229 ]], [[ 270 ]], [[
230 std::pmr::vector<int> my_int_vec { &the_mx_memory_resource }; 271 std::pmr::vector<int> my_int_vec { &the_mx_memory_resource };
231 ]])], 272 ]])],
232 octave_cv_std_pmr_polymorphic_allocator=yes, 273 octave_cv_std_pmr_polymorphic_allocator=yes,
233 octave_cv_std_pmr_polymorphic_allocator=no) 274 octave_cv_std_pmr_polymorphic_allocator=no)])
234 AC_LANG_POP(C++) 275 AC_LANG_POP(C++)
235 ]) 276 ])
236 if test $octave_cv_std_pmr_polymorphic_allocator = yes; then 277 if test $octave_cv_std_pmr_polymorphic_allocator = yes; then
237 AC_DEFINE(OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR, 1, 278 AC_DEFINE(OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR, 1,
238 [Define to 1 if std::pmr::polymorphic_allocator is available.]) 279 [Define to 1 if std::pmr::polymorphic_allocator is available.])