#############################################################################
#
#  $Id$
#
#  Copyright 2013 Andreas Stewering-Bone
#
#  This file is part of the canrestbus library.
#
#  The canrestbus library is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or (at your
#  option) any later version.
#
#  The canrestbus library is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
#  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
#  License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with the canrestbus library. If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

INCLUDE_DIRECTORIES(
        ${PROJECT_BINARY_DIR}
        ${PROJECT_SOURCE_DIR}
        ${PROJECT_INCLUDE_DIR}
        ${LIBPCRE_INCLUDE_DIRS}
        "${PROJECT_SOURCE_DIR}/src"
        )

if (DEBUG)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -fstack-usage -fstack-check")
else (DEBUG)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
endif (DEBUG)

SET(CMAKE_C_STANDARD 99)

ADD_LIBRARY( ${PROJECT_NAME} SHARED
    cs_signal.c cs_signal_private.h
    cs_message.c cs_message_private.h
    cs_dbc.c cs_dbc_private.h
    cs_schedule.c cs_schedule_private.h
    cs_uds.c cs_uds_private.h
    cs_socketcan.c cs_socketcan_private.h
    cs_isotp.c cs_isotp_private.h
    cs_xcp_can.c
    cs_xcp.c
    cs_calibration_utils.c
    cs_a2l.c
    cs_xcp_a2l.c
    cs_xcp_api.c
    cs_ccp_a2l.c
    cs_ccp.c
    cs_ccp_api.c
    cs_ccp_decoder.c
    cs_trc_parser.c cs_trc_parser.h
    cs_asc_parser.c cs_asc_parser.h
    cs_file_parser.c
    cs_parser.c
    cs_vbf.c
    cs_vbf_crc_ccitt.c
    cs_lists.c
    cs_isotp_decoder.c
    cs_uds_decoder.c
    cs_time.c cs_time.h
    cs_byteorder.c cs_byteorder.h
    cs_lin.c cs_lin_private.h
    cs_lin_bit.c cs_lin_bit_private.h
    cs_lin_ldf.c
    cs_process.c
    cs_debug.c cs_debug_private.h
    cs_version.c
    )

SET_TARGET_PROPERTIES ( ${PROJECT_NAME} PROPERTIES
    VERSION ${VERSION}
    SOVERSION "${SOVERSION}"
    CLEAN_DIRECT_OUTPUT 1)

TARGET_LINK_LIBRARIES (${PROJECT_NAME} ${LIBPCRE_LIBRARIES} -lrt -lm)
INSTALL (TARGETS ${PROJECT_NAME}
    DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY)

# pkgconfig files
CONFIGURE_FILE (
    "${CMAKE_CURRENT_SOURCE_DIR}/libcanrestbus.pc.in"
    "${CMAKE_CURRENT_BINARY_DIR}/libcanrestbus.pc" @ONLY
    )
INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcanrestbus.pc"
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
