aboutsummaryrefslogtreecommitdiff
path: root/build/cmake/programs/CMakeLists.txt
blob: 58d998e427538e0fc155da9e0b6b1abc3fca3eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# ################################################################
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under both the BSD-style license (found in the
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
# in the COPYING file in the root directory of this source tree).
# ################################################################

project(programs C)

set(CMAKE_INCLUDE_CURRENT_DIR TRUE)

# Define programs directory, where sources and header files are located
set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder)

if (ZSTD_LEGACY_SUPPORT)
    set(PROGRAMS_LEGACY_DIR ${PROGRAMS_DIR}/legacy)
    include_directories(${PROGRAMS_LEGACY_DIR} ${LIBRARY_DIR}/legacy)
endif ()

if (ZSTD_PROGRAMS_LINK_SHARED)
    set(PROGRAMS_ZSTD_LINK_TARGET libzstd_shared)
else ()
    set(PROGRAMS_ZSTD_LINK_TARGET libzstd_static)
endif ()

if (MSVC)
    set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/zstd)
    set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc)
endif ()

add_executable(zstd ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/fileio_asyncio.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/dibio.c ${PROGRAMS_DIR}/zstdcli_trace.c ${PlatformDependResources})
target_link_libraries(zstd ${PROGRAMS_ZSTD_LINK_TARGET})
if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
    target_link_libraries(zstd rt)
endif ()
install(TARGETS zstd
  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
  BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}")

if (UNIX)
    add_custom_target(zstdcat ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdcat DEPENDS zstd COMMENT "Creating zstdcat symlink")
    add_custom_target(unzstd ALL ${CMAKE_COMMAND} -E create_symlink zstd unzstd DEPENDS zstd COMMENT "Creating unzstd symlink")
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdcat DESTINATION "${CMAKE_INSTALL_BINDIR}")
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unzstd DESTINATION "${CMAKE_INSTALL_BINDIR}")
    install(PROGRAMS ${PROGRAMS_DIR}/zstdgrep DESTINATION "${CMAKE_INSTALL_BINDIR}")
    install(PROGRAMS ${PROGRAMS_DIR}/zstdless DESTINATION "${CMAKE_INSTALL_BINDIR}")

    add_custom_target(zstd.1 ALL
        ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstd.1 .
        COMMENT "Copying manpage zstd.1")
    add_custom_target(zstdgrep.1 ALL
        ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdgrep.1 .
        COMMENT "Copying manpage zstdgrep.1")
    add_custom_target(zstdless.1 ALL
        ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdless.1 .
        COMMENT "Copying manpage zstdless.1")
    add_custom_target(zstdcat.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 zstdcat.1 DEPENDS zstd.1 COMMENT "Creating zstdcat.1 symlink")
    add_custom_target(unzstd.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 unzstd.1 DEPENDS zstd.1 COMMENT "Creating unzstd.1 symlink")

    # Define MAN_INSTALL_DIR if necessary
    if (MAN_INSTALL_DIR)
    else ()
        set(MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
    endif ()

    install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/zstd.1
        ${CMAKE_CURRENT_BINARY_DIR}/zstdcat.1
        ${CMAKE_CURRENT_BINARY_DIR}/unzstd.1
        ${CMAKE_CURRENT_BINARY_DIR}/zstdgrep.1
        ${CMAKE_CURRENT_BINARY_DIR}/zstdless.1
        DESTINATION "${MAN_INSTALL_DIR}")

    add_executable(zstd-frugal ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/fileio_asyncio.c)
    target_link_libraries(zstd-frugal ${PROGRAMS_ZSTD_LINK_TARGET})
    set_property(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT;ZSTD_NOTRACE")
endif ()

# Add multi-threading support definitions

if (ZSTD_MULTITHREAD_SUPPORT)
    set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")

    if (UNIX)
        target_link_libraries(zstd ${THREADS_LIBS})

        add_custom_target(zstdmt ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdmt DEPENDS zstd COMMENT "Creating zstdmt symlink")
        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdmt DESTINATION "${CMAKE_INSTALL_BINDIR}")
    endif ()
endif ()

option(ZSTD_ZLIB_SUPPORT "ZLIB SUPPORT" OFF)
option(ZSTD_LZMA_SUPPORT "LZMA SUPPORT" OFF)
option(ZSTD_LZ4_SUPPORT "LZ4 SUPPORT" OFF)

# Add gzip support
if (ZSTD_ZLIB_SUPPORT)
    find_package(ZLIB REQUIRED)

    if (ZLIB_FOUND)
        include_directories(${ZLIB_INCLUDE_DIRS})
        target_link_libraries(zstd ${ZLIB_LIBRARIES})
        set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_GZCOMPRESS;ZSTD_GZDECOMPRESS")
    else ()
        message(SEND_ERROR "zlib library is missing")
    endif ()
endif ()

# Add lzma support
if (ZSTD_LZMA_SUPPORT)
    find_package(LibLZMA REQUIRED)

    if (LIBLZMA_FOUND)
        include_directories(${LIBLZMA_INCLUDE_DIRS})
        target_link_libraries(zstd ${LIBLZMA_LIBRARIES})
        set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZMACOMPRESS;ZSTD_LZMADECOMPRESS")
    else ()
        message(SEND_ERROR "lzma library is missing")
    endif ()
endif ()

# Add lz4 support
if (ZSTD_LZ4_SUPPORT)
    find_package(LibLZ4 REQUIRED)

    if (LIBLZ4_FOUND)
        include_directories(${LIBLZ4_INCLUDE_DIRS})
        target_link_libraries(zstd ${LIBLZ4_LIBRARIES})
        set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZ4COMPRESS;ZSTD_LZ4DECOMPRESS")
    else ()
        message(SEND_ERROR "lz4 library is missing")
    endif ()
endif ()