Newer
Older
cmake_minimum_required(VERSION 3.0)
project(lib4neuro)
kra568
committed
Martin Beseda
committed
#TODO request newer version of CMake >=3.12
#TODO rewrite to use add_compile_definitions
add_compile_options("/D BOOST_ALL_NO_LIB")
add_compile_options("/D NOMINMAX")
Martin Beseda
committed
add_compile_options("-DBOOST_TEST_DYN_LINK")
kra568
committed
#------------#
# Build type #
#------------#
# Release / None / Debug
Martin Beseda
committed
set (CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are: None Debug Release."
FORCE)
elseif("CMAKE_BUILD_TYPE" STREQUAL "Debug")
#TODO rewrite to use add_compile_definitions
add_compile_options(-DDEBUG)
#------------------------#
# Dependencies link type #
#------------------------#
if(NOT DEPENDENCIES_LINK_TYPE AND NOT ENV{DEPENDENCIES_LINK_TYPE})
message(FATAL_ERROR "Please, set the variable DEPENDENCIES_LINK_TYPE to either 'static' or 'shared'!")
endif()
#--------------------------------#
# Setting C++ compiler flags #
#--------------------------------#
set(CMAKE_CXX_STANDARD 17)
kra568
committed
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost" )
add_compile_options("/D _SCL_SECURE_NO_WARNINGS")
add_compile_options("/D_CRT_SECURE_NO_WARNINGS")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
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)
#set(CMAKE_INCLUDE_PATH ${BOOST_INCLUDEDIR} "${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost" ${CMAKE_INCLUDE_PATH})
#set(CMAKE_LIBRARY_PATH ${BOOST_LIBRARYDIR} "${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost/stage/lib" ${CMAKE_LIBRARY_PATH})
message("CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}")
message("CMAKE_LIBRARY_PATH: ${CMAKE_LIBRARY_PATH}")
find_package(
Boost
COMPONENTS
system
serialization
random
kra568
committed
message(FATAL_ERROR "Boost was NOT found! Specify variables BOOST_INCLUDEDIR and BOOST_LIBRARYDIR!")
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
#------------------------------------------#
# 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(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib)
Martin Beseda
committed
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
#----------------------------------------#
# Dependencies for the lib4neuro library #
#----------------------------------------#
message("Running CMake in: ${SRC_DIR} ${PROJECT_BINARY_DIR}")
kra568
committed
add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR})