#
# 7-Zip CMakeLists.txt
#
project(7Zip)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(7ZIP_SOURCES
    ${CMAKE_CURRENT_BINARY_DIR}/C/Bcj2.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Bra.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Bra86.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/BraIA64.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/CpuArch.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Delta.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Lzma2Dec.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/LzmaDec.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Ppmd7.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Ppmd7Dec.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zCrc.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zCrcOpt.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Sha256.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/Sha256Opt.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zAlloc.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zArcIn.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zBuf.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zBuf2.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zDec.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zFile.c
    ${CMAKE_CURRENT_BINARY_DIR}/C/7zStream.c
)

add_custom_command(
    OUTPUT ${7ZIP_SOURCES}
    COMMAND ${CMAKE_COMMAND} -E tar "xvz" "${CMAKE_CURRENT_SOURCE_DIR}/lzma2201.tar.gz"
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_definitions(-D_7ZIP_PPMD_SUPPPORT -DNDEBUG -D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)

add_library(7Zip STATIC ${7ZIP_SOURCES})
