cmake_minimum_required(VERSION 2.6...3.29)
project(libmpg123)

set(LIBMPG123_SOURCES
    compat.c
    dct64.c
    equalizer.c
    format.c
    frame.c
    id3.c
    layer3.c
    libmpg123.c
    optimize.c
    parse.c
    readers.c
    synth.c
    tabinit.c
)

file(GLOB_RECURSE LIBMPG123_HEADERS *.h)

if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64 bits
    message("libmpg123 building for 64 bit.")

    set(LIBMPG123_SOURCES
        ${LIBMPG123_SOURCES}
        dct64_x86_64.S
        synth_stereo_x86_64.S
        synth_x86_64.S
    )
    add_definitions(-DWIN64 -DOPT_X86_64 -DREAL_IS_FLOAT)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32 bits
    message("libmpg123 building for 32 bit.")

    set(LIBMPG123_SOURCES
        ${LIBMPG123_SOURCES}
        dct64_i386.c
        dct64_sse.S
        synth_sse.S
        tabinit_mmx.S
    )
    add_definitions(-DWIN32 -DOPT_SSE -DREAL_IS_FLOAT)
endif()

include_directories(${zlib_SOURCE_DIR})
add_library(libmpg123 STATIC ${LIBMPG123_SOURCES} ${LIBMPG123_HEADERS}) # remove static, cmake should take care of that
target_include_directories(libmpg123 PUBLIC ${LIBMPG123_HEADERS})

set_target_properties(libmpg123 PROPERTIES FOLDER deps)
