1 # ################################################################
2 # Copyright (c) Meta Platforms, Inc. and affiliates.
5 # This source code is licensed under both the BSD-style license (found in the
6 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 # in the COPYING file in the root directory of this source tree).
8 # ################################################################
12 set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
14 # Define programs directory, where sources and header files are located
15 set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
16 set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
17 include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder)
19 if (ZSTD_LEGACY_SUPPORT)
20 set(PROGRAMS_LEGACY_DIR ${PROGRAMS_DIR}/legacy)
21 include_directories(${PROGRAMS_LEGACY_DIR} ${LIBRARY_DIR}/legacy)
24 if (ZSTD_PROGRAMS_LINK_SHARED)
25 set(PROGRAMS_ZSTD_LINK_TARGET libzstd_shared)
27 set(PROGRAMS_ZSTD_LINK_TARGET libzstd_static)
31 set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/zstd)
32 set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc)
35 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})
36 target_link_libraries(zstd ${PROGRAMS_ZSTD_LINK_TARGET})
37 if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
38 target_link_libraries(zstd rt)
41 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
42 BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}")
45 add_custom_target(zstdcat ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdcat DEPENDS zstd COMMENT "Creating zstdcat symlink")
46 add_custom_target(unzstd ALL ${CMAKE_COMMAND} -E create_symlink zstd unzstd DEPENDS zstd COMMENT "Creating unzstd symlink")
47 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdcat DESTINATION "${CMAKE_INSTALL_BINDIR}")
48 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unzstd DESTINATION "${CMAKE_INSTALL_BINDIR}")
49 install(PROGRAMS ${PROGRAMS_DIR}/zstdgrep DESTINATION "${CMAKE_INSTALL_BINDIR}")
50 install(PROGRAMS ${PROGRAMS_DIR}/zstdless DESTINATION "${CMAKE_INSTALL_BINDIR}")
52 add_custom_target(zstd.1 ALL
53 ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstd.1 .
54 COMMENT "Copying manpage zstd.1")
55 add_custom_target(zstdgrep.1 ALL
56 ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdgrep.1 .
57 COMMENT "Copying manpage zstdgrep.1")
58 add_custom_target(zstdless.1 ALL
59 ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdless.1 .
60 COMMENT "Copying manpage zstdless.1")
61 add_custom_target(zstdcat.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 zstdcat.1 DEPENDS zstd.1 COMMENT "Creating zstdcat.1 symlink")
62 add_custom_target(unzstd.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 unzstd.1 DEPENDS zstd.1 COMMENT "Creating unzstd.1 symlink")
64 # Define MAN_INSTALL_DIR if necessary
67 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
71 ${CMAKE_CURRENT_BINARY_DIR}/zstd.1
72 ${CMAKE_CURRENT_BINARY_DIR}/zstdcat.1
73 ${CMAKE_CURRENT_BINARY_DIR}/unzstd.1
74 ${CMAKE_CURRENT_BINARY_DIR}/zstdgrep.1
75 ${CMAKE_CURRENT_BINARY_DIR}/zstdless.1
76 DESTINATION "${MAN_INSTALL_DIR}")
78 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)
79 target_link_libraries(zstd-frugal ${PROGRAMS_ZSTD_LINK_TARGET})
80 set_property(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT;ZSTD_NOTRACE")
83 # Add multi-threading support definitions
85 if (ZSTD_MULTITHREAD_SUPPORT)
86 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
89 target_link_libraries(zstd ${THREADS_LIBS})
91 add_custom_target(zstdmt ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdmt DEPENDS zstd COMMENT "Creating zstdmt symlink")
92 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdmt DESTINATION "${CMAKE_INSTALL_BINDIR}")
96 option(ZSTD_ZLIB_SUPPORT "ZLIB SUPPORT" OFF)
97 option(ZSTD_LZMA_SUPPORT "LZMA SUPPORT" OFF)
98 option(ZSTD_LZ4_SUPPORT "LZ4 SUPPORT" OFF)
101 if (ZSTD_ZLIB_SUPPORT)
102 find_package(ZLIB REQUIRED)
105 include_directories(${ZLIB_INCLUDE_DIRS})
106 target_link_libraries(zstd ${ZLIB_LIBRARIES})
107 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_GZCOMPRESS;ZSTD_GZDECOMPRESS")
109 message(SEND_ERROR "zlib library is missing")
114 if (ZSTD_LZMA_SUPPORT)
115 find_package(LibLZMA REQUIRED)
118 include_directories(${LIBLZMA_INCLUDE_DIRS})
119 target_link_libraries(zstd ${LIBLZMA_LIBRARIES})
120 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZMACOMPRESS;ZSTD_LZMADECOMPRESS")
122 message(SEND_ERROR "lzma library is missing")
127 if (ZSTD_LZ4_SUPPORT)
128 find_package(LibLZ4 REQUIRED)
131 include_directories(${LIBLZ4_INCLUDE_DIRS})
132 target_link_libraries(zstd ${LIBLZ4_LIBRARIES})
133 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZ4COMPRESS;ZSTD_LZ4DECOMPRESS")
135 message(SEND_ERROR "lz4 library is missing")