Skip to content

Commit

Permalink
Proper Autotools use for Boost library for gzip input
Browse files Browse the repository at this point in the history
- Add a ./configure option --with-boost-iostreams (enabled by default)
- Add a ./configure option --with-boost-include-path so the user can
  tell configure where to find the libraries if they are not in the
  default locations
- Add an Automake option WITH_BOOST_IOSTREAMS that is true if the lib
  can be found (well, if the gzip.hpp file can be found) and use this to
  add the LDADD flags for the binaries that need it. This option is also
  used in the C++ code to switch between compiling with or without
  Boost::iostreams.
- Print the version of the Boost library if Boost is used
- In gendata.cpp keep the option open to read files when the library is
  not present. Unfortunately this does leave the code more ugly with a
  bunch of #ifdefs...
  • Loading branch information
lckarssen committed Nov 13, 2015
1 parent 64d9a68 commit b5ff7cd
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
31 changes: 31 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ if test x$ac_cv_header_Eigen_Dense = xno; then
fi


# See if we can use the Boost IOstreams libraries for reading gzipped
# files
AC_ARG_WITH([boost-iostreams],
AS_HELP_STRING([--with-boost-iostreams], [Use the Boost Iostreams library to
allow reading from gzipped files. This is enabled by default]
)
)

if test "x$with_boost_iostreams" != "xno"; then
AC_MSG_NOTICE([building using the Boost IOstreams library enabled])

AC_ARG_WITH([boost-include-path],
[AS_HELP_STRING([--with-boost-include-path],
[location of the Boost headers, defaults to /usr/include/boost])],
[CPPFLAGS+=" -I${withval}"],
[CPPFLAGS+=' -I/usr/include/'])

# Check for the Boost IOstreams header files
AC_CHECK_HEADER([boost/iostreams/filter/gzip.hpp],
[],
[AC_MSG_ERROR([Could not find the Boost IOstreams header files. Did \
you specify --with-boost-include-path correctly? Or use --without-boost \
to disable the reading of gzipped files.])]
)
else
AC_MSG_NOTICE([not using the Boost IOstreams libraries, so input \
from gzipped files is not possible])
fi
AM_CONDITIONAL([WITH_BOOST_IOSTREAMS], test "x$with_boost_iostreams" != "xno")


# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
Expand Down
15 changes: 13 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ RHEADERS = include/R.h include/Rmath.h include/R_ext/Arith.h \
include/R_ext/Print.h include/R_ext/Random.h include/R_ext/Utils.h \
include/R_ext/RS.h

LDADD = -lboost_iostreams -lz

bin_PROGRAMS =
if BUILD_palinear
bin_PROGRAMS += palinear
Expand All @@ -62,19 +60,32 @@ endif

palinear_SOURCES = $(REGFILES) $(FVSRC) $(FVHEADERS)
palinear_CPPFLAGS = -DLINEAR $(AM_CPPFLAGS)
palinear_LDADD =
palinear_SOURCES += $(EIGENFILES)

palogist_SOURCES = $(REGFILES) $(FVSRC) $(FVHEADERS)
palogist_CPPFLAGS = -DLOGISTIC $(AM_CPPFLAGS)
palogist_LDADD =
palogist_SOURCES += $(EIGENFILES)

pacoxph_SOURCES = $(COXSRC) $(REGFILES) $(FVSRC) $(FVHEADERS) \
$(RHEADERS) survS.h survproto.h coxph_data.h coxph_data.cpp
pacoxph_CXXFLAGS = -I $(top_srcdir)/src/include $(AM_CXXFLAGS)
pacoxph_CPPFLAGS = -DCOXPH $(AM_CPPFLAGS)
pacoxph_CFLAGS = -I $(top_srcdir)/src/include $(AM_CFLAGS)
pacoxph_LDADD =
pacoxph_SOURCES += $(EIGENFILES)

if WITH_BOOST_IOSTREAMS
palinear_CPPFLAGS += -DWITH_BOOST_IOSTREAMS
palinear_LDADD += -lboost_iostreams -lz
palogist_CPPFLAGS += -DWITH_BOOST_IOSTREAMS
palogist_LDADD += -lboost_iostreams -lz
pacoxph_CPPFLAGS += -DWITH_BOOST_IOSTREAMS
pacoxph_LDADD += -lboost_iostreams -lz
endif


extract_snp_SOURCES = extract-snp.cpp $(FVSRC) $(FVHEADERS)

## Install these scripts in the bin directory as well:
Expand Down
26 changes: 25 additions & 1 deletion src/gendata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
#include "utilities.h"
#include <iostream>
#include <fstream>

#if WITH_BOOST_IOSTREAMS
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>

#endif

void gendata::mldose_line_to_matrix(const int k,
const char *all_numbers,
Expand Down Expand Up @@ -251,9 +253,15 @@ void gendata::re_gendata(const char * fname,

G.reinit(nids, (nsnps * ngpreds));

#if WITH_BOOST_IOSTREAMS
std::ifstream file(fname, std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_istream infile;
std::string filename = fname;
// Note: a better check would be to read the first two bytes of
// the file and check for the gzip signature: 0x1f8b
// W.r.t. endianness and bytt width: compare each byte separately,
// see the comment to this SE answer:
// http://stackoverflow.com/a/6059342/881084
if (filename.compare(filename.length() - 2, 2, "gz") == 0)
{
infile.push(boost::iostreams::gzip_decompressor());
Expand All @@ -263,8 +271,16 @@ void gendata::re_gendata(const char * fname,
std::cout << "no gziped:" << ":\n";
}
infile.push(file);
#else
std::ifstream infile;
infile.open(fname);
#endif

#if WITH_BOOST_IOSTREAMS
if (!file)
#else
if (!infile)
#endif
{
std::cerr << "gendata: cannot open file " << fname << endl;
exit(1);
Expand Down Expand Up @@ -297,7 +313,11 @@ void gendata::re_gendata(const char * fname,
cerr << "phenotype file and dose or probability file "
<< "did not match at line " << i + 2 << " ("
<< tmpid << " != " << idnames[k] << ")" << endl;
#if WITH_BOOST_IOSTREAMS
file.close();
#else
infile.close();
#endif
exit(1);
}
}
Expand Down Expand Up @@ -327,7 +347,11 @@ void gendata::re_gendata(const char * fname,
}
}

#if WITH_BOOST_IOSTREAMS
file.close();
#else
infile.close();
#endif
}

// HERE NEED A NEW CONSTRUCTOR BASED ON DATABELBASECPP OBJECT
Expand Down
8 changes: 8 additions & 0 deletions src/usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "config.h"
#endif

#if WITH_BOOST_IOSTREAMS
#include <boost/version.hpp>
#endif

#include "eigen_mematrix.h"


Expand Down Expand Up @@ -103,6 +107,10 @@ void print_version(void) {
cout << "Using EIGEN version " << EIGEN_WORLD_VERSION
<< "." << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION
<< " for matrix operations\n";
#if WITH_BOOST_IOSTREAMS
cout << "Using Boost libraries version " << BOOST_LIB_VERSION << endl;
#endif

}


Expand Down

0 comments on commit b5ff7cd

Please sign in to comment.