option(STATIC_ALL "Use static libraries" ON)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    set(GCC_LIKE_COMPILER ON)
endif()

if(NOT MSVC AND NOT GCC_LIKE_COMPILER)
    message(FATAL_ERROR "Supports only gcc, clang or msvc compilers")
endif()

if(STATIC_ALL)
    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_STATIC_RUNTIME ON)
    if(MSVC)
        set(MSVC_RUNTIME static)
    endif()
    if(GCC_LIKE_COMPILER)
        set(CMAKE_EXE_LINKER_FLAGS "-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
    endif()
else()
    set(Boost_USE_STATIC_LIBS OFF)
    set(Boost_USE_STATIC_RUNTIME OFF)
    if(MSVC)
        set(MSVC_RUNTIME dynamic)
    endif()
    if(GCC_LIKE_COMPILER)
        set(CMAKE_EXE_LINKER_FLAGS)
    endif()
endif()

if(MSVC)
    include(../cmake/MSVCRuntime.cmake)
    configure_msvc_runtime()
endif()

if(GCC_LIKE_COMPILER)
    add_definitions(-std=c++14 -pthread)
endif()

include(CMakeParseArguments)

function(use_boost_libraries USE_BOOST_TARGET)
    cmake_parse_arguments(USE_BOOST "" "" LIBS ${ARGN})

    set(Boost_USE_MULTITHREADED ON)
    find_package(Boost 1.56 REQUIRED COMPONENTS ${USE_BOOST_LIBS})
    target_include_directories(${USE_BOOST_TARGET} PRIVATE ${Boost_INCLUDE_DIR})
    target_link_libraries(${USE_BOOST_TARGET} ${Boost_LIBRARIES})
endfunction()
