set(POST_INSTALL "")
set( ndswrapcxx_srcs 
     bash_pattern.c
     nds_bash_pattern.cc
     nds_buffer.cc
     nds_channel.cc
     nds_connection.cc
     nds_connection_ptype.cc
     nds_db.cc
     nds_db_sqlite3.cc
     nds_helper.cc
     nds_str_helper.cc
     nds_availability.cc
     nds_request_fragment.cc
     nds_composer.cc
     nds_gap_handler.cc
     nds_static_val.cc
     nds_version.cc
     nds_parameter_block.cc
     debug_stream.cc
	 nds_connection_ptype.hh
     nds_channel_internal.hh
     nds_availability_helper.hh
     nds_errno.hh
     nds_foreach.hh
        nds_iterate_handler.hh
     nds_iterate_handlers.hh
     nds_param_str.h
)

# headers that get installed
set( ndswrapcxx_hdrs
     nds.hh 
     nds_buffer.hh 
     nds_channel.hh 
     nds_connection.hh 
     nds_availability.hh 
     nds_epoch.hh
     nds_export.hh
     nds_version.hh 
)
# generated headers that get installed
set( ndswrapcxx_gen_hdrs
     ${CMAKE_CURRENT_BINARY_DIR}/nds_memory.hh
)

find_shared_ptr( )
if( NOT HAVE_SHARED_PTR_IN_STD_NAMESPACE )
  set( HAVE_SHARED_PTR_IN_STD_NAMESPACE 0 )
endif( NOT HAVE_SHARED_PTR_IN_STD_NAMESPACE )
if( NOT HAVE_SHARED_PTR_IN_TR1_NAMESPACE )
  set( HAVE_SHARED_PTR_IN_TR1_NAMESPACE 0 )
endif( NOT HAVE_SHARED_PTR_IN_TR1_NAMESPACE )
if( NOT HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER )
  set( HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER 0 )
endif( NOT HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER )

find_library( sqliteLib sqlite3 )
if ( HAVE_SQLITE3_H )
  set( SQLITE_EXTERNAL "no" CACHE INTERNAL "" FORCE )
else ( HAVE_SQLITE3_H )
  set( ndswrap_srcs ${ndswrap_srcs} sqlite3.c )
  set( ndswrapcxx_srcs ${ndswrapcxx_srcs} sqlite3.c )
  set( SQLITE_EXTERNAL "yes" CACHE INTERNAL "" FORCE )
endif ( HAVE_SQLITE3_H )

include_directories( ${CMAKE_CURRENT_BINARY_DIR}
                     ${CMAKE_CURRENT_SOURCE_DIR}
		     ${PROJECT_BINARY_DIR}/src/client
		     ${PROJECT_SOURCE_DIR}/src/client )
add_definitions( "-DHAVE_CONFIG_H=1" )

#========================================================================
# Setup 
#========================================================================
configure_file(
  ${CMAKE_CURRENT_SOURCE_DIR}/nds_memory.hh.in
  ${CMAKE_CURRENT_BINARY_DIR}/nds_memory.hh
  @ONLY )
#========================================================================
# Build rules
#========================================================================
cmake_policy(PUSH)
cmake_policy(SET CMP0003 NEW)
add_library(
  ndswrapcxx
  SHARED ${ndswrapcxx_srcs} ${ndswrapcxx_hdrs}
)
target_link_libraries( ndswrapcxx ndsclient )
set_target_properties(
  ndswrapcxx
  PROPERTIES
      C_STANDARD 99
      CXX_STANDARD 11
      COMPILE_DEFINITIONS "NDS_EXPORT=1" )
set( install_libs ndswrapcxx )
add_library(
  ndswrapcxxStatic
  STATIC ${ndswrapcxx_srcs} ${ndswrapcxx_hdrs}
)
target_link_libraries( ndswrapcxx ndsclient ${CMAKE_DL_LIBS})
set_target_properties(
  ndswrapcxxStatic
  PROPERTIES
      COMPILE_DEFINITIONS "NDS_EXPORT=1" )
cmake_policy(POP)

set_target_properties(
  ndswrapcxx PROPERTIES
  OUTPUT_NAME ndsxxwrap
)
if( UNIX )
  set_target_properties(
    ndswrapcxxStatic PROPERTIES
    OUTPUT_NAME ndsxxwrap
  )
  set( install_libs ${install_libs} ndswrapcxxStatic )
endif( UNIX )

if ( sqliteLib )
  target_link_libraries(ndswrapcxx ${sqliteLib})
endif ( sqliteLib )

set( NDSWRAPCXX_SOVERSION_CURRENT  1 )
set( NDSWRAPCXX_SOVERSION_REVISION 0 )
set( NDSWRAPCXX_SOVERSION_AGE      0 )

if ( UNIX )
  nds_libtool_version_calculation( NDSWRAPCXX
    ${NDSWRAPCXX_SOVERSION_CURRENT}
    ${NDSWRAPCXX_SOVERSION_REVISION}
    ${NDSWRAPCXX_SOVERSION_AGE} )
  set_target_properties(
    ndswrapcxx PROPERTIES
    VERSION ${NDSWRAPCXX_VERSION}
    SOVERSION ${NDSWRAPCXX_SOVERSION} )
endif ( UNIX )

#========================================================================
# Installation Rules
#========================================================================
install(
  TARGETS ${install_libs}
  RUNTIME
    DESTINATION ${RUNTIME_DESTINATION}
    COMPONENT applications
  LIBRARY
    DESTINATION ${LIBRARY_DESTINATION}
    COMPONENT applications
  ARCHIVE
    DESTINATION ${CMAKE_INSTALL_LIBDIR}
    COMPONENT Development
)
install(
  FILES ${ndswrapcxx_hdrs} ${ndswrapcxx_gen_hdrs}
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
  COMPONENT Development
)
