add_library(brender STATIC)

option(BRENDER_FIX_BUGS "Fix BRender bugs" ON)

target_include_directories(brender 
    PRIVATE 
        .
        include
    PUBLIC
        include
)

target_link_libraries(brender PRIVATE harness compile_with_werror)

if(NOT MSVC)
    target_compile_options(brender PRIVATE
        -Wall
    )
    add_compile_flags_if_supported(brender
        -Wno-return-type
        -Wno-unused-variable
        -Wno-unused-parameter
        -Wno-sign-compare
        -Wno-int-conversion  #todo!
        -Wno-strict-aliasing
        -Wstrict-prototypes
    )
    
    target_link_libraries(brender PUBLIC m)
else()
    target_compile_definitions(brender PRIVATE -D_CRT_SECURE_NO_WARNINGS)
    target_compile_options(brender PRIVATE
        /wd4101
        /wd4996
    )
endif()
if(BRENDER_FIX_BUGS)
    target_compile_definitions(brender PRIVATE BRENDER_FIX_BUGS)
endif()

if(IS_BIGENDIAN)
    target_compile_definitions(brender PRIVATE BR_ENDIAN_BIG=1)
else()
    target_compile_definitions(brender PRIVATE BR_ENDIAN_LITTLE=1)
endif()

target_sources(brender PRIVATE
    include/brender/brender.h
    include/brender/br_types.h
    include/brender/br_defs.h
    include/brender/br_inline_funcs.h
    CORE/DOSIO/dosio.c
    CORE/DOSIO/dosio.h
    CORE/DOSIO/eventq.c
    CORE/DOSIO/eventq.h
    CORE/DOSIO/readmse.c
    CORE/DOSIO/readmse.h
    CORE/FW/assocarr.c
    CORE/FW/assocarr.h
    CORE/FW/brbegin.c
    CORE/FW/brbegin.h
    CORE/FW/brbhook.c
    CORE/FW/brbhook.h
    CORE/FW/brlists.c
    CORE/FW/brlists.h
    CORE/FW/brprintf.c
    CORE/FW/brprintf.h
    CORE/FW/brqsort.c
    CORE/FW/brqsort.h
    CORE/FW/bswap.c
    CORE/FW/bswap.h
    CORE/FW/datafile.c
    CORE/FW/datafile.h
    CORE/FW/devlist.c
    CORE/FW/devlist.h
    CORE/FW/devsetup.c
    CORE/FW/devsetup.h
    CORE/FW/diag.c
    CORE/FW/diag.h
    CORE/FW/error.c
    CORE/FW/error.h
    CORE/FW/file.c
    CORE/FW/file.h
    CORE/FW/fwsetup.c
    CORE/FW/fwsetup.h
    CORE/FW/genfile.c
    CORE/FW/genfile.h
    CORE/FW/image.c
    CORE/FW/image.h
    CORE/FW/lexer.c
    CORE/FW/lexer.h
    CORE/FW/loader.c
    CORE/FW/loader.h
    CORE/FW/mem.c
    CORE/FW/mem.h
    CORE/FW/object.c
    CORE/FW/object.h
    CORE/FW/objectc.c
    CORE/FW/objectc.h
    CORE/FW/pattern.c
    CORE/FW/pattern.h
    CORE/FW/register.c
    CORE/FW/register.h
    CORE/FW/resource.c
    CORE/FW/resource.h
    CORE/FW/resreg.c
    CORE/FW/resreg.h
    CORE/FW/scratch.c
    CORE/FW/scratch.h
    CORE/FW/sys_conf.c
    CORE/FW/sys_conf.h
    CORE/FW/token.c
    CORE/FW/token.h
    CORE/FW/tokenval.c
    CORE/FW/tokenval.h
    CORE/HOST/himage.c
    CORE/HOST/himage.h
    CORE/HOST/hook.c
    CORE/HOST/hook.h
    CORE/HOST/hostcfg.c
    CORE/HOST/hostcfg.h
    CORE/HOST/hstsetup.c
    CORE/HOST/hstsetup.h
    CORE/HOST/memmgmt.c
    CORE/HOST/memmgmt.h
    CORE/MATH/angles.c
    CORE/MATH/angles.h
    CORE/MATH/fixed.c
    CORE/MATH/fixed.h
    CORE/MATH/matrix23.c
    CORE/MATH/matrix23.h
    CORE/MATH/matrix34.c
    CORE/MATH/matrix34.h
    CORE/MATH/matrix4.c
    CORE/MATH/matrix4.h
    CORE/MATH/plane.c
    CORE/MATH/plane.h
    CORE/MATH/quat.c
    CORE/MATH/quat.h
    CORE/MATH/transfrm.c
    CORE/MATH/transfrm.h
    CORE/MATH/vector.c
    CORE/MATH/vector.h
    CORE/PIXELMAP/fontptrs.c
    CORE/PIXELMAP/fontptrs.h
    CORE/PIXELMAP/genclip.c
    CORE/PIXELMAP/genclip.h
    CORE/PIXELMAP/gencopy.c
    CORE/PIXELMAP/gencopy.h
    CORE/PIXELMAP/pixelmap.c
    CORE/PIXELMAP/pixelmap.h
    CORE/PIXELMAP/pmmemops.c
    CORE/PIXELMAP/pmmemops.h
    CORE/PIXELMAP/pmdsptch.c
    CORE/PIXELMAP/pmdsptch.h
    CORE/PIXELMAP/pmfile.c
    CORE/PIXELMAP/pmfile.h
    CORE/PIXELMAP/pmgen.c
    CORE/PIXELMAP/pmgen.h
    CORE/PIXELMAP/pmmem.c
    CORE/PIXELMAP/pmmem.h
    CORE/PIXELMAP/pmnull.c
    CORE/PIXELMAP/pmnull.h
    CORE/PIXELMAP/pmsetup.c
    CORE/PIXELMAP/pmsetup.h
    CORE/STD/brexcept.c
    CORE/STD/brexcept.h
    CORE/STD/brmath.c
    CORE/STD/brmath.h
    CORE/STD/brstddiag.c
    CORE/STD/brstddiag.h
    CORE/STD/brstdfile.c
    CORE/STD/brstdfile.h
    CORE/STD/brstdlib.c
    CORE/STD/brstdlib.h
    CORE/STD/brstdmem.c
    CORE/STD/brstdmem.h
    CORE/STD/logwrite.c
    CORE/STD/logwrite.h
    CORE/V1DB/actsupt.c
    CORE/V1DB/actsupt.h
    CORE/V1DB/chunkids.h
    CORE/V1DB/custsupt.c
    CORE/V1DB/custsupt.h
    CORE/V1DB/dbsetup.c
    CORE/V1DB/dbsetup.h
    CORE/V1DB/def_mat.c
    CORE/V1DB/def_mat.h
    CORE/V1DB/def_mdl.c
    CORE/V1DB/def_mdl.h
    CORE/V1DB/def_otab.c
    CORE/V1DB/def_otab.h
    CORE/V1DB/enables.c
    CORE/V1DB/enables.h
    CORE/V1DB/matsupt.c
    CORE/V1DB/matsupt.h
    CORE/V1DB/modrend.c
    CORE/V1DB/modrend.h
    CORE/V1DB/modsupt.c
    CORE/V1DB/modsupt.h
    CORE/V1DB/otable.c
    CORE/V1DB/otable.h
    CORE/V1DB/prepmap.c
    CORE/V1DB/prepmap.h
    CORE/V1DB/prepmatl.c
    CORE/V1DB/prepmatl.h
    CORE/V1DB/prepmesh.c
    CORE/V1DB/prepmesh.h
    CORE/V1DB/preptab.c
    CORE/V1DB/preptab.h
    CORE/V1DB/regsupt.c
    CORE/V1DB/regsupt.h
    CORE/V1DB/render.c
    CORE/V1DB/render.h
    CORE/V1DB/stackids.h
    CORE/V1DB/v1dbfile.c
    CORE/V1DB/v1dbfile.h
)
