Skip to content

Commit

Permalink
Merge pull request #47 from jonassibbesen/static-build
Browse files Browse the repository at this point in the history
Add static build option
  • Loading branch information
jonassibbesen authored Mar 24, 2023
2 parents 7f15a7c + de1c2ab commit 301f553
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 62 deletions.
165 changes: 108 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ project(rpvg)

set(CMAKE_CXX_STANDARD 14)

set(BUILD_STATIC 0 CACHE BOOL "Build static version")

if(${BUILD_STATIC} EQUAL 1)

set(Protobuf_USE_STATIC_LIBS ON)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

endif(${BUILD_STATIC} EQUAL 1)

find_package(OpenMP REQUIRED)
find_package(Protobuf REQUIRED)

Expand Down Expand Up @@ -50,27 +60,6 @@ ExternalProject_Add(libvgio-proj
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

add_library(xg
deps/xg/src/xg.cpp
)

add_library(${PROJECT_NAME}
src/fragment_length_dist.cpp
src/paths_index.cpp
src/alignment_path.cpp
src/alignment_path_finder.cpp
src/path_clusters.cpp
src/read_path_probabilities.cpp
src/path_estimator.cpp
src/path_posterior_estimator.cpp
src/path_abundance_estimator.cpp
src/threaded_output_writer.cpp
src/io/register_libvg_io.cpp
src/io/register_loader_saver_gbwt.cpp
src/io/register_loader_saver_r_index.cpp
src/io/register_loader_saver_xg.cpp
)

include_directories(
${HTSlib_INCLUDE_DIRS}
${Protobuf_INCLUDE_DIRS}
Expand All @@ -93,22 +82,79 @@ include_directories(
)

link_directories(
${HTSlib_LIBRARY_DIRS}
${PROJECT_SOURCE_DIR}/deps/sdsl-lite/lib
${PROJECT_SOURCE_DIR}/deps/gbwt/lib
${PROJECT_SOURCE_DIR}/deps/libvgio
${PROJECT_SOURCE_DIR}/deps/libvgio/handlegraph-prefix/lib
)

add_library(xg
deps/xg/src/xg.cpp
)

target_link_libraries(xg
sdsl
handlegraph
divsufsort
divsufsort64
)

add_dependencies(xg gbwt-proj)
add_dependencies(xg libvgio-proj)

set(SOURCE_FILES
src/fragment_length_dist.cpp
src/paths_index.cpp
src/alignment_path.cpp
src/alignment_path_finder.cpp
src/path_clusters.cpp
src/read_path_probabilities.cpp
src/path_estimator.cpp
src/path_posterior_estimator.cpp
src/path_abundance_estimator.cpp
src/threaded_output_writer.cpp
src/io/register_libvg_io.cpp
src/io/register_loader_saver_gbwt.cpp
src/io/register_loader_saver_r_index.cpp
src/io/register_loader_saver_xg.cpp
)

if(${BUILD_STATIC} EQUAL 0)

link_directories(
${HTSlib_LIBRARY_DIRS}
)

add_library(${PROJECT_NAME}
${SOURCE_FILES}
)

target_link_libraries(${PROJECT_NAME}
${HTSlib_LIBRARIES}
)

else(${BUILD_STATIC} EQUAL 0)

message(STATUS "Building static version")

link_directories(
${HTSlib_STATIC_LIBRARY_DIRS}
)

add_executable(${PROJECT_NAME}
src/main.cpp
${SOURCE_FILES}
)

target_link_libraries(${PROJECT_NAME}
${HTSlib_STATIC_LIBRARIES}
)

set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

endif(${BUILD_STATIC} EQUAL 0)

target_link_libraries(${PROJECT_NAME}
${HTSlib_LIBRARIES}
${PROTOBUF_LIBRARIES}
sdsl
gbwt
Expand All @@ -119,9 +165,6 @@ target_link_libraries(${PROJECT_NAME}
xg
)

add_dependencies(xg gbwt-proj)
add_dependencies(xg libvgio-proj)

add_dependencies(${PROJECT_NAME} gbwt-proj)
add_dependencies(${PROJECT_NAME} libvgio-proj)
add_dependencies(${PROJECT_NAME} xg)
Expand All @@ -140,34 +183,42 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")

endif()

add_executable(${PROJECT_NAME}-bin src/main.cpp)
target_link_libraries(${PROJECT_NAME}-bin ${PROJECT_NAME})

set_target_properties(${PROJECT_NAME}-bin PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

add_executable(${PROJECT_NAME}-tests
src/tests/main_test.cpp
src/tests/fragment_length_dist_test.cpp
src/tests/paths_index_test.cpp
src/tests/alignment_path_test.cpp
src/tests/alignment_path_finder_test.cpp
src/tests/read_path_probabilities_test.cpp
src/tests/path_clusters_test.cpp
src/tests/path_abundance_estimator_test.cpp
)

include_directories(
${PROJECT_SOURCE_DIR}/deps/catch2/single_include
)

target_link_libraries(${PROJECT_NAME}-tests
${PROJECT_NAME}
)

enable_testing()

add_test(
NAME ${PROJECT_NAME}-tests
COMMAND ${PROJECT_NAME}-tests
)

if(${BUILD_STATIC} EQUAL 0)

add_executable(${PROJECT_NAME}-bin
src/main.cpp
)

target_link_libraries(${PROJECT_NAME}-bin
${PROJECT_NAME}
)

set_target_properties(${PROJECT_NAME}-bin PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

add_executable(${PROJECT_NAME}-tests
src/tests/main_test.cpp
src/tests/fragment_length_dist_test.cpp
src/tests/paths_index_test.cpp
src/tests/alignment_path_test.cpp
src/tests/alignment_path_finder_test.cpp
src/tests/read_path_probabilities_test.cpp
src/tests/path_clusters_test.cpp
src/tests/path_abundance_estimator_test.cpp
)

include_directories(
${PROJECT_SOURCE_DIR}/deps/catch2/single_include
)

target_link_libraries(${PROJECT_NAME}-tests
${PROJECT_NAME}
)

enable_testing()

add_test(
NAME ${PROJECT_NAME}-tests
COMMAND ${PROJECT_NAME}-tests
)

endif(${BUILD_STATIC} EQUAL 0)
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mirror.gcr.io/library/ubuntu:20.04

MAINTAINER [email protected]
MAINTAINER https://github.com/jonassibbesen

WORKDIR /home

Expand All @@ -13,13 +13,13 @@ RUN apt-get update && \
### Install htslib

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends perl zlib1g-dev libbz2-dev liblzma-dev libcurl4-gnutls-dev libssl-dev && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends perl zlib1g-dev libbz2-dev liblzma-dev libssl-dev && \
rm -rf /var/lib/apt/lists/*

RUN wget --no-check-certificate https://github.com/samtools/htslib/releases/download/1.16/htslib-1.16.tar.bz2 && \
tar -xvjf htslib-1.16.tar.bz2 && \
cd htslib-1.16 && \
./configure && \
./configure --disable-s3 --disable-gcs --disable-libcurl --disable-plugins && \
make install && \
cd .. && \
rm -r *
Expand All @@ -38,8 +38,8 @@ RUN cd rpvg && \
RUN cd rpvg && \
mkdir build && \
cd build && \
cmake .. && \
cmake -DBUILD_STATIC=1 .. && \
make && \
cd ../../ && \
mv rpvg/bin/rpvg /usr/bin/ && \
unlink rpvg/deps/libvgio/vg
rm -r *

0 comments on commit 301f553

Please sign in to comment.