# ===========================================================================
#
#                            PUBLIC DOMAIN NOTICE
#               National Center for Biotechnology Information
#
#  This software/database is a "United States Government Work" under the
#  terms of the United States Copyright Act.  It was written as part of
#  the author's official duties as a United States Government employee and
#  thus cannot be copyrighted.  This software/database is freely available
#  to the public for use. The National Library of Medicine and the U.S.
#  Government have not placed any restriction on its use or reproduction.
#
#  Although all reasonable efforts have been taken to ensure the accuracy
#  and reliability of the software and data, the NLM and the U.S.
#  Government do not and cannot warrant the performance or results that
#  may be obtained by using this software or data. The NLM and the U.S.
#  Government disclaim all warranties, express or implied, including
#  warranties of performance, merchantability or fitness for any particular
#  purpose.
#
#  Please cite the author in any work or product based on this material.
#
# ===========================================================================

set ( UNIX_BASE_SRC unix/misc.c unix/syslog.c unix/systime.c unix/syswriter.c )
set ( UNIX_SRC ${UNIX_BASE_SRC} unix/syserrcode.c )
set ( LINUX_SRC ${UNIX_BASE_SRC} linux/syserrcode.c )
set ( MAC_SRC ${UNIX_SRC} )
set ( WIN_SRC win/misc.c win/sysalloc.c win/syserrcode.c win/syslog.c win/systime.c win/syswriter.c )

if ( "windows" STREQUAL ${OS} )
    set ( OS_SPECIFIC_SRC ${WIN_SRC} )
elseif( "linux" STREQUAL ${OS} )
    set ( OS_SPECIFIC_SRC ${LINUX_SRC} )
elseif( "mac" STREQUAL ${OS} )
    set ( OS_SPECIFIC_SRC ${MAC_SRC} )
endif()

if( FLEX_FOUND AND BISON_FOUND )
    # the generated files have names prefized with zz_ to make sure they get checked out last
    # in order to prevent unneeded invokation of bison and flex
    FLEX_TARGET( JsonFlex json-lex.l ${CMAKE_CURRENT_SOURCE_DIR}/zz_json-lex.c
        COMPILE_FLAGS "--debug --noline" )
    set( JsonScanner ${FLEX_JsonFlex_OUTPUTS} )
    BISON_TARGET( JsonGrammar json-grammar.y ${CMAKE_CURRENT_SOURCE_DIR}/zz_json-grammar.c
        COMPILE_FLAGS "-Wno-other --no-lines -r state --defines=${CMAKE_CURRENT_SOURCE_DIR}/zz_json-grammar.h" )
    set( JsonParser ${BISON_JsonGrammar_OUTPUT_SOURCE} )
    ADD_FLEX_BISON_DEPENDENCY(JsonFlex JsonGrammar)
    SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM 1)
else()
    set( JsonScanner zz_json-lex.c )
    set( JsonParser zz_json-grammar.c )
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set( BUILD_SPECIFIC_SRC debug.c )
else()
    set( BUILD_SPECIFIC_SRC release.c )
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")

add_subdirectory( judy )

set( SRC
    all-vdb-version
    base64
    bsearch
    bstpersist #TODO: bstpersist.nopt
    btree
    container
    cp1252
    crc32
    data-buffer
    guid
    hashfile # TODO: dead code
    hashtable # TODO: dead code
    iso8859-1
    iso8859
    ${JsonParser}
    ${JsonScanner}
    json
    judy-vector
    ksort
    log
    md5
    namelist
    num-gen
    out
    pack
    # NOTE:
    # pbstree-impl.nopt pbstree-native.c ptpersist.nopt ptrie.nopt
    # were generated by the old gmake build but are not used anywhere, apparently
    pbstree-impl
    pbstree-swapped.c # was 'pbstree-impl.swap.nopt' in the old gmake build
    pbstree
    #
    printf
    progressbar
    ptpersist
    ptrie
    qsort
    rc-idx-tbl
    rc-tbl
    refcount
    report-klib
    SHA-32bit
    SHA-64bit
    sra-release-version
    status-rc-strings
    status-rc
    status
    symtab
    text
    time
    token
    trie
    unpack
    utf8
    vector
    vector_namelist
    vlen-encode
    writer
    ${BUILD_SPECIFIC_SRC}
    ${OS_SPECIFIC_SRC}
)

GenerateStaticLibs( klib "${SRC}" )

add_compile_definitions (__mod__="libs/klib")
add_compile_definitions (_ARCH_BITS=${BITS})
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} )
