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,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
# ===-----------------------------------------------------------------------===#
set(CPM_DOWNLOAD_VERSION 0.38.5)
if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a
# tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION
"${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake"
)
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION
"$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake"
)
else()
set(CPM_DOWNLOAD_LOCATION
"${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake"
)
endif()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()
include(${CPM_DOWNLOAD_LOCATION})

View File

@@ -0,0 +1,42 @@
# ===-----------------------------------------------------------------------===#
# 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(CMakePackageConfigHelpers)
# ------------------------------------------------------------------------------
# Generate module config files for cmake and pkgconfig
# ------------------------------------------------------------------------------
function(_module_cmake_config_files)
message(STATUS "[cryptopp] Generating cmake package config files")
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cryptoppConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
endfunction()
function(_module_pkgconfig_files)
message(STATUS "[cryptopp] Generating pkgconfig files")
set(MODULE_PKGCONFIG_FILE cryptopp.pc)
if(CMAKE_BUILD_TYPE EQUAL "Debug")
get_target_property(target_debug_postfix cryptopp DEBUG_POSTFIX)
if(${target_debug_postfix} MATCHES "-NOTFOUND$")
set(target_debug_postfix "")
endif()
endif()
set(MODULE_LINK_LIBS "-lcryptopp${target_debug_postfix}")
configure_file(
config.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${MODULE_PKGCONFIG_FILE}
@ONLY
)
endfunction()
function(create_module_config_files)
_module_cmake_config_files()
_module_pkgconfig_files()
endfunction()

View File

@@ -0,0 +1,23 @@
# ===-----------------------------------------------------------------------===#
# 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
# ===-----------------------------------------------------------------------===#
# ------------------------------------------------------------------------------
# Reduce build time by using ccache when available
# ------------------------------------------------------------------------------
find_program(CCACHE_TOOL_PATH ccache)
if(NOT WIN32 AND USE_CCACHE AND CCACHE_TOOL_PATH)
message(STATUS "Using ccache (${CCACHE_TOOL_PATH}) (via wrapper).")
# see https://github.com/TheLartians/Ccache.cmake enables CCACHE support
# through the USE_CCACHE flag possible values are: YES, NO or equivalent
include("${CMAKE_CURRENT_LIST_DIR}/CPM.cmake")
cpmaddpackage("gh:TheLartians/Ccache.cmake@1.2.3")
elseif(WIN32 AND USE_CCACHE AND CCACHE_TOOL_PATH)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE)
message(STATUS "Using ccache (${CCACHE_TOOL_PATH}).")
endif()

View File

@@ -0,0 +1,43 @@
# ===-----------------------------------------------------------------------===#
# 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(FetchContent)
set(version_underscore
"${cryptopp-cmake_VERSION_MAJOR}_${cryptopp-cmake_VERSION_MINOR}_${cryptopp-cmake_VERSION_PATCH}"
)
if(GIT_FOUND)
if(${CRYPTOPP_USE_MASTER_BRANCH})
set(source_location "master")
else()
set(source_location "CRYPTOPP_${version_underscore}")
endif()
fetchcontent_declare(
cryptopp
GIT_REPOSITORY ${cryptopp-cmake_HOMEPAGE_URL}
GIT_TAG ${source_location}
QUIET
SOURCE_DIR
${CRYPTOPP_INCLUDE_PREFIX}
)
else()
message(STATUS "Downloading crypto++ from URL...")
cmake_policy(SET CMP0135 NEW)
set(source_location "${cryptopp-cmake_HOMEPAGE_URL}/")
if(NOT ${CRYPTOPP_USE_MASTER_BRANCH})
string(
APPEND
source_location
"releases/download/CRYPTOPP_${version_underscore}/cryptopp${cryptopp-cmake_VERSION_MAJOR}${cryptopp-cmake_VERSION_MINOR}${cryptopp-cmake_VERSION_PATCH}"
)
else()
string(APPEND source_location "archive/refs/heads/master")
endif()
fetchcontent_declare(
cryptopp
URL "${source_location}.zip" QUIET SOURCE_DIR ${CRYPTOPP_INCLUDE_PREFIX}
)
endif()
fetchcontent_populate(cryptopp)

View File

@@ -0,0 +1,126 @@
# * Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can trust
# the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git
# describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting the
# output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree, and
# adjusting the output so that it tests false if there was no exact matching
# tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu>
# <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University
# HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010. Distributed under the Boost
# Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
# at http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time, to
# find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(
REGEX REPLACE
"gitdir: (.*)\n$"
"\\1"
GIT_DIR_RELATIVE
${submodule}
)
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(
GIT_DIR
${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
ABSOLUTE
)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file(
"${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY
)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,46 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HEAD_HASH)
set(HEAD_REF)
if (NOT EXISTS "@HEAD_FILE@")
return()
endif()
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/packed-refs")
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH AND EXISTS "@GIT_DATA@/head-ref")
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()

View File

@@ -0,0 +1,34 @@
# ===-----------------------------------------------------------------------===#
# 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
# ===-----------------------------------------------------------------------===#
# This module is loaded by `cmake` while enabling support for each language from
# either the project() or enable_language() commands. It is loaded after CMake's
# builtin compiler and platform information modules have been loaded but before
# the information is used. The file may set platform information variables to
# override CMake's defaults.
#
# To load this module, set the variable `CMAKE_USER_MAKE_RULES_OVERRIDE` before
# you declare the project or enable a language:
# ~~~
# set(CMAKE_USER_MAKE_RULES_OVERRIDE "ResetInitialCompilerOptions")
# ~~~
# We use this module to strip compiler options that are not really needed but
# will cause compatibility issues with `ccache`.
if(MSVC AND USE_CCACHE)
# As of ccache 4.6, /Zi option automatically added by cmake is unsupported.
# Given that we are doing ccache only in development environments (USE_CCACHE
# controls if ccache is enabled), we can just strip that option.
macro(strip_unwanted_options_from cmake_flags)
if(${cmake_flags} MATCHES "/Zi")
string(REPLACE "/Zi" "/Z7" ${cmake_flags} ${${cmake_flags}})
endif()
endmacro()
strip_unwanted_options_from(CMAKE_CXX_FLAGS_DEBUG_INIT)
strip_unwanted_options_from(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT)
strip_unwanted_options_from(CMAKE_C_FLAGS_DEBUG_INIT)
strip_unwanted_options_from(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT)
endif()

View File

@@ -0,0 +1,139 @@
# Based on the Qt 5 processor detection code, so should be very accurate
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
# Regarding POWER/PowerPC, just as is noted in the Qt source, "There are many
# more known variants/revisions that we do not handle/detect."
set(archdetect_c_code
"
/*
ARM family, known revisions: V5, V6, V7, V8
*/
#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC) || defined(__aarch64__) || defined(__ARM64__)
# if defined(__aarch64__) || defined(__ARM64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
# error cmake_ARCH arm64
# else
# error cmake_ARCH arm
# endif
#elif defined(__CYGWIN__)
#error cmake_ARCH cygwin
#elif defined(__MINGW64__)
#error cmake_ARCH mingw64
#elif defined(__MINGW32__)
#error cmake_ARCH mingw32
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
"
)
# Set ppc_support to TRUE before including this file or ppc and ppc64 will be
# treated as invalid architectures since they are no longer supported by Apple
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set First let's
# normalize the order of the values
# Note that it's not possible to compile PowerPC applications if you are
# using the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that,
# so we disable it by default See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending
# on the CPU type detected at runtime. On OS X 10.6+ the default is x86_64
# if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
elseif("${osx_arch}" STREQUAL "arm64")
set(osx_arch_arm64 TRUE)
elseif("${osx_arch}" STREQUAL "$(ARCHS_STANDARD)")
set(osx_arch_arm64 TRUE)
set(osx_arch_x86_64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
if(osx_arch_arm64)
list(APPEND ARCH arm64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way... This compiles a small
# C program which is a series of ifdefs that selects a particular #error
# preprocessor directive whose message string contains the target
# architecture. The program will always fail to compile (both because file
# is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in
# this way, we can detect the correct target architecture even when
# cross-compiling, since the program itself never needs to be run (only the
# compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due to a
# typo in the code), then set it to unknown
if(NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1 @@
set(CRYPTOPP_MINIMUM_CMAKE_VERSION 3.20)

View File

@@ -0,0 +1,96 @@
//===----------------------------------------------------------------------===//
// 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
//===----------------------------------------------------------------------===//
// -----------------------------------------------------------------------------
// Detect the dominant newline character of a string, from 'detect-newline'
// https://github.com/sindresorhus/detect-newline
//
// MIT License
// -----------------------------------------------------------------------------
function detectNewline(string) {
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
const newlines = string.match(/(?:\r?\n)/g) || [];
if (newlines.length === 0) {
return;
}
const crlf = newlines.filter(newline => newline === '\r\n').length;
const lf = newlines.length - crlf;
return crlf > lf ? '\r\n' : '\n';
}
function detectNewlineGraceful(string) {
return (typeof string === 'string' && detectNewline(string)) || '\n';
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Version reader/updated for standard-version that uses the mETA information in
// the CmakeLists.txt file
// -----------------------------------------------------------------------------
const major_rex = /set\(META_VERSION_MAJOR\s+\"(\d+)\"\)/;
const minor_rex = /set\(META_VERSION_MINOR\s+\"(\d+)\"\)/;
const patch_rex = /set\(META_VERSION_PATCH\s+\"(\d+)\"\)/;
module.exports.readVersion = function (contents) {
var major = null, minor = null, patch = null;
const lines = contents.split(/\r?\n/);
for (let index in lines) {
let line = lines[index];
var match = null;
if (major == null) {
var match = major_rex.exec(line);
if (match != null) {
major = match[1];
}
}
if (match == null && minor == null) {
var match = minor_rex.exec(line);
if (match != null) {
minor = match[1];
}
}
if (match == null && patch == null) {
var match = patch_rex.exec(line);
if (match != null) {
patch = match[1];
}
}
if (major != null && minor != null && patch != null) break;
};
if (major == null)
console.error("Your CmakeLists.txt is missing META_VERSION_MAJOR variable!");
if (minor == null)
console.error("Your CmakeLists.txt is missing META_VERSION_MINOR variable!");
if (patch == null)
console.error("Your CmakeLists.txt is missing META_VERSION_PATCH variable!");
return major + "." + minor + "." + patch;
}
module.exports.writeVersion = function (contents, version) {
var [major, minor, patch] = version.split(".");
var newContents = [];
const lines = contents.split(/\r?\n/);
lines.forEach(line => {
var newLine = line.replace(major_rex, "set(META_VERSION_MAJOR \"" + major + "\")")
.replace(minor_rex, "set(META_VERSION_MINOR \"" + minor + "\")")
.replace(patch_rex, "set(META_VERSION_PATCH \"" + patch + "\")");
newContents.push(newLine);
});
let newline = detectNewlineGraceful(contents)
return newContents.join(newline);
}