#############################################################################
#
#  $Id$
#
#  Copyright 2020 Andreas Stewering-Bone
#
#  This is the main cmake file for the snap7 package
#
#  The following options can be specified on the command line of cmake to
#  change the installation paths (Defaults are in <>)
#       -DCMAKE_INSTALL_PREFIX=</usr/local>
#       -DCMAKE_INSTALL_INCLUDEDIR=<${CMAKE_INSTALL_PREFIX}/include>
#       -DCMAKE_INSTALL_LIBDIR=<${CMAKE_INSTALL_PREFIX}/lib(64)>
#       -DCMAKE_INSTALL_LOCALSTATEDIR=<${CMAKE_INSTALL_PREFIX}/var>
#
#  For debugging, use the
#       -DCMAKE_BUILD_TYPE=Debug|Release|RelWithDebInfo|MinSizeRel
#  option
#
#
#  This file is part of the snap7 package.
#
#  snap7 is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  snap7 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 General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with canrestbus. See COPYING. If not, see
#  <http://www.gnu.org/licenses/>.
#
#############################################################################


CMAKE_MINIMUM_REQUIRED (VERSION 2.8.5)
PROJECT (snap7)
SET (CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)

#
# Release Instructions
#
# - Update version numbers below
# - Update SOVERSION below
# - Update ChangeLog (hg log --branch <branch> --style=changelog > ChangeLog)
# - Update NEWS file
# - make dist
#
SET (MAJOR_VERSION 1)
SET (MINOR_VERSION 4)
SET (PATCH_LEVEL 2)
SET (VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_LEVEL})

# library version
SET (SOVERSION ${MAJOR_VERSION}.${MINOR_VERSION})

IF (DEFINED PREFIX)
    MESSAGE (WARNING "Using PREFIX is deprecated. Use CMAKE_INSTALL_PREFIX")
    SET (CMAKE_INSTALL_PREFIX ${PREFIX})
ENDIF ()

# GNU Paths:
#       CMAKE_INSTALL_*
INCLUDE (GNUInstallDirs)


INCLUDE (InstallRequiredSystemLibraries)

INSTALL (FILES
  release/Wrappers/c-cpp/snap7.h
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  )

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

SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall -g -O3 -pedantic")

SET(CMAKE_C_STANDARD 99)
SET (CMAKE_CXX_STANDARD 11)

ADD_LIBRARY( ${PROJECT_NAME} SHARED
  src/sys/snap_msgsock.cpp src/sys/snap_msgsock.h
  src/sys/snap_sysutils.cpp src/sys/snap_sysutils.h
  src/sys/snap_tcpsrvr.cpp src/sys/snap_tcpsrvr.h
  src/sys/snap_threads.cpp src/sys/snap_threads.h
  src/core/s7_client.cpp src/core/s7_client.h
  src/core/s7_isotcp.cpp src/core/s7_isotcp.h
  src/core/s7_partner.cpp src/core/s7_partner.h
  src/core/s7_peer.cpp src/core/s7_peer.h
  src/core/s7_server.cpp src/core/s7_server.h
  src/core/s7_text.cpp src/core/s7_text.h
  src/core/s7_micro_client.cpp src/core/s7_micro_client.h
  src/lib/snap7_libmain.cpp src/lib/snap7_libmain.h
  )

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

TARGET_LINK_LIBRARIES (${PROJECT_NAME} -lpthread)
INSTALL (TARGETS ${PROJECT_NAME}
  DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY)
