### Configure SEAL Build with Examples Enabled Source: https://github.com/microsoft/seal/blob/main/README.md This command configures the Microsoft SEAL build to include examples. It sets the SEAL_BUILD_EXAMPLES option to ON. This is useful when you want to build and run the provided C++ examples. ```PowerShell cmake -S . -B build -DSEAL_BUILD_EXAMPLES=ON ``` -------------------------------- ### Build Standalone SEAL Examples, Tests, or Benchmarks Source: https://github.com/microsoft/seal/blob/main/README.md Build examples, tests, or benchmarks as standalone CMake projects. Ensure SEAL_ROOT is set if the library is not installed globally. ```PowerShell cd native/ cmake -S . -B build -DSEAL_ROOT=~/mylibs cmake --build build ``` -------------------------------- ### Enable Building C++ Examples Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets an option to control whether C++ examples for Microsoft SEAL are built. If enabled, it adds the examples subdirectory to the build. ```cmake # [option] SEAL_BUILD_EXAMPLES set(SEAL_BUILD_EXAMPLES_OPTION_STR "Build C++ examples for Microsoft SEAL") option(SEAL_BUILD_EXAMPLES ${SEAL_BUILD_EXAMPLES_OPTION_STR} OFF) message(STATUS "SEAL_BUILD_EXAMPLES: ${SEAL_BUILD_EXAMPLES}") if(SEAL_BUILD_EXAMPLES) add_subdirectory(native/examples) endif() ``` -------------------------------- ### Configure and Install Header File Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Configures a header file from a template and installs it to the specified include directory. ```cmake configure_file(${SEAL_CONFIG_H_IN_FILENAME} ${SEAL_CONFIG_H_FILENAME}) install( FILES ${SEAL_CONFIG_H_FILENAME} DESTINATION ${SEAL_INCLUDES_INSTALL_DIR}/seal/util) ``` -------------------------------- ### Build and Run .NET Examples Source: https://github.com/microsoft/seal/blob/main/README.md Build and run the .NET examples for Microsoft SEAL. Use Debug or Release configuration as needed. ```PowerShell dotnet run -p build/dotnet/examples ``` -------------------------------- ### Install Microsoft SEAL with vcpkg Source: https://github.com/microsoft/seal/blob/main/README.md Installs the Microsoft SEAL library using the vcpkg dependency manager. This command clones the vcpkg repository, bootstraps it, integrates it with your system, and then installs the 'seal' package. Optional features can be specified. ```shell git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh # ./bootstrap-vcpkg.bat for Windows ./vcpkg integrate install ./vcpkg install seal # Optional features can be selected with `seal[,...]`; see the `seal` port (its `vcpkg.json` manifest and `portfile.cmake`) for the full feature list. ``` -------------------------------- ### Manual iOS XCFramework Build Steps Source: https://github.com/microsoft/seal/blob/main/README.md Provides detailed manual steps to configure, build, and install SEAL for iOS device and simulator, then create XCFrameworks. This includes staging headers separately for each slice. ```bash D=out/ios-xcframework # working directory # Configure for device (iphoneos) and simulator (iphonesimulator), both arm64. cmake -S . -B $D/build-device -GXcode \ -DSEAL_BUILD_SEAL_C=ON \ -DSEAL_BUILD_STATIC_SEAL_C=ON \ -DCMAKE_SYSTEM_NAME=iOS \ -DCMAKE_OSX_SYSROOT=iphoneos \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ -C cmake/functions.ios.cmake cmake -S . -B $D/build-simulator -GXcode \ -DSEAL_BUILD_SEAL_C=ON \ -DSEAL_BUILD_STATIC_SEAL_C=ON \ -DCMAKE_SYSTEM_NAME=iOS \ -DCMAKE_OSX_SYSROOT=iphonesimulator \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ -C cmake/functions.ios.cmake # Build and install each. cmake --build $D/build-device --config Release cmake --build $D/build-simulator --config Release cmake --install $D/build-device --config Release --prefix $D/install-device cmake --install $D/build-simulator --config Release --prefix $D/install-simulator # Stage headers per slice. XCFramework requires separate header trees because # generated files (e.g. config.h) can differ between device and simulator. mkdir -p $D/staging/device $D/staging/simulator rsync -a $D/install-device/include/SEAL-4.3/ $D/staging/device/ rsync -a $D/install-simulator/include/SEAL-4.3/ $D/staging/simulator/ # xcodebuild refuses to overwrite an existing .xcframework output. rm -rf libseal-4.3.xcframework libsealc-4.3.xcframework # Create the XCFrameworks. xcodebuild -create-xcframework \ -library $D/install-device/lib/libseal-4.3.a \ -headers $D/staging/device \ -library $D/install-simulator/lib/libseal-4.3.a \ -headers $D/staging/simulator \ -output libseal-4.3.xcframework xcodebuild -create-xcframework \ -library $D/install-device/lib/libsealc-4.3.a \ -headers $D/staging/device \ -library $D/install-simulator/lib/libsealc-4.3.a \ -headers $D/staging/simulator \ -output libsealc-4.3.xcframework ``` -------------------------------- ### Install Microsoft SEAL Globally Source: https://github.com/microsoft/seal/blob/main/README.md If you have root access, use these commands to install Microsoft SEAL system-wide. ```PowerShell cmake -S . -B build cmake --build build sudo cmake --install build ``` -------------------------------- ### Install pkg-config Files Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Installs the generated pkg-config files to the specified destination directory. This ensures that other projects can find and link against the SEAL library using pkg-config. ```cmake if(EXISTS ${SEAL_PKGCONFIG_FILENAME}) install( FILES ${SEAL_PKGCONFIG_FILENAME} DESTINATION ${SEAL_PKGCONFIG_INSTALL_DIR}) endif() if(EXISTS ${SEAL_PKGCONFIG_SHARED_FILENAME}) install( FILES ${SEAL_PKGCONFIG_SHARED_FILENAME} DESTINATION ${SEAL_PKGCONFIG_INSTALL_DIR}) endif() if(EXISTS ${SEAL_PKGCONFIG_MSGSL_FILENAME}) install( FILES ${SEAL_PKGCONFIG_MSGSL_FILENAME} DESTINATION ${SEAL_PKGCONFIG_INSTALL_DIR}) endif() ``` -------------------------------- ### Project Setup and SEAL Import Source: https://github.com/microsoft/seal/blob/main/native/examples/CMakeLists.txt Configures the CMake project, sets the minimum required version, and imports the Microsoft SEAL library. This snippet is typically found at the beginning of the CMakeLists.txt file. ```cmake cmake_minimum_required(VERSION 3.22) project(SEALExamples VERSION 4.3.3 LANGUAGES CXX) # If not called from root CMakeLists.txt if(NOT DEFINED SEAL_BUILD_EXAMPLES) set(SEAL_BUILD_EXAMPLES ON) # Import Microsoft SEAL find_package(SEAL 4.3.3 EXACT REQUIRED) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) endif() ``` -------------------------------- ### Install emsdk toolchain for WebAssembly Source: https://github.com/microsoft/seal/blob/main/README.md Installs and activates the latest emscripten toolchain. This is a prerequisite for building SEAL for WebAssembly. ```PowerShell # Install the latest toolchain ./emsdk install latest ./emsdk activate latest # Source the environment source ./emsdk_env.sh ``` -------------------------------- ### Build WebAssembly Module with emcc Source: https://github.com/microsoft/seal/blob/main/README.md Use this command to compile a static library into a WebAssembly module with JavaScript bindings. Ensure you have emcc installed and the necessary build flags configured. ```bash emcc \ -Wall \ -flto \ -O3 \ build/lib/libseal-4.3.a \ --bind \ -o "build/bin/seal_wasm.js" \ -s WASM=1 \ -s ALLOW_MEMORY_GROWTH=1 ``` -------------------------------- ### Install Microsoft SEAL Locally Source: https://github.com/microsoft/seal/blob/main/README.md To install Microsoft SEAL locally to a specified prefix (e.g., ~/mylibs/), use these commands. ```PowerShell cmake -S . -B build -DCMAKE_INSTALL_PREFIX=~/mylibs cmake --build build sudo cmake --install build ``` -------------------------------- ### Integrate Intel HEXL Dependency (Shared Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against Intel HEXL, includes its compile options, and installs the shared HEXL library. ```cmake if(SEAL_USE_INTEL_HEXL) target_link_libraries(seal_shared PRIVATE HEXL::hexl) target_compile_options(seal_shared PRIVATE $) get_target_property(HEXL_INTERFACE_LINK_OPTIONS HEXL::hexl INTERFACE_LINK_OPTIONS) if(NOT "${HEXL_INTERFACE_LINK_OPTIONS}" STREQUAL "HEXL_INTERFACE_LINK_OPTIONS-NOTFOUND") target_link_libraries(seal_shared INTERFACE ${HEXL_INTERFACE_LINK_OPTIONS}) endif() # Install shared HEXL library to installation directory install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_LIBRARY_PREFIX} FILES_MATCHING PATTERN "*hexl*") endif() ``` -------------------------------- ### Dependency Management for GoogleBenchmark Source: https://github.com/microsoft/seal/blob/main/native/bench/CMakeLists.txt Configures how GoogleBenchmark is handled, either by fetching and building it if SEAL_BUILD_DEPS is enabled, or by finding an existing installation. An error is raised if it's not found and building is disabled. ```cmake if(SEAL_BUILD_BENCH) if(SEAL_BUILD_DEPS) seal_fetch_thirdparty_content(ExternalBenchmark) else() find_package(benchmark REQUIRED) if(NOT benchmark_FOUND) message(FATAL_ERROR "GoogleBenchmark: not found") else() message(STATUS "GoogleBenchmark: found") endif() endif() add_executable(sealbench) # If we're targeting WASM, add the appropriate link flags if(EMSCRIPTEN) set_target_properties(sealbench PROPERTIES LINK_FLAGS "-flto -O3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB") endif() target_sources(sealbench PRIVATE ${CMAKE_CURRENT_LIST_DIR}/bench.cpp ${CMAKE_CURRENT_LIST_DIR}/keygen.cpp ${CMAKE_CURRENT_LIST_DIR}/ntt.cpp ${CMAKE_CURRENT_LIST_DIR}/bfv.cpp ${CMAKE_CURRENT_LIST_DIR}/bgv.cpp ${CMAKE_CURRENT_LIST_DIR}/ckks.cpp ) if(TARGET SEAL::seal) target_link_libraries(sealbench PRIVATE SEAL::seal benchmark::benchmark) elseif(TARGET SEAL::seal_shared) target_link_libraries(sealbench PRIVATE SEAL::seal_shared benchmark::benchmark) else() message(FATAL_ERROR "Cannot find target SEAL::seal or SEAL::seal_shared") endif() endif() ``` -------------------------------- ### Find or Download Zstandard Dependency Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Handles finding an installed Zstandard library or downloading it if SEAL_BUILD_DEPS is ON. It checks for static library compatibility. ```cmake if(SEAL_USE_ZSTD) if(SEAL_BUILD_DEPS) message(STATUS "Zstandard: download ...") seal_fetch_thirdparty_content(ExternalZSTD) set(zstd_static "libzstd_static") else() find_package(zstd 1 CONFIG) if(NOT zstd_FOUND) message(FATAL_ERROR "Zstandard: not found") else() if(TARGET zstd::libzstd_static) set(zstd_static "zstd::libzstd_static") elseif(TARGET libzstd) get_target_property(libzstd_type libzstd TYPE) if(libzstd_type STREQUAL "STATIC_LIBRARY") set(zstd_static "libzstd") message(STATUS "Zstandard: found") else() message(FATAL_ERROR "Zstandard: must be static") endif() elseif(TARGET zstd::libzstd_shared) message(FATAL_ERROR "Zstandard: must be static") else() message(FATAL_ERROR "Zstandard: not found") endif() endif() endif() endif() ``` -------------------------------- ### Configure CMake with Local SEAL Installation Source: https://github.com/microsoft/seal/blob/main/README.md When SEAL is installed locally, specify its directory using CMAKE_PREFIX_PATH during CMake configuration. ```powershell cd cmake . -DCMAKE_PREFIX_PATH=~/mylibs ``` -------------------------------- ### Find and Link Microsoft SEAL Library Source: https://github.com/microsoft/seal/blob/main/README.md Add this to your CMakeLists.txt to find and link the SEAL library. Ensure SEAL is installed or its prefix path is set. ```cmake find_package(SEAL 4.3 REQUIRED) target_link_libraries( SEAL::seal) ``` -------------------------------- ### Building the sealexamples Executable Source: https://github.com/microsoft/seal/blob/main/native/examples/CMakeLists.txt Defines the 'sealexamples' executable and specifies the source files to be compiled. This is conditional on SEAL_BUILD_EXAMPLES being set. ```cmake if(SEAL_BUILD_EXAMPLES) add_executable(sealexamples) target_sources(sealexamples PRIVATE ${CMAKE_CURRENT_LIST_DIR}/examples.cpp ${CMAKE_CURRENT_LIST_DIR}/1_bfv_basics.cpp ${CMAKE_CURRENT_LIST_DIR}/2_encoders.cpp ${CMAKE_CURRENT_LIST_DIR}/3_levels.cpp ${CMAKE_CURRENT_LIST_DIR}/4_bgv_basics.cpp ${CMAKE_CURRENT_LIST_DIR}/5_ckks_basics.cpp ${CMAKE_CURRENT_LIST_DIR}/6_rotation.cpp ${CMAKE_CURRENT_LIST_DIR}/7_serialization.cpp ${CMAKE_CURRENT_LIST_DIR}/8_performance.cpp ) if(TARGET SEAL::seal) target_link_libraries(sealexamples PRIVATE SEAL::seal) elseif(TARGET SEAL::seal_shared) target_link_libraries(sealexamples PRIVATE SEAL::seal_shared) else() message(FATAL_ERROR "Cannot find target SEAL::seal or SEAL::seal_shared") endif() endif() ``` -------------------------------- ### Setting up GoogleTest and SEAL Test Executable Source: https://github.com/microsoft/seal/blob/main/native/tests/CMakeLists.txt This snippet configures the build process for the SEAL test executable, including fetching GoogleTest if SEAL_BUILD_DEPS is enabled, or finding it otherwise. It then adds the executable and links it with the SEAL library. ```cmake if(SEAL_BUILD_TESTS) if(SEAL_BUILD_DEPS) seal_fetch_thirdparty_content(ExternalGTest) else() find_package(GTest 1 CONFIG) if(NOT GTest_FOUND) message(FATAL_ERROR "GoogleTest: not found") else() message(STATUS "GoogleTest: found") endif() endif() add_executable(sealtest "") add_subdirectory(seal) if(TARGET SEAL::seal) target_link_libraries(sealtest PRIVATE SEAL::seal GTest::gtest) elseif(TARGET SEAL::seal_shared) target_link_libraries(sealtest PRIVATE SEAL::seal_shared GTest::gtest) else() message(FATAL_ERROR "Cannot find target SEAL::seal or SEAL::seal_shared") endif() # In Debug mode, enable AddressSanitizer (and LeakSanitizer) on Unix-like platforms. if(SEAL_DEBUG AND UNIX) # On macOS, only AddressSanitizer is enabled. # On Linux, LeakSanitizer is default. target_compile_options(sealtest PUBLIC -fsanitize=address) target_link_options(sealtest PUBLIC -fsanitize=address) if(NOT APPLE) message(STATUS "Sanitizers enabled: address, leak") else() message(STATUS "Sanitizers enabled: address") endif() endif() endif() ``` -------------------------------- ### Build .NET Wrapper Library Source: https://github.com/microsoft/seal/blob/main/README.md Build the .NET wrapper library for Microsoft SEAL. Use Debug or Release configuration as needed. ```PowerShell dotnet build build/dotnet/src --configuration ``` -------------------------------- ### Basic CMake Configuration for SEAL Benchmarks Source: https://github.com/microsoft/seal/blob/main/native/bench/CMakeLists.txt Sets up the minimum CMake version, project name, and version. It also handles importing the SEAL library and setting output directories for libraries and executables. ```cmake cmake_minimum_required(VERSION 3.22) project(SEALBench VERSION 4.3.3 LANGUAGES CXX) # If not called from root CMakeLists.txt if(NOT DEFINED SEAL_BUILD_BENCH) set(SEAL_BUILD_BENCH ON) # Import Microsoft SEAL find_package(SEAL 4.3.3 EXACT REQUIRED) # Must define these variables and include macros set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${OUTLIB_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) set(SEAL_THIRDPARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../thirdparty) set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty) include(FetchContent) mark_as_advanced(FETCHCONTENT_BASE_DIR) mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) mark_as_advanced(FETCHCONTENT_QUIET) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) include(SEALMacros) else() set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../thirdparty) endif() ``` -------------------------------- ### Create SEALNet NuGet Package Source: https://github.com/microsoft/seal/blob/main/dotnet/nuget/NUGET.md Run this command in the dotnet\nuget directory after compiling SEAL and SEAL_C projects. It packs the SEALNet.nuspec file into a release configuration, outputting the package to the Release directory. ```bash cd dotnet\nuget nuget pack SEALNet.nuspec -properties Configuration=Release -Verbosity detailed -OutputDir Release cd ..\.. ``` -------------------------------- ### Collect System Information for Bug Reports Source: https://github.com/microsoft/seal/blob/main/ISSUES.md Run this command to generate a system information archive for bug reports. Attach the resulting `system_info.tar.gz` file to your GitHub issue. ```bash make -C tools system_info ``` -------------------------------- ### Build and Run .NET Unit Tests Source: https://github.com/microsoft/seal/blob/main/README.md Build and execute the .NET unit tests for Microsoft SEAL. Verbosity can be increased with --verbosity detailed. ```PowerShell dotnet test build/dotnet/tests ``` -------------------------------- ### Configure and Build SEAL for WebAssembly Source: https://github.com/microsoft/seal/blob/main/README.md Configures the CMake build for WebAssembly using emcmake and then builds the static library. Shared libraries are not supported with emscripten. ```PowerShell # Configure CMake. Example flags for a release build emcmake cmake -S . -B build \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG -flto -O3" \ -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG -flto -O3" \ -DSEAL_BUILD_BENCH=OFF \# Benchmark can be built for WASM. Change this to ON. \ -DSEAL_BUILD_EXAMPLES=OFF \ -DSEAL_BUILD_TESTS=OFF \ -DSEAL_USE_CXX17=ON \ -DSEAL_USE_INTRIN=ON \ -DSEAL_USE_MSGSL=OFF \ -DSEAL_USE_ZLIB=ON \ -DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=ON # Make the static library (shared libs are not supported with emscripten) emmake make -C build -j ``` -------------------------------- ### Generate and Build for x64 Release on Windows (VS 2022) Source: https://github.com/microsoft/seal/blob/main/README.md Configure and build the library for x64 in Release mode using the Visual Studio 2022 generator. ```PowerShell cmake -S . -B build -G "Visual Studio 17 2022" -A x64 cmake --build build --config Release ``` -------------------------------- ### Build Microsoft SEAL (Out-of-Source) Source: https://github.com/microsoft/seal/blob/main/README.md Execute these commands in the SEAL directory to build the library. Output binaries are located in build/lib/ and build/bin/. ```PowerShell cmake -S . -B build cmake --build build ``` -------------------------------- ### Configure SEALNet and NuGet Package Files Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Configures the project files for SEALNet, including .csproj files for different components and the solution file for Visual Studio. It also prepares the .nuspec file for creating a multi-platform NuGet package. ```cmake configure_file( ${CMAKE_CURRENT_LIST_DIR}/dotnet/src/SEALNet.csproj.in ${CMAKE_CURRENT_BINARY_DIR}/dotnet/src/SEALNet.csproj @ONLY) configure_file( ${CMAKE_CURRENT_LIST_DIR}/dotnet/tests/SEALNetTest.csproj.in ${CMAKE_CURRENT_BINARY_DIR}/dotnet/tests/SEALNetTest.csproj @ONLY) configure_file( ${CMAKE_CURRENT_LIST_DIR}/dotnet/examples/SEALNetExamples.csproj.in ${CMAKE_CURRENT_BINARY_DIR}/dotnet/examples/SEALNetExamples.csproj @ONLY) # Create SEALNet.sln for Visual Studio to build all dotnet projects configure_file( ${CMAKE_CURRENT_LIST_DIR}/dotnet/SEALNet.sln.in ${CMAKE_CURRENT_BINARY_DIR}/dotnet/SEALNet.sln @ONLY) # Set the sealc dynamic library file names to be included in creating # the NuGet package. When building a multi-platform NuGet package, the # dynamic library paths need to be specified explicitly in the NuGet # command. See dotnet/nuget/SEALNet.nuspec.in. # Create SEALNet-multi.nuspec for a multi-platform NuGet package configure_file( ${CMAKE_CURRENT_LIST_DIR}/dotnet/nuget/SEALNet-multi.nuspec.in ${CMAKE_CURRENT_BINARY_DIR}/dotnet/nuget/SEALNet-multi.nuspec @ONLY) set(NUGET_WINDOWS_SEAL_C_PATH "") set(NUGET_LINUX_SEAL_C_PATH "") set(NUGET_MACOS_X64_SEAL_C_PATH "") set(NUGET_MACOS_ARM64_SEAL_C_PATH "") # Supporting local building of multi-platform NuGet package. For the NuGet ``` -------------------------------- ### Integrate Intel HEXL Dependency (Static Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against Intel HEXL or includes its headers and compile options if building dependencies. ```cmake if(SEAL_USE_INTEL_HEXL) if(SEAL_BUILD_DEPS) add_dependencies(seal HEXL::hexl) target_include_directories(seal PRIVATE $>) target_compile_options(seal PRIVATE $) get_target_property(HEXL_INTERFACE_LINK_OPTIONS HEXL::hexl INTERFACE_LINK_OPTIONS) if(NOT "${HEXL_INTERFACE_LINK_OPTIONS}" STREQUAL "HEXL_INTERFACE_LINK_OPTIONS-NOTFOUND") target_link_libraries(seal INTERFACE ${HEXL_INTERFACE_LINK_OPTIONS}) endif() seal_combine_archives(seal HEXL::hexl) else() target_link_libraries(seal PUBLIC HEXL::hexl) endif() endif() ``` -------------------------------- ### Generate and Build for x86 Release on Windows (VS 2022) Source: https://github.com/microsoft/seal/blob/main/README.md Configure and build the library for x86 in Release mode using the Visual Studio 2022 generator. ```PowerShell cmake -S . -B build -G "Visual Studio 17 2022" -A Win32 cmake --build build --config Release ``` -------------------------------- ### Setting up SEAL Test Build Source: https://github.com/microsoft/seal/blob/main/native/tests/CMakeLists.txt This snippet configures the build environment for SEAL tests, including setting output directories and including necessary CMake modules. It's typically used when SEAL_BUILD_TESTS is not defined. ```cmake cmake_minimum_required(VERSION 3.22) project(SEALTest VERSION 4.3.3 LANGUAGES CXX C) # If not called from root CMakeLists.txt if(NOT DEFINED SEAL_BUILD_TESTS) set(SEAL_BUILD_TESTS ON) # Import Microsoft SEAL find_package(SEAL 4.3.3 EXACT REQUIRED) # Must define these variables and include macros set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${OUTLIB_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) set(SEAL_THIRDPARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../thirdparty) set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty) include(FetchContent) mark_as_advanced(FETCHCONTENT_BASE_DIR) mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) mark_as_advanced(FETCHCONTENT_QUIET) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) include(SEALMacros) else() set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../thirdparty) endif() ``` -------------------------------- ### Build Microsoft SEAL with Ninja Generator on Windows Source: https://github.com/microsoft/seal/blob/main/README.md Use these commands in a developer command prompt for Visual Studio when using the Ninja generator. ```PowerShell cmake -S . -B build -G Ninja cmake --build build ``` -------------------------------- ### Integrate zlib Dependency (Static Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against zlib or includes its headers if building dependencies. ```cmake if(SEAL_USE_ZLIB) if(SEAL_BUILD_DEPS) add_dependencies(seal ${zlib}) target_include_directories(seal PRIVATE $) target_include_directories(seal PRIVATE $>) seal_combine_archives(seal ${zlib}) else() target_link_libraries(seal PRIVATE ${zlib}) endif() endif() ``` -------------------------------- ### Build Static SEAL Library Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Defines and configures a static SEAL library, including versioning, language settings, and dependency linking. ```cmake add_library(seal STATIC ${SEAL_SOURCE_FILES}) seal_set_version_filename(seal) seal_set_language(seal) seal_set_include_directories(seal) if(CMAKE_CONFIGURATION_TYPES) seal_add_debug_compile_definition(seal) endif() seal_set_version(seal) seal_link_threads(seal) seal_install_target(seal SEALTargets) ``` -------------------------------- ### Integrate zlib Dependency (Shared Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against zlib and includes its headers. ```cmake if(SEAL_USE_ZLIB) target_link_libraries(seal_shared PRIVATE ${zlib}) target_include_directories(seal_shared PRIVATE $) target_include_directories(seal_shared PRIVATE $>) endif() ``` -------------------------------- ### Configuring Dependency Building Option Source: https://github.com/microsoft/seal/blob/main/native/tests/CMakeLists.txt This snippet defines an option to control whether missing dependencies should be automatically downloaded and built. It sets the default to ON. ```cmake if(NOT DEFINED SEAL_BUILD_DEPS) # [option] SEAL_BUILD_DEPS (default: ON) # Download and build missing dependencies, throw error if disabled. set(SEAL_BUILD_DEPS_OPTION_STR "Automatically download and build unmet dependencies") option(SEAL_BUILD_DEPS ${SEAL_BUILD_DEPS_OPTION_STR} ON) endif() ``` -------------------------------- ### Configure Intel HEXL Option Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets the SEAL_USE_INTEL_HEXL option to enable or disable the use of the Intel HEXL library. ```cmake set(SEAL_USE_INTEL_HEXL_OPTION_STR "Use Intel HEXL library") option(SEAL_USE_INTEL_HEXL ${SEAL_USE_INTEL_HEXL_OPTION_STR} OFF) message(STATUS "SEAL_USE_INTEL_HEXL: ${SEAL_USE_INTEL_HEXL}") ``` -------------------------------- ### Build iOS XCFramework with Debug Configuration Source: https://github.com/microsoft/seal/blob/main/README.md Configures and builds SEAL for iOS, creating XCFrameworks for both device and simulator. Intermediate build files are placed in a specified output directory. ```bash cmake -DBUILD_TYPE=Debug -DOUTPUT_DIR=./out -P cmake/ios_xcframework.cmake ``` -------------------------------- ### Integrate Microsoft GSL Dependency (Static Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against the Microsoft GSL library or includes its headers if building dependencies. ```cmake if(SEAL_USE_MSGSL) if(SEAL_BUILD_DEPS) target_include_directories(seal PUBLIC $) else() target_link_libraries(seal PUBLIC Microsoft.GSL::GSL) endif() endif() ``` -------------------------------- ### Add SEAL Source Files Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Initializes the SEAL_SOURCE_FILES variable and adds the SEAL source directory to the build. ```cmake set(SEAL_SOURCE_FILES "") add_subdirectory(native/src/seal) ``` -------------------------------- ### Build iOS XCFrameworks with CMake Source: https://github.com/microsoft/seal/blob/main/README.md Use this CMake script to build XCFrameworks for iOS. Release builds write to the project root by default. ```bash cmake -P cmake/ios_xcframework.cmake ``` -------------------------------- ### Find or Use Intel HEXL Dependency Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Handles finding the Intel HEXL library. It checks if the target HEXL::hexl exists, otherwise it reports an error. ```cmake if(SEAL_USE_INTEL_HEXL) if(SEAL_BUILD_DEPS) message(STATUS "Intel HEXL: download ...") seal_fetch_thirdparty_content(ExternalIntelHEXL) else() find_package(HEXL) if(NOT TARGET HEXL::hexl) message(FATAL_ERROR "Intel HEXL: not found") endif() endif() endif() ``` -------------------------------- ### Enable Building C++ Benchmarks Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets an option to control whether C++ benchmarks for Microsoft SEAL are built. If enabled, it adds the benchmarks subdirectory to the build. ```cmake # [option] SEAL_BUILD_BENCH set(SEAL_BUILD_BENCH_OPTION_STR "Build C++ benchmarks for Microsoft SEAL") option(SEAL_BUILD_BENCH ${SEAL_BUILD_BENCH_OPTION_STR} OFF) message(STATUS "SEAL_BUILD_BENCH: ${SEAL_BUILD_BENCH}") if(SEAL_BUILD_BENCH) add_subdirectory(native/bench) endif() ``` -------------------------------- ### Configure SEALNet.nuspec for NuGet Packaging Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Configures the SEALNet.nuspec file from a template for creating a local NuGet package. It uses CMake's configure_file command to substitute variables. ```cmake configure_file( ${CMAKE_CURRENT_LIST_DIR}/dotnet/nuget/SEALNet.nuspec.in ${CMAKE_CURRENT_BINARY_DIR}/dotnet/nuget/SEALNet.nuspec @ONLY) ``` -------------------------------- ### Configure Intrinsics Usage Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets the SEAL_USE_INTRIN option to enable or disable the use of CPU intrinsics. Includes the EnableIntrinsics module. ```cmake set(SEAL_USE_INTRIN_OPTION_STR "Use intrinsics") option(SEAL_USE_INTRIN ${SEAL_USE_INTRIN_OPTION_STR} ON) message(STATUS "SEAL_USE_INTRIN: ${SEAL_USE_INTRIN}") include(EnableIntrinsics) ``` -------------------------------- ### Configure Gaussian Noise Sampling Option Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets the SEAL_USE_GAUSSIAN_NOISE option to choose between Gaussian distribution (ON) or centered binomial distribution (OFF) for noise sampling. ```cmake set(SEAL_USE_GAUSSIAN_NOISE_STR "Use a rounded Gaussian distribution for noise sampling instead of a Centered Binomial Distribution") option(SEAL_USE_GAUSSIAN_NOISE ${SEAL_USE_GAUSSIAN_NOISE_STR} OFF) message(STATUS "SEAL_USE_GAUSSIAN_NOISE: ${SEAL_USE_GAUSSIAN_NOISE}") mark_as_advanced(FORCE SEAL_USE_GAUSSIAN_NOISE) ``` -------------------------------- ### Integrate zstd Dependency (Static Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against zstd or includes its headers if building dependencies. ```cmake if(SEAL_USE_ZSTD) if(SEAL_BUILD_DEPS) add_dependencies(seal ${zstd_static}) target_include_directories(seal PRIVATE $) target_include_directories(seal PRIVATE $) seal_combine_archives(seal ${zstd_static}) else() target_link_libraries(seal PRIVATE ${zstd_static}) endif() endif() ``` -------------------------------- ### Configure Zstandard Compression Option Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets the SEAL_USE_ZSTD option to control Zstandard compression for serialization. It can be enabled or disabled. ```cmake set(SEAL_USE_ZSTD_OPTION_STR "Use Zstandard for compressed serialization") option(SEAL_USE_ZSTD ${SEAL_USE_ZSTD_OPTION_STR} ON) message(STATUS "SEAL_USE_ZSTD: ${SEAL_USE_ZSTD}") ``` -------------------------------- ### Configure Transparent Ciphertext Exception Option Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Sets the SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT option to control whether an exception is thrown when the Evaluator outputs a transparent ciphertext. ```cmake set(SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT_STR "Throw an exception when Evaluator outputs a transparent ciphertext") option(SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT ${SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT_STR} ON) message(STATUS "SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT: ${SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT}") mark_as_advanced(FORCE SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT) ``` -------------------------------- ### Integrate Microsoft GSL Dependency (Shared Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Links against the Microsoft GSL library or includes its headers if building dependencies. ```cmake if(SEAL_USE_MSGSL) if(SEAL_BUILD_DEPS) target_include_directories(seal_shared PUBLIC $) else() target_link_libraries(seal_shared PUBLIC Microsoft.GSL::GSL) endif() endif() ``` -------------------------------- ### Integrate zstd Dependency (Shared Library) Source: https://github.com/microsoft/seal/blob/main/CMakeLists.txt Includes zstd headers and links against the static zstd library. ```cmake if(SEAL_USE_ZSTD) target_include_directories(seal_shared PRIVATE $) target_include_directories(seal_shared PRIVATE $) target_link_libraries(seal_shared PRIVATE ${zstd_static}) endif() ```