First Commit

This commit is contained in:
2025-02-06 22:24:29 +08:00
parent ed7df4c81e
commit 7539e6a53c
18116 changed files with 6181499 additions and 0 deletions

View File

@ -0,0 +1,128 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
set(INT_TEST_CMAKE_FILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CRYPTOPP_CMAKE_INSTALL_ROOT
"${CMAKE_BINARY_DIR}/test-dirs/install")
define_property(TEST PROPERTY install_dir
BRIEF_DOCS "Install-dir of the test"
FULL_DOCS "Just set because not optional (yet)")
file(GLOB tests "${CMAKE_CURRENT_SOURCE_DIR}/int-install-*")
foreach(test ${tests})
cmake_path(GET test FILENAME test_name)
message(STATUS "Adding install integration test: ${test_name}")
string (REPLACE "int-" "" short_name cryptopp-${test_name})
# Configure
add_test(
NAME cryptopp-${test_name}-configure
COMMAND
${CMAKE_COMMAND}
-G${CMAKE_GENERATOR}
# Pass the locations for common cmake test files
-D "TEST_CMAKE_FILES_DIR=${TEST_CMAKE_FILES_DIR}"
-D "INT_TEST_CMAKE_FILES_DIR=${INT_TEST_CMAKE_FILES_DIR}"
# Pass the locations for common test source files
-D "TEST_EXAMPLE_SOURCES_DIR=${TEST_EXAMPLE_SOURCES_DIR}"
# Use ccache
-D "USE_CCACHE=TRUE"
# Override cmake compiler flags for ccache/MSVC
-D
"CMAKE_USER_MAKE_RULES_OVERRIDE=${TEST_CMAKE_FILES_DIR}/ResetInitialCompilerOptions.cmake"
# Set the install prefix
-D "CMAKE_INSTALL_PREFIX=${CRYPTOPP_CMAKE_INSTALL_ROOT}/${test_name}"
# Setup cmake source/build dirs
-S "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}" -B
"${CMAKE_BINARY_DIR}/test-dirs/${test_name}"
# Use local source code for cryptopp-cmake
-D "CPM_cryptopp-cmake_SOURCE=${CMAKE_CURRENT_SOURCE_DIR}/../.."
# Enable verbose makefiles so we can see the full compile command line
-D "CMAKE_VERBOSE_MAKEFILE=ON"
# Throw the version in
-D CRYPTOPP_MINIMUM_CMAKE_VERSION=${CRYPTOPP_MINIMUM_CMAKE_VERSION}
# Set the build-type to what we are building
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
set_tests_properties(cryptopp-${test_name}-configure PROPERTIES
FIXTURES_SETUP ${test_name}-config
install_dir "${CRYPTOPP_CMAKE_INSTALL_ROOT}/${test_name}"
LABELS "cryptopp;cryptopp-integration-tests;${short_name}")
# Build
add_test(NAME cryptopp-${test_name}-build
COMMAND ${CMAKE_COMMAND} --build
"${CMAKE_BINARY_DIR}/test-dirs/${test_name}"
--config ${CMAKE_BUILD_TYPE})
set_tests_properties(cryptopp-${test_name}-build PROPERTIES
FIXTURES_SETUP ${test_name}-build
FIXTURES_REQUIRED ${test_name}-config
LABELS "cryptopp;cryptopp-integration-tests;${short_name}")
# Install
add_test(
NAME cryptopp-${test_name}-install
COMMAND ${CMAKE_COMMAND} --build
"${CMAKE_BINARY_DIR}/test-dirs/${test_name}" --target install
--config ${CMAKE_BUILD_TYPE})
set_tests_properties(cryptopp-${test_name}-install PROPERTIES
FIXTURES_SETUP ${test_name}-install
FIXTURES_REQUIRED ${test_name}-build
LABELS "cryptopp;cryptopp-integration-tests;${short_name}")
# Check installed files
add_test(
NAME cryptopp-${test_name}-checks
COMMAND ${CMAKE_COMMAND} --build
"${CMAKE_BINARY_DIR}/test-dirs/${test_name}" --target do-checks
--config ${CMAKE_BUILD_TYPE})
set_tests_properties(cryptopp-${test_name}-checks PROPERTIES
FIXTURES_REQUIRED ${test_name}-install
LABELS "cryptopp;cryptopp-integration-tests;${short_name}")
endforeach()
# ------------------------------------------------------------------------------
# Use cryptopp via find_package
# ------------------------------------------------------------------------------
set(test_name "int-find-package")
get_test_property(cryptopp-int-install-default-configure
install_dir CRYPTOPP_SEARCH_ROOT)
# Configure
add_test(
NAME cryptopp-${test_name}-configure
COMMAND
${CMAKE_COMMAND}
-G${CMAKE_GENERATOR}
# Pass the locations for common test source files
-D "TEST_EXAMPLE_SOURCES_DIR=${TEST_EXAMPLE_SOURCES_DIR}"
# Set the install prefix
-D "CRYPTOPP_CMAKE_INSTALL_ROOT=${CRYPTOPP_CMAKE_INSTALL_ROOT}"
# Setup cmake source/build dirs
-S "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}" -B
"${CMAKE_BINARY_DIR}/test-dirs/${test_name}"
# Enable verbose makefiles so we can see the full compile command line
-D "CMAKE_VERBOSE_MAKEFILE=ON"
# Throw the version in
-D CRYPTOPP_MINIMUM_CMAKE_VERSION=${CRYPTOPP_MINIMUM_CMAKE_VERSION}
# Set the build-type to what we are building
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# Tell the test where to find installed package
-D cryptopp_DIR=${CRYPTOPP_SEARCH_ROOT}/share/cmake/cryptopp)
set_tests_properties(cryptopp-${test_name}-configure PROPERTIES
FIXTURES_SETUP ${test_name}-config
FIXTURES_REQUIRED "int-install-default-install"
LABELS "cryptopp;cryptopp-find_package")
# Build
add_test(NAME cryptopp-${test_name}-build
COMMAND ${CMAKE_COMMAND} --build
"${CMAKE_BINARY_DIR}/test-dirs/${test_name}"
--config ${CMAKE_BUILD_TYPE})
set_tests_properties(cryptopp-${test_name}-build PROPERTIES
FIXTURES_REQUIRED ${test_name}-config
LABELS "cryptopp;cryptopp-find_package")

View File

@ -0,0 +1,12 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
# Helper script to check if a file exists at build time
message(STATUS "Checking if installed file \"${FILE_TO_CHECK}\" exists")
if(NOT EXISTS ${FILE_TO_CHECK})
message(FATAL_ERROR "\"${FILE_TO_CHECK}\" doesn't exist.")
endif()

View File

@ -0,0 +1,36 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
include(GNUInstallDirs)
# add custom target to check the installed files at build time
add_custom_target(do-checks)
function(check_file_exists file_to_check)
add_custom_command(
TARGET do-checks
POST_BUILD
COMMAND ${CMAKE_COMMAND} -DFILE_TO_CHECK=${file_to_check} -P
${CMAKE_CURRENT_LIST_DIR}/CheckFileExists.cmake
COMMENT "Checking if ${file_to_check} exists...")
endfunction()
if(MSVC)
if(CRYPTOPP_BUILD_SHARED)
check_file_exists(${CMAKE_INSTALL_FULL_LIBDIR}/cryptopp.dll)
else()
check_file_exists(${CMAKE_INSTALL_FULL_LIBDIR}/cryptopp.lib)
endif()
else()
check_file_exists(${CMAKE_INSTALL_FULL_LIBDIR}/$<TARGET_FILE_NAME:cryptopp>)
endif()
check_file_exists(${CMAKE_INSTALL_FULL_INCLUDEDIR}/${CRYPTOPP_INCLUDE_PREFIX})
check_file_exists(
${CMAKE_INSTALL_FULL_INCLUDEDIR}/${CRYPTOPP_INCLUDE_PREFIX}/config.h)
check_file_exists(${CMAKE_INSTALL_FULL_DATAROOTDIR}/pkgconfig/cryptopp.pc)
check_file_exists(${CMAKE_INSTALL_FULL_DATAROOTDIR}/cmake/cryptopp)
check_file_exists(
${CMAKE_INSTALL_FULL_DATAROOTDIR}/cmake/cryptopp/cryptoppConfig.cmake)

View File

@ -0,0 +1,19 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
cmake_minimum_required(VERSION ${CRYPTOPP_MINIMUM_CMAKE_VERSION})
# Test project for cryptopp-cmake installation
project(CryptoppCmakeFindPackageTest)
# Explicitly request the static library component to avoid cmake defaulting to
# the shared component, which is currently not being built.
find_package(cryptopp REQUIRED static)
# compile and link a test program using crypto++
add_executable(rng-test ${TEST_EXAMPLE_SOURCES_DIR}/main.cpp)
target_link_libraries(rng-test cryptopp::cryptopp)
target_compile_features(rng-test PRIVATE cxx_constexpr)

View File

@ -0,0 +1,35 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
cmake_minimum_required(VERSION ${CRYPTOPP_MINIMUM_CMAKE_VERSION})
# Test project for cryptopp-cmake installation
project(CryptoppCmakeInstallDefaultTest)
# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info
include(${TEST_CMAKE_FILES_DIR}/CPM.cmake)
# ---- Speedup build using ccache (needs CPM) ----
include(${TEST_CMAKE_FILES_DIR}/FasterBuild.cmake)
set(CRYPTOPP_INCLUDE_PREFIX "cryptopp")
cpmaddpackage(
NAME
cryptopp-cmake
GIT_REPOSITORY
https://github.com./abdes/cryptopp-cmake
GIT_TAG
master
OPTIONS
"CRYPTOPP_BUILD_TESTING OFF"
"CRYPTOPP_INSTALL ON")
add_executable(rng-test ${TEST_EXAMPLE_SOURCES_DIR}/main.cpp)
target_link_libraries(rng-test PUBLIC cryptopp::cryptopp)
target_compile_features(rng-test PRIVATE cxx_constexpr)
include(${INT_TEST_CMAKE_FILES_DIR}/ProjectInstallTests.cmake)

View File

@ -0,0 +1,36 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
cmake_minimum_required(VERSION ${CRYPTOPP_MINIMUM_CMAKE_VERSION})
# Test project for cryptopp-cmake installation
project(CryptoppCmakeInstallPrefixTest)
# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info
include(${TEST_CMAKE_FILES_DIR}/CPM.cmake)
# ---- Speedup build using ccache (needs CPM) ----
include(${TEST_CMAKE_FILES_DIR}/FasterBuild.cmake)
set(CRYPTOPP_INCLUDE_PREFIX "crypto++")
cpmaddpackage(
NAME
cryptopp-cmake
GIT_REPOSITORY
https://github.com./abdes/cryptopp-cmake
GIT_TAG
master
OPTIONS
"CRYPTOPP_BUILD_TESTING OFF"
"CRYPTOPP_INSTALL ON"
"CRYPTOPP_INCLUDE_PREFIX ${CRYPTOPP_INCLUDE_PREFIX}")
add_executable(rng-test main.cpp)
target_link_libraries(rng-test PUBLIC cryptopp::cryptopp)
target_compile_features(rng-test PRIVATE cxx_constexpr)
include(${INT_TEST_CMAKE_FILES_DIR}/ProjectInstallTests.cmake)

View File

@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
// Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
// copy at https://opensource.org/licenses/BSD-3-Clause).
// SPDX-License-Identifier: BSD-3-Clause
//===----------------------------------------------------------------------===//
#include <array>
#include <cstdint>
#include <crypto++/osrng.h> // for random number generation
int main(int argc, char **argv) {
constexpr size_t c_buffer_size = 16;
std::array<uint8_t, c_buffer_size> output;
CryptoPP::AutoSeededRandomPool rng;
rng.GenerateBlock(output.data(), c_buffer_size);
}