Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/cmake-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ jobs:
cmake -S "${{ env.SRC_DIR }}/build/cmake" -B build -DBUILD_TESTING=ON -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=Release --install-prefix "${{ runner.temp }}/install"
cmake --build build --config Release
cmake --install build --config Release
- name: Configure subdirectory consumers
run: |
cmake -S "${{ env.SRC_DIR }}/build/cmake/tests/consumer" -B consumer-build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_COMPILE_WARNING_AS_ERROR=ON
- name: Build subdirectory consumers
run: cmake --build consumer-build --config Release
- name: Test subdirectory consumers
run: ctest --test-dir consumer-build -C Release --output-on-failure

# Windows-specific cmake testing with Visual Studio 2022
# Tests multiple generators and toolchains to ensure broad Windows compatibility
Expand Down
29 changes: 29 additions & 0 deletions build/cmake/tests/consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# 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).
# You may select, at your option, one of the above-listed licenses.

cmake_minimum_required(VERSION 3.10)
project(zstd_consumer C CXX)

set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "Build command-line programs")
set(ZSTD_BUILD_TESTS OFF CACHE BOOL "Build zstd's test suite")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../.." zstd)

enable_testing()
foreach(kind IN ITEMS static shared)
add_executable(consumer_${kind} main.cpp)
# Consumers must receive the public headers through the linked target,
# without inheriting zstd's directory-scoped include paths.
target_link_libraries(consumer_${kind} PRIVATE libzstd_${kind})
set_target_properties(consumer_${kind} PROPERTIES CXX_STANDARD 98 CXX_STANDARD_REQUIRED ON)
add_test(NAME consumer_${kind} COMMAND consumer_${kind})
endforeach()

if(WIN32)
add_custom_command(TARGET consumer_shared POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"$<TARGET_FILE:libzstd_shared>" "$<TARGET_FILE_DIR:consumer_shared>"
VERBATIM)
endif()
29 changes: 29 additions & 0 deletions build/cmake/tests/consumer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* 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).
* You may select, at your option, one of the above-listed licenses.
*/

#include <zstd.h>
#include <zstd_errors.h>
#include <zdict.h>
#include <string.h>

int main()
{
const char input[] = "CMake subdirectory consumer round trip";
char compressed[128];
char decompressed[sizeof(input)];
const size_t compressedSize = ZSTD_compress(compressed, sizeof(compressed), input, sizeof(input), 1);
if (ZSTD_isError(compressedSize)) return 1;

const size_t decompressedSize = ZSTD_decompress(decompressed, sizeof(decompressed), compressed, compressedSize);
if (ZSTD_isError(decompressedSize) || decompressedSize != sizeof(input)) return 1;
if (memcmp(input, decompressed, sizeof(input)) != 0) return 1;

if (ZSTD_getErrorCode(decompressedSize) != ZSTD_error_no_error) return 1;
if (ZDICT_getDictID(input, sizeof(input)) != 0) return 1;
return 0;
}