Something went wrong on our end
-
Martin Beseda authoredMartin Beseda authored
CMakeLists.txt 3.75 KiB
cmake_minimum_required(VERSION 3.0)
project(lib4neuro)
message("Using CMake ${CMAKE_VERSION}")
#TODO request newer version of CMake >=3.12
#TODO rewrite to use add_compile_definitions
if(WIN32)
add_compile_options("-DBOOST_ALL_NO_LIB")
else()
add_compile_options("-DBOOST_TEST_DYN_LINK")
endif()
#------------#
# Build type #
#------------#
# Release / 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)
elseif("CMAKE_BUILD_TYPE" STREQUAL "Debug")
#TODO rewrite to use add_compile_definitions
add_compile_options(-DDEBUG)
endif (NOT CMAKE_BUILD_TYPE)
#------------------------#
# 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)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost" )
elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /bigobj")
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(Boost_DEBUG 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
)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost was NOT found! Specify variables BOOST_INCLUDEDIR and BOOST_LIBRARYDIR!")
endif()
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")
message("lib4neuro LIB DIR: ${LIB4NEURO_DIR}")
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(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)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
#----------------------------------------#
# Dependencies for the lib4neuro library #
#----------------------------------------#
message("Running CMake in: ${SRC_DIR} ${PROJECT_BINARY_DIR}")
add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR})