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

Use CMakeLists.txt instead of Makefile #4

Merged
merged 41 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
65e5b0b
Use CMakeLists.txt instead of Makefile
adamant-pwn Apr 24, 2024
106eb03
Update CMakeLists.txt
adamant-pwn May 13, 2024
660268d
Refactor CMakeLists.txt
adamant-pwn May 15, 2024
3fbcda9
Update
adamant-pwn May 15, 2024
0b10e4e
Use .a instead of .so, link pod5 with zstd
adamant-pwn May 15, 2024
d0863fc
Fix docker failure
adamant-pwn May 15, 2024
837cd9b
Update README.md
adamant-pwn May 15, 2024
6d530c7
Update README.md
adamant-pwn May 15, 2024
ae2e122
Add basic Dockerfile
adamant-pwn May 13, 2024
45d6504
Update Dockerfile
adamant-pwn May 15, 2024
1804191
Make test workflow
adamant-pwn May 15, 2024
20a273d
Checkout recursive
adamant-pwn May 15, 2024
a07df3e
Update branch name in workflow
adamant-pwn May 15, 2024
0882d3f
Redundant include <array>
adamant-pwn May 15, 2024
1617247
Use -h in GH workflow
adamant-pwn May 16, 2024
7b2c9d2
Run workflow for any PR
adamant-pwn May 16, 2024
f445400
Remove python bindings WIP, add proper handling of C/CXX
adamant-pwn May 16, 2024
35cacaf
Testing simplified RUCLIENT_ENABLED
adamant-pwn May 16, 2024
d894b6e
Use TARGET_NAME as an argument
adamant-pwn May 16, 2024
8d317cb
Try caching for workflows
adamant-pwn May 16, 2024
2a320c8
Try NOHDF5=ON by default
adamant-pwn May 16, 2024
33ce9dc
Try NOPOD5=ON
adamant-pwn May 16, 2024
722cf0f
Update
adamant-pwn May 17, 2024
ddcb274
Remove readuntil_fake
adamant-pwn May 17, 2024
721bee5
Remove log.txt
adamant-pwn May 17, 2024
001425e
Try build with POD5 and HDF5
adamant-pwn May 17, 2024
8f273f4
merged tflite branch and fixed cmake setup
maximilianmordig May 24, 2024
f8f053c
adding some fixes to the cmake file, and prototyping python integration
maximilianmordig May 24, 2024
dd0ac71
Fix slow5lib.so
adamant-pwn May 31, 2024
95fd6ae
wrote crude wrapper around rawhash for signal mapping
maximilianmordig Jun 3, 2024
1351418
added option to skip querying revcomp signal, small fixes
maximilianmordig Jun 4, 2024
e97d2fd
confirmed that alignment is the same for a single read
maximilianmordig Jun 4, 2024
4d6dbf5
cleaned up rawhash python wrapper
maximilianmordig Jun 4, 2024
a70f641
Try caching build directory
adamant-pwn Jun 5, 2024
1afd7a1
Lowercase repo owner
adamant-pwn Jun 5, 2024
feba398
Use CACHE STRING on ccache
adamant-pwn Jun 5, 2024
1f439d8
Remove build from .dockerignore for caching
adamant-pwn Jun 5, 2024
619ccce
Only run build-push-action once
adamant-pwn Jun 5, 2024
f4319f2
Try -j 2 with cached build directory
adamant-pwn Jun 5, 2024
63e1001
Use 3 cores and only cache build dir
adamant-pwn Jun 5, 2024
fcea20c
Try to use less space in workflows
adamant-pwn Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Docker Build and Test

on:
push:
branches:
- make_cmake_migrate
- main
pull_request:
branches:
- make_cmake_migrate
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
run: docker build -t build_test .

- name: Run Docker container
run: docker run --rm build_test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
build/
run_dir/

test/data/d1_*
Expand Down Expand Up @@ -84,4 +85,4 @@ extern/pod5*
test/evaluation/rawsamble/

extern/tensorflow/tflite_build/
test/evaluation/read_mapping/*.features
test/evaluation/read_mapping/*.features
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project(RawHash2)

add_subdirectory(src)
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM gcc:latest

RUN apt-get update && apt-get install -y \
cmake \
make \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /rawhash2
COPY . /rawhash2

RUN mkdir build && cd build \
&& cmake .. \
&& make -j

ENTRYPOINT ["./build/bin/rawhash2"]

LABEL Name=rawhash2 Version=0.0.1
29 changes: 0 additions & 29 deletions Makefile

This file was deleted.

39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,51 @@ RawHash performs real-time mapping of nanopore raw signals. When the prefix of r

# Installation

* Clone the code from its GitHub repository (`--recursive` must be used):
* Clone the code from its GitHub repository and recursively initialize submodules:

```bash
git clone --recursive https://github.com/CMU-SAFARI/RawHash.git rawhash2
git clone https://github.com/CMU-SAFARI/RawHash.git rawhash2
cd rawhash2 && git submodule update --init --recursive
```

* Compile (Make sure you have a C++ compiler and GNU make):

```bash
cd rawhash2 && make
mkdir build && cd build
cmake ..
make -j
```

If the compilation is successful, the path to the binary will be `bin/rawhash2`.
If the compilation is successful, the default path to the binary will be `bin/rawhash2`.

## Compiling with HDF5, SLOW5, and POD5

We are aware that some of the pre-compiled libraries (e.g., POD5) may not work in your system and you may need to compile these libraries from scratch. Additionally, it may be possible that you may not want to compile any of the HDF5, SLOW5, or POD5 libraries if you are not going to use them. RawHash2 provides a flexible Makefile to enable custom compilation of these libraries.
We are aware that some of the pre-compiled libraries (e.g., POD5) may not work in your system and you may need to compile these libraries from scratch. Additionally, it may be possible that you may not want to compile any of the HDF5, SLOW5, or POD5 libraries if you are not going to use them. RawHash2 provides several CMake options to enable custom compilation of these libraries.

* It is possible to provide your own include and lib directories for *any* of the HDF5, SLOW5, and POD5 libraries, if you do not want to use the source code or the pre-compiled binaries that come with RawHash2. To use your own include and lib directories you should pass them to `make` when compiling as follows:
It is possible to provide your own include and lib directories for *any* of the HDF5, SLOW5, and POD5 libraries, if you do not want to use the source code or the pre-compiled binaries that come with RawHash2. To use your own include and lib directories you should pass them to `cmake` when compiling as follows:

```bash
#Provide the path to all of the HDF5/SLOW5/POD5 include and lib directories during compilation
make HDF5_INCLUDE_DIR=/path/to/hdf5/include HDF5_LIB_DIR=/path/to/hdf5/lib \
SLOW5_INCLUDE_DIR=/path/to/slow5/include SLOW5_LIB_DIR=/path/to/slow5/lib \
POD5_INCLUDE_DIR=/path/to/pod5/include POD5_LIB_DIR=/path/to/pod5/lib
# Provide the path to all of the HDF5/SLOW5/POD5 include and lib directories during compilation
cmake -DHDF5_DIR=/path/to/hdf5 -DSLOW5_DIR=/path/to/slow5 -DPOD5_DIR=/path/to/pod5 ..

#Provide the path to only POD5 include and lib directories during compilation
make POD5_INCLUDE_DIR=/path/to/pod5/include POD5_LIB_DIR=/path/to/pod5/lib
# Provide the path to only POD5 include and lib directories during compilation
cmake -DPOD5_DIR=/path/to/pod5
```

* It is possible to disable compiling *any* of the HDF5, SLOW5, and POD5 libraries. To disable them, you can use the following variables
Note that the provided path should generally contain _both_ `include/` and `lib/` folders with the corresponding project's include and library files.

It is possible to disable compiling *any* of the HDF5, SLOW5, and POD5 libraries. To disable them, you can use the following variables

```bash
#Disables compiling HDF5
make NOHDF5=1
# Disables compiling HDF5
cmake -DNOHDF5=1 ..

#Disables compiling SLOW5 and POD5
make NOSLOW5=1 NOPOD5=1
# Disables compiling SLOW5 and POD5
cmake -DNOSLOW5=1 -DNOPOD5=1 ..
```

The variables and paths will be stored in CMake cache, meaning that you would need to run `cmake` again with explicitly provided new values to change them.

# Usage

## Getting help
Expand Down
22 changes: 22 additions & 0 deletions cmake/SetupCCacheMold.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function(setup_ccache_mold)
if(USE_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "ccache found: ${CCACHE_PROGRAM}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
else()
message(WARNING "ccache not found, using default compiler")
endif()
endif()

if(USE_MOLD)
find_program(MOLD_PROGRAM mold)
if(MOLD_PROGRAM)
message(STATUS "mold found: ${MOLD_PROGRAM}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${MOLD_PROGRAM}")
else()
message(WARNING "mold not found, using default linker")
endif()
endif()
endfunction()
28 changes: 28 additions & 0 deletions cmake/SetupHDF5.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)

function(setup_hdf5)
if(NOHDF5)
target_compile_definitions(${TARGET_NAME} PRIVATE NHDF5RH=1)
adamant-pwn marked this conversation as resolved.
Show resolved Hide resolved
else()
if(HDF5_COMPILE)
if(NOT HDF5_DIR)
override_cached(HDF5_DIR ${WORKDIR}/hdf5)
endif()
set(HDF5_BUILD_DIR ${HDF5_DIR}/build)
ExternalProject_Add(
hdf5_build
SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/hdf5
BINARY_DIR ${HDF5_BUILD_DIR}
CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/extern/hdf5/configure --enable-threadsafe --disable-hl --prefix=${HDF5_BUILD_DIR}
# INSTALL_DIR and DCMAKE_INSTALL_PREFIX are ignored by hdf5
INSTALL_COMMAND make install prefix=${HDF5_DIR}
)
add_dependencies(${TARGET_NAME} hdf5_build)
else()
if(NOT HDF5_DIR)
message(FATAL_ERROR "HDF5_COMPILE is OFF, but no dir provided")
endif()
endif()
link_imported_library(hdf5 ${HDF5_DIR})
endif()
endfunction()
71 changes: 71 additions & 0 deletions cmake/SetupMainTarget.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function(setup_main_target)
if(PYBINDING)
message(STATUS "Building with Python binding support")
set(TARGET_NAME rawhash_pybinding CACHE INTERNAL "Main target")
# TODO: Non-existent in git?
add_executable(${TARGET_NAME} rawhash_mapper.cpp)
adamant-pwn marked this conversation as resolved.
Show resolved Hide resolved
else()
set(TARGET_NAME rawhash2 CACHE INTERNAL "Main target")
add_executable(${TARGET_NAME} main.cpp)
endif()
set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 11)
set_target_properties(${TARGET_NAME} PROPERTIES C_STANDARD 11)

find_package(Threads REQUIRED)
target_link_libraries(${TARGET_NAME} PRIVATE Threads::Threads m z dl)
target_compile_options(${TARGET_NAME} PRIVATE -Wall -fopenmp -march=native -O3)
target_compile_definitions(${TARGET_NAME} PRIVATE HAVE_KALLOC)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
target_compile_options(${TARGET_NAME} PRIVATE -D_FILE_OFFSET_BITS=64 -fsigned-char)
elseif(DEFINED ARM_NEON)
target_compile_options(${TARGET_NAME} PRIVATE -D_FILE_OFFSET_BITS=64 -mfpu=neon -fsigned-char)
endif()

if(ENABLE_ASAN)
message(STATUS "AddressSanitizer enabled")
target_compile_options(${TARGET_NAME} PRIVATE -fsanitize=address)
target_link_libraries(${TARGET_NAME} PRIVATE -fsanitize=address)
endif()

if(ENABLE_TSAN)
message(STATUS "ThreadSanitizer enabled")
target_compile_options(${TARGET_NAME} PRIVATE -fsanitize=thread)
target_link_libraries(${TARGET_NAME} PRIVATE -fsanitize=thread)
endif()

target_sources(${TARGET_NAME} PRIVATE
bseq.c
dtw.cpp
hit.c
kalloc.c
kthread.c
lchain.c
revent.c
rindex.c
rmap.cpp
roptions.c
rseed.c
rsig.c
rsketch.c
rutils.c
sequence_until.c
)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${TARGET_NAME} PRIVATE
-g
-fsanitize=address
)
endif()

if(PROFILE)
target_compile_options(${TARGET_NAME} PRIVATE
-g
-fno-omit-frame-pointer
)
target_compile_definitions(${TARGET_NAME} PRIVATE
PROFILERH=1
)
endif()
endfunction()
79 changes: 79 additions & 0 deletions cmake/SetupPOD5.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)

function(setup_zstd)
set(ZSTD_DIR ${WORKDIR}/zstd)
ExternalProject_Add(
zstd_build
SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/zstd/build/cmake
BINARY_DIR ${ZSTD_DIR}/build
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${ZSTD_DIR}
)
add_dependencies(${TARGET_NAME} zstd_build)
link_imported_library(zstd ${ZSTD_DIR})
endfunction()

function(setup_pod5)
if(NOPOD5)
target_compile_definitions(${TARGET_NAME} PRIVATE NPOD5RH=1)
else()
setup_zstd()

set(POD5_VERSION "0.2.2")
set(POD5_URLDIR "pod5-${POD5_VERSION}-${CMAKE_SYSTEM_NAME}")
set(POD5_REPO "https://github.com/nanoporetech/pod5-file-format")

resolve_pod5_url()

if(POD5_DOWNLOAD)
if(NOT POD5_DIR)
override_cached(POD5_DIR ${WORKDIR}/${POD5_URLDIR})
endif()
ExternalProject_Add(
pod5_build
PREFIX ${WORKDIR}/pod5
SOURCE_DIR ${POD5_DIR}
URL ${POD5_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
add_dependencies(${TARGET_NAME} pod5_build)
else()
if(NOT POD5_DIR)
message(FATAL_ERROR "POD5_DOWNLOAD is OFF, but no dir provided")
endif()
endif()
include_directories(${POD5_DIR}/include)
target_link_libraries(${TARGET_NAME} PRIVATE ${POD5_LIBRARIES} zstd)
endif()
endfunction()

# POD5_URL and POD5_LIBRARIES are set at PARENT_SCOPE
function(resolve_pod5_url)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(POD5_LIB "lib64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm)")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
set(POD5_URL "${POD5_REPO}/releases/download/${POD5_VERSION}/lib_pod5-${POD5_VERSION}-linux-gcc7-arm64.tar.gz")
set(POD5_LIB "lib")
else()
set(POD5_URL "${POD5_REPO}/releases/download/${POD5_VERSION}/lib_pod5-${POD5_VERSION}-linux-arm64.tar.gz" PARENT_SCOPE)
endif()
else()
set(POD5_URL "${POD5_REPO}/releases/download/${POD5_VERSION}/lib_pod5-${POD5_VERSION}-linux-x64.tar.gz" PARENT_SCOPE)
endif()

set(POD5_LIB_DIR "${WORKDIR}/${POD5_URLDIR}/${POD5_LIB}")
set(POD5_LIBRARIES "${POD5_LIB_DIR}/libpod5_format.a"
"${POD5_LIB_DIR}/libarrow.a"
"${POD5_LIB_DIR}/libjemalloc_pic.a" PARENT_SCOPE)
elseif(SYSTEM_NAME STREQUAL "Darwin")
set(POD5_URL "${POD5_REPO}/releases/download/${POD5_VERSION}/lib_pod5-${POD5_VERSION}-osx-11.0-arm64.tar.gz")
set(POD5_LIB_DIR "${WORKDIR}/${POD5_URLDIR}/lib")
set(POD5_LIBRARIES "${POD5_LIB_DIR}/libpod5_format.a"
"${POD5_LIB_DIR}/libarrow.a" PARENT_SCOPE)
elseif(SYSTEM_NAME STREQUAL "Windows_NT")
set(POD5_URL "${POD5_REPO}/releases/download/${POD5_VERSION}/lib_pod5-${POD5_VERSION}-win" PARENT_SCOPE)
endif()
endfunction()