From 1962e0153a896a55c63807c7715cae71051f397a Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 10 Jul 2024 16:02:16 +0200 Subject: [PATCH 1/9] Define and link targets separately --- cmake/SetupHDF5.cmake | 14 +++++-- cmake/SetupPOD5.cmake | 35 ++++++++++++++---- cmake/SetupRUClient.cmake | 15 +++++--- cmake/SetupRawHashLikeTarget.cmake | 18 +++++++++ cmake/SetupSLOW5.cmake | 14 +++++-- cmake/SetupTFLite.cmake | 7 +++- cmake/Util.cmake | 10 ++++- src/CMakeLists.txt | 59 ++++-------------------------- 8 files changed, 99 insertions(+), 73 deletions(-) diff --git a/cmake/SetupHDF5.cmake b/cmake/SetupHDF5.cmake index ca60beb..f746f7b 100644 --- a/cmake/SetupHDF5.cmake +++ b/cmake/SetupHDF5.cmake @@ -1,9 +1,18 @@ include(${CMAKE_CURRENT_LIST_DIR}/Util.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() + link_imported_library(${TARGET_NAME} hdf5 ${HDF5_DIR}) + 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}") @@ -21,12 +30,11 @@ function(setup_hdf5 TARGET_NAME) # 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}) endif() endfunction() diff --git a/cmake/SetupPOD5.cmake b/cmake/SetupPOD5.cmake index 008a4b2..71bc27f 100644 --- a/cmake/SetupPOD5.cmake +++ b/cmake/SetupPOD5.cmake @@ -1,22 +1,44 @@ include(${CMAKE_CURRENT_LIST_DIR}/Util.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) + link_imported_library(${TARGET_NAME} zstd ${ZSTD_DIR}) +endfunction() + +function(setup_zstd) + set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/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(${TARGET_NAME} zstd ${ZSTD_DIR}) + define_imported_library(zstd ${ZSTD_DIR}) 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(${TAARGET_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} zstd) + 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}") @@ -45,7 +67,6 @@ function(setup_pod5 TARGET_NAME) endif() endif() include_directories(${POD5_DIR}/include) - target_link_libraries(${TARGET_NAME} PRIVATE ${POD5_LIBRARIES} zstd) endif() endfunction() diff --git a/cmake/SetupRUClient.cmake b/cmake/SetupRUClient.cmake index 00d5d98..5b20695 100644 --- a/cmake/SetupRUClient.cmake +++ b/cmake/SetupRUClient.cmake @@ -1,10 +1,16 @@ include(${CMAKE_CURRENT_LIST_DIR}/Util.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) + add_dependencies(${TARGET_NAME} ruclient_build) + 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() @@ -15,7 +21,6 @@ function(setup_ruclient TARGET_NAME) CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${RUCLIENT_DIR} ) - add_dependencies(${TARGET_NAME} ruclient_build) include_directories(${RUCLIENT_DIR}/include) message(STATUS "ruclient enabled") else() diff --git a/cmake/SetupRawHashLikeTarget.cmake b/cmake/SetupRawHashLikeTarget.cmake index 9a43cf3..72bb806 100644 --- a/cmake/SetupRawHashLikeTarget.cmake +++ b/cmake/SetupRawHashLikeTarget.cmake @@ -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") @@ -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() diff --git a/cmake/SetupSLOW5.cmake b/cmake/SetupSLOW5.cmake index cd9770b..c19cfc3 100644 --- a/cmake/SetupSLOW5.cmake +++ b/cmake/SetupSLOW5.cmake @@ -1,9 +1,18 @@ include(${CMAKE_CURRENT_LIST_DIR}/Util.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() + link_imported_library(${TARGET_NAME} slow5 ${SLOW5_DIR}) + endif() +endfunction() + +function(setup_slow5) + if(NOT NOSLOW5) set(SLOW5_SOURCE_DIR ${CMAKE_SOURCE_DIR}/extern/slow5lib) if(SLOW5_COMPILE) if(NOT SLOW5_DIR) @@ -19,13 +28,12 @@ function(setup_slow5 TARGET_NAME) && ${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}) endif() endfunction() diff --git a/cmake/SetupTFLite.cmake b/cmake/SetupTFLite.cmake index 97bb5ee..f92968b 100644 --- a/cmake/SetupTFLite.cmake +++ b/cmake/SetupTFLite.cmake @@ -1,8 +1,11 @@ include(${CMAKE_CURRENT_LIST_DIR}/Util.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() diff --git a/cmake/Util.cmake b/cmake/Util.cmake index f062898..45060e6 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -7,9 +7,8 @@ function(override_cached name value) set(${name} ${value} CACHE ${type} ${doc_string} FORCE) endfunction() + function(link_imported_library TARGET_NAME LIB_NAME LIB_DIR) - add_library(${LIB_NAME} SHARED IMPORTED) - file(MAKE_DIRECTORY ${LIB_DIR}/include) set_target_properties(${LIB_NAME} PROPERTIES IMPORTED_LOCATION ${LIB_DIR}/lib/lib${LIB_NAME}.so INTERFACE_INCLUDE_DIRECTORIES ${LIB_DIR}/include @@ -17,6 +16,13 @@ function(link_imported_library TARGET_NAME LIB_NAME LIB_DIR) target_link_libraries(${TARGET_NAME} PRIVATE ${LIB_NAME}) endfunction() + +function(define_imported_library LIB_NAME LIB_DIR) + add_library(${LIB_NAME} SHARED IMPORTED) + file(MAKE_DIRECTORY ${LIB_DIR}/include) +endfunction() + + function(check_directory_exists_and_non_empty DIR) if(NOT EXISTS ${DIR}) message(FATAL_ERROR "Directory ${DIR} does not exist.") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1377d81..90a6585 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,62 +34,19 @@ set(EXTERNAL_PROJECTS_BUILD_DIR ${CMAKE_BINARY_DIR}/extern) # default build dire file(MAKE_DIRECTORY ${EXTERNAL_PROJECTS_BUILD_DIR}) message(STATUS "External projects build directory: ${EXTERNAL_PROJECTS_BUILD_DIR}") -include(../cmake/SetupCCacheMold.cmake) -include(../cmake/SetupRawHashLikeTarget.cmake) -include(../cmake/SetupRUClient.cmake) -include(../cmake/SetupPOD5.cmake) -include(../cmake/SetupHDF5.cmake) -include(../cmake/SetupSLOW5.cmake) -include(../cmake/SetupTFLite.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/SetupCCacheMold.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/SetupRawHashLikeTarget.cmake) set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "verbose makefile" FORCE) # print compilation commands enable_ccache() set_alternate_linker(mold) -# todo: currently can only compile rawhash2 or the below, not both -# this happens because functions like setup_hdf5 define the hdf5 target and the relationship to the target name -# rather than doing it separately -set(build_cli ON) +add_executable(rawhash2 main.cpp) +setup_rawhashlike_target(rawhash2) -if (build_cli) - message(STATUS "Building CLI") - - set(TARGET_NAME rawhash2) - add_executable(${TARGET_NAME} main.cpp) - setup_rawhashlike_target(${TARGET_NAME}) - setup_pod5(${TARGET_NAME}) - setup_ruclient(${TARGET_NAME}) - setup_hdf5(${TARGET_NAME}) - setup_slow5(${TARGET_NAME}) - setup_tflite(${TARGET_NAME}) +add_library(rawhash2_wrapper SHARED rawhash_wrapper.cpp rawhash_wrapper.hpp) +setup_rawhashlike_target(rawhash2_wrapper) -else() - message(STATUS "Building shared library") - - # set(TARGET_NAME rawhash2_wrapper_example) - # add_executable(${TARGET_NAME} wrapper_example.cpp rawhash_wrapper.cpp rawhash_wrapper.hpp) - set(TARGET_NAME rawhash2_wrapper) - add_library(${TARGET_NAME} SHARED rawhash_wrapper.cpp rawhash_wrapper.hpp) - setup_rawhashlike_target(${TARGET_NAME}) - setup_pod5(${TARGET_NAME}) - setup_ruclient(${TARGET_NAME}) - setup_hdf5(${TARGET_NAME}) - setup_slow5(${TARGET_NAME}) - setup_tflite(${TARGET_NAME}) - - set(TARGET_NAME rawhash2_usinglib) - add_executable(${TARGET_NAME} wrapper_example.cpp) - target_link_libraries(${TARGET_NAME} PRIVATE rawhash2_wrapper) - # setup_rawhashlike_target(${TARGET_NAME}) - # # setup_pod5(${TARGET_NAME}) - # target_compile_definitions(${TARGET_NAME} PRIVATE NPOD5RH=1) # todo: workaround - # setup_ruclient(${TARGET_NAME}) - # setup_hdf5(${TARGET_NAME}) - # setup_slow5(${TARGET_NAME}) - # setup_tflite(${TARGET_NAME}) -endif() - - -# setup_pod5() -# add_pod5_to_target(${TARGET_NAME}) +add_executable(rawhash2_usinglib wrapper_example.cpp) +target_link_libraries(rawhash2_usinglib PRIVATE rawhash2_wrapper) From c677cb81d1a50a8541de33992f5fc069cea264c7 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 24 Jul 2024 01:20:22 +0200 Subject: [PATCH 2/9] Handle RawHash2 installation --- CMakeLists.txt | 2 +- cmake/SetupHDF5.cmake | 4 ++-- cmake/SetupPOD5.cmake | 6 +++--- cmake/SetupRUClient.cmake | 2 +- cmake/SetupSLOW5.cmake | 4 ++-- cmake/SetupTFLite.cmake | 2 +- cmake/{Util.cmake => Utils.cmake} | 18 +++++++++--------- src/CMakeLists.txt | 12 +++++++++++- 8 files changed, 30 insertions(+), 20 deletions(-) rename cmake/{Util.cmake => Utils.cmake} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c94148..3953cca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.10) -project(RawHash2) +project(RawHash2Root) add_subdirectory(src) diff --git a/cmake/SetupHDF5.cmake b/cmake/SetupHDF5.cmake index f746f7b..686e75c 100644 --- a/cmake/SetupHDF5.cmake +++ b/cmake/SetupHDF5.cmake @@ -1,4 +1,4 @@ -include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) function(add_hdf5_to_target TARGET_NAME) if(NOHDF5) @@ -7,7 +7,7 @@ function(add_hdf5_to_target TARGET_NAME) if(HDF5_COMPILE) add_dependencies(${TARGET_NAME} hdf5_build) endif() - link_imported_library(${TARGET_NAME} hdf5 ${HDF5_DIR}) + target_link_libraries(${TARGET_NAME} PRIVATE hdf5) endif() endfunction() diff --git a/cmake/SetupPOD5.cmake b/cmake/SetupPOD5.cmake index 71bc27f..0ef360c 100644 --- a/cmake/SetupPOD5.cmake +++ b/cmake/SetupPOD5.cmake @@ -1,9 +1,9 @@ -include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) function(add_zstd_to_target TARGET_NAME) set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/zstd) add_dependencies(${TARGET_NAME} zstd_build) - link_imported_library(${TARGET_NAME} zstd ${ZSTD_DIR}) + target_link_libraries(${TARGET_NAME} PRIVATE zstd) endfunction() function(setup_zstd) @@ -100,7 +100,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) diff --git a/cmake/SetupRUClient.cmake b/cmake/SetupRUClient.cmake index 5b20695..4c91361 100644 --- a/cmake/SetupRUClient.cmake +++ b/cmake/SetupRUClient.cmake @@ -1,4 +1,4 @@ -include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) function(add_ruclient_to_target TARGET_NAME) if(RUCLIENT_ENABLED) diff --git a/cmake/SetupSLOW5.cmake b/cmake/SetupSLOW5.cmake index c19cfc3..81fa67d 100644 --- a/cmake/SetupSLOW5.cmake +++ b/cmake/SetupSLOW5.cmake @@ -1,4 +1,4 @@ -include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) function(add_slow5_to_target TARGET_NAME) if(NOSLOW5) @@ -7,7 +7,7 @@ function(add_slow5_to_target TARGET_NAME) if(SLOW5_COMPILE) add_dependencies(${TARGET_NAME} slow5_build) endif() - link_imported_library(${TARGET_NAME} slow5 ${SLOW5_DIR}) + target_link_libraries(${TARGET_NAME} PRIVATE slow5) endif() endfunction() diff --git a/cmake/SetupTFLite.cmake b/cmake/SetupTFLite.cmake index f92968b..49fdc31 100644 --- a/cmake/SetupTFLite.cmake +++ b/cmake/SetupTFLite.cmake @@ -1,4 +1,4 @@ -include(${CMAKE_CURRENT_LIST_DIR}/Util.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) function(add_tflite_to_target TARGET_NAME) target_link_libraries(${TARGET_NAME} PRIVATE tensorflow-lite) diff --git a/cmake/Util.cmake b/cmake/Utils.cmake similarity index 73% rename from cmake/Util.cmake rename to cmake/Utils.cmake index 45060e6..81134e3 100644 --- a/cmake/Util.cmake +++ b/cmake/Utils.cmake @@ -8,18 +8,18 @@ function(override_cached name value) endfunction() -function(link_imported_library TARGET_NAME LIB_NAME LIB_DIR) - set_target_properties(${LIB_NAME} PROPERTIES - IMPORTED_LOCATION ${LIB_DIR}/lib/lib${LIB_NAME}.so - INTERFACE_INCLUDE_DIRECTORIES ${LIB_DIR}/include - ) - target_link_libraries(${TARGET_NAME} PRIVATE ${LIB_NAME}) -endfunction() - - function(define_imported_library LIB_NAME LIB_DIR) add_library(${LIB_NAME} SHARED IMPORTED) + set_target_properties(${LIB_NAME} PROPERTIES + IMPORTED_LOCATION ${LIB_DIR}/lib/lib${LIB_NAME}.so + INTERFACE_INCLUDE_DIRECTORIES ${LIB_DIR}/include) file(MAKE_DIRECTORY ${LIB_DIR}/include) + # Can't install(TARGETS ...) for external projects + # Also some .so are symlinks, so install all + install(DIRECTORY ${LIB_DIR}/lib/ DESTINATION lib + FILES_MATCHING PATTERN "*.so*") + install(DIRECTORY ${LIB_DIR}/include/ + DESTINATION include/${PROJECT_NAME}) endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90a6585..bec1f38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(RawHash2Src) +project(RawHash2) # option(USE_CCACHE "Use ccache to speed up rebuilds" ON) # option(USE_MOLD "Use mold linker for faster linking" ON) @@ -48,5 +48,15 @@ setup_rawhashlike_target(rawhash2) add_library(rawhash2_wrapper SHARED rawhash_wrapper.cpp rawhash_wrapper.hpp) setup_rawhashlike_target(rawhash2_wrapper) +file(GLOB_RECURSE HEADER_FILES ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_SOURCE_DIR}/src/*.hpp) +set_property(TARGET rawhash2_wrapper PROPERTY PUBLIC_HEADER ${HEADER_FILES}) +set_target_properties(rawhash2_wrapper PROPERTIES INSTALL_RPATH $ORIGIN) + add_executable(rawhash2_usinglib wrapper_example.cpp) target_link_libraries(rawhash2_usinglib PRIVATE rawhash2_wrapper) +set_target_properties(rawhash2_usinglib PROPERTIES INSTALL_RPATH $ORIGIN/../lib) + +install(TARGETS rawhash2_wrapper rawhash2_usinglib + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}) \ No newline at end of file From b94a89be15f8d50e7fada02cbf16d4edaa5907a6 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 24 Jul 2024 01:44:31 +0200 Subject: [PATCH 3/9] Update README.md --- README.md | 22 +++++++++++++++++++++- src/CMakeLists.txt | 27 +++++++++++++-------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b31bb44..d7f1b3a 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bec1f38..9178c25 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,21 +42,20 @@ set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "verbose makefile" FORCE) # print com enable_ccache() set_alternate_linker(mold) -add_executable(rawhash2 main.cpp) -setup_rawhashlike_target(rawhash2) +add_executable(rawhash2_builtin main.cpp) +setup_rawhashlike_target(rawhash2_builtin) -add_library(rawhash2_wrapper SHARED rawhash_wrapper.cpp rawhash_wrapper.hpp) -setup_rawhashlike_target(rawhash2_wrapper) +add_library(rawhash2_lib SHARED rawhash_wrapper.cpp rawhash_wrapper.hpp) +setup_rawhashlike_target(rawhash2_lib) file(GLOB_RECURSE HEADER_FILES ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_SOURCE_DIR}/src/*.hpp) -set_property(TARGET rawhash2_wrapper PROPERTY PUBLIC_HEADER ${HEADER_FILES}) -set_target_properties(rawhash2_wrapper PROPERTIES INSTALL_RPATH $ORIGIN) - -add_executable(rawhash2_usinglib wrapper_example.cpp) -target_link_libraries(rawhash2_usinglib PRIVATE rawhash2_wrapper) -set_target_properties(rawhash2_usinglib PROPERTIES INSTALL_RPATH $ORIGIN/../lib) - -install(TARGETS rawhash2_wrapper rawhash2_usinglib - RUNTIME DESTINATION bin +set_property(TARGET rawhash2_lib PROPERTY PUBLIC_HEADER ${HEADER_FILES}) +set_target_properties(rawhash2_lib PROPERTIES INSTALL_RPATH $ORIGIN OUTPUT_NAME rawhash2) +install(TARGETS rawhash2_lib LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}) \ No newline at end of file + PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}) + +add_executable(rawhash2 wrapper_example.cpp) +target_link_libraries(rawhash2 PRIVATE rawhash2_lib) +set_target_properties(rawhash2 PROPERTIES INSTALL_RPATH $ORIGIN/../lib) +install(TARGETS rawhash2 RUNTIME DESTINATION bin) From f7626b0f8b0aafef5194f84de00a010e8bd25e17 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 24 Jul 2024 04:52:36 +0200 Subject: [PATCH 4/9] Update timestamp on .a files in cache --- .github/workflows/docker-build.yml | 1 + Dockerfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 7579061..9741555 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -56,6 +56,7 @@ jobs: run: | container_id=$(docker create ghcr.io/${{ steps.repo_owner.outputs.owner }}/build_test:latest) docker cp $container_id:/rawhash2/build ./build + find ./build -type f -name "*.a" -exec touch {} \; docker rm $container_id - name: Run Docker container diff --git a/Dockerfile b/Dockerfile index c298825..f1208dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY . /rawhash2 RUN mkdir -p build && cd build \ && cmake .. \ - && make -j 3 + && make -j ENTRYPOINT ["./build/bin/rawhash2"] From 8d57f84021e324b655674ba3c6cc5b3924fe1176 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 24 Jul 2024 04:59:17 +0200 Subject: [PATCH 5/9] Update --- .github/workflows/docker-build.yml | 1 + Dockerfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 9741555..24ff124 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -56,6 +56,7 @@ jobs: run: | container_id=$(docker create ghcr.io/${{ steps.repo_owner.outputs.owner }}/build_test:latest) docker cp $container_id:/rawhash2/build ./build + find ./build -type f -name "*.o" -exec touch {} \; find ./build -type f -name "*.a" -exec touch {} \; docker rm $container_id diff --git a/Dockerfile b/Dockerfile index f1208dc..c298825 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY . /rawhash2 RUN mkdir -p build && cd build \ && cmake .. \ - && make -j + && make -j 3 ENTRYPOINT ["./build/bin/rawhash2"] From c9a7472fd4fb9d64a89a5aefe9266a11e7c71a0b Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 24 Jul 2024 14:17:24 +0200 Subject: [PATCH 6/9] Add option to not cache build directory --- .github/workflows/docker-build.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 24ff124..038b154 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -5,6 +5,12 @@ on: branches: - main pull_request: + workflow_dispatch: + inputs: + use_cache: + description: 'Use cache for this run' + required: true + default: 'true' jobs: build: @@ -30,6 +36,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Cache build directory + if: github.event.inputs.use_cache == 'true' uses: actions/cache@v3 with: path: build @@ -56,8 +63,6 @@ jobs: run: | container_id=$(docker create ghcr.io/${{ steps.repo_owner.outputs.owner }}/build_test:latest) docker cp $container_id:/rawhash2/build ./build - find ./build -type f -name "*.o" -exec touch {} \; - find ./build -type f -name "*.a" -exec touch {} \; docker rm $container_id - name: Run Docker container From 6c0d639654c07c6d5adad6b842b31afbff4ecdb7 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 24 Jul 2024 14:34:17 +0200 Subject: [PATCH 7/9] Always cache outside manual runs --- .github/workflows/docker-build.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 038b154..986c95b 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -36,7 +36,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Cache build directory - if: github.event.inputs.use_cache == 'true' + if: github.event_name != 'workflow_dispatch' || github.event.inputs.use_cache == 'true' uses: actions/cache@v3 with: path: build diff --git a/Dockerfile b/Dockerfile index c298825..72b4e3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY . /rawhash2 RUN mkdir -p build && cd build \ && cmake .. \ - && make -j 3 + && make -j 2 ENTRYPOINT ["./build/bin/rawhash2"] From 698075d874546bcbf00b191e6154ba23aac0b191 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 14 Aug 2024 05:30:18 +0200 Subject: [PATCH 8/9] RUCLIENT_ENABLED support --- cmake/SetupHDF5.cmake | 5 +++-- cmake/SetupPOD5.cmake | 9 +++++---- cmake/SetupRUClient.cmake | 14 ++++---------- cmake/SetupSLOW5.cmake | 5 +++-- cmake/Utils.cmake | 18 +++++++++++++----- src/CMakeLists.txt | 2 +- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/cmake/SetupHDF5.cmake b/cmake/SetupHDF5.cmake index 686e75c..dae4c68 100644 --- a/cmake/SetupHDF5.cmake +++ b/cmake/SetupHDF5.cmake @@ -7,7 +7,7 @@ function(add_hdf5_to_target TARGET_NAME) if(HDF5_COMPILE) add_dependencies(${TARGET_NAME} hdf5_build) endif() - target_link_libraries(${TARGET_NAME} PRIVATE hdf5) + add_imported_library(${TARGET_NAME} hdf5) endif() endfunction() @@ -24,6 +24,7 @@ function(setup_hdf5) 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} @@ -35,6 +36,6 @@ function(setup_hdf5) message(FATAL_ERROR "HDF5_COMPILE is OFF, but no dir provided") endif() endif() - define_imported_library(hdf5 ${HDF5_DIR}) + define_imported_library(hdf5 ${HDF5_DIR} SHARED) endif() endfunction() diff --git a/cmake/SetupPOD5.cmake b/cmake/SetupPOD5.cmake index 0ef360c..9acc711 100644 --- a/cmake/SetupPOD5.cmake +++ b/cmake/SetupPOD5.cmake @@ -3,25 +3,26 @@ include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) function(add_zstd_to_target TARGET_NAME) set(ZSTD_DIR ${EXTERNAL_PROJECTS_BUILD_DIR}/zstd) add_dependencies(${TARGET_NAME} zstd_build) - target_link_libraries(${TARGET_NAME} PRIVATE zstd) + 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} ) - define_imported_library(zstd ${ZSTD_DIR}) + define_imported_library(zstd ${ZSTD_DIR} SHARED) endfunction() function(add_pod5_to_target TARGET_NAME) if(NOPOD5) target_compile_definitions(${TARGET_NAME} PRIVATE NPOD5RH=1) else() - add_zstd_to_target(${TAARGET_NAME}) + add_zstd_to_target(${TARGET_NAME}) set(POD5_VERSION "0.2.2") set(POD5_URLDIR "pod5-${POD5_VERSION}-${CMAKE_SYSTEM_NAME}") @@ -32,7 +33,7 @@ function(add_pod5_to_target TARGET_NAME) if(POD5_DOWNLOAD) add_dependencies(${TARGET_NAME} pod5_download) endif() - target_link_libraries(${TARGET_NAME} PRIVATE ${POD5_LIBRARIES} zstd) + target_link_libraries(${TARGET_NAME} PRIVATE ${POD5_LIBRARIES}) endif() endfunction() diff --git a/cmake/SetupRUClient.cmake b/cmake/SetupRUClient.cmake index 4c91361..c817827 100644 --- a/cmake/SetupRUClient.cmake +++ b/cmake/SetupRUClient.cmake @@ -5,7 +5,7 @@ function(add_ruclient_to_target TARGET_NAME) 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) - add_dependencies(${TARGET_NAME} ruclient_build) + target_link_libraries(${TARGET_NAME} PRIVATE ont_device_client_LIB ru_method_LIB) endif() endfunction() @@ -14,15 +14,9 @@ function(setup_ruclient) 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} - ) - 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() diff --git a/cmake/SetupSLOW5.cmake b/cmake/SetupSLOW5.cmake index 81fa67d..ec04a38 100644 --- a/cmake/SetupSLOW5.cmake +++ b/cmake/SetupSLOW5.cmake @@ -7,7 +7,7 @@ function(add_slow5_to_target TARGET_NAME) if(SLOW5_COMPILE) add_dependencies(${TARGET_NAME} slow5_build) endif() - target_link_libraries(${TARGET_NAME} PRIVATE slow5) + add_imported_library(${TARGET_NAME} slow5) endif() endfunction() @@ -21,6 +21,7 @@ function(setup_slow5) 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 @@ -34,6 +35,6 @@ function(setup_slow5) endif() endif() message(STATUS "Using slow5 from ${SLOW5_DIR}") - define_imported_library(slow5 ${SLOW5_DIR}) + define_imported_library(slow5 ${SLOW5_DIR} SHARED) endif() endfunction() diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index 81134e3..4c827db 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -8,16 +8,24 @@ function(override_cached name value) endfunction() -function(define_imported_library LIB_NAME LIB_DIR) - add_library(${LIB_NAME} SHARED IMPORTED) - set_target_properties(${LIB_NAME} PROPERTIES - IMPORTED_LOCATION ${LIB_DIR}/lib/lib${LIB_NAME}.so +function(add_imported_library TARGET_NAME LIB_NAME) + target_link_libraries(${TARGET_NAME} PRIVATE ${LIB_NAME}_RAWHASH_LIB) +endfunction() + +function(define_imported_library LIB_NAME LIB_DIR LIB_TYPE) + add_library(${LIB_NAME}_RAWHASH_LIB ${LIB_TYPE} IMPORTED) + set(EXTENSION ".a") + if(LIB_TYPE STREQUAL SHARED) + set(EXTENSION ".so") + endif() + set_target_properties(${LIB_NAME}_RAWHASH_LIB PROPERTIES + IMPORTED_LOCATION ${LIB_DIR}/lib/lib${LIB_NAME}${EXTENSION} INTERFACE_INCLUDE_DIRECTORIES ${LIB_DIR}/include) file(MAKE_DIRECTORY ${LIB_DIR}/include) # Can't install(TARGETS ...) for external projects # Also some .so are symlinks, so install all install(DIRECTORY ${LIB_DIR}/lib/ DESTINATION lib - FILES_MATCHING PATTERN "*.so*") + FILES_MATCHING PATTERN *${EXTENSION}*) install(DIRECTORY ${LIB_DIR}/include/ DESTINATION include/${PROJECT_NAME}) endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9178c25..ba9d5df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,7 @@ option(RUCLIENT_ENABLED "Enable ReadUntil client" OFF) set(POD5_DIR "" CACHE PATH "Path to POD5 directory (already built or where it should be built)") set(HDF5_DIR "" CACHE PATH "Path to HDF5 directory (already built or where it should be built)") set(SLOW5_DIR "" CACHE PATH "Path to SLOW5 directory (already built or where it should be built)") -set(RUCLIENT_DIR "" CACHE PATH "Path to ReadUntil directory (already built or where it should be built)") +set(RUCLIENT_DIR "" CACHE PATH "Path to ReadUntil directory (where it should be built)") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Directory where to put binaries") From 3fa7c33d375ba35d9bcf07470ff0e9dfee16301c Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 28 Aug 2024 03:28:28 +0200 Subject: [PATCH 9/9] Use RAWHASH_NUM_BUILD_JOBS in Dockerfile --- .github/workflows/docker-build.yml | 5 +++++ Dockerfile | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 986c95b..8277385 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -11,6 +11,10 @@ on: description: 'Use cache for this run' required: true default: 'true' + num_build_jobs: + description: 'Number of build jobs' + required: true + default: '2' jobs: build: @@ -58,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: | diff --git a/Dockerfile b/Dockerfile index 72b4e3e..4792071 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 2 + && make -j $RAWHASH_NUM_BUILD_JOBS ENTRYPOINT ["./build/bin/rawhash2"]