diff --git a/CMakeLists.txt b/CMakeLists.txt index 01149b4a9b..e062b3ea61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -591,6 +591,19 @@ if (BOUT_USE_SCOREP) endif() set(BOUT_HAS_SCOREP ${BOUT_USE_SCOREP}) +option(BOUT_USE_UUID_SYSTEM_GENERATOR "Enable support for using a system UUID generator" ON) +if (BOUT_USE_UUID_SYSTEM_GENERATOR) + find_package(Libuuid QUIET) + if (Libuuid_FOUND) + target_link_libraries(bout++ + PUBLIC Libuuid::libuuid) + else() + message(STATUS "libuuid not found, using fallback UUID generator") + endif() +endif() +message(STATUS "UUID_SYSTEM_GENERATOR: ${BOUT_USE_UUID_SYSTEM_GENERATOR}") +set(BOUT_HAS_UUID_SYSTEM_GENERATOR ${BOUT_USE_UUID_SYSTEM_GENERATOR}) + include(CheckCXXSourceCompiles) check_cxx_source_compiles("int main() { const char* name = __PRETTY_FUNCTION__; }" HAS_PRETTY_FUNCTION) diff --git a/autoconf_build_defines.hxx.in b/autoconf_build_defines.hxx.in index fa2d95d3e8..f6556bbdee 100644 --- a/autoconf_build_defines.hxx.in +++ b/autoconf_build_defines.hxx.in @@ -48,6 +48,9 @@ /* SUNDIALS support */ #undef BOUT_HAS_SUNDIALS +/* Use libuuid for UUID generation */ +#undef BOUT_HAS_UUID_SYSTEM_GENERATOR + /* OpenMP schedule */ #undef BOUT_OPENMP_SCHEDULE diff --git a/cmake/FindLibuuid.cmake b/cmake/FindLibuuid.cmake new file mode 100644 index 0000000000..91880487a2 --- /dev/null +++ b/cmake/FindLibuuid.cmake @@ -0,0 +1,58 @@ +# FindLibuuid +# ---------- +# +# Find a libuuid UUID generator library +# +# This module will define the following variables: +# +# :: +# +# Libuuid_FOUND - true if Libuuid was found +# Libuuid_INCLUDE_DIRS - Location of the Libuuid includes +# Libuuid_LIBRARIES - Required libraries +# +# This module will also export the ``Libuuid::libuuid`` target. +# +# You can also set the following variables: +# +# ``Libuuid_ROOT`` +# Specify the path to the Libuuid installation to use +# +# ``Libuuid_DEBUG`` +# Set to TRUE to get extra debugging output + +include (FindPackageHandleStandardArgs) + +if (WIN32) + find_package_handle_standard_args(Libuuid DEFAULT_MSG) + return() +endif() + +if (APPLE) + find_library(CFLIB CoreFoundation) + find_package_handle_standard_args(Libuuid DEFAULT_MSG CFLIB) + mark_as_advanced(${CFLIB}) + + if (Libuuid_FOUND AND NOT TARGET Libuuid::libuuid) + add_library(Libuuid::libuuid UNKNOWN IMPORTED) + set_target_properties(Libuuid::libuuid PROPERTIES + IMPORTED_LOCATION ${CFLIB} + ) + endif() + return() +endif () + +find_path(Libuuid_INCLUDE_DIRS uuid/uuid.h) +find_library(Libuuid_LIBRARIES uuid) + +find_package_handle_standard_args(Libuuid DEFAULT_MSG Libuuid_LIBRARIES Libuuid_INCLUDE_DIRS) + +mark_as_advanced(Libuuid_LIBRARIES Libuuid_INCLUDE_DIRS) + +if (Libuuid_FOUND AND NOT TARGET Libuuid::libuuid) + add_library(Libuuid::libuuid UNKNOWN IMPORTED) + set_target_properties(Libuuid::libuuid PROPERTIES + IMPORTED_LOCATION "${Libuuid_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Libuuid_INCLUDE_DIRS}" + ) +endif() diff --git a/cmake_build_defines.hxx.in b/cmake_build_defines.hxx.in index f7bee53892..8ca9ed0cb9 100644 --- a/cmake_build_defines.hxx.in +++ b/cmake_build_defines.hxx.in @@ -18,6 +18,7 @@ #cmakedefine01 BOUT_HAS_SCOREP #cmakedefine01 BOUT_HAS_SLEPC #cmakedefine01 BOUT_HAS_SUNDIALS +#cmakedefine01 BOUT_HAS_UUID_SYSTEM_GENERATOR #cmakedefine01 BOUT_USE_BACKTRACE #cmakedefine01 BOUT_USE_COLOR #cmakedefine01 BOUT_USE_OPENMP diff --git a/configure b/configure index 0c4e13bee2..891b8edb0a 100755 --- a/configure +++ b/configure @@ -636,6 +636,7 @@ BOUT_USE_OPENMP BOUT_USE_OUTPUT_DEBUG BOUT_USE_COLOR BOUT_USE_BACKTRACE +BOUT_HAS_UUID_SYSTEM_GENERATOR BOUT_HAS_SUNDIALS BOUT_HAS_SLEPC BOUT_HAS_SCOREP @@ -810,6 +811,7 @@ with_pvode with_arkode with_scorep with_system_mpark +with_system_uuid enable_warnings enable_checks enable_signal @@ -1505,6 +1507,7 @@ Optional Packages: --with-scorep Enable support for scorep based instrumentation --with-system-mpark Use mpark.variant already installed rather then the bundled one + --with-system-uuid Use libuuid to generate UUIDs --with-openmp-schedule=static/dynamic/guided/auto Set OpenMP schedule (default: static) --with-gcov=GCOV use given GCOV for coverage (GCOV=gcov). @@ -2653,6 +2656,13 @@ else fi +# Check whether --with-system_uuid was given. +if test "${with_system_uuid+set}" = set; then : + withval=$with_system_uuid; +else + with_system_uuid=auto +fi + # Check whether --enable-warnings was given. if test "${enable_warnings+set}" = set; then : @@ -10571,6 +10581,273 @@ fi OWN_MPARK=yes fi + +############################################################# +# Check for libuuid +############################################################# + +if test ".$with_system_uuid" = "no"; then : + + BOUT_HAS_UUID_SYSTEM_GENERATOR=no + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for system UUID generator" >&5 +$as_echo_n "checking for system UUID generator... " >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid/uuid.h" >&5 +$as_echo_n "checking for uuid/uuid.h... " >&6; } + + save_CPPFLAGS=$CPPFLAGS + BACH_found=no + + if test ."$with_system_uuid" != .yes; then : + extra_prefix="$with_system_uuid" +else + extra_prefix="" +fi + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + BACH_found=yes + + + break +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + if test $BACH_found != yes; then : + + for search_prefix in $extra_prefix /usr /opt $HOME $HOME/local /usr/local + do + for path in $search_prefix $search_prefix/include + do + if test -d $path; then : + + CPPFLAGS="$save_CPPFLAGS -I$path" + + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + BACH_found=yes + EXTRA_INCS="$EXTRA_INCS -I$path" + + + break +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi + done + if test .$BACH_found = .yes; then : + break; +fi + done + +fi + + if test $BACH_found = yes; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CPPFLAGS=$save_CPPFLAGS + +fi + if test .$BACH_found = .yes; then : + + save_LIBS=$LIBS + save_LDFLAGS=$LDFLAGS + save_CPPFLAGS=$CPPFLAGS + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libuuid" >&5 +$as_echo_n "checking for libuuid... " >&6; } + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + BACL_found=no + + # Try with no extra libraries first + if test ."$with_system_uuid" = .yes; then : + extra_prefix="" +else + extra_prefix="$with_system_uuid" +fi + LIBS="$save_LIBS $EXTRA_LIBS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + extern "C" + char uuid_generate(); + +int +main () +{ +return uuid_generate(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + BACL_found=yes + + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LIBS=$save_LIBS + + # Now try with explicitly linking library + if test $BACL_found != yes; then : + + LIBS="$save_LIBS $EXTRA_LIBS -luuid" + if test ."$with_system_uuid" = .yes; then : + extra_prefix="" +else + extra_prefix="$with_system_uuid" +fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + extern "C" + char uuid_generate(); + +int +main () +{ +return uuid_generate(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + BACL_found=yes + EXTRA_LIBS="$EXTRA_LIBS -luuid" + + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +fi + + if test $BACL_found != yes; then : + + for search_prefix in $extra_prefix /usr /opt $HOME $HOME/local /usr/local ; do + for path in $search_prefix $search_prefix/lib $search_prefix/lib64 $search_prefix/x86_64-linux-gnu + do + if test -d $path; then : + + LIBS="$save_LIBS $EXTRA_LIBS -luuid" + LDFLAGS="$save_LDFLAGS -L$path" + + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + extern "C" + char uuid_generate(); + +int +main () +{ +return uuid_generate(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + BACL_found=yes + EXTRA_LIBS="$EXTRA_LIBS -L$path -luuid" + + + break +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +fi + done + if test .$BACL_found = .yes; then : + break; +fi + done + +fi + + if test $BACL_found = yes; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi + + if test $BACL_found = yes; then : + BOUT_HAS_UUID_SYSTEM_GENERATOR=yes +else + BOUT_HAS_UUID_SYSTEM_GENERATOR=no +fi + + LIBS=$save_LIBS + LDFLAGS=$save_LDFLAGS + CPPFLAGS=$save_CPPFLAGS + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + +else + BOUT_HAS_UUID_SYSTEM_GENERATOR=no +fi + + if test "$with_system_uuid" = "yes"; then : + + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "*** System UUID generator not found, but explicitly requested +See \`config.log' for more details" "$LINENO" 5; } + +fi + +fi + ############################################################# # Download + Build PVODE '98 ############################################################# @@ -14974,6 +15251,18 @@ fi +if test "x$BOUT_HAS_UUID_SYSTEM_GENERATOR" = "xyes"; then : + +$as_echo "#define BOUT_HAS_UUID_SYSTEM_GENERATOR 1" >>confdefs.h + +else + +$as_echo "#define BOUT_HAS_UUID_SYSTEM_GENERATOR 0" >>confdefs.h + +fi + + + if test "x$BOUT_USE_BACKTRACE" = "xyes"; then : $as_echo "#define BOUT_USE_BACKTRACE 1" >>confdefs.h diff --git a/configure.ac b/configure.ac index 263bbc074a..3a6be1a0f6 100644 --- a/configure.ac +++ b/configure.ac @@ -62,6 +62,8 @@ AC_ARG_WITH(scorep, [AS_HELP_STRING([--with-scorep], [Enable support for scorep based instrumentation])],,[with_scorep=no]) AC_ARG_WITH(system_mpark, [AS_HELP_STRING([--with-system-mpark], [Use mpark.variant already installed rather then the bundled one])],,[with_system_mpark=auto]) +AC_ARG_WITH(system_uuid, [AS_HELP_STRING([--with-system-uuid], + [Use libuuid to generate UUIDs])],,[with_system_uuid=auto]) AC_ARG_ENABLE(warnings, [AS_HELP_STRING([--disable-warnings], [Disable compiler warnings])],,[]) @@ -1112,6 +1114,27 @@ AS_IF([test "$SYSTEM_HAS_MPARK" = "yes"], [ MPARK_INCLUDE="-I$MPARK_VARIANT_INCLUDE_PATH" OWN_MPARK=yes ]) + +############################################################# +# Check for libuuid +############################################################# + +AS_IF([test ".$with_system_uuid" = "no"], [ + BOUT_HAS_UUID_SYSTEM_GENERATOR=no +], [ + AC_MSG_CHECKING([for system UUID generator]) + BOUT_ADDPATH_CHECK_HEADER(uuid/uuid.h, + BOUT_ADDPATH_CHECK_LIB(uuid, uuid_generate, + BOUT_HAS_UUID_SYSTEM_GENERATOR=yes, + BOUT_HAS_UUID_SYSTEM_GENERATOR=no, + [$with_system_uuid]), + BOUT_HAS_UUID_SYSTEM_GENERATOR=no, + [$with_system_uuid]) + AS_IF([test "$with_system_uuid" = "yes"], [ + AC_MSG_FAILURE([*** System UUID generator not found, but explicitly requested]) + ]) +]) + ############################################################# # Download + Build PVODE '98 ############################################################# @@ -1323,6 +1346,7 @@ BOUT_DEFINE_SUBST(BOUT_HAS_PVODE, [PVODE support]) BOUT_DEFINE_SUBST(BOUT_HAS_SCOREP, [Score-P support]) BOUT_DEFINE_SUBST(BOUT_HAS_SLEPC, [SLEPc support]) BOUT_DEFINE_SUBST(BOUT_HAS_SUNDIALS, [SUNDIALS support]) +BOUT_DEFINE_SUBST(BOUT_HAS_UUID_SYSTEM_GENERATOR, [Use libuuid for UUID generation]) BOUT_DEFINE_SUBST(BOUT_USE_BACKTRACE, [Enable backtrace in exceptions]) BOUT_DEFINE_SUBST(BOUT_USE_COLOR, [Enable color logs option]) BOUT_DEFINE_SUBST(BOUT_USE_OUTPUT_DEBUG, [Enabled extra debug output]) diff --git a/include/bout/build_config.hxx b/include/bout/build_config.hxx index 07bd38dd95..cd30574cd3 100644 --- a/include/bout/build_config.hxx +++ b/include/bout/build_config.hxx @@ -21,6 +21,7 @@ constexpr auto has_petsc = static_cast(BOUT_HAS_PETSC); constexpr auto has_pretty_function = static_cast(BOUT_HAS_PRETTY_FUNCTION); constexpr auto has_pvode = static_cast(BOUT_HAS_PVODE); constexpr auto has_scorep = static_cast(BOUT_HAS_SCOREP); +constexpr auto has_uuid_system_generator = static_cast(BOUT_HAS_UUID_SYSTEM_GENERATOR); constexpr auto has_slepc = static_cast(BOUT_HAS_SLEPC); constexpr auto has_sundials = static_cast(BOUT_HAS_SUNDIALS); constexpr auto use_backtrace = static_cast(BOUT_USE_BACKTRACE); diff --git a/include/bout/sys/uuid.h b/include/bout/sys/uuid.h index f48e81006f..de8adf9d20 100644 --- a/include/bout/sys/uuid.h +++ b/include/bout/sys/uuid.h @@ -21,6 +21,10 @@ // SOFTWARE. #pragma once +#ifndef BOUT_UUID_H +#define BOUT_UUID_H + +#include "bout/build_config.hxx" #include #include @@ -45,7 +49,7 @@ #define NOMINMAX #endif -#ifdef UUID_SYSTEM_GENERATOR +#ifdef BOUT_HAS_UUID_SYSTEM_GENERATOR #include #endif @@ -56,13 +60,13 @@ #elif defined(__linux__) || defined(__unix__) -#ifdef UUID_SYSTEM_GENERATOR +#ifdef BOUT_HAS_UUID_SYSTEM_GENERATOR #include #endif #elif defined(__APPLE__) -#ifdef UUID_SYSTEM_GENERATOR +#ifdef BOUT_HAS_UUID_SYSTEM_GENERATOR #include #endif @@ -652,7 +656,7 @@ namespace uuids // uuid generators // -------------------------------------------------------------------------------------------------------------------------- -#ifdef UUID_SYSTEM_GENERATOR +#ifdef BOUT_HAS_UUID_SYSTEM_GENERATOR class uuid_system_generator { public: @@ -966,3 +970,5 @@ namespace std } }; } + +#endif // BOUT_UUID_H