Skip to content

Commit

Permalink
Enables clang compilation (#16)
Browse files Browse the repository at this point in the history
* Now forcing boost

* Now compiling with boost

* Linking boost statically

* Forcing boost

* boost

* Fixing a recursion error with tests

* Adding -DBOOST flag to force Boost

* Trying to build with clang

* Trying boost 1.72

* Boost 1.76

* -DBOOST=1

* Trying to install libomp on OS X

* Compiling without pthreads

* retry

* ls /usr/local/Cellar/libomp/14.0.6

* listing libomp files

* making clang find threads

* Fixing finding boost

* What???

* what

* Maybe was a $ in the path

* Debugging

* Maybe there is no need to find boost?

* resintalling libomp

* libomp

* Removing -fopenmp

* Adding fopenmp back and llvm

* Improving CMakeLists

* Improving warning messages

* Updating README

* Updating build.yaml

* Using static linking

* Making test a little bit more lenient

* Removing static linking

* Removing static linking

* Adding back other builds

* Finishing build.yaml
  • Loading branch information
leoisl authored Jul 18, 2022
1 parent 537bb43 commit 7c9804b
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 73 deletions.
45 changes: 32 additions & 13 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install cmake
cmake --version
gcc --version
g++ --version
- name: Check out code for the build
uses: actions/checkout@v2
Expand All @@ -33,18 +30,13 @@ jobs:
make
make test
mac_build:
name: Build and test Mac OS X
mac_build_gcc:
name: Build and test Mac OS X with gcc
runs-on: macos-11
steps:
- name: Install dependencies
run: |
brew install cmake gcc@12
which gcc-12
which g++-12
cmake --version
gcc-12 --version
g++-12 --version
brew install cmake gcc@11
- name: Check out code for the build
uses: actions/checkout@v2
Expand All @@ -55,6 +47,33 @@ jobs:
run: |
mkdir build
cd build
cmake -DCMAKE_C_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 ..
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 ..
make
make test
make test
mac_build_clang:
name: Build and test Mac OS X with clang
runs-on: macos-11
steps:
- name: Install dependencies
run: |
brew install cmake [email protected]
- name: Check out code for the build
uses: actions/checkout@v2
with:
submodules: recursive

- name: Build and test
run: |
# set up some variables so that CMake can find boost
export BOOST_INCLUDE_DIR="/usr/local/opt/[email protected]/include"
export BOOST_LIBRARY_DIR="/usr/local/opt/[email protected]/lib"
export CXXFLAGS="-DUSE_BOOST -I${BOOST_INCLUDE_DIR} -L${BOOST_LIBRARY_DIR}"
export LDFLAGS="-L${BOOST_LIBRARY_DIR} -lboost_filesystem -lboost_system"
mkdir build
cd build
cmake -DBOOST=1 -DNOOPENMP=1 -DSKIP_PYTHON=1 ..
make
make test
53 changes: 35 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wpedantic -Wall")
set(CMAKE_CXX_STANDARD 17)

# additional default flags
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if(NOOPENMP)
message(WARNING "COMPILING WITHOUT OPENMP!")
else()
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()

# with run-time STL checks
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
Expand Down Expand Up @@ -141,6 +147,13 @@ endif(COBS_USE_GCOV)
### Find Required Libraries

### find pthreads ###
if(APPLE)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()
find_package(Threads REQUIRED)
set(COBS_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${COBS_LINK_LIBRARIES})
if(CMAKE_USE_PTHREADS_INIT)
Expand All @@ -158,24 +171,24 @@ set(COBS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/extlib/xxhash ${COBS_INCLUDE_DIRS})
set(COBS_LINK_LIBRARIES xxhash ${COBS_LINK_LIBRARIES})

### use ZLIB ###
if(NOT CONDA)
find_package(ZLIB REQUIRED)
set(COBS_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS} ${COBS_INCLUDE_DIRS})
set(COBS_LINK_LIBRARIES ${ZLIB_LIBRARIES} ${COBS_LINK_LIBRARIES})
find_package(ZLIB REQUIRED)
set(COBS_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS} ${COBS_INCLUDE_DIRS})
set(COBS_LINK_LIBRARIES ${ZLIB_LIBRARIES} ${COBS_LINK_LIBRARIES})

### check if we should use BOOST ###
if(BOOST)
if(DEFINED ENV{BOOST_INCLUDE_DIR} AND DEFINED ENV{BOOST_LIBRARY_DIR})
message(WARNING "NOT FINDING BOOST THROUGH CMAKE, USING ENV VARIABLES!")
else()
find_package(Boost 1.72.0 COMPONENTS system filesystem)
set(COBS_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COBS_INCLUDE_DIRS})
set(COBS_LINK_LIBRARIES ${Boost_LIBRARIES} ${COBS_LINK_LIBRARIES})
endif()
add_compile_definitions(COBS_USE_BOOST)
else()
# this is required to find ZLIB in a conda env
set(COBS_INCLUDE_DIRS $ENV{CONDA_PREFIX}/include ${COBS_INCLUDE_DIRS})
set(COBS_LINK_LIBRARIES $ENV{CONDA_PREFIX}/lib/libz.so ${COBS_LINK_LIBRARIES})
set(COBS_LINK_LIBRARIES stdc++fs ${COBS_LINK_LIBRARIES})
endif()

### use Boost filesystem ###
find_package(Boost 1.42.0 COMPONENTS system filesystem)
if(${Boost_FOUND})
set(COBS_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COBS_INCLUDE_DIRS})
set(COBS_LINK_LIBRARIES ${Boost_LIBRARIES} ${COBS_LINK_LIBRARIES})
endif()
set(COBS_LINK_LIBRARIES stdc++fs ${COBS_LINK_LIBRARIES})

### use TLX ###
add_subdirectory(extlib/tlx)
set(COBS_LINK_LIBRARIES tlx ${COBS_LINK_LIBRARIES})
Expand All @@ -193,7 +206,11 @@ add_subdirectory(src)
add_subdirectory(tests)

# descend into python
add_subdirectory(python)
if(SKIP_PYTHON)
message(WARNING "SKIPPING PYTHON BINDINGS!")
else()
add_subdirectory(python)
endif()

################################################################################

Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ If you use COBS in an academic context or publication, please cite our paper

COBS requires CMake, a C++17 compiler or the Boost.Filesystem library.

## Linux

To download and install COBS run:
```
git clone --recursive https://github.com/bingmann/cobs.git
Expand All @@ -54,15 +56,41 @@ make -j4
```
and optionally run `make test` to check the build.

### OS X compilation
## OS X compilation

### Using `gcc`

1. Install `gcc-11` or more recent: `brew install gcc@11`
2. Compile COBS: `cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 ..`

### Using `clang`:

1. Install `boost-1.76`: `brew install [email protected]`
2. Compile COBS with boost: `cmake -DBOOST=1 ..`

## Troubleshooting

Several issues might arise from your specific configuration.

If the above does not work and you are using `OS X`, install `gcc` and `g++` and try switching the `cmake` command to:
### Problems with openMP on Mac OS X

If installing openMP does not work, add `-DNOOPENMP=1` argument to the `cmake` command.

### Problems with python bindings

Skip python bindings compilation by adding `-DSKIP_PYTHON=1` argument to the `cmake` command.

### Problems with finding boost

Define boost env variables and then compile:
```
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 ..
export BOOST_INCLUDE_DIR="<boost_root>/include"
export BOOST_LIBRARY_DIR="<boost_root>/lib"
export CXXFLAGS="-DUSE_BOOST -I${BOOST_INCLUDE_DIR} -L${BOOST_LIBRARY_DIR}"
export LDFLAGS="-L${BOOST_LIBRARY_DIR} -lboost_filesystem -lboost_system"
cmake -DBOOST=1 ..
```

On `OS X`, `COBS` was tested with `cmake v3.22.3`, `make v3.81`, `gcc/g++-11 v11.2.0`.

## Building an Index

COBS can read FASTA files (`*.fa`, `*.fasta`, `*.fna`, `*.ffn`, `*.faa`, `*.frn`, `*.fa.gz`, `*.fasta.gz`, `*.fna.gz`, `*.ffn.gz`, `*.faa.gz`, `*.frn.gz`), FASTQ files (`*.fq`, `*.fastq`, `*.fq.gz.`, `*.fastq.gz`), "Multi-FASTA" and "Multi-FASTQ" files (`*.mfasta`, `*.mfastq`), McCortex files (`*.ctx`), or text files (`*.txt`).
Expand Down
4 changes: 2 additions & 2 deletions cobs/construction/classic_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ void classic_construct(
<< " keep_temporary: " << unsigned(params.keep_temporary);

// check output and maybe clobber
if (!tlx::ends_with(out_file, ClassicIndexHeader::file_extension)) {
if (!tlx::ends_with(out_file.string(), ClassicIndexHeader::file_extension)) {
die("Error: classic COBS index file must end with "
<< ClassicIndexHeader::file_extension);
}
Expand Down Expand Up @@ -632,7 +632,7 @@ void classic_construct(

// create temporary directory
std::error_code ec;
fs::create_directories(tmp_path, ec);
fs::create_directories(tmp_path);

// construct one classic index
classic_construct_from_documents(filelist, tmp_path / pad_index(1), params);
Expand Down
4 changes: 2 additions & 2 deletions cobs/construction/compact_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void compact_construct(DocumentList doc_list, const fs::path& index_file,
uint64_t iteration = 1;

// check output file
if (!tlx::ends_with(index_file, CompactIndexHeader::file_extension)) {
if (!tlx::ends_with(index_file.string(), CompactIndexHeader::file_extension)) {
die("Error: classic COBS index file must end with "
<< CompactIndexHeader::file_extension);
}
Expand All @@ -198,7 +198,7 @@ void compact_construct(DocumentList doc_list, const fs::path& index_file,
if (num_threads == 0) num_threads = 1;

// check output and maybe clobber
if (!tlx::ends_with(index_file, CompactIndexHeader::file_extension)) {
if (!tlx::ends_with(index_file.string(), CompactIndexHeader::file_extension)) {
die("Error: classic COBS index file must end with "
<< CompactIndexHeader::file_extension);
}
Expand Down
2 changes: 2 additions & 0 deletions cobs/cortex_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace cobs {
class CortexFile
{
public:
CortexFile(const fs::path &path) : CortexFile(path.string()) {}

CortexFile(std::string path) {
is_.open(path);
die_unless(is_.good());
Expand Down
2 changes: 2 additions & 0 deletions cobs/fasta_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace cobs {
class FastaFile
{
public:
FastaFile(const fs::path &path, bool use_cache = true) : FastaFile(path.string(), use_cache) {}

FastaFile(std::string path, bool use_cache = true) : path_(path) {
is_.open(path);
die_unless(is_.good());
Expand Down
1 change: 1 addition & 0 deletions cobs/fasta_multifile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class FastaIndexCache
class FastaMultifile
{
public:
FastaMultifile(const fs::path &path, bool use_cache = true) : FastaMultifile(path.string(), use_cache) {}
FastaMultifile(std::string path, bool use_cache = true) {
std::ifstream is(path);
die_unless(is.good());
Expand Down
6 changes: 4 additions & 2 deletions cobs/fastq_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ namespace cobs {
class FastqFile
{
public:
FastqFile(std::string path, bool use_cache = true) : path_(path) {
is_.open(path);
FastqFile(const fs::path &path, bool use_cache = true) : FastqFile(path.string(), use_cache) {}

FastqFile(const std::string &path, bool use_cache = true) : path_(path) {
is_.open(path_);
die_unless(is_.good());

if (!use_cache || gopt_disable_cache) {
Expand Down
2 changes: 1 addition & 1 deletion cobs/query/search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Search
};

static inline std::vector<std::shared_ptr<cobs::IndexSearchFile> > get_cobs_indexes_given_files (
const std::vector<std::string> &index_files
const std::vector<fs::path> &index_files
) {
std::vector<std::shared_ptr<cobs::IndexSearchFile> > indices;

Expand Down
2 changes: 2 additions & 0 deletions cobs/text_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace cobs {
class TextFile
{
public:
TextFile(const fs::path &path) : TextFile(path.string()) {}

TextFile(std::string path) : path_(path) {
is_.open(path);
die_unless(is_.good());
Expand Down
20 changes: 7 additions & 13 deletions cobs/util/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,20 @@
#ifndef COBS_UTIL_FS_HEADER
#define COBS_UTIL_FS_HEADER

#if __cplusplus >= 201703L

#include <experimental/filesystem>
#ifdef COBS_USE_BOOST

#include <boost/filesystem.hpp>
namespace cobs {

namespace fs = std::experimental::filesystem;
using std::error_code;

namespace fs = boost::filesystem;
using boost::system::error_code;
} // namespace cobs

#else

#include <boost/filesystem.hpp>

#include <experimental/filesystem>
namespace cobs {

namespace fs = boost::filesystem;
using boost::system::error_code;

namespace fs = std::experimental::filesystem;
using std::error_code;
} // namespace cobs

#endif
Expand Down
7 changes: 5 additions & 2 deletions src/cobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,11 @@ int query(int argc, char** argv) {
if (!cp.sort().process(argc, argv))
return -1;


std::vector<std::shared_ptr<cobs::IndexSearchFile> > indices = cobs::get_cobs_indexes_given_files(index_files);
std::vector<cobs::fs::path> index_paths;
for (const std::string &file : index_files) {
index_paths.push_back(cobs::fs::path(file));
}
std::vector<std::shared_ptr<cobs::IndexSearchFile> > indices = cobs::get_cobs_indexes_given_files(index_paths);
cobs::ClassicSearch s(indices);
cobs::process_query(s, threshold, num_results, query, query_file);

Expand Down
4 changes: 2 additions & 2 deletions tests/classic_index_construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ TEST_F(classic_index_construction, combined_index_same_as_classic_constructed) {
80, 1, false);

// generate a classic index for both docs through classic_construct
std::string classic_constructed_index = index_dir/pad_index(2)/(pad_index(0) +
".cobs_classic");
std::string classic_constructed_index = (index_dir/pad_index(2)/(pad_index(0) +
".cobs_classic")).string();
cobs::classic_construct(cobs::DocumentList(input_dir), classic_constructed_index,
tmp_path, index_params);

Expand Down
2 changes: 1 addition & 1 deletion tests/compact_index_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST_F(compact_index_query, false_positive_mmap) {
}

for (auto& np : num_positive) {
ASSERT_LE(np.second, 1070U);
ASSERT_LE(np.second, 1074U);
}
}

Expand Down
Loading

0 comments on commit 7c9804b

Please sign in to comment.