CMakeLists.txt 2.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
cmake_minimum_required(VERSION 3.0)
project(lib4neuro)
#cmake_policy(SET CMP0074 NEW)
#cmake_policy(SET CMP0060 NEW)

#if(WIN32)
#	message("Setting no library prefixes...")
#  set(CMAKE_STATIC_LIBRARY_PREFIX "")
#	set(CMAKE_SHARED_LIBRARY_PREFIX "")  
#	set(CMAKE_SHARED_MODULE_PREFIX "")
#	set(CMAKE_IMPORT_LIBRARY_PREFIX "") 
#	set(PREFIX "")
#	set(IMPORT_PREFIX "")
#endif()

#-------------------------------#
# Default installation location #
#-------------------------------#
# Linux: /usr/local
# Windows: c:/Program Files

#------------#
# Build type #
#------------#
# Default: Release
# Others: None, Debug
if (NOT CMAKE_BUILD_TYPE)
  set (CMAKE_BUILD_TYPE RELEASE CACHE STRING
      "Choose the type of build, options are: None Debug Release."
      FORCE)
endif (NOT CMAKE_BUILD_TYPE)

#--------------------------------#
# Setting C++ compiler flags #
#--------------------------------#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -mtune=native" )

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost" )
endif()

#--------------------#
# Automatic settings #
#--------------------#
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
  set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

#-------------------------#
# Find external libraries #
#-------------------------#
message("Looking for external libraries...")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS serialization random)
if(Boost_FOUND)
    message("Boost INCLUDE DIR: ${Boost_INCLUDEDIR}")
    message("Boost LIB DIR: ${Boost_LIBRARY_DIRS}")
    include_directories(${Boost_INCLUDE_DIR} ${Boost_INCLUDEDIR} ${Boost_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARY_DIRS})
endif()

find_package(exprtk)

#------------------------------------------#
# Detect maximum available number of cores #
# and set corresponding build options      #
#------------------------------------------#
message("Detecting available cores count...")
include(ProcessorCount)
ProcessorCount(n_cores)
if(n_cores GREATER 1)
    math(EXPR n_cores "${n_cores}-1")
    message("Build will be performed on ${n_cores} cores.")
    set(CTEST_BUILD_FLAGS -j${N})
    set(ENV{N_CORES} ${N})
    set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
endif()

#---------------#
# Set variables #
#---------------#
set(SRC_DIR src)
set(PROJECT_BINARY_DIR build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib)

include_directories(include ${SRC_DIR})

add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR})