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

Added building using CMake and packaging using CPack and have solved some issues. #154

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
17 changes: 17 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[submodule "cmake/thirdParty/Boilerplate"]
path = cmake/thirdParty/Boilerplate
url = https://github.com/KOLANICH-libs/Boilerplate.cmake
branch = master
shallow = true

[submodule "cmake/thirdParty/DoxygenUtils"]
path = cmake/thirdParty/DoxygenUtils
url = https://github.com/KOLANICH-libs/DoxygenUtils.cmake
branch = master
shallow = true

[submodule "cmake/thirdParty/DetectDependentHeaders"]
path = cmake/thirdParty/DetectDependentHeaders
url = https://github.com/KOLANICH-libs/DetectDependentHeaders.cmake
branch = master
shallow = true
9 changes: 9 additions & 0 deletions C/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_subdirectory("include")

set(C_SUBLIBS "knetfile;bgzf;kalloc;keigen;kexpr;khmm;kmath;knhx;kson;kstring;ksw;kthread;kurl;kopen;ksa") # order matters!

foreach(C_SUBLIB ${C_SUBLIBS})
add_subdirectory("${C_SUBLIB}")
endforeach()

pass_through_cpack_vars()
30 changes: 30 additions & 0 deletions C/bgzf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
buildAndPackageLib("bzgf"
COMPONENT "bzgf"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nSomething related to compression."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

option(BGZF_WITH_CACHE "Enable caching in bzgf" ON)
if(BGZF_WITH_CACHE)
target_compile_definitions(bzgf PRIVATE "-DBGZF_CACHE") #khash is header-only
target_link_libraries(bzgf PRIVATE "${PROJECT_NAME}")
endif()

option(BGZF_WITH_KNETFILE "Use knetfile in bzgf" OFF)
if(BGZF_WITH_KNETFILE)
target_compile_definitions(bzgf PRIVATE "-D_USE_KNETFILE")
target_link_libraries(bzgf PRIVATE knetfile)
set(CPACK_COMPONENT_BGZF_DEPENDS "${CPACK_COMPONENT_BGZF_DEPENDS};knetfile")

list(APPEND CPACK_DEBIAN_BZGF_PACKAGE_DEPENDS "${CPACK_DEBIAN_KNETFILE_PACKAGE_NAME}")
string(REPLACE ";" ", " CPACK_DEBIAN_BZGF_PACKAGE_DEPENDS "${CPACK_DEBIAN_BZGF_PACKAGE_DEPENDS}")
set(CPACK_DEBIAN_BZGF_PACKAGE_DEPENDS "${CPACK_DEBIAN_BZGF_PACKAGE_DEPENDS}" PARENT_SCOPE)

list(APPEND CPACK_RPM_BZGF_PACKAGE_DEPENDS "${CPACK_RPM_KNETFILE_PACKAGE_NAME}")
string(REPLACE ";" ", " CPACK_RPM_BZGF_PACKAGE_DEPENDS "${CPACK_RPM_BZGF_PACKAGE_DEPENDS}")
set(CPACK_RPM_BZGF_PACKAGE_DEPENDS "${CPACK_RPM_BZGF_PACKAGE_DEPENDS}" PARENT_SCOPE)

pass_through_cpack_vars()
endif()
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("${PROJECT_NAME}"
COMPONENT "headers"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nHeader-only libraries"
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/kalloc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("kalloc"
COMPONENT "kalloc"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nAn allocator of memory"
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/keigen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("keigen"
COMPONENT "keigen"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nAn eigensolver"
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/kexpr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("kexpr"
COMPONENT "keigen"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nA small rudimentary scripting language for arythmetic expressions"
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/khmm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("khmm"
COMPONENT "khmm"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nA basic HMM library."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions C/kmath/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
buildAndPackageLib("kmath"
COMPONENT "kmath"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nA numerical routines including MT19937-64 pseudorandom generator, basic nonlinear programming and a few special math functions."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

if(MSVC)
else()
target_link_libraries(kmath PUBLIC m)
endif()
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/knetfile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("knetfile"
COMPONENT "knetfile"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nRandom access to remote files on HTTP or FTP."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/knhx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("knhx"
COMPONENT "knhx"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nNewick tree format parser."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/kopen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("kopen"
COMPONENT "kopen"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nA library for smart stream, files and sockets opening."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
3 changes: 3 additions & 0 deletions kopen.c → C/kopen/kopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <arpa/inet.h>
#include <sys/socket.h>
#endif
#ifdef _POSIX_VERSION
#include <sys/wait.h>
#endif

#ifdef _WIN32
#define _KO_NO_NET
Expand Down
4 changes: 4 additions & 0 deletions C/kopen/kopen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

int kclose(void *a);
void *kopen(char const *fn, int *_fd);
19 changes: 19 additions & 0 deletions C/ksa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(DESCR "Constructs suffix arrays for strings with multiple sentinels, based on a revised SAIS algorithm.")

buildAndPackageLib("ksa32"
COMPONENT "ksa32"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\n${DESCR}\n\nUses 32-bit integers."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}/ksa32.h"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

buildAndPackageLib("ksa64"
COMPONENT "ksa64"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\n${DESCR}\n\nUses 64-bit integers."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}/ksa64.h"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

target_compile_definitions(ksa64 PRIVATE "-D_KSA64")
File renamed without changes.
30 changes: 30 additions & 0 deletions C/ksa/ksa32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

int ksa_bwt(unsigned char *T, int n, int k);

/**
* Recursively construct the suffix array for a string containing multiple
* sentinels. NULL is taken as the sentinel.
*
* @param T NULL terminated input string (there can be multiple NULLs)
* @param SA output suffix array
* @param fs working space available in SA (typically 0 when first called)
* @param n length of T, including the trailing NULL
* @param k size of the alphabet (typically 256 when first called)
* @param cs # bytes per element in T; 1 or sizeof(saint_t) (typically 1 when first called)
*
* @return 0 upon success
*/
int ksa_core(unsigned char const *T, int *SA, int fs, int n, int k, int cs);

/**
* Construct the suffix array for a NULL terminated string possibly containing
* multiple sentinels (NULLs).
*
* @param T[0..n-1] NULL terminated input string
* @param SA[0..n-1] output suffix array
* @param n length of the given string, including NULL
* @param k size of the alphabet including the sentinel; no more than 256
* @return 0 upon success
*/
int ksa_sa(unsigned char const *T, int *SA, int n, int k);
30 changes: 30 additions & 0 deletions C/ksa/ksa64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

int ksa_bwt64(unsigned char *T, long int n, int k);

/**
* Recursively construct the suffix array for a string containing multiple
* sentinels. NULL is taken as the sentinel.
*
* @param T NULL terminated input string (there can be multiple NULLs)
* @param SA output suffix array
* @param fs working space available in SA (typically 0 when first called)
* @param n length of T, including the trailing NULL
* @param k size of the alphabet (typically 256 when first called)
* @param cs # bytes per element in T; 1 or sizeof(saint_t) (typically 1 when first called)
*
* @return 0 upon success
*/
int ksa_core64(unsigned char const *T, long int *SA, long int fs, long int n, long int k, int cs);

/**
* Construct the suffix array for a NULL terminated string possibly containing
* multiple sentinels (NULLs).
*
* @param T[0..n-1] NULL terminated input string
* @param SA[0..n-1] output suffix array
* @param n length of the given string, including NULL
* @param k size of the alphabet including the sentinel; no more than 256
* @return 0 upon success
*/
int ksa_sa64(unsigned char const *T, long int *SA, long int n, int k);
7 changes: 7 additions & 0 deletions C/kson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("kson"
COMPONENT "kson"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nA small and lightweight JSON parser."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/kstring/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("kstring"
COMPONENT "kstring"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nA basic string library."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions C/ksw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildAndPackageLib("ksw"
COMPONENT "ksw"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nStriped Smith-Waterman algorithm."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions C/kthread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
find_package(Threads REQUIRED)

set(CPACK_DEBIAN_KTHREAD_PACKAGE_SHLIBDEPS ON)
buildAndPackageLib("kthread"
COMPONENT "kthread"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nSimple threading models."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
PRIVATE_LIBS "Threads::Threads"
)
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions C/kurl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
find_package(CURL)

if(CURL_FOUND)
set(CPACK_DEBIAN_KURL_PACKAGE_SHLIBDEPS ON)
buildAndPackageLib("kurl"
COMPONENT "kurl"
DESCRIPTION "${PROJECT_DESCRIPTION}\n\nSomething like knetfile, but implemented above cURL."
CMAKE_EXPORT_NAMESPACE "${PROJECT_NAME}"
PUBLIC_INCLUDES "${CMAKE_CURRENT_LIST_DIR}"
INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
PRIVATE_LIBS "CURL::libcurl"
#PKG_CONFIG_REQUIRES "libcurl"
)
endif()
File renamed without changes.
File renamed without changes.
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.7.2)

set(CMAKE_USE_RELATIVE_PATHS TRUE)
project("klib")
set("PROJECT_DESCRIPTION" "A standalone and lightweight C library that strives for efficiency and a small memory footprint, some of which components are among the most efficient
implementations of similar algorithms or data structures in all programming languages, in terms of both speed and memory use.")
set("PROJECT_HOMEPAGE_URL" "https://github.com/attractivechaos/klib")

set(CPACK_PACKAGE_VENDOR "klib developers")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

set(OUR_CMAKE_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(OUR_CMAKE_3PARTY_MODULES_DIR "${OUR_CMAKE_MODULES_DIR}/thirdParty")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OUR_CMAKE_MODULES_DIR}" "${OUR_CMAKE_3PARTY_MODULES_DIR}" "${OUR_CMAKE_3PARTY_MODULES_DIR}/Boilerplate" "${OUR_CMAKE_3PARTY_MODULES_DIR}/DetectDependentHeaders" "${OUR_CMAKE_3PARTY_MODULES_DIR}/DoxygenUtils")


include(Boilerplate)
include(DetectDependentHeaders)
include(DoxygenUtils)

set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
set(CPACK_RPM_ENABLE_COMPONENT_DEPENDS ON)

set(C_dir "${CMAKE_CURRENT_SOURCE_DIR}/C")
set(CPP_dir "${CMAKE_CURRENT_SOURCE_DIR}/cpp")
set(tests_dir "${CMAKE_CURRENT_SOURCE_DIR}/test")

add_subdirectory("${C_dir}")
add_subdirectory("${CPP_dir}")

option(WITH_EXAMPLES "Build examples" OFF)
if(WITH_EXAMPLES)
#file(GLOB EXAMPLES "${tests_dir}/*.c" "${tests_dir}/*.cc" "${tests_dir}/*.cpp")
file(GLOB EXAMPLES "${tests_dir}/*.c" "${tests_dir}/*.cpp")
foreach(example ${EXAMPLES})
detect_dependencies_by_headers("k" "${example}" EXAMPLE_DEPS)
get_filename_component(exampleName "${example}" NAME_WE)
add_executable("${exampleName}" "${example}")
target_link_libraries("${exampleName}" PRIVATE ${PROJECT_NAME} ${EXAMPLE_DEPS})
endforeach()

find_package(ZLIB REQUIRED)
target_link_libraries(kseq_test PRIVATE ZLIB::ZLIB)
target_link_libraries(kseq_bench PRIVATE ZLIB::ZLIB)
endif()

option(WITH_DOCS "Build docs" OFF)
if(WITH_DOCS)
find_package(Doxygen REQUIRED dot)
load_doxyfile("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile")

set(DOXYGEN_PROJECT_BRIEF "${CPACK_PACKAGE_DESCRIPTION}")
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CPACK_RESOURCE_FILE_README}")

set("DOXYGEN_GENERATE_HTML" YES)
set("DOXYGEN_GENERATE_MAN" YES)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Compiler is CLang, enabling CLang-assisted parsing in Doxygen.")
set(DOXYGEN_CLANG_ASSISTED_PARSING YES)
list(JOIN C_SUBLIBS " -I" DOXYGEN_CLANG_OPTIONS)
set(DOXYGEN_CLANG_OPTIONS "-I${C_dir} -I${CPP_dir} -I${Include_dir} -I${DOXYGEN_CLANG_OPTIONS}")
endif()

set(DOXYGEN_EXAMPLE_PATH "${tests_dir}")
set(DOXYGEN_STRIP_FROM_PATH "${Include_dir}")
set(DOXYGEN_STRIP_FROM_INC_PATH "${Include_dir}")


file(GLOB SOURCES_TO_DOCUMENT "${C_dir}/*.[hc]" "${CPP_dir}/*.[ch]xx" "${CPP_dir}/*.[ch]pp")
doxygen_add_docs(docs
"${SOURCES_TO_DOCUMENT}"
ALL
USE_STAMP_FILE
)
endif()

#pass_through_cpack_vars()

include(CPack)
Loading