# Copyright © 2016 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Authored by: Gary Wang <gary.wang@canonical.com>
include(assets)

message("MCLOUD_CLIENT_ID " ${MCLOUD_CLIENT_ID})
message("MCLOUD_CLIENT_PASS " ${MCLOUD_CLIENT_PASS})

add_definitions(-DCLIENT_ID="${MCLOUD_CLIENT_ID}")
add_definitions(-DCLIENT_PASS="${MCLOUD_CLIENT_PASS}")

find_package(Boost COMPONENTS regex filesystem system REQUIRED)
find_package(PkgConfig REQUIRED)

include_directories(${Boost_INCLUDE_DIRS} ${NET_CPP_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS})

pkg_check_modules(tinyxml2 tinyxml2 REQUIRED)
pkg_check_modules(NET_CPP net-cpp>=1.3.0 REQUIRED)
pkg_check_modules(PROCESS_CPP process-cpp REQUIRED)
pkg_check_modules(LIBSSL libssl REQUIRED)
pkg_check_modules(OPENSSL openssl REQUIRED)

add_library(
  mcloud SHARED

  ${MCLOUD_LIB_INTERFACE_HEADERS}

  mcloud/api/client.cpp
  mcloud/api/client_priv.cpp
  mcloud/api/cloudfolder.cpp
  mcloud/api/cloudcontent.cpp
  mcloud/api/downloadtask.cpp
  mcloud/api/downloadtask_priv.cpp
  mcloud/api/uploadtask.cpp
  mcloud/api/uploadtask_priv.cpp
  mcloud/api/syncmanager.cpp
  mcloud/api/syncmanager_priv.cpp
  mcloud/api/syncthread.cpp
  mcloud/api/diskinfo.cpp
  mcloud/api/outlink.cpp    
  mcloud/api/client.cpp
)

target_link_libraries(
  mcloud

  ${CMAKE_THREAD_LIBS_INIT}

  ${Boost_LIBRARIES}
  ${tinyxml2_LIBRARIES}
  ${PROCESS_CPP_LDFALGS}
  ${NET_CPP_LDFLAGS}
  ${LIBSSL_LDFLAGS}
  ${OPENSSL_LIBRARIES}
)

set(symbol_map "${CMAKE_SOURCE_DIR}/symbols.map")
set_target_properties(
  mcloud

  PROPERTIES
  LINK_FLAGS "${ldflags} -Wl,--version-script,${symbol_map}"
  LINK_DEPENDS ${symbol_map}
  VERSION ${MCLOUD_LIB_VERSION_MAJOR}.${MCLOUD_LIB_VERSION_MINOR}.${MCLOUD_LIB_VERSION_PATCH}
  SOVERSION ${MCLOUD_SOVERSION}
)

install(
  TARGETS mcloud
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
