cmake_minimum_required(VERSION 3.0)
project(Acontis)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

set (Acontis_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDK/INC ${CMAKE_CURRENT_SOURCE_DIR}/SDK/INC/Linux)
set (Acontis_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDK/LIB/Linux/x64)
set (Acontis_LIBRARIES  EcMasterRasServer EcMaster)
set (Acontis_EXTRA_LIBRARIES pthread dl rt)

# Setting up Acontis version, not sure if this is the correct version number or not (shrug)
set(Acontis_VERSION_MAJOR "3")
set(Acontis_VERSION_MINOR "0")
set(Acontis_VERSION_SERVICEPACK "3")
set(Acontis_VERSION_BUILD "100")
set(Acontis_VERSION "${Acontis_VERSION_MAJOR}.${Acontis_VERSION_MINOR}.${Acontis_VERSION_SERVICEPACK}.${Acontis_VERSION_BUILD}")


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Examples/EcMasterDemo
  ${CMAKE_CURRENT_SOURCE_DIR}/Examples/PMC_Acontis
  ${CMAKE_CURRENT_SOURCE_DIR}/SDK/INC/Linux
  ${CMAKE_CURRENT_SOURCE_DIR}/SDK/INC
  ${CMAKE_CURRENT_SOURCE_DIR}/Sources/Common)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/SDK/LIB/Linux/x64)

add_subdirectory(Examples/Common)

add_executable(EcMasterDemo
  ${CMAKE_CURRENT_SOURCE_DIR}/Examples/EcMasterDemo/EcDemoApp.cpp
)

add_custom_command(TARGET EcMasterDemo
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/Bin/Linux/x64/*.so
${CMAKE_CURRENT_BINARY_DIR}/)

add_custom_command(TARGET EcMasterDemo
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/*.xml
${CMAKE_CURRENT_BINARY_DIR}/)

target_link_libraries(EcMasterDemo ${Acontis_LIBRARIES} ${Acontis_EXTRA_LIBRARIES})
target_link_libraries(EcMasterDemo libEcDemoLib)
target_link_libraries(EcMasterDemo PMC_Cpp_API)
target_link_libraries(EcMasterDemo PMC_Acontis_Cpp_API)

# Generate AcontisConfig.cmake
set (CONF_INCLUDE_DIR ${Acontis_INCLUDE_DIR})
set (CONF_LIBRARY_DIR ${Acontis_LIBRARY_DIR})
set (CONF_LIBRARIES   ${Acontis_LIBRARIES} ${Acontis_EXTRA_LIBRARIES})
configure_file (cmake/AcontisConfig.cmake.in
  "${Acontis_BINARY_DIR}/AcontisConfig.cmake" @ONLY)