Skip to content

Commit

Permalink
Add configure option to use system UUID generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree authored and johnomotani committed Feb 9, 2021
1 parent f74bd22 commit 0d6b0c1
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 4 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,19 @@ if (USE_SCOREP)
endif()
set(BOUT_HAS_SCOREP ${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)
Expand Down
58 changes: 58 additions & 0 deletions cmake/FindLibuuid.cmake
Original file line number Diff line number Diff line change
@@ -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()
277 changes: 277 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ PETSC_ARCH
PETSC_DIR
PETSC_MAKE_INCLUDE
PETSC_HAS_SUNDIALS
BOUT_HAS_UUID_SYSTEM_GENERATOR
HAS_SLEPC
HAS_PETSC
HAS_LAPACK
Expand Down Expand Up @@ -806,6 +807,7 @@ with_mumps
with_arkode
with_scorep
with_system_mpark
with_system_uuid
enable_warnings
enable_checks
enable_signal
Expand Down Expand Up @@ -1495,6 +1497,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).
Expand Down Expand Up @@ -2644,6 +2647,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 :
Expand Down Expand Up @@ -12155,6 +12165,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 <uuid/uuid.h>

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 <uuid/uuid.h>

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
#############################################################
Expand Down
Loading

0 comments on commit 0d6b0c1

Please sign in to comment.