From b4b9d6ed4368636852883fcc85d6102a435cba21 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Thu, 26 Oct 2023 10:34:33 +0300 Subject: [PATCH 1/5] Make it clang compatible --- kmc_api/kmer_defs.h | 10 +++++++--- kmc_core/defs.h | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/kmc_api/kmer_defs.h b/kmc_api/kmer_defs.h index 027f4105..c4a7b602 100644 --- a/kmc_api/kmer_defs.h +++ b/kmc_api/kmer_defs.h @@ -34,9 +34,13 @@ #include - #include - #include - + #if defined(__clang__) + #include + #elif defined(__GNUC__) + #include + using __gnu_cxx::copy_n; + #endif + #include #else #define my_fopen fopen #define my_fseek _fseeki64 diff --git a/kmc_core/defs.h b/kmc_core/defs.h index 151332aa..83cea438 100644 --- a/kmc_core/defs.h +++ b/kmc_core/defs.h @@ -109,9 +109,13 @@ using uint64 = uint64_t; #include #include + +#if defined(__clang__) +#include +#elif defined(__GNUC__) #include using __gnu_cxx::copy_n; - +#endif #endif From 85c11614d6879358936e315a188311c8cce7f8c0 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Thu, 26 Oct 2023 12:05:02 +0300 Subject: [PATCH 2/5] First cut of cmake-based system. --- 3rd_party/CMakeLists.txt | 12 +++++++ CMakeLists.txt | 70 ++++++++++++++++++++++++++++++++++++++++ kmc_CLI/CMakeLists.txt | 11 +++++++ kmc_api/CMakeLists.txt | 11 +++++++ kmc_core/CMakeLists.txt | 43 ++++++++++++++++++++++++ kmc_dump/CMakeLists.txt | 11 +++++++ kmc_tools/CMakeLists.txt | 16 +++++++++ 7 files changed, 174 insertions(+) create mode 100644 3rd_party/CMakeLists.txt create mode 100644 CMakeLists.txt create mode 100644 kmc_CLI/CMakeLists.txt create mode 100644 kmc_api/CMakeLists.txt create mode 100644 kmc_core/CMakeLists.txt create mode 100644 kmc_dump/CMakeLists.txt create mode 100644 kmc_tools/CMakeLists.txt diff --git a/3rd_party/CMakeLists.txt b/3rd_party/CMakeLists.txt new file mode 100644 index 00000000..5665baad --- /dev/null +++ b/3rd_party/CMakeLists.txt @@ -0,0 +1,12 @@ +# -*- cmake -*- +include(ExternalProject) + +include(FetchContent) + +FetchContent_Declare(cloudflare_zlib + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cloudflare") +FetchContent_GetProperties(cloudflare_zlib) +if (NOT cloudflare_zlib_POPULATED) + FetchContent_Populate(cloudflare_zlib) + add_subdirectory(${cloudflare_zlib_SOURCE_DIR} ${cloudflare_zlib_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..9a4aaa8d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +# -*- cmake -*- + +# Hard prerequisites +cmake_minimum_required(VERSION 3.16) + +project(KMC + VERSION 3.2.2 + LANGUAGES C CXX) + +# FIXME: +# set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) + +# Sanity check our source directory to make sure that we are not trying to +# generate an in-tree build +if ((CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) OR + (CMAKE_SOURCE_DIR STREQUAL "${CMAKE_BINARY_DIR}/src")) + message(FATAL_ERROR "In-source builds are not allowed. +Please create a directory and run cmake from there, passing the path +to this source directory as the last argument. +This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. +Please delete them.") +endif() + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# FIXME: Add option to build pybindings + +# External dependencies +add_subdirectory(3rd_party) + +# Default build configuration +set(KMC_DEFAULT_BUILD_TYPE "RelWithDebInfo" CACHE STRING "KMC default build type") +if (NOT CMAKE_BUILD_TYPE) + message("Setting default build configuration: ${KMC_DEFAULT_BUILD_TYPE}") + set(CMAKE_BUILD_TYPE "${KMC_DEFAULT_BUILD_TYPE}" CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithAsserts RelWithDebInfo." + FORCE) +endif() + +# Default compiler flags +if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") + message("Making Debug Configuration...") + + add_compile_options(-g3) + add_definitions(-D_GLIBCXX_DEBUG) +else() + message("Making Release Configuration...") + + if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + add_compile_options(-g1) + else() + add_compile_options(-g0) + endif() + + add_compile_options(-O3) + if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithAsserts" OR + ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + add_definitions(-UNDEBUG) + else() + add_definitions(-DNDEBUG) + endif() +endif() +add_compile_options(-Wall -fsigned-char) + +add_subdirectory(kmc_api) +add_subdirectory(kmc_core) +add_subdirectory(kmc_CLI) +add_subdirectory(kmc_dump) +add_subdirectory(kmc_tools) diff --git a/kmc_CLI/CMakeLists.txt b/kmc_CLI/CMakeLists.txt new file mode 100644 index 00000000..576de0aa --- /dev/null +++ b/kmc_CLI/CMakeLists.txt @@ -0,0 +1,11 @@ +# -*- cmake -*- + +project(KMC_CLI + LANGUAGES CXX) + +add_executable(kmc kmc.cpp) +target_link_libraries(kmc kmc_core) + +install(TARGETS kmc + DESTINATION bin + COMPONENT kmc) diff --git a/kmc_api/CMakeLists.txt b/kmc_api/CMakeLists.txt new file mode 100644 index 00000000..5e729008 --- /dev/null +++ b/kmc_api/CMakeLists.txt @@ -0,0 +1,11 @@ +# -*- cmake -*- + +project(KMC_API + VERSION 3.2.2 + LANGUAGES C CXX) + +# make list of all API source files +file(GLOB sources "[a-zA-Z]*.cpp") + +add_library(kmc_api OBJECT + ${sources}) diff --git a/kmc_core/CMakeLists.txt b/kmc_core/CMakeLists.txt new file mode 100644 index 00000000..ad08267b --- /dev/null +++ b/kmc_core/CMakeLists.txt @@ -0,0 +1,43 @@ +# -*- cmake -*- + +project(KMC_CORE + LANGUAGES C CXX) + +# determine & normalize architecture +set(_system_processor ${CMAKE_SYSTEM_PROCESSOR}) +if (APPLE AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") + set(_system_processor ${CMAKE_OSX_ARCHITECTURES}) +endif() +if(${_system_processor} STREQUAL "arm64") + set(ARCH "arm64") +elseif(${_system_processor} STREQUAL "aarch64") + set(ARCH "arm64") +elseif(${_system_processor} STREQUAL "x86_64") + set(ARCH "x86_64") +elseif(${_system_processor} STREQUAL "AMD64") + set(ARCH "x86_64") +else() + message(FATAL_ERROR "unknown architecture " ${_system_processor}) +endif() + +if (${ARCH} STREQUAL "arm64") + set(raduls_sources raduls_neon.cpp) +elseif (${ARCH} STREQUAL "x86_64") + set(raduls_sources + raduls_sse2.cpp + raduls_sse41.cpp + raduls_avx2.cpp + raduls_avx.cpp) +endif() + +add_library(kff_core OBJECT + kff_writer.cpp) + +add_library(kmc_core STATIC + mem_disk_file.cpp rev_byte.cpp bkb_writer.cpp + cpu_info.cpp bkb_reader.cpp fastq_reader.cpp + timer.cpp develop.cpp kb_completer.cpp + kb_storer.cpp kmer.cpp splitter.cpp kb_collector.cpp kmc_runner.cpp + ${raduls_sources} +) +target_link_libraries(kmc_core kmc_api kff_core zlib) diff --git a/kmc_dump/CMakeLists.txt b/kmc_dump/CMakeLists.txt new file mode 100644 index 00000000..1220eab3 --- /dev/null +++ b/kmc_dump/CMakeLists.txt @@ -0,0 +1,11 @@ +# -*- cmake -*- + +project(KMC_DUMP + LANGUAGES CXX) + +add_executable(kmc_dump kmc_dump.cpp nc_utils.cpp) +target_link_libraries(kmc_dump kmc_api) + +install(TARGETS kmc_dump + DESTINATION bin + COMPONENT kmc) diff --git a/kmc_tools/CMakeLists.txt b/kmc_tools/CMakeLists.txt new file mode 100644 index 00000000..bf2be09f --- /dev/null +++ b/kmc_tools/CMakeLists.txt @@ -0,0 +1,16 @@ +# -*- cmake -*- + +project(KMC_TOOLS + LANGUAGES CXX) + +add_executable(kmc_tools + kmer_file_header.cpp kmc_tools.cpp nc_utils.cpp + parameters_parser.cpp parser.cpp tokenizer.cpp + fastq_filter.cpp fastq_reader.cpp fastq_writer.cpp + percent_progress.cpp kff_info_reader.cpp) +target_link_libraries(kmc_tools kmc_api kff_core zlib) + +install(TARGETS kmc_tools + DESTINATION bin + COMPONENT kmc) + From e914cc58f39fde4a056d55bb0d2ecf3c5db7b62d Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Thu, 26 Oct 2023 12:06:29 +0300 Subject: [PATCH 3/5] Ignore compilation database --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f5e9a3e0..32de1bff 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,9 @@ Icon .Spotlight-V100 .Trashes +# Compilation database +compile_commands.json + # Directories potentially created on remote AFP share .AppleDB .AppleDesktop From cdfd8addfc6bf397c8b63cea23d41a752b5ddba7 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sat, 28 Oct 2023 09:34:35 +0300 Subject: [PATCH 4/5] Pass proper compiler options --- kmc_core/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kmc_core/CMakeLists.txt b/kmc_core/CMakeLists.txt index ad08267b..6e17eed5 100644 --- a/kmc_core/CMakeLists.txt +++ b/kmc_core/CMakeLists.txt @@ -8,13 +8,13 @@ set(_system_processor ${CMAKE_SYSTEM_PROCESSOR}) if (APPLE AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") set(_system_processor ${CMAKE_OSX_ARCHITECTURES}) endif() -if(${_system_processor} STREQUAL "arm64") +if (${_system_processor} STREQUAL "arm64") set(ARCH "arm64") -elseif(${_system_processor} STREQUAL "aarch64") +elseif (${_system_processor} STREQUAL "aarch64") set(ARCH "arm64") -elseif(${_system_processor} STREQUAL "x86_64") +elseif (${_system_processor} STREQUAL "x86_64") set(ARCH "x86_64") -elseif(${_system_processor} STREQUAL "AMD64") +elseif (${_system_processor} STREQUAL "AMD64") set(ARCH "x86_64") else() message(FATAL_ERROR "unknown architecture " ${_system_processor}) @@ -28,6 +28,10 @@ elseif (${ARCH} STREQUAL "x86_64") raduls_sse41.cpp raduls_avx2.cpp raduls_avx.cpp) + set_source_files_properties(raduls_sse2.cpp PROPERTIES COMPILE_OPTIONS "-msse2") + set_source_files_properties(raduls_sse41.cpp PROPERTIES COMPILE_OPTIONS "-msse4.1") + set_source_files_properties(raduls_avx.cpp PROPERTIES COMPILE_OPTIONS "-mavx") + set_source_files_properties(raduls_avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2") endif() add_library(kff_core OBJECT From 0faf155211fb134d82465c40c720369a658b0701 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sat, 28 Oct 2023 10:14:51 +0300 Subject: [PATCH 5/5] Enable building python API --- CMakeLists.txt | 9 +++++---- kmc_api/CMakeLists.txt | 2 ++ py_kmc_api/CMakeLists.txt | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 py_kmc_api/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a4aaa8d..2fa8e833 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,6 @@ project(KMC VERSION 3.2.2 LANGUAGES C CXX) -# FIXME: -# set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) - # Sanity check our source directory to make sure that we are not trying to # generate an in-tree build if ((CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) OR @@ -24,7 +21,8 @@ endif() set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# FIXME: Add option to build pybindings +# Options +option(KMC_BUILD_PYTHON_API "Turn on / off building python API" ON) # External dependencies add_subdirectory(3rd_party) @@ -68,3 +66,6 @@ add_subdirectory(kmc_core) add_subdirectory(kmc_CLI) add_subdirectory(kmc_dump) add_subdirectory(kmc_tools) +if (KMC_BUILD_PYTHON_API) + add_subdirectory(py_kmc_api) +endif() diff --git a/kmc_api/CMakeLists.txt b/kmc_api/CMakeLists.txt index 5e729008..3490491c 100644 --- a/kmc_api/CMakeLists.txt +++ b/kmc_api/CMakeLists.txt @@ -6,6 +6,8 @@ project(KMC_API # make list of all API source files file(GLOB sources "[a-zA-Z]*.cpp") +# export it to the parent scope, so python module could reuse it +set(PY_KMC_API_SOURCES ${sources} PARENT_SCOPE) add_library(kmc_api OBJECT ${sources}) diff --git a/py_kmc_api/CMakeLists.txt b/py_kmc_api/CMakeLists.txt new file mode 100644 index 00000000..145d2e8c --- /dev/null +++ b/py_kmc_api/CMakeLists.txt @@ -0,0 +1,21 @@ +# -*- cmake -*- + +project(PY_KMC_API + LANGUAGES C CXX) + +find_package(Python COMPONENTS Interpreter Development REQUIRED) + +# FIXME: switch to pybind11 cmake +Python_add_library(py_kmc_api MODULE + ${PY_KMC_API_SOURCES} + py_kmc_api.cpp) +target_include_directories(py_kmc_api PRIVATE "libs/pybind11/include") +# FIXME: a bit hacky +target_include_directories(py_kmc_api PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kmc_api) + +install(TARGETS py_kmc_api + DESTINATION bin + COMPONENT python_module) +install(FILES py_kmc_dump.py + DESTINATION bin + COMPONENT python_module)