project(testproviderprovider C)
cmake_minimum_required(VERSION 2.6)

include(MessageUtils)
include(FindUaOpenSSL)
include(InstallIfNewer)
include(InstallPDBFiles)
include(ConfigureCompiler)
include(ConfigureUaStack)
include(ConfigureAnsiCSdk)

display_project_header()

####################################### Different Configurations ########################################

string(REPLACE "-Waggregate-return" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-Wcast-align" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})

# Build with shared stack
if (BUILD_SHARED_STACK OR BUILD_SHARED_LIBS)
    add_definitions(-D_UA_STACK_USE_DLL)
endif ()

# configure Dll/Lib
if (BUILD_SHARED_LIBS)
    add_definitions(-DBUILD_SHARED_LIBS)
    add_definitions(-D_UA_BASE_USE_DLL)
    add_definitions(-D_UA_SERVER_USE_DLL)
    add_definitions(-D_UA_TESTPROVIDERPROVIDER_BUILD_DLL)
endif ()

################################################ Encodings #################################################

add_definitions(-DHAVE_ENCODING_BINARY=1)
add_definitions(-DHAVE_ENCODING_XML=0)

####################################### Get all needed Source Files ########################################

if (UASERVER_HISTORYREAD)
    set(SRC_HISTORY_TESTPROVIDER ${SRC_HISTORY_TESTPROVIDER} uaprovider_testprovider_historyread.c)
endif ()

if (UASERVER_HISTORYUPDATE)
    set(SRC_HISTORYUPDATE_TESTPROVIDER ${SRC_HISTORYUPDATE_TESTPROVIDER})
endif ()

if (UASERVER_CALL)
    set(SRC_CALL_TESTPROVIDER ${SRC_CALL_TESTPROVIDER}
        uaprovider_testprovider_call.c
    )
    set(testprovider_INSTALL_HEADERS ${testprovider_INSTALL_HEADERS}
    )
endif ()


# add sources
set(testproviderProvider_SRCS ${SRC_HISTORY_TESTPROVIDER} ${SRC_HISTORYUPDATE_TESTPROVIDER} ${SRC_CALL_TESTPROVIDER} ${SRC_EVENTS_TESTPROVIDER}
    uaprovider_testprovider_nodes_1.c
    uaprovider_testprovider_read.c
    uaprovider_testprovider_subscription.c
    uaprovider_testprovider_write.c
    uaprovider_testprovider_browse.c
    uaprovider_testprovider_strings_1.c
    uaprovider_testprovider_hooks.c
    uaprovider_testprovider_utils.c
    uaprovider_testprovider.c
)

# define headers to be installed
set(testprovider_INSTALL_HEADERS ${testprovider_INSTALL_HEADERS}
    uaprovider_testprovider.h
    uaprovider_testprovider_helper.h
    uaprovider_testprovider_strings_1.h
    uaprovider_testprovider_nodes_1.h
    uaprovider_testprovider_utils.h
    uaprovider_testprovider_identifiers_1.h
    uaprovider_testprovider_browsenames_1.h
)

####################################### Include Paths ########################################

include_directories(${UASTACK_INCLUDE})
include_directories(${UABASEC_INCLUDE})
include_directories(${UASERVERC_INCLUDE})
include_directories(${DATALOGGER_INCLUDE})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if (NOT TARGET uastack)
    link_directories(${UA_LIB_DIR})
endif ()

####################################### Create Library ########################################

add_library(${PROJECT_NAME} ${testproviderProvider_SRCS} ${testprovider_INSTALL_HEADERS})

# link dependencies
target_link_libraries(${PROJECT_NAME} ${UASERVERC_LIBRARY} ${UABASEC_LIBRARY} ${UASTACK_LIBRARY})

# INSTALL target
install(FILES ${testprovider_INSTALL_HEADERS} DESTINATION include/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
)

install_pdb_files()
