cmake_minimum_required(VERSION 2.6)

project (humidityserver CXX)

set(HUMIDITYSERVER_HEADERS humidityserver.h)

set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(HUMIDITYSERVER_CODEGEN_DIR "${PROJECT_BINARY_DIR}/codegen")

PREPEND(HUMIDITYSERVER_HEADERS_PATHS ${PROJECT_SOURCE_DIR} ${HUMIDITYSERVER_HEADERS})

CODEGEN_FILES(HUMIDITYSERVER_CODEGEN_SOURCES ${HUMIDITYSERVER_CODEGEN_DIR} ${HUMIDITYSERVER_HEADERS})

add_custom_command(OUTPUT ${HUMIDITYSERVER_CODEGEN_SOURCES}
    COMMAND ${NGREST_BIN_PATH}ngrestcg -i "${PROJECT_SOURCE_DIR}" -o ${HUMIDITYSERVER_CODEGEN_DIR} -t service ${HUMIDITYSERVER_HEADERS}
    DEPENDS ${HUMIDITYSERVER_HEADERS_PATHS}
)

file(GLOB HUMIDITYSERVER_SOURCES ${PROJECT_SOURCE_DIR}/*.c*)

list(APPEND HUMIDITYSERVER_SOURCES ${HUMIDITYSERVER_CODEGEN_SOURCES})

include_directories(${PROJECT_SOURCE_DIR} $ENV{NGREST_EXT_INCLUDES})

add_library(humidityserver MODULE ${HUMIDITYSERVER_SOURCES})

set_target_properties(humidityserver PROPERTIES PREFIX "")
set_target_properties(humidityserver PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SERVICES_DIR}"
)

target_link_libraries(humidityserver ngrestutils ngrestcommon ngrestjson ngrestengine $ENV{NGREST_EXT_LIBS})
