1# ################################################################ 2# Copyright (c) 2015-present, Yann Collet, Facebook, Inc. 3# All rights reserved. 4# 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# ################################################################ 9 10project(programs) 11 12set(CMAKE_INCLUDE_CURRENT_DIR TRUE) 13 14# Define programs directory, where sources and header files are located 15set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib) 16set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs) 17include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder) 18 19if (ZSTD_LEGACY_SUPPORT) 20 set(PROGRAMS_LEGACY_DIR ${PROGRAMS_DIR}/legacy) 21 include_directories(${PROGRAMS_LEGACY_DIR} ${LIBRARY_DIR}/legacy) 22endif () 23 24if (ZSTD_PROGRAMS_LINK_SHARED) 25 set(PROGRAMS_ZSTD_LINK_TARGET libzstd_shared) 26else () 27 set(PROGRAMS_ZSTD_LINK_TARGET libzstd_static) 28endif () 29 30if (MSVC) 31 set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/zstd) 32 set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc) 33endif () 34 35add_executable(zstd ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/dibio.c ${PlatformDependResources}) 36target_link_libraries(zstd ${PROGRAMS_ZSTD_LINK_TARGET}) 37if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") 38 target_link_libraries(zstd rt) 39endif () 40install(TARGETS zstd RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") 41 42if (UNIX) 43 add_custom_target(zstdcat ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdcat DEPENDS zstd COMMENT "Creating zstdcat symlink") 44 add_custom_target(unzstd ALL ${CMAKE_COMMAND} -E create_symlink zstd unzstd DEPENDS zstd COMMENT "Creating unzstd symlink") 45 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdcat DESTINATION "${CMAKE_INSTALL_BINDIR}") 46 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unzstd DESTINATION "${CMAKE_INSTALL_BINDIR}") 47 install(PROGRAMS ${PROGRAMS_DIR}/zstdgrep DESTINATION "${CMAKE_INSTALL_BINDIR}") 48 install(PROGRAMS ${PROGRAMS_DIR}/zstdless DESTINATION "${CMAKE_INSTALL_BINDIR}") 49 50 add_custom_target(zstd.1 ALL 51 ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstd.1 . 52 COMMENT "Copying manpage zstd.1") 53 add_custom_target(zstdgrep.1 ALL 54 ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdgrep.1 . 55 COMMENT "Copying manpage zstdgrep.1") 56 add_custom_target(zstdless.1 ALL 57 ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdless.1 . 58 COMMENT "Copying manpage zstdless.1") 59 add_custom_target(zstdcat.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 zstdcat.1 DEPENDS zstd.1 COMMENT "Creating zstdcat.1 symlink") 60 add_custom_target(unzstd.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 unzstd.1 DEPENDS zstd.1 COMMENT "Creating unzstd.1 symlink") 61 62 # Define MAN_INSTALL_DIR if necessary 63 if (MAN_INSTALL_DIR) 64 else () 65 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1) 66 endif () 67 68 install(FILES 69 ${CMAKE_CURRENT_BINARY_DIR}/zstd.1 70 ${CMAKE_CURRENT_BINARY_DIR}/zstdcat.1 71 ${CMAKE_CURRENT_BINARY_DIR}/unzstd.1 72 ${CMAKE_CURRENT_BINARY_DIR}/zstdgrep.1 73 ${CMAKE_CURRENT_BINARY_DIR}/zstdless.1 74 DESTINATION "${MAN_INSTALL_DIR}") 75 76 add_executable(zstd-frugal ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c) 77 target_link_libraries(zstd-frugal ${PROGRAMS_ZSTD_LINK_TARGET}) 78 set_property(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT") 79endif () 80 81# Add multi-threading support definitions 82 83if (ZSTD_MULTITHREAD_SUPPORT) 84 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD") 85 86 if (UNIX) 87 target_link_libraries(zstd ${THREADS_LIBS}) 88 89 add_custom_target(zstdmt ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdmt DEPENDS zstd COMMENT "Creating zstdmt symlink") 90 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdmt DESTINATION "${CMAKE_INSTALL_BINDIR}") 91 endif () 92endif () 93 94option(ZSTD_ZLIB_SUPPORT "ZLIB SUPPORT" OFF) 95option(ZSTD_LZMA_SUPPORT "LZMA SUPPORT" OFF) 96option(ZSTD_LZ4_SUPPORT "LZ4 SUPPORT" OFF) 97 98# Add gzip support 99if (ZSTD_ZLIB_SUPPORT) 100 find_package(ZLIB REQUIRED) 101 102 if (ZLIB_FOUND) 103 include_directories(${ZLIB_INCLUDE_DIRS}) 104 target_link_libraries(zstd ${ZLIB_LIBRARIES}) 105 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_GZCOMPRESS;ZSTD_GZDECOMPRESS") 106 else () 107 message(SEND_ERROR "zlib library is missing") 108 endif () 109endif () 110 111# Add lzma support 112if (ZSTD_LZMA_SUPPORT) 113 find_package(LibLZMA REQUIRED) 114 115 if (LIBLZMA_FOUND) 116 include_directories(${LIBLZMA_INCLUDE_DIRS}) 117 target_link_libraries(zstd ${LIBLZMA_LIBRARIES}) 118 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZMACOMPRESS;ZSTD_LZMADECOMPRESS") 119 else () 120 message(SEND_ERROR "lzma library is missing") 121 endif () 122endif () 123 124# Add lz4 support 125if (ZSTD_LZ4_SUPPORT) 126 find_package(LibLZ4 REQUIRED) 127 128 if (LIBLZ4_FOUND) 129 include_directories(${LIBLZ4_INCLUDE_DIRS}) 130 target_link_libraries(zstd ${LIBLZ4_LIBRARIES}) 131 set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZ4COMPRESS;ZSTD_LZ4DECOMPRESS") 132 else () 133 message(SEND_ERROR "lz4 library is missing") 134 endif () 135endif () 136