|
| 1 | +cmake_minimum_required(VERSION 3.2) |
| 2 | +string(ASCII 27 Esc) |
| 3 | +set(ColourBold "${Esc}[1m") |
| 4 | +set(ColourReset "${Esc}[m") |
| 5 | +set(ColourRed "${Esc}[31m") |
| 6 | + |
| 7 | +include(ExternalProject) |
| 8 | + |
| 9 | +message("${ColourBold}Compiler Detection${ColourReset}") # This needs to go before "project ()". |
| 10 | + |
| 11 | +project(PhyloCSF++ CXX) |
| 12 | + |
| 13 | +# ---------------------------------------------------------------------------- |
| 14 | +# Compiler detection |
| 15 | +# ---------------------------------------------------------------------------- |
| 16 | +# TODO: check whether older compilers work as well |
| 17 | +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 18 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.1) |
| 19 | + message(FATAL_ERROR "Your GCC version is too old. Minimum version is GCC-4.9.1!") |
| 20 | + return() |
| 21 | + endif () |
| 22 | +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 23 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) |
| 24 | + message(FATAL_ERROR "Your Clang version seems too old. Please upgrade to 3.8.0 or use GCC.") |
| 25 | + return() |
| 26 | + elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8) |
| 27 | + message(WARNING "Your Clang version is too old, you will not have parallelism! Upgrade to 3.8.0 or newer.") |
| 28 | + endif () |
| 29 | +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel") |
| 30 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) |
| 31 | + message(WARNING "Your Intel Compiler version is too old. Please upgrade to 17.0.0 or newer!") |
| 32 | + endif () |
| 33 | +else () |
| 34 | + message(WARNING "Unknown compiler, you are on your own!") |
| 35 | +endif () |
| 36 | + |
| 37 | +message(STATUS "Compiling with ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}.") |
| 38 | +message(STATUS "The requirements were met.") |
| 39 | + |
| 40 | +# ---------------------------------------------------------------------------- |
| 41 | +# Dependency detection |
| 42 | +# ---------------------------------------------------------------------------- |
| 43 | + |
| 44 | +message("\n${ColourBold}Dependency detection${ColourReset}") |
| 45 | + |
| 46 | +find_package(OpenMP QUIET) |
| 47 | +find_package(Git) |
| 48 | +find_package(GSL REQUIRED) |
| 49 | + |
| 50 | +# TODO: don't build in source in case we have multiple build folders with different compiler flags |
| 51 | +ExternalProject_Add(libBigWig |
| 52 | + GIT_REPOSITORY "https://github.com/cpockrandt/libBigWig" |
| 53 | + UPDATE_COMMAND "" |
| 54 | + DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/external/" |
| 55 | + SOURCE_DIR "${CMAKE_BINARY_DIR}/libBigWig" |
| 56 | + BUILD_IN_SOURCE 1 |
| 57 | + CONFIGURE_COMMAND "" |
| 58 | + BUILD_COMMAND ${MAKE} |
| 59 | + INSTALL_COMMAND "" |
| 60 | +) |
| 61 | + |
| 62 | +# Pass git hash and git date to C++ compiler as macros to include them into the help string. |
| 63 | +# Source: https://stackoverflow.com/a/21028226 (by Drew Noakes) |
| 64 | +if (GIT_FOUND) |
| 65 | + execute_process(COMMAND |
| 66 | + "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=8 --dirty |
| 67 | + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 68 | + OUTPUT_VARIABLE GIT_HASH |
| 69 | + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 70 | + execute_process(COMMAND |
| 71 | + "${GIT_EXECUTABLE}" log -1 --date=short --format=%cd |
| 72 | + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 73 | + OUTPUT_VARIABLE GIT_DATE |
| 74 | + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 75 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGIT_HASH=\"${GIT_HASH}\" -DGIT_DATE=\"${GIT_DATE}\"") |
| 76 | +endif() |
| 77 | + |
| 78 | +message(STATUS "These dependencies where found:") |
| 79 | +message( " GSL ${GSL_FOUND} ${GSL_VERSION}") |
| 80 | +message( " OPENMP ${OPENMP_FOUND} ${OpenMP_CXX_FLAGS}") |
| 81 | +message( " GIT ${GIT_FOUND} (optional)") |
| 82 | + |
| 83 | +if (OPENMP_FOUND) |
| 84 | + add_definitions(-DENABLE_OPENMP) |
| 85 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") |
| 86 | +else () |
| 87 | + message(WARNING "WARNING WARNING WARNING\nWARNING: OpenMP not found. PhyloCSF++ will be built without multi-threading! " |
| 88 | + "This is probably not what you want! Use GCC >= 4.9.1 or Clang >= 3.8.0\nWARNING WARNING WARNING") |
| 89 | +endif () |
| 90 | + |
| 91 | +include_directories(${GSL_INCLUDE_DIRS}) |
| 92 | + |
| 93 | +message(STATUS "The requirements were met.") |
| 94 | + |
| 95 | +# ---------------------------------------------------------------------------- |
| 96 | +# Build configuration |
| 97 | +# ---------------------------------------------------------------------------- |
| 98 | + |
| 99 | +message("\n${ColourBold}Build configuration${ColourReset}") |
| 100 | + |
| 101 | +# ---------------------------------------------------------------------------- |
| 102 | +# Make "Release" the default cmake build type |
| 103 | +# ---------------------------------------------------------------------------- |
| 104 | + |
| 105 | +if (NOT CMAKE_BUILD_TYPE) |
| 106 | + set(CMAKE_BUILD_TYPE Release CACHE STRING |
| 107 | + "Choose the type of build, options are: Debug Release RelWithDebInfo" |
| 108 | + FORCE) |
| 109 | +endif () |
| 110 | + |
| 111 | +# ---------------------------------------------------------------------------- |
| 112 | +# Warn if cmake build type is not "Release" |
| 113 | +# ---------------------------------------------------------------------------- |
| 114 | + |
| 115 | +if (NOT CMAKE_BUILD_TYPE STREQUAL Release) |
| 116 | + message(STATUS "${ColourRed}CMAKE_BUILD_TYPE is not \"Release\", your binaries will be slow.${ColourReset}") |
| 117 | +endif () |
| 118 | + |
| 119 | +option(PHYLOCSFPP_NATIVE_BUILD "Architecture-specific optimizations, i.e., g++ -march=native." ON) |
| 120 | +if (PHYLOCSFPP_NATIVE_BUILD) |
| 121 | + add_definitions(-DPHYLOCSFPP_NATIVE_BUILD=1) |
| 122 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") |
| 123 | + if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") |
| 124 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHOST -ipo -no-prec-div -fp-model fast=2") |
| 125 | + endif () |
| 126 | +endif () |
| 127 | + |
| 128 | +include_directories(SYSTEM ${CMAKE_BINARY_DIR}/libBigWig) |
| 129 | +link_directories(${CMAKE_BINARY_DIR}/libBigWig) |
| 130 | + |
| 131 | +message(STATUS "The following options are selected for the build:") |
| 132 | +message( " PHYLOCSFPP_NATIVE_BUILD ${PHYLOCSFPP_NATIVE_BUILD}") |
| 133 | +message(STATUS "Run 'cmake -LH' to get a comment on each option.") |
| 134 | +message(STATUS "Remove CMakeCache.txt and re-run cmake with -DOPTIONNAME=ON|OFF to change an option.") |
| 135 | + |
| 136 | +# ---------------------------------------------------------------------------- |
| 137 | +# Build Setup |
| 138 | +# ---------------------------------------------------------------------------- |
| 139 | + |
| 140 | +add_definitions(-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}") |
| 141 | + |
| 142 | +# TODO: -Wconversion |
| 143 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -DNOCURL -std=c++11 -fpermissive -DHAVE_INLINE") |
| 144 | + |
| 145 | +add_executable(phylocsf++ src/phylocsf++.cpp) |
| 146 | +add_dependencies(phylocsf++ libBigWig) |
| 147 | +target_link_libraries(phylocsf++ z) |
| 148 | +target_link_libraries(phylocsf++ gsl) |
| 149 | +target_link_libraries(phylocsf++ gslcblas) |
| 150 | +target_link_libraries(phylocsf++ BigWig) |
| 151 | + |
| 152 | +install(TARGETS phylocsf++ DESTINATION bin) |
| 153 | + |
| 154 | +message("\n${ColourBold}Finishing up${ColourReset}") |
0 commit comments