Skip to content

Commit

Permalink
Uses CXX17 if it cannot find timespec_get or TIME_UTC with CXX11. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara committed Jun 1, 2020
1 parent c20d9c4 commit 1dd40c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 29 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,37 @@ else
EXTRA_PKG_LIBS=-latomic
fi

# Detect whether it requires c++17
echo "#include <cstdio>
#include <ctime>
// Example adapted from https://en.cppreference.com/w/cpp/chrono/c/timespec_get
namespace std {
int main()
{
timespec ts;
timespec_get(&ts, TIME_UTC);
char buf[100];
strftime(buf, sizeof buf, "%D %T", gmtime(&ts.tv_sec));
printf("Current time: %s.%09ld UTC\n", buf, ts.tv_nsec);
return 0;
}
}
" | ${CXX} -x c++ -std=c++11 - -o /dev/null > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "c++11 is enough."
CXX_STD=CXX11
else
echo "c++17 required."
CXX_STD=CXX17
# See https://github.com/r-lib/later/issues/115
fi


# Write to Makevars
sed -e "s|@extra_pkg_libs@|$EXTRA_PKG_LIBS|" src/Makevars.in > src/Makevars
sed -e "s|@extra_pkg_libs@|$EXTRA_PKG_LIBS|;s|@cxx_std@|$CXX_STD|" src/Makevars.in > src/Makevars

# Success
exit 0
3 changes: 1 addition & 2 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Use C++11 if available
CXX_STD=CXX11
CXX_STD=@cxx_std@

PKG_CPPFLAGS = -pthread -DSTRICT_R_HEADERS
PKG_LIBS = -pthread @extra_pkg_libs@
Expand Down

0 comments on commit 1dd40c8

Please sign in to comment.