git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.5 / build / cmake / programs / CMakeLists.txt
1 # ################################################################
2 # Copyright (c) Meta Platforms, Inc. and affiliates.
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
10 project(programs C)
11
12 set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
13
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)
18
19 if (ZSTD_LEGACY_SUPPORT)
20     set(PROGRAMS_LEGACY_DIR ${PROGRAMS_DIR}/legacy)
21     include_directories(${PROGRAMS_LEGACY_DIR} ${LIBRARY_DIR}/legacy)
22 endif ()
23
24 if (ZSTD_PROGRAMS_LINK_SHARED)
25     set(PROGRAMS_ZSTD_LINK_TARGET libzstd_shared)
26 else ()
27     set(PROGRAMS_ZSTD_LINK_TARGET libzstd_static)
28 endif ()
29
30 if (MSVC)
31     set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/zstd)
32     set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc)
33 endif ()
34
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)
39 endif ()
40 install(TARGETS zstd
41   RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
42   BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}")
43
44 if (UNIX)
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}")
51
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")
63
64     # Define MAN_INSTALL_DIR if necessary
65     if (MAN_INSTALL_DIR)
66     else ()
67         set(MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
68     endif ()
69
70     install(FILES
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}")
77
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")
81 endif ()
82
83 # Add multi-threading support definitions
84
85 if (ZSTD_MULTITHREAD_SUPPORT)
86     set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
87
88     if (UNIX)
89         target_link_libraries(zstd ${THREADS_LIBS})
90
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}")
93     endif ()
94 endif ()
95
96 option(ZSTD_ZLIB_SUPPORT "ZLIB SUPPORT" OFF)
97 option(ZSTD_LZMA_SUPPORT "LZMA SUPPORT" OFF)
98 option(ZSTD_LZ4_SUPPORT "LZ4 SUPPORT" OFF)
99
100 # Add gzip support
101 if (ZSTD_ZLIB_SUPPORT)
102     find_package(ZLIB REQUIRED)
103
104     if (ZLIB_FOUND)
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")
108     else ()
109         message(SEND_ERROR "zlib library is missing")
110     endif ()
111 endif ()
112
113 # Add lzma support
114 if (ZSTD_LZMA_SUPPORT)
115     find_package(LibLZMA REQUIRED)
116
117     if (LIBLZMA_FOUND)
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")
121     else ()
122         message(SEND_ERROR "lzma library is missing")
123     endif ()
124 endif ()
125
126 # Add lz4 support
127 if (ZSTD_LZ4_SUPPORT)
128     find_package(LibLZ4 REQUIRED)
129
130     if (LIBLZ4_FOUND)
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")
134     else ()
135         message(SEND_ERROR "lz4 library is missing")
136     endif ()
137 endif ()