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

Improve CMake #9

Open
wants to merge 9 commits into
base: rawhash2_tflite
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
12 changes: 12 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ on:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
use_cache:
description: 'Use cache for this run'
required: true
default: 'true'
num_build_jobs:
description: 'Number of build jobs'
required: true
default: '2'

jobs:
build:
Expand All @@ -30,6 +40,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache build directory
if: github.event_name != 'workflow_dispatch' || github.event.inputs.use_cache == 'true'
uses: actions/cache@v3
with:
path: build
Expand All @@ -51,6 +62,7 @@ jobs:
cache-to: type=gha,mode=max
build-args: |
BUILDKIT_INLINE_CACHE=1
RAWHASH_NUM_BUILD_JOBS=${{ github.event.inputs.num_build_jobs || '2' }}

- name: Extract build directory from Docker image
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project(RawHash2)
project(RawHash2Root)

add_subdirectory(src)
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ RUN apt-get update && apt-get install -y \
WORKDIR /rawhash2
COPY . /rawhash2

ARG RAWHASH_NUM_BUILD_JOBS
RUN mkdir -p build && cd build \
&& cmake .. \
&& make -j 3
&& make -j $RAWHASH_NUM_BUILD_JOBS

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

Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cd rawhash2 && git submodule update --init --recursive
# if not doing a fresh clone, make sure that the submodules don't have anything built from previous makefile-based
# setup , i.e. delete extern directory, then initialize submodules as above
(mkdir -p build && cd build && cmake .. && make -j)
build/bin/rawhash2
build/bin/rawhash2 -h
```

Troubleshooting:
Expand All @@ -54,6 +54,26 @@ Troubleshooting:

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

* Installation

You can install RawHash2 into the CMake-provided platform-specific destination (e.g. `/usr/local/` on UNIX) with `make install`:

```bash
make install
rawhash2 -h
```

Installation directory can be overridden by providing `-DCMAKE_INSTALL_PREFIX=...` argument to the `cmake ..` command, e.g.

```bash
cmake -DCMAKE_INSTALL_PREFIX=./install ..
make -j
make install
./install/bin/rawhash2 -h
```

Note that `CMAKE_INSTALL_PREFIX` is a cached variable in CMake.

## 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 several CMake options to enable custom compilation of these libraries.
Expand Down
17 changes: 13 additions & 4 deletions cmake/SetupHDF5.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)

function(setup_hdf5 TARGET_NAME)
function(add_hdf5_to_target TARGET_NAME)
if(NOHDF5)
target_compile_definitions(${TARGET_NAME} PRIVATE NHDF5RH=1)
else()
if(HDF5_COMPILE)
add_dependencies(${TARGET_NAME} hdf5_build)
endif()
add_imported_library(${TARGET_NAME} hdf5)
endif()
endfunction()

function(setup_hdf5)
if(NOT NOHDF5)
# print HDF5_DIR
message(STATUS "EXTERNAL_PROJECTS_BUILD_DIR: ${EXTERNAL_PROJECTS_BUILD_DIR}")
message(STATUS "HDF5_DIR: ${HDF5_DIR}")
Expand All @@ -15,18 +24,18 @@ function(setup_hdf5 TARGET_NAME)
set(HDF5_BUILD_DIR ${HDF5_DIR}/build)
ExternalProject_Add(
hdf5_build
BUILD_ALWAYS 1 # Rebuild if local checkout is updated
SOURCE_DIR ${HDF5_SOURCE_DIR}
BINARY_DIR ${HDF5_BUILD_DIR}
CONFIGURE_COMMAND ${HDF5_SOURCE_DIR}/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(${TARGET_NAME} hdf5 ${HDF5_DIR})
define_imported_library(hdf5 ${HDF5_DIR} SHARED)
endif()
endfunction()
40 changes: 31 additions & 9 deletions cmake/SetupPOD5.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)

function(setup_zstd TARGET_NAME)
set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/zstd)
function(add_zstd_to_target TARGET_NAME)
set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/zstd)
add_dependencies(${TARGET_NAME} zstd_build)
add_imported_library(${TARGET_NAME} zstd)
endfunction()

function(setup_zstd)
set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/zstd)
ExternalProject_Add(
zstd_build
BUILD_ALWAYS 1 # Rebuild if local checkout is updated
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(${TARGET_NAME} zstd ${ZSTD_DIR})
define_imported_library(zstd ${ZSTD_DIR} SHARED)
endfunction()

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

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)
add_dependencies(${TARGET_NAME} pod5_download)
endif()
target_link_libraries(${TARGET_NAME} PRIVATE ${POD5_LIBRARIES})
endif()
endfunction()

function(setup_pod5)
if(NOT NOPOD5)
setup_zstd()

set(POD5_VERSION "0.2.2")
set(POD5_URLDIR "pod5-${POD5_VERSION}-${CMAKE_SYSTEM_NAME}")
Expand Down Expand Up @@ -45,7 +68,6 @@ function(setup_pod5 TARGET_NAME)
endif()
endif()
include_directories(${POD5_DIR}/include)
target_link_libraries(${TARGET_NAME} PRIVATE ${POD5_LIBRARIES} zstd)
endif()
endfunction()

Expand Down Expand Up @@ -79,7 +101,7 @@ endfunction()


# not working because of improper design, PARENT_SCOPE should not be used, rather define targets properly
# include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)
# include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)

# set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/zstd)

Expand Down
29 changes: 14 additions & 15 deletions cmake/SetupRUClient.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)

function(setup_ruclient TARGET_NAME)
function(add_ruclient_to_target TARGET_NAME)
if(RUCLIENT_ENABLED)
set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 20)
target_compile_definitions(${TARGET_NAME} PRIVATE RUCLIENT_ENABLED)
target_sources(${TARGET_NAME} PRIVATE rawhash_ruclient.cpp)
target_link_libraries(${TARGET_NAME} PRIVATE ont_device_client_LIB ru_method_LIB)
endif()
endfunction()

function(setup_ruclient)
if(RUCLIENT_ENABLED)
set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 20)
target_compile_definitions(${TARGET_NAME} PRIVATE RUCLIENT_ENABLED)
target_sources(${TARGET_NAME} PRIVATE rawhash_ruclient.cpp)
if(NOT RUCLIENT_DIR)
override_cached(RUCLIENT_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/ruclient)
endif()
ExternalProject_Add(
ruclient_build
SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/readuntil_fake
BINARY_DIR ${RUCLIENT_DIR}/build
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${RUCLIENT_DIR}
)
add_dependencies(${TARGET_NAME} ruclient_build)
include_directories(${RUCLIENT_DIR}/include)
message(STATUS "ruclient enabled")
set(RUCLIENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/readuntil_fake)
add_subdirectory(${RUCLIENT_SOURCE_DIR} ${RUCLIENT_DIR})
include_directories(${RUCLIENT_SOURCE_DIR}/include)
else()
message(STATUS "ruclient disabled")
endif()
Expand Down
18 changes: 18 additions & 0 deletions cmake/SetupRawHashLikeTarget.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
include(${CMAKE_CURRENT_LIST_DIR}/SetupRUClient.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/SetupPOD5.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/SetupHDF5.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/SetupSLOW5.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/SetupTFLite.cmake)

setup_pod5()
setup_ruclient()
setup_hdf5()
setup_slow5()
setup_tflite()

function(setup_rawhashlike_target TARGET_NAME)
# if(PYBINDING)
# message(FATAL_ERROR "Building with Python binding support is not implemented")
Expand Down Expand Up @@ -77,4 +89,10 @@ function(setup_rawhashlike_target TARGET_NAME)
PROFILERH=1
)
endif()

add_pod5_to_target(${TARGET_NAME})
add_hdf5_to_target(${TARGET_NAME})
add_slow5_to_target(${TARGET_NAME})
add_tflite_to_target(${TARGET_NAME})
add_ruclient_to_target(${TARGET_NAME})
endfunction()
17 changes: 13 additions & 4 deletions cmake/SetupSLOW5.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)

function(setup_slow5 TARGET_NAME)
function(add_slow5_to_target TARGET_NAME)
if(NOSLOW5)
target_compile_definitions(${TARGET_NAME} PRIVATE NSLOW5RH=1)
else()
if(SLOW5_COMPILE)
add_dependencies(${TARGET_NAME} slow5_build)
endif()
add_imported_library(${TARGET_NAME} slow5)
endif()
endfunction()

function(setup_slow5)
if(NOT NOSLOW5)
set(SLOW5_SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/slow5lib)
if(SLOW5_COMPILE)
if(NOT SLOW5_DIR)
Expand All @@ -12,20 +21,20 @@ function(setup_slow5 TARGET_NAME)
message(STATUS "Compiling slow5 to ${SLOW5_DIR}")
ExternalProject_Add(
slow5_build
BUILD_ALWAYS 1 # Rebuild if local checkout is updated
BINARY_DIR ${SLOW5_DIR}
SOURCE_DIR ${SLOW5_SOURCE_DIR}
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${SLOW5_SOURCE_DIR}/include ${SLOW5_DIR}/include
&& ${CMAKE_COMMAND} -E make_directory ${SLOW5_DIR}/lib
&& ${CMAKE_COMMAND} -E rename ${SLOW5_DIR}/libslow5.so ${SLOW5_DIR}/lib/libslow5.so
)
message(STATUS "Current dir: ${CMAKE_CURRENT_BINARY_DIR}")
add_dependencies(${TARGET_NAME} slow5_build)
else()
if(NOT SLOW5_DIR)
message(FATAL_ERROR "SLOW5_COMPILE is OFF, but no dir provided")
endif()
endif()
message(STATUS "Using slow5 from ${SLOW5_DIR}")
link_imported_library(${TARGET_NAME} slow5 ${SLOW5_DIR})
define_imported_library(slow5 ${SLOW5_DIR} SHARED)
endif()
endfunction()
9 changes: 6 additions & 3 deletions cmake/SetupTFLite.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)

function(setup_tflite TARGET_NAME)
function(add_tflite_to_target TARGET_NAME)
target_link_libraries(${TARGET_NAME} PRIVATE tensorflow-lite)
endfunction()

function(setup_tflite)
set(TF_SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/tensorflow)
add_subdirectory(${TF_SOURCE_DIR}/tensorflow/lite ${EXTERNAL_PROJECTS_BUILD_DIR}/tflite EXCLUDE_FROM_ALL)
include_directories(${TF_SOURCE_DIR})
target_link_libraries(${TARGET_NAME} PRIVATE tensorflow-lite)
endfunction()
31 changes: 0 additions & 31 deletions cmake/Util.cmake

This file was deleted.

Loading
Loading