### Set output and include directories Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Defines the Eurydice root and output directory, and sets include directories for LSP-based editors. ```cmake set(EURYDICE_ROOT "../..") set(OUT_DIR "../../out/test-libcrux-ml-kem") # For LSP-based editors set(CMAKE_EXPORT_COMPILE_COMMANDS 1) include_directories( ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/intrinsics ${OUT_DIR} ${OUT_DIR}/internal ${EURYDICE_ROOT}/include ${EURYDICE_ROOT}/karamel/include ) ``` -------------------------------- ### CMake build commands for libcrux-ml-kem Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Commands to configure and build the project with CMake, including a release build for benchmarks. ```cmake # cmake -B build -G "Ninja Multi-Config" # cmake --build build # # For release (benchmarks) # cmake --build build --config Release ``` -------------------------------- ### Set color diagnostics and build directories Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Enables color diagnostics and sets the Eurydice root and output directory variables used for source and include paths. ```cmake set(CMAKE_COLOR_DIAGNOSTICS "ON") set(EURYDICE_ROOT "../..") set(OUT_DIR "../../out/test-libcrux-ml-dsa") ``` -------------------------------- ### Build test executable ml_dsa_test Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Creates an executable from tests/mldsa65.cc and links it against ml_dsa_static, gtest_main, and nlohmann_json. ```cmake add_executable(ml_dsa_test ${PROJECT_SOURCE_DIR}/tests/mldsa65.cc ) target_link_libraries(ml_dsa_test PRIVATE ml_dsa_static gtest_main nlohmann_json::nlohmann_json ) ``` -------------------------------- ### Fetch GoogleTest dependency Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Uses FetchContent to download GoogleTest v1.17.0 and sets gtest_force_shared_crt to ON for Windows compatibility. ```cmake # Get gtests include(FetchContent) FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.17.0 ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) ``` -------------------------------- ### Commented-out LTO options for Linux Release Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Shows commented-out code for enabling link-time optimization on Linux Release builds. ```cmake # if(${CMAKE_SYSTEM_NAME} MATCHES Linux AND CMAKE_BUILD_TYPE MATCHES "Release") # add_compile_options( # -flto # ) # add_link_options(-flto) # endif(${CMAKE_SYSTEM_NAME} MATCHES Linux AND CMAKE_BUILD_TYPE MATCHES "Release") ``` -------------------------------- ### Glob NEON source files Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Collects the NEON-optimized C source files for ML-KEM and SHA3. ```cmake file(GLOB SOURCES_vec128 ${OUT_DIR}/libcrux_mlkem_neon.c ${OUT_DIR}/libcrux_mlkem512_neon.c ${OUT_DIR}/libcrux_mlkem768_neon.c ${OUT_DIR}/libcrux_mlkem1024_neon.c ${OUT_DIR}/libcrux_sha3_neon.c ) ``` -------------------------------- ### Glob AVX2 source files Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Collects the AVX2-optimized C source files for ML-KEM and SHA3. ```cmake file(GLOB SOURCES_vec256 ${OUT_DIR}/libcrux_mlkem_avx2.c ${OUT_DIR}/libcrux_mlkem512_avx2.c ${OUT_DIR}/libcrux_mlkem768_avx2.c ${OUT_DIR}/libcrux_mlkem1024_avx2.c ${OUT_DIR}/libcrux_sha3_avx2.c ) ``` -------------------------------- ### Define shared and static library targets Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Creates shared library ml_dsa and static library ml_dsa_static from the portable sources. ```cmake add_library(ml_dsa SHARED ${SOURCES}) add_library(ml_dsa_static STATIC ${SOURCES}) ``` -------------------------------- ### Fetch nlohmann/json dependency Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Uses FetchContent to download nlohmann/json v3.11.3. ```cmake # Get nlohmann json FetchContent_Declare(json GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG v3.11.3 ) FetchContent_MakeAvailable(json) ``` -------------------------------- ### Glob portable source files Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Collects the portable C source files for the ML-KEM implementations. ```cmake file(GLOB SOURCES ${OUT_DIR}/libcrux_core.c ${OUT_DIR}/libcrux_platform.c ${OUT_DIR}/libcrux_sha3_portable.c ${OUT_DIR}/libcrux_mlkem512.c ${OUT_DIR}/libcrux_mlkem768.c ${OUT_DIR}/libcrux_mlkem1024.c ${OUT_DIR}/libcrux_mlkem_portable.c ${OUT_DIR}/libcrux_mlkem512_portable.c ${OUT_DIR}/libcrux_mlkem768_portable.c ${OUT_DIR}/libcrux_mlkem1024_portable.c ) ``` -------------------------------- ### Glob source files for portable and AVX2 implementations Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Collects portable C source files and AVX2-specific source files into variables SOURCES and SOURCES_vec256. ```cmake file(GLOB SOURCES ${OUT_DIR}/libcrux_mldsa44_portable.c ${OUT_DIR}/libcrux_mldsa65_portable.c ${OUT_DIR}/libcrux_mldsa87_portable.c ${OUT_DIR}/libcrux_mldsa_core.c ${OUT_DIR}/libcrux_mldsa_portable.c ) file(GLOB SOURCES_vec256 ${OUT_DIR}/libcrux_mldsa44_avx2.c ${OUT_DIR}/libcrux_mldsa65_avx2.c ${OUT_DIR}/libcrux_mldsa87_avx2.c ${OUT_DIR}/libcrux_mldsa_avx2.c ${OUT_DIR}/libcrux_sha3_avx2.c ) ``` -------------------------------- ### Enable color diagnostics Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Enables colored compiler diagnostics. ```cmake set(CMAKE_COLOR_DIAGNOSTICS "ON") ``` -------------------------------- ### CMake project configuration for libcrux-ml-kem Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Sets the minimum CMake version, project name, version, and supported languages (C and CXX). ```cmake cmake_minimum_required(VERSION 3.10..4.0) project(libcrux-ml-kem VERSION 0.1.0 LANGUAGES C CXX ) ``` -------------------------------- ### Export compile commands and include directories Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Exports compile commands for LSP-based editors and adds include directories for the project, intrinsics, output, and Eurydice/Karamel headers. ```cmake # For LSP-based editors set(CMAKE_EXPORT_COMPILE_COMMANDS 1) include_directories( ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/intrinsics ${OUT_DIR} ${OUT_DIR}/internal ${EURYDICE_ROOT}/include ${EURYDICE_ROOT}/karamel/include ) ``` -------------------------------- ### Set C/C++ standards and macOS architecture Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Defines the C standard as C11, C++ standard as C++20, and sets the macOS architecture to x86_64. ```cmake set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) set(CMAKE_OSX_ARCHITECTURES "x86_64") ``` -------------------------------- ### CMake project configuration for libcrux-ml-dsa Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Sets minimum CMake version, project name, version, and required languages (C and CXX). Also sets C and C++ standards and macOS architecture. ```cmake cmake_minimum_required(VERSION 3.10..4.0) project(libcrux-ml-kem VERSION 0.1.0 LANGUAGES C CXX ) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) set(CMAKE_OSX_ARCHITECTURES "x86_64") ``` -------------------------------- ### Add -fPIC on Linux Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Adds the -fPIC compiler option when building on Linux. ```cmake if(${CMAKE_SYSTEM_NAME} MATCHES Linux) add_compile_options( -fPIC ) endif(${CMAKE_SYSTEM_NAME} MATCHES Linux) ``` -------------------------------- ### Add NEON vectorized object library on arm64 Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Detects arm64 architecture and LIBCRUX_NEON environment variable, defines LIBCRUX_AARCH64, and adds an object library ml_dsa_vec128 from SOURCES_vec128 to both ml_dsa and ml_dsa_static. ```cmake # This is only for local testing and we assume neon on arm64. if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm64v8" AND DEFINED ENV{LIBCRUX_NEON}) message(STATUS "Detected an arm64 architecture") add_compile_definitions(LIBCRUX_AARCH64) add_library(ml_dsa_vec128 OBJECT ${SOURCES_vec128}) target_sources(ml_dsa_static PRIVATE $) target_sources(ml_dsa PRIVATE $) endif() ``` -------------------------------- ### Compiler options for non-MSVC builds Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-kem/CMakeLists.txt Adds warning flags and debug/release optimization flags for non-MSVC compilers. ```cmake if(NOT MSVC) # TODO: Clean up add_compile_options( -Wall # -Wextra # -pedantic # -Wconversion # -Wsign-conversion $<$:-g> $<$:-Og> $<$:-g> $<$:-O3> ) endif(NOT MSVC) ``` -------------------------------- ### Add AVX2 vectorized object library on x64 Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Detects x64 architecture, defines LIBCRUX_X64, creates an object library ml_dsa_vec256 from AVX2 sources, and adds it to both ml_dsa and ml_dsa_static. Adds -mavx and -mavx2 flags for non-MSVC. ```cmake # This is only for local testing and we assume avx2 on x64. if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") message(STATUS "Detected an x64 architecture") add_compile_definitions(LIBCRUX_X64) add_library(ml_dsa_vec256 OBJECT ${SOURCES_vec256}) target_sources(ml_dsa_static PRIVATE $) target_sources(ml_dsa PRIVATE $) if(NOT MSVC) target_compile_options(ml_dsa_vec256 PRIVATE -mavx -mavx2 ) endif(NOT MSVC) endif() ``` -------------------------------- ### Define LIBCRUX_UNPACKED if environment variable set Source: https://github.com/aeneasverif/eurydice/blob/main/test/libcrux-ml-dsa/CMakeLists.txt Adds the LIBCRUX_UNPACKED compile definition when the LIBCRUX_UNPACKED environment variable is defined. ```cmake # --- Tests if(DEFINED ENV{LIBCRUX_UNPACKED}) add_compile_definitions(LIBCRUX_UNPACKED) endif(DEFINED ENV{LIBCRUX_UNPACKED}) ```