Codebase list kissplice / HEAD CMakeLists.txt
HEAD

Tree @HEAD (Download .tar.gz)

CMakeLists.txt @HEADraw · history · blame

# 3.1 required by: zlib targets, Threads (OpenMP target fallback)
cmake_minimum_required(VERSION 3.1)

project(
  kissplice
  VERSION 2.6.2 # Definition which is propagated through PROJECT_VERSION
  LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 11) # Default to C++11 for C++ targets
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Fail if not supported (very old compiler at this point)

# Build type, should be set by user. Useful predefined values (see `cmake -LH`): Debug, Release, RelWithDebInfo.
# Default to non-persistent RelWithDebInfo (-g -O2) if no build type is specified.
if(NOT CMAKE_BUILD_TYPE)
  # Not cached : this keeps the help string (`cmake -LH`) and user setting intact.
  set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

# Cmake already adds -g in Debug and -O3 in Release, so no need to set them manually.
# Enables common warnings for ALL targets.
add_compile_options(-Wall)
# Profiling with gprof requires -pg which is better to add manually with -DCMAKE_(C|CXX)_FLAGS=-pg
# `perf` is a more modern replacement anyway and does not require special compilation.

# Date for manpage and pdf doc
string(TIMESTAMP CONFIGURE_DATE "%Y-%m-%d" UTC)

###############################################################################
# structure and paths
# kissplice is composed of:
# - internal binaries which should go to <prefix>/libexec/kissplice
# - a main frontend "binary" which is a python script which should go to <prefix>/bin
# The frontend script expects this architecture to hold (with relative paths) to find the internal binaries.
# For tests to work, this architecture is replicated in the temporary build directory wih <prefix>=<build_dir>
include(GNUInstallDirs) # GNU standard installation directories definitions (bin, libexec, and definitions for doc/man)
# Path to internal binaries relative to prefix. This is used in install() for internal binaries, to let the cmake prefix handling work.
set(RELATIVE_INTERNAL_BINDIR "${CMAKE_INSTALL_LIBEXECDIR}/kissplice") 
# Absolute path to build location of internal binaries. This is used to define RUNTIME_OUTPUT_DIRECTORY of internal binaries (build dir).
set(BUILD_INTERNAL_BINDIR "${PROJECT_BINARY_DIR}/${RELATIVE_INTERNAL_BINDIR}")
# Absolute path to build location of frontend binaries (kissplice script only for now)
set(BUILD_BINDIR "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
# Relative path from script to internal binaries directory, written to kissplice script
file(RELATIVE_PATH KISSPLICE_BINDIR_TO_INTERNAL_BINDIR "${BUILD_BINDIR}" "${BUILD_INTERNAL_BINDIR}")

# Complete the main script template to include the relative directory
configure_file("${PROJECT_SOURCE_DIR}/kissplice.in.py" "${BUILD_BINDIR}/kissplice" @ONLY)
install(PROGRAMS "${BUILD_BINDIR}/kissplice" DESTINATION "${CMAKE_INSTALL_BINDIR}")

###############################################################################
# bcalm dependency
# bcalm is a binary program needed for tests and after install.
# It is packaged on debian, so default to using the system wide version (best practice for packaging kissplice).
# The USE_BUNDLED_BCALM option can be used to locally build and ship an install of bcalm, placed in the internal binaries directory.
# In either case a "bcalm" executable will be placed in internal binaries (bundled binary or a redirect script).
# This simplifies kissplice.py which can always look in libexec/kissplice/bcalm.
# This "bcalm" is placed in both build dir and install dir.
option(
  USE_BUNDLED_BCALM
  "by default kissplice requires an already installed bcalm program ; enable this option to bundle a local bcalm with kissplice."
  OFF
)
if(NOT USE_BUNDLED_BCALM)
  # Check system bcalm
  find_program(SYSTEM_BCALM_PATH NAMES bcalm)
  mark_as_advanced(SYSTEM_BCALM_PATH)
  if(NOT SYSTEM_BCALM_PATH)
    message(
      FATAL_ERROR "bcalm not found. install it with system packages,\
      or provide path to a custom install with -DCMAKE_PROGRAM_PATH=<prefix>,\
      or use bundled bcalm version with -DUSE_BUNDLED_BCALM=TRUE"
    )
  endif()
  message(STATUS "Found bcalm tool: ${SYSTEM_BCALM_PATH}")
  # Add a simple redirection to system bcalm in internal binaries, as kissplice expects bcalm there.
  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/bcalm_redirect.in" "${BUILD_INTERNAL_BINDIR}/bcalm" @ONLY)
else()
  message(STATUS "using bundled version of bcalm (will be compiled at make time)")
  include(ExternalProject)
  ExternalProject_Add(
    bundled_bcalm
    PREFIX bundled_bcalm
    GIT_REPOSITORY "https://github.com/GATB/bcalm.git"
    GIT_TAG v2.2.3
    UPDATE_COMMAND "" # Prevent rebuilding bcalm everytime
    # Prevent install which is broken (vendored hdf5 ignores CMAKE_INSTALL_PREFIX).
    # Manually extract the bcalm binary to our internal binary build dir. This is run inside bcalm build dir.
    INSTALL_COMMAND "${CMAKE_COMMAND}" -E copy bcalm "${BUILD_INTERNAL_BINDIR}"
  )
endif()
install(PROGRAMS "${BUILD_INTERNAL_BINDIR}/bcalm" DESTINATION "${RELATIVE_INTERNAL_BINDIR}")

###############################################################################
# subdirs
add_subdirectory(thirdparty) # kissreads
add_subdirectory(modules) # various ks_* internal tools
add_subdirectory(man) # manpage
add_subdirectory(doc) # user guide

enable_testing()
add_subdirectory(tests)