Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #115 #121

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,44 @@ case "$CC" in
;;
esac

# By default CXX_STD is CXX11
CXX_STD=CXX11

# But if it works, use CXX17
CXX=`"${R_HOME}"/bin/R CMD config CXX17`
CXX17STD=`"${R_HOME}"/bin/R CMD config CXX17STD`
CXX17FLAGS=`"${R_HOME}"/bin/R CMD config CXX17FLAGS`
if [ "$CXX" != "" -a "$CXX17FLAGS" != "" -a "$CXX17STD" != "" ]; then
ptimespec='#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", buf, ts.tv_nsec);
return 0;
}

}'
echo "$ptimespec" | ${CXX} -x c++ -c $CXX17FLAGS $CXX17STD - -o /dev/null > /dev/null 2>&1
if [ $? -eq 0 ]; then
# See https://github.com/r-lib/later/issues/115
echo "Using c++17."
CXX_STD=CXX17
else
echo "Cannot use c++17 using default configuration for c++11"
fi
fi


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

# Success
Expand Down
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_cppflags@
PKG_LIBS = -pthread @extra_pkg_libs@
Expand Down