# A place for common parts of SEMS sbc call_controle rules

include(${CMAKE_SOURCE_DIR}/cmake/config.rules.txt)

# We must add base apps/sbc directory as INCLUDEDIR
include_directories(../..)

# We adding sems_sbc_ prefix to the internal name of the library to avoid nasty
# issue then this name is equals to external library, our module links to. E.g.
# the issue, then speex module should be linked to -lspeex

add_library(sems_sbc_${sems_sbc_call_control_name} MODULE
            ${${sems_sbc_call_control_name}_SRCS})

if(APPLE)
  set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS
      "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} -flat_namespace -undefined suppress"
  )
  set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
      "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined suppress"
  )
endif(APPLE)

# all modules should be linked against ${CMAKE_DL_LIBS} at least and with
# additional ${sems_sbc_module_libs} if they exists
target_link_libraries(sems_sbc_${sems_sbc_call_control_name} ${CMAKE_DL_LIBS}
                      ${sems_sbc_module_libs})

set_target_properties(sems_sbc_${sems_sbc_call_control_name}
                      PROPERTIES OUTPUT_NAME ${sems_sbc_call_control_name})
set_target_properties(sems_sbc_${sems_sbc_call_control_name} PROPERTIES PREFIX
                                                                        "")

add_definitions(-DMOD_NAME="${sems_sbc_call_control_name}")

install(TARGETS sems_sbc_${sems_sbc_call_control_name}
        LIBRARY DESTINATION ${SEMS_EXEC_PREFIX}/${SEMS_LIBDIR}/sems/plug-in/)

if(NOT DEFINED ${sems_sbc_call_control_name}_config_files)
  sems_install_configs("${sems_sbc_call_control_name}")
else(NOT DEFINED ${sems_sbc_call_control_name}_config_files)
  sems_install_configs("${${sems_sbc_call_control_name}_config_files}")
endif(NOT DEFINED ${sems_sbc_call_control_name}_config_files)
