# Copyright (C) 2007  University of Rostock
#
# This program 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 2 of the
# License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.

################################################################################
# Common for all ws4d-gsoap projects, don't change this !
################################################################################

# directory to put all generated files in
SET(gen_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen)

# If the directory for the generated sources does not
# already exists, create it.
IF(NOT EXISTS ${gen_DIR})
	FILE(MAKE_DIRECTORY ${gen_DIR})
ENDIF(NOT EXISTS ${gen_DIR})

# set include paths
INCLUDE_DIRECTORIES(${GSOAP_INCLUDE_DIR} ${GSOAP_INCLUDE_DIR}/plugin ${DPWS_INCLUDES} ${OPENSSL_INCLUDE_DIR} ${gen_DIR})

# set options for gSOAP runtime
GSOAP_SET_RUNTIME_FLAGS("-DWITH_NONAMESPACES -DWITH_UDP -DWITH_OPENSSL -DWITH_DOM")

# Copy certificates
ADD_CUSTOM_TARGET(install_certs ALL
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/device.pem ${EXECUTABLE_OUTPUT_PATH}/
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/client.pem ${EXECUTABLE_OUTPUT_PATH}/
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cacert.pem ${EXECUTABLE_OUTPUT_PATH}/)

###############################################################################
###############################################################################
##                                                                           ##
## Simple airconditioner device                                              ##
##                                                                           ##
###############################################################################
###############################################################################

###############################################################################
# Code generation - for custom projects this must be modified
###############################################################################

# generate code and C data binding operations of service
GSOAP_GENERATE(acs.gsoap acs1 ${gen_DIR})   # normal service

# generate device description and setup code
DPWS_METADATA_GENERATE(metadata.xml acs ${gen_DIR})

# embed wsdl files into c code
SET(AIRCONDITIONER_WSDL ${CMAKE_CURRENT_SOURCE_DIR}/AirConditioner.wsdl)
DPWS_EMBEDD_WSDL(${gen_DIR} acs ${AIRCONDITIONER_WSDL})

################################################################################
# create config.h
################################################################################

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
               ${gen_DIR}/config.h
               @ONLY)

################################################################################
# build simple air conditioner - for custom projects this must be modified
################################################################################

# create airconditioner executable und define dependencies
# the device includes the airconditioner.c and event_worker.c, the
# gsoap runtime (${GSOAP_STDSOAP2_SOURCE}), the server lib by gsoap
# (${gen_DIR}/acs1ServerLib.c), the client lib of the inverted service
# by gsoap for eventing (${gen_DIR}/acs_inv1ClientLib.c), the device
# description and setup code (${gen_DIR}/acs_metadata.c) and the embedded
# wsdl files (${gen_DIR}/acs_wsdl.c)

SET(simple_arcondtitioner_SRCS
	simple_airconditioner.c
	${GSOAP_STDSOAP2_SOURCE}
	${gen_DIR}/acs1ServerLib.c
	${gen_DIR}/acs_metadata.c
	${gen_DIR}/acs_wsdl.c
	${GSOAP_INCLUDE_DIR}/plugin/wsseapi.c
	${GSOAP_INCLUDE_DIR}/plugin/smdevp.c
	${GSOAP_INCLUDE_DIR}/dom.c)


# compile all files in simple_arcondtitioner_SRCS and link them into
# the acs_simple_device executable
ADD_EXECUTABLE(acs_simple_device ${simple_arcondtitioner_SRCS})

EXTEND_TGT_COMPILE_FLAGS(acs_simple_device FLAGS "-DDPWS_DEVICE -DWITH_OPENSSL")

# link the device specific dpws libraries into the airconditioner executable
TARGET_LINK_LIBRARIES(acs_simple_device
    ${DPWS_LIBRARIES}
    ${DPWS-D_LIBRARIES}
    ${OPENSSL_LIBRARIES})

###############################################################################
###############################################################################
##                                                                           ##
## GetStatus client                                                          ##
##                                                                           ##
###############################################################################
###############################################################################

################################################################################
# build advanced client - for custom projects this must be modified
################################################################################

SET(GetStatus_client_SRCS
    GetStatus_client.c
    ${GSOAP_STDSOAP2_SOURCE}
    ${gen_DIR}/acs1ClientLib.c
    ${GSOAP_INCLUDE_DIR}/plugin/wsseapi.c
    ${GSOAP_INCLUDE_DIR}/plugin/smdevp.c
    ${GSOAP_INCLUDE_DIR}/dom.c)

ADD_EXECUTABLE(acs_GetStatus_client ${GetStatus_client_SRCS})

EXTEND_TGT_COMPILE_FLAGS(acs_GetStatus_client FLAGS "-DDPWS_CLIENT -DWITH_OPENSSL")

TARGET_LINK_LIBRARIES(acs_GetStatus_client
    ${DPWS_LIBRARIES}
    ${DPWS-C_LIBRARIES}
    ${OPENSSL_LIBRARIES})

###############################################################################
###############################################################################
##                                                                           ##
## SetTargetTemperature client                                               ##
##                                                                           ##
###############################################################################
###############################################################################

################################################################################
# build simple client - for custom projects this must be modified
################################################################################

SET(SetTargetTemperature_client_SRCS
    SetTargetTemperature_client.c
    ${GSOAP_STDSOAP2_SOURCE}
    ${gen_DIR}/acs1ClientLib.c
    ${GSOAP_INCLUDE_DIR}/plugin/wsseapi.c
    ${GSOAP_INCLUDE_DIR}/plugin/smdevp.c
    ${GSOAP_INCLUDE_DIR}/dom.c
    )

ADD_EXECUTABLE(acs_SetTargetTemperature_client
    ${SetTargetTemperature_client_SRCS})

EXTEND_TGT_COMPILE_FLAGS(acs_SetTargetTemperature_client
    FLAGS "-DDPWS_CLIENT -DWITH_OPENSSL")

TARGET_LINK_LIBRARIES(acs_SetTargetTemperature_client
    ${DPWS_LIBRARIES}
    ${DPWS-C_LIBRARIES}
    ${OPENSSL_LIBRARIES})