CMakeLists.txt 2.87 KB
#
# CMakeLists.txt
#
# Copyright (C) 2015, GreenSocs ltd.
#
# Developed by Frederic Konrad <fred.konrad@greensocs.com>
#              Guillaume Delbergue <guillaume.delbergue@greensocs.com>
#

project(TCPSerial)

#########################
###       CMAKE       ###
#########################

cmake_minimum_required(VERSION 2.6)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

option(USE_BOOST_THREAD "Use Boost.Thread instead of POSIX Threads" OFF)
option(USE_BOOST_ASIO "Use Boost.ASIO instead of UNIX/WIN32 Sockets" OFF)

##########################
### REQUIRED LIBRARIES ###
##########################

find_package(SystemC)
if(SystemC_FOUND)
    include_directories(${SystemC_INCLUDE_DIRS})
else()
    message(FATAL_ERROR "SystemC library not found.")
endif()

find_package(TLM)
if(TLM_FOUND)
    include_directories(${TLM_INCLUDE_DIRS})
else()
    message(FATAL_ERROR "TLM library not found.")
endif()

find_package(GREENLIB)
if(GREENLIB_FOUND)
    include_directories(${GREENLIB_INCLUDE_DIRS})
    link_directories(${GREENLIB_LIBRARY_DIRS})
else()
    message(FATAL_ERROR "GreenLib not found.")
endif()

if(USE_BOOST_THREAD OR USE_BOOST_ASIO)
    set(BOOST_COMPONENTS system)
    if(USE_BOOST_THREAD)
        list(APPEND BOOST_COMPONENTS thread)
        add_definitions(-DUSE_BOOST_THREAD)
    endif()
    if(USE_BOOST_ASIO)
        add_definitions(-DUSE_BOOST_ASIO)
    endif()

    find_package(Boost 1.40 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
    if(Boost_FOUND)
        include_directories(${Boost_INCLUDE_DIRS})
    endif()
endif()

##########################
###       FLAGS        ###
##########################

set(CMAKE_CXX_FLAGS "-Wall -Werror -DSC_INCLUDE_DYNAMIC_PROCESSES")

if (WIN32 AND CMAKE_SYSTEM_VERSION)
    set(ver ${CMAKE_SYSTEM_VERSION})
    string(REPLACE "." "" ver ${ver})
    string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
    set(version "0x${ver}")

    # https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
    add_definitions(-D_WIN32_WINNT=${version})
endif()

##########################
###     TCP Serial     ###
##########################

include_directories(include)

if(MINGW)
    add_library(tcpserial STATIC src/TCPSerial.cpp)
else()
    add_library(tcpserial SHARED src/TCPSerial.cpp)
endif()

if(USE_BOOST_THREAD OR USE_BOOST_ASIO)
    set(TCPSERIAL_LINK_LIBRARIES ${Boost_LIBRARIES})
endif()

if(NOT USE_BOOST_THREAD)
    list(APPEND TCPSERIAL_LINK_LIBRARIES pthread)
endif()

if(WIN32)
    list(APPEND TCPSERIAL_LINK_LIBRARIES ws2_32)
endif()

target_link_libraries(tcpserial ${TCPSERIAL_LINK_LIBRARIES})

# Installation paths
install(DIRECTORY include/TCPSerial
        DESTINATION include
)

# Not sure it's the right destination? Maybe we want lib64 in case of 64bits?
install(TARGETS tcpserial DESTINATION lib)

##########################
###        Tests       ###
##########################

enable_testing()
add_subdirectory(test)