# ##############################################################################
# Target

add_library(pj_ilbc
  FrameClassify.c
  LPCdecode.c
  LPCencode.c
  StateConstructW.c
  StateSearchW.c
  anaFilter.c
  constants.c
  createCB.c
  doCPLC.c
  enhancer.c
  filter.c
  gainquant.c
  getCBvec.c
  helpfun.c
  hpInput.c
  hpOutput.c
  iCBConstruct.c
  iCBSearch.c
  iLBC_decode.c
  iLBC_encode.c
  lsf.c
  packing.c
  syntFilter.c
)

# headers
target_sources(pj_ilbc
  PUBLIC
    FILE_SET HEADERS
      FILES
        anaFilter.h
        constants.h
        createCB.h
        doCPLC.h
        enhancer.h
        filter.h
        FrameClassify.h
        gainquant.h
        getCBvec.h
        helpfun.h
        hpInput.h
        hpOutput.h
        iCBConstruct.h
        iCBSearch.h
        iLBC_decode.h
        iLBC_define.h
        iLBC_encode.h
        LPCdecode.h
        LPCencode.h
        lsf.h
        packing.h
        StateConstructW.h
        StateSearchW.h
        syntFilter.h
)

# Warnings in the bundled code, which is kept as upstream has it
target_compile_options(pj_ilbc
  PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-shorten-64-to-32>
)

# ##############################################################################
# Dependencies

if (NOT (WIN32 OR CYGWIN OR MINGW))
  # The codec calls libm functions (cos(), sqrt(), ...), a separate library
  # on these systems that the final link needs. Linked by name so that a
  # cross toolchain picks the libm matching its CPU flags; a Generic one
  # resolves -lm through its multilib specs, where find_library() does
  # not look.
  find_library(MATH_LIBRARY m)
  if(MATH_LIBRARY OR CMAKE_SYSTEM_NAME STREQUAL "Generic")
    target_link_libraries(pj_ilbc PRIVATE m)
  endif()
endif()
