### Installation and Documentation Options Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googlebenchmark/CMakeLists.txt Defines options related to installing the library and its documentation. `BENCHMARK_ENABLE_INSTALL` controls library installation, while `BENCHMARK_ENABLE_DOXYGEN` and `BENCHMARK_INSTALL_DOCS` control Doxygen documentation generation and installation. ```cmake option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" ON) option(BENCHMARK_ENABLE_DOXYGEN "Build documentation with Doxygen." OFF) option(BENCHMARK_INSTALL_DOCS "Enable installation of documentation." ON) ``` -------------------------------- ### Install Benchmark Library and Components (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googlebenchmark/src/CMakeLists.txt Installs the Benchmark library, headers, CMake configuration files, and pkg-config files to the appropriate system locations. This installation is conditional on the BENCHMARK_ENABLE_INSTALL flag. ```cmake if (BENCHMARK_ENABLE_INSTALL) # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable) install( TARGETS ${targets_to_export} EXPORT ${targets_export_name} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install( DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark" "${PROJECT_BINARY_DIR}/include/benchmark" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.*h") install( FILES "${project_config}" "${version_config}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") install( FILES "${pkg_config}" "${pkg_config_main}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install( EXPORT "${targets_export_name}" NAMESPACE "${namespace}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif() ``` -------------------------------- ### Install Rules for Google Mock Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googlemock/CMakeLists.txt This snippet defines the installation rules for the Google Mock project, specifying which targets to install. ```cmake install_project(gmock gmock_main) ``` -------------------------------- ### Install Configuration (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Configures the installation process for the project, including generating package configuration files (`.cmake`) and version files. This ensures that the project can be correctly found and used by other CMake projects. ```cmake if(NOA_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) configure_package_config_file( config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPATIBILITY SameMajorVersion) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" COMPONENT sourcemeta_noa_dev) endif() ``` -------------------------------- ### Install Noa Hash Library Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/src/hash/CMakeLists.txt Installs the Noa Hash library for the 'sourcemeta' namespace if the NOA_INSTALL flag is set. This ensures the library is available for use. ```cmake if(NOA_INSTALL) noa_library_install(NAMESPACE sourcemeta PROJECT noa NAME hash) endif() ``` -------------------------------- ### Install Project Rules for gtest and gtest_main Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googletest/CMakeLists.txt Applies installation rules for the gtest and gtest_main targets. This ensures that the built libraries are correctly installed for use in other projects. ```cmake install_project(gtest gtest_main) ``` -------------------------------- ### Configure Project and Options (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/alterschema/CMakeLists.txt Sets up the CMake project, defines build options for core components (engine, linter, tests, docs, install), and enables/disables sanitizers. These options control which parts of the project are built and with what features. ```cmake cmake_minimum_required(VERSION 3.16) project(alterschema VERSION 0.0.1 LANGUAGES CXX DESCRIPTION "Perform advanced transformations on JSON Schemas" HOMEPAGE_URL "https://alterschema.sourcemeta.com") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Options option(ALTERSCHEMA_ENGINE "Build the AlterSchema Engine library" ON) option(ALTERSCHEMA_LINTER "Build the AlterSchema Linter library" ON) option(ALTERSCHEMA_TESTS "Build the AlterSchema tests" OFF) option(ALTERSCHEMA_DOCS "Build the AlterSchema docs" OFF) option(ALTERSCHEMA_INSTALL "Install the AlterSchema library" ON) option(ALTERSCHEMA_ADDRESS_SANITIZER "Build AlterSchema with an address sanitizer" OFF) option(ALTERSCHEMA_UNDEFINED_SANITIZER "Build AlterSchema with an undefined behavior sanitizer" OFF) ``` -------------------------------- ### CMake Project Configuration and Setup for Google Mock Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googlemock/CMakeLists.txt This snippet configures the CMake project for Google Mock. It sets the minimum CMake version, project name, version, and languages. It also includes setup for hermetic builds and adds Google Test as a subdirectory. ```cmake cmake_minimum_required(VERSION 3.13) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") ``` -------------------------------- ### Define and Install Noa Flat Map Library Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/src/flat_map/CMakeLists.txt This snippet defines the 'flat_map' library within the 'sourcemeta.noa' namespace using the Noa build system. It includes conditional installation logic, ensuring the library is installed only when NOA_INSTALL is true. ```noa noa_library(NAMESPACE sourcemeta PROJECT noa NAME flat_map FOLDER "Noa/Flat Map") if(NOA_INSTALL) noa_library_install(NAMESPACE sourcemeta PROJECT noa NAME flat_map) endif() ``` -------------------------------- ### End-to-End JSONBinPack Workflow in C++ Source: https://context7.com/sourcemeta/jsonbinpack/llms.txt Demonstrates a complete workflow for JSONBinPack, from defining a JSON schema to compiling it, loading the encoding, encoding data, and finally decoding it. This example covers schema creation, compilation, encoding, and decoding, including verification of the round-trip process and reporting binary size. ```cpp #include #include #include #include #include #include // 1. Define JSON Schema auto schema = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "array", "items": { "type": "integer", "minimum": 0, "maximum": 255 }, "minItems": 3, "maxItems": 10 })JSON"); // 2. Compile schema to encoding sourcemeta::jsonbinpack::compile( schema, sourcemeta::core::schema_walker, sourcemeta::core::schema_resolver); // 3. Load encoding const sourcemeta::jsonbinpack::Encoding encoding{ sourcemeta::jsonbinpack::load(schema)}; // 4. Encode data auto instance = sourcemeta::core::parse_json("[100, 200, 150, 50]"); std::ofstream output_file("output.bin", std::ios::binary); sourcemeta::jsonbinpack::Encoder encoder{output_file}; encoder.write(instance, encoding); output_file.close(); // 5. Decode data std::ifstream input_file("output.bin", std::ios::binary); sourcemeta::jsonbinpack::Decoder decoder{input_file}; const sourcemeta::core::JSON result = decoder.read(encoding); input_file.close(); // 6. Verify round-trip if (result == instance) { std::cout << "Success! Round-trip encoding/decoding complete.\n"; std::cout << "Binary size: " << std::filesystem::file_size("output.bin") << " bytes\n"; } else { std::cerr << "Error: Decoded data doesn't match original\n"; } ``` -------------------------------- ### Configure Package Installation (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googletest/CMakeLists.txt This section details the CMake code for configuring and installing package configuration files (e.g., Config.cmake, ConfigVersion.cmake) for Google Test. It uses helper functions like 'write_basic_package_version_file' and 'configure_package_config_file' to generate these files, making Google Test easily discoverable by other CMake projects. ```cmake if (INSTALL_GTEST) include(CMakePackageConfigHelpers) set(targets_export_name ${cmake_package_name}Targets CACHE INTERNAL "") set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "") set(cmake_files_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${cmake_package_name}") set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake") write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion) install(EXPORT ${targets_export_name} COMPONENT "${PROJECT_NAME}" NAMESPACE ${cmake_package_name}:: DESTINATION ${cmake_files_install_dir}) set(config_file "${generated_dir}/${cmake_package_name}Config.cmake") configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in" "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir}) install(FILES ${version_file} ${config_file} COMPONENT "${PROJECT_NAME}" DESTINATION ${cmake_files_install_dir}) endif() ``` -------------------------------- ### CMake Project Setup and Options Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/CMakeLists.txt Initializes the CMake project, sets the project name and version, and defines various boolean options to control which components of the Sourcemeta Core library are built. These options allow fine-grained control over the library's features, dependencies, and build targets. ```cmake cmake_minimum_required(VERSION 3.16) project(core VERSION 0.0.0 LANGUAGES C CXX ASM_MASM DESCRIPTION "Sourcemeta Core") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Options option(SOURCEMETA_CORE_LANG_IO "Build the Sourcemeta Core language I/O library" ON) option(SOURCEMETA_CORE_LANG_PROCESS "Build the Sourcemeta Core language Process library" ON) option(SOURCEMETA_CORE_LANG_PARALLEL "Build the Sourcemeta Core language parallel library" ON) option(SOURCEMETA_CORE_LANG_NUMERIC "Build the Sourcemeta Core language numeric library" ON) option(SOURCEMETA_CORE_PUNYCODE "Build the Sourcemeta Core Punycode library" ON) option(SOURCEMETA_CORE_TIME "Build the Sourcemeta Core time library" ON) option(SOURCEMETA_CORE_UUID "Build the Sourcemeta Core UUID library" ON) option(SOURCEMETA_CORE_MD5 "Build the Sourcemeta Core MD5 library" ON) option(SOURCEMETA_CORE_REGEX "Build the Sourcemeta Core Regex library" ON) option(SOURCEMETA_CORE_URI "Build the Sourcemeta Core URI library" ON) option(SOURCEMETA_CORE_URITEMPLATE "Build the Sourcemeta Core URI Template library" ON) option(SOURCEMETA_CORE_JSON "Build the Sourcemeta Core JSON library" ON) option(SOURCEMETA_CORE_JSONSCHEMA "Build the Sourcemeta Core JSON Schema library" ON) option(SOURCEMETA_CORE_JSONPOINTER "Build the Sourcemeta Core JSON Pointer library" ON) option(SOURCEMETA_CORE_JSONL "Build the Sourcemeta Core JSONL library" ON) option(SOURCEMETA_CORE_YAML "Build the Sourcemeta Core YAML library" ON) option(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA "Build the Sourcemeta Core AlterSchema library" ON) option(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA "Build the Sourcemeta Core EditorSchema library" ON) option(SOURCEMETA_CORE_EXTENSION_SCHEMACONFIG "Build the Sourcemeta Core SchemaConfig library" ON) option(SOURCEMETA_CORE_EXTENSION_OPTIONS "Build the Sourcemeta Core Options library" ON) option(SOURCEMETA_CORE_EXTENSION_BUILD "Build the Sourcemeta Core Build library" ON) option(SOURCEMETA_CORE_TESTS "Build the Sourcemeta Core tests" OFF) option(SOURCEMETA_CORE_BENCHMARK "Build the Sourcemeta Core benchmarks" OFF) option(SOURCEMETA_CORE_DOCS "Build the Sourcemeta Core docs" OFF) option(SOURCEMETA_CORE_INSTALL "Install the Sourcemeta Core library" ON) option(SOURCEMETA_CORE_ADDRESS_SANITIZER "Build Sourcemeta Core with an address sanitizer" OFF) option(SOURCEMETA_CORE_UNDEFINED_SANITIZER "Build Sourcemeta Core with an undefined behavior sanitizer" OFF) option(SOURCEMETA_CORE_CONTRIB_GOOGLETEST "Build the GoogleTest library for downstream consumers" OFF) option(SOURCEMETA_CORE_CONTRIB_GOOGLEBENCHMARK "Build the GoogleBenchmark library for downstream consumers" OFF) include(Sourcemeta) # Don't force downstream consumers on this if(PROJECT_IS_TOP_LEVEL) sourcemeta_enable_simd() endif() ``` -------------------------------- ### Configure Package Installation (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/CMakeLists.txt Configures and installs package configuration files for CMake, including 'config.cmake' and 'config-version.cmake'. This is typically used for libraries to allow other CMake projects to find and use them. It depends on the 'GNUInstallDirs' and 'CMakePackageConfigHelpers' modules. ```cmake if(SOURCEMETA_CORE_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) configure_package_config_file( config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPATIBILITY SameMajorVersion) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" COMPONENT sourcemeta_${PROJECT_NAME}_dev) endif() ``` -------------------------------- ### CMake Minimum Required Version and Project Setup Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googlebenchmark/CMakeLists.txt Specifies the minimum required CMake version and sets the project name and supported languages. It also defines several build options that control features like testing, exceptions, LTO, and compiler warnings. ```cmake cmake_minimum_required (VERSION 3.10...3.22) project (benchmark VERSION 1.8.5 LANGUAGES CXX) option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON) option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF) option(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF) option(BENCHMARK_ENABLE_WERROR "Build Release candidates with -Werror." ON) option(BENCHMARK_FORCE_WERROR "Build Release candidates with -Werror regardless of compiler issues." OFF) ``` -------------------------------- ### CMake Build Configuration for jsonbinpack Project Source: https://github.com/sourcemeta/jsonbinpack/blob/main/test/packaging/find_package/CMakeLists.txt This CMakeLists.txt file sets up the build environment for the jsonbinpack project. It defines project metadata, C++ standard, and links necessary libraries for building the 'jsonbinpack_hello' executable. It requires CMake version 3.18 or higher and depends on the JSONBinPack package. ```cmake cmake_minimum_required(VERSION 3.18) project(jsonbinpack_hello VERSION 0.0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) find_package(JSONBinPack REQUIRED) add_executable(jsonbinpack_hello hello.cc) target_link_libraries(jsonbinpack_hello PRIVATE sourcemeta::jsonbinpack::runtime) target_link_libraries(jsonbinpack_hello PRIVATE sourcemeta::jsonbinpack::compiler) ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googlebenchmark/CMakeLists.txt Specifies the minimum required CMake version and initializes the project with its name, version, and languages. It supports CMake versions from 3.10 up to 3.22. ```cmake cmake_minimum_required (VERSION 3.10...3.22) project (benchmark VERSION 1.8.5 LANGUAGES CXX) ``` -------------------------------- ### Handle JSONBinPack Encoding Errors in C++ Source: https://context7.com/sourcemeta/jsonbinpack/llms.txt Demonstrates how to handle potential encoding errors using C++ exception handling. The example attempts an invalid encoding operation and catches `sourcemeta::jsonbinpack::EncodingError` or other standard exceptions, allowing for graceful error management such as logging or alternative processing. ```cpp #include #include #include #include try { auto document = sourcemeta::core::parse_json(R"({\"invalid\": \"data\"})"); std::ostringstream stream; sourcemeta::jsonbinpack::Encoder encoder{stream}; // Attempt to encode with wrong encoding type encoder.BOUNDED_MULTIPLE_8BITS_ENUM_FIXED(document, {0, 100, 1}); } catch (const sourcemeta::jsonbinpack::EncodingError &e) { std::cerr << "Encoding error: " << e.what() << std::endl; // Handle error: log, retry, or fail gracefully } catch (const std::exception &e) { std::cerr << "Unexpected error: " << e.what() << std::endl; } ``` -------------------------------- ### Configure Doxygen Documentation (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googlebenchmark/src/CMakeLists.txt Configures Doxygen to generate documentation for the Benchmark project. It sets various Doxygen options and uses the 'doxygen_add_docs' command to process the source files. The generated HTML documentation can be installed. ```cmake if (BENCHMARK_ENABLE_DOXYGEN) find_package(Doxygen REQUIRED) set(DOXYGEN_QUIET YES) set(DOXYGEN_RECURSIVE YES) set(DOXYGEN_GENERATE_HTML YES) set(DOXYGEN_GENERATE_MAN NO) set(DOXYGEN_MARKDOWN_SUPPORT YES) set(DOXYGEN_BUILTIN_STL_SUPPORT YES) set(DOXYGEN_EXTRACT_PACKAGE YES) set(DOXYGEN_EXTRACT_STATIC YES) set(DOXYGEN_SHOW_INCLUDE_FILES YES) set(DOXYGEN_BINARY_TOC YES) set(DOXYGEN_TOC_EXPAND YES) set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "index.md") doxygen_add_docs(benchmark_doxygen docs include src ALL WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Building documentation with Doxygen.") if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS) install( DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" DESTINATION ${CMAKE_INSTALL_DOCDIR}) endif() else() if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS) install( DIRECTORY "${PROJECT_SOURCE_DIR}/docs/" DESTINATION ${CMAKE_INSTALL_DOCDIR}) endif() endif() ``` -------------------------------- ### Configure Include Directories for gtest and gtest_main Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googletest/googletest/CMakeLists.txt Configures system include directories for 'gtest' and 'gtest_main'. It replaces ';' with '$' for directory paths and sets up build and installation interfaces. ```cmake string(REPLACE ";" "$" dirs "${gtest_build_include_dirs}") target_include_directories(gtest SYSTEM INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") target_include_directories(gtest_main SYSTEM INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") ``` -------------------------------- ### CMake Build Options Configuration Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googlebenchmark/CMakeLists.txt Defines various build options for the benchmark library using CMake's 'option' command. These options control features like testing, exceptions, LTO, libc++, warnings, installation, and dependency handling. ```cmake option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON) option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF) option(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF) option(BENCHMARK_ENABLE_WERROR "Build Release candidates with -Werror." ON) option(BENCHMARK_FORCE_WERROR "Build Release candidates with -Werror regardless of compiler issues." OFF) option(BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF) option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" ON) option(BENCHMARK_ENABLE_DOXYGEN "Build documentation with Doxygen." OFF) option(BENCHMARK_INSTALL_DOCS "Enable installation of documentation." ON) option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF) option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON) option(BENCHMARK_USE_BUNDLED_GTEST "Use bundled GoogleTest. If disabled, the find_package(GTest) will be used." ON) option(BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF) ``` -------------------------------- ### Install Linter Library (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/alterschema/src/linter/CMakeLists.txt This CMake code snippet conditionally installs the 'alterschema' linter library under the 'sourcemeta' namespace if the ALTERSCHEMA_INSTALL flag is set. It uses the 'noa_library_install' function for this purpose. ```cmake if(ALTERSCHEMA_INSTALL) noa_library_install(NAMESPACE sourcemeta PROJECT alterschema NAME linter) endif() ``` -------------------------------- ### Configure Package Configuration Files (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googlebenchmark/src/CMakeLists.txt Generates CMake package configuration files (Config.cmake.in and ConfigVersion.cmake) and pkg-config files (.pc) for the Benchmark project. These files are essential for other projects to find and use the installed Benchmark library. ```cmake set(generated_dir "${PROJECT_BINARY_DIR}") set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc") set(pkg_config_main "${generated_dir}/${PROJECT_NAME}_main.pc") include(CMakePackageConfigHelpers) configure_package_config_file ( ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in ${project_config} INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO ) write_basic_package_version_file( "${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion ) configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark_main.pc.in" "${pkg_config_main}" @ONLY) ``` -------------------------------- ### CMake Configuration for Google Mock Build Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googletest/googlemock/CMakeLists.txt This CMake script sets up the build environment for Google Mock. It includes options for building tests, finding Google Test sources, and configuring project-wide settings like the minimum CMake version and project name. It also handles hermetic build setups. ```cmake option(gmock_build_tests "Build all of Google Mock's own tests." OFF) # A directory to find Google Test sources. if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") set(gtest_dir gtest) else() set(gtest_dir ../googletest) endif() # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) if (COMMAND pre_project_set_up_hermetic_build) # Google Test also calls hermetic setup functions from add_subdirectory, # although its changes will not affect things at the current scope. pre_project_set_up_hermetic_build() endif() # Project-wide settings # Name of the project. # # CMake files in this project can refer to the root source directory # as ${gmock_SOURCE_DIR} and to the root binary directory as # ${gmock_BINARY_DIR}. # Language "C" is required for find_package(Threads). cmake_minimum_required(VERSION 3.13) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() # Instructs CMake to process Google Test's CMakeLists.txt and add its # targets to the current scope. We are placing Google Test's binary # directory in a subdirectory of our own as VC compilation may break # if they are the same (the default). add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") # These commands only run if this is the main project if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to # make it prominent in the GUI. option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) else() mark_as_advanced(gmock_build_tests) endif() # Although Google Test's CMakeLists.txt calls this function, the # changes there don't affect the current scope. Therefore we have to # call it again here. config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake # Adds Google Mock's and Google Test's header directories to the search path. # Get Google Test's include dirs from the target, gtest_SOURCE_DIR is broken # when using fetch-content with the name "GTest". get_target_property(gtest_include_dirs gtest INCLUDE_DIRECTORIES) set(gmock_build_include_dirs "${gmock_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}" "${gtest_include_dirs}") include_directories(${gmock_build_include_dirs}) ``` -------------------------------- ### Export Targets for CMake (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googlebenchmark/src/CMakeLists.txt Exports the defined targets (benchmark and benchmark_main) for use by other CMake projects. This creates a CMake file that allows other projects to find and link against the installed Benchmark library. ```cmake set(targets_to_export benchmark benchmark_main) set(targets_export_name "${PROJECT_NAME}Targets") set(namespace "${PROJECT_NAME}::") export ( TARGETS ${targets_to_export} NAMESPACE "${namespace}" FILE ${generated_dir}/${targets_export_name}.cmake ) ``` -------------------------------- ### Configure CXX Library for gtest and gtest_main Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googletest/CMakeLists.txt Defines the cxx_library targets for gtest and gtest_main, setting properties like version and conditionally linking against ABSL libraries if defined. It also configures system include directories for both build and install interfaces. ```cmake cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) set_target_properties(gtest PROPERTIES VERSION ${GOOGLETEST_VERSION}) if(GTEST_HAS_ABSL) target_compile_definitions(gtest PUBLIC GTEST_HAS_ABSL=1) target_link_libraries(gtest PUBLIC absl::failure_signal_handler absl::stacktrace absl::symbolize absl::flags_parse absl::flags_reflection absl::flags_usage absl::strings absl::any absl::optional absl::variant re2::re2 ) endif() cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) string(REPLACE ";" "$" dirs "${gtest_build_include_dirs}") target_include_directories(gtest SYSTEM INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>" ) target_include_directories(gtest_main SYSTEM INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>" ) if(CMAKE_SYSTEM_NAME MATCHES "QNX" AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 7.1) target_link_libraries(gtest PUBLIC regex) endif() target_link_libraries(gtest_main PUBLIC gtest) ``` -------------------------------- ### Define Sourcemeta Core Parallel Library (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/src/lang/parallel/CMakeLists.txt Defines the 'sourcemeta_core_parallel' library within the sourcemeta namespace. It specifies the private header 'for_each.h' and conditionally installs the library if SOURCEMETA_CORE_INSTALL is enabled. ```cmake sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME parallel PRIVATE_HEADERS for_each.h) if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME parallel) endif() ``` -------------------------------- ### Conditional GoogleTest and GoogleBenchmark Setup in CMake Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/CMakeLists.txt This snippet configures the project to find and use GoogleTest and GoogleBenchmark based on CMake variables. It ensures that testing is enabled and specific test subdirectories are added if the corresponding language or feature flags are set. ```cmake if(SOURCEMETA_CORE_CONTRIB_GOOGLETEST OR SOURCEMETA_CORE_TESTS) find_package(GoogleTest REQUIRED) endif() if(SOURCEMETA_CORE_CONTRIB_GOOGLEBENCHMARK OR SOURCEMETA_CORE_BENCHMARK) find_package(GoogleBenchmark REQUIRED) endif() if(SOURCEMETA_CORE_TESTS) enable_testing() if(SOURCEMETA_CORE_LANG_IO) add_subdirectory(test/io) endif() if(SOURCEMETA_CORE_LANG_PROCESS) add_subdirectory(test/process) endif() if(SOURCEMETA_CORE_LANG_PARALLEL) add_subdirectory(test/parallel) endif() if(SOURCEMETA_CORE_LANG_NUMERIC) add_subdirectory(test/numeric) endif() if(SOURCEMETA_CORE_PUNYCODE) add_subdirectory(test/punycode) endif() if(SOURCEMETA_CORE_TIME) add_subdirectory(test/time) endif() if(SOURCEMETA_CORE_UUID) add_subdirectory(test/uuid) endif() if(SOURCEMETA_CORE_MD5) add_subdirectory(test/md5) endif() if(SOURCEMETA_CORE_REGEX) add_subdirectory(test/regex) endif() if(SOURCEMETA_CORE_URI) add_subdirectory(test/uri) endif() if(SOURCEMETA_CORE_URITEMPLATE) add_subdirectory(test/uritemplate) endif() if(SOURCEMETA_CORE_JSON) add_subdirectory(test/json) endif() if(SOURCEMETA_CORE_JSONPOINTER) add_subdirectory(test/jsonpointer) endif() if(SOURCEMETA_CORE_JSONSCHEMA) add_subdirectory(test/jsonschema) endif() if(SOURCEMETA_CORE_JSONL) add_subdirectory(test/jsonl) endif() if(SOURCEMETA_CORE_YAML) add_subdirectory(test/yaml) endif() if(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA) add_subdirectory(test/alterschema) endif() if(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA) add_subdirectory(test/editorschema) endif() if(SOURCEMETA_CORE_EXTENSION_SCHEMACONFIG) add_subdirectory(test/schemaconfig) endif() if(SOURCEMETA_CORE_EXTENSION_OPTIONS) add_subdirectory(test/options) endif() if(SOURCEMETA_CORE_EXTENSION_BUILD) add_subdirectory(test/build) endif() if(PROJECT_IS_TOP_LEVEL) if(NOT SOURCEMETA_CORE_ADDRESS_SANITIZER AND NOT SOURCEMETA_CORE_UNDEFINED_SANITIZER) add_subdirectory(test/packaging) endif() endif() endif() if(SOURCEMETA_CORE_BENCHMARK) add_subdirectory(benchmark) endif() ``` -------------------------------- ### CMakeLists.txt Configuration for Googletest Build Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googletest/CMakeLists.txt This snippet is the main CMakeLists.txt file for the googletest distribution. It sets the minimum CMake version, project name, and GoogleTest version. It also includes options for building GoogleMock, installing GoogleTest, and integrating with Abseil and RE2 libraries. The configuration dynamically adds subdirectories based on build options. ```cmake cmake_minimum_required(VERSION 3.13) project(googletest-distribution) set(GOOGGTEST_VERSION 1.14.0) if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) set(CMAKE_CXX_EXTENSIONS OFF) endif() enable_testing() include(CMakeDependentOption) include(GNUInstallDirs) # Note that googlemock target already builds googletest. option(BUILD_GMOCK "Builds the googlemock subproject" ON) option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) if(GTEST_HAS_ABSL) if(NOT TARGET absl::base) find_package(absl REQUIRED) endif() if(NOT TARGET re2::re2) find_package(re2 REQUIRED) endif() endif() if(BUILD_GMOCK) add_subdirectory( googlemock ) else() add_subdirectory( googletest ) endif() ``` -------------------------------- ### Configure Project and Options (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Sets up the minimum CMake version, project details, and defines various build options for different components such as Hash, Flat Map, Regex, Google Test, and Google Benchmark. These options control which parts of the project are built and included. ```cmake cmake_minimum_required(VERSION 3.16) project(noa VERSION 0.0.0 LANGUAGES CXX DESCRIPTION "A set of re-usable and opinionated utilities for Sourcemeta projects") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(noa) # Options option(NOA_HASH "Build the Noa Hash library" ON) option(NOA_FLAT_MAP "Build the Noa Flat Map library" ON) option(NOA_REGEX "Build the Noa Regex library" ON) option(NOA_GOOGLETEST "Build the Google Test library" ON) option(NOA_GOOGLEBENCHMARK "Build the Google Benchmark library" ON) option(NOA_TESTS "Build the Noa tests" OFF) option(NOA_BENCHMARK "Build the Noa benchmarks" OFF) option(NOA_DOCS "Build the Noa docs" OFF) option(NOA_INSTALL "Install the Noa library" ON) option(NOA_ADDRESS_SANITIZER "Build Noa with an address sanitizer" OFF) option(NOA_UNDEFINED_SANITIZER "Build Noa with an undefined behavior sanitizer" OFF) ``` -------------------------------- ### Configure Testing Frameworks (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Finds and enables Google Test and Google Benchmark if their respective build options are enabled. This prepares the build environment for unit tests and performance benchmarks. ```cmake if(NOA_GOOGLETEST) find_package(GoogleTest REQUIRED) endif() if(NOA_GOOGLEBENCHMARK) find_package(GoogleBenchmark REQUIRED) endif() ``` -------------------------------- ### Get Flag Value with GMOCK_FLAG_GET Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googlemock/include/gmock/internal/custom/README.md This macro retrieves the current value of a specified flag. It takes the flag name as an argument and is used to access the configured flag values. ```c++ #define GMOCK_FLAG_GET(flag_name) ``` -------------------------------- ### Configure Testing and Packaging (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/alterschema/CMakeLists.txt Enables testing if configured, adds subdirectories for engine and linter tests, and includes packaging tests. This section ensures that the project's functionality is verified and properly packaged. ```cmake # Testing if(ALTERSCHEMA_TESTS) enable_testing() if(ALTERSCHEMA_ENGINE) add_subdirectory(test/engine) endif() if(ALTERSCHEMA_LINTER) add_subdirectory(test/linter) endif() if(PROJECT_IS_TOP_LEVEL) # Otherwise we need the child project to link # against the sanitizers too. if(NOT ALTERSCHEMA_ADDRESS_SANITIZER AND NOT ALTERSCHEMA_UNDEFINED_SANITIZER) add_subdirectory(test/packaging) endif() endif() endif() ``` -------------------------------- ### Define Sourcemeta Core URI Library Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/src/core/uri/CMakeLists.txt Defines the Sourcemeta core library for handling URIs. It lists private headers and source files, and includes conditional installation logic. ```cmake sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME uri PRIVATE_HEADERS error.h SOURCES uri.cc parse.cc accessors.cc setters.cc recompose.cc canonicalize.cc resolution.cc filesystem.cc escaping.h normalize.h grammar.h) if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME uri) endif() ``` -------------------------------- ### Build C++ Tests with Google Mock using CMake Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googletest/googlemock/CMakeLists.txt This snippet shows how to enable testing and build various C++ test executables using the `cxx_test` macro, which likely integrates with Google Mock. It includes setting up testing, conditional compilation for specific platforms (MINGW, CYGWIN), and building tests like `gmock-actions_test` and `gmock_test`. ```cmake if (gmock_build_tests) # This must be set in the root directory for the tests to be run by # 'make test' or ctest. enable_testing() if (MINGW OR CYGWIN) add_compile_options("-Wa,-mbig-obj") endif() ############################################################ # C++ tests built with standard compiler flags. cxx_test(gmock-actions_test gmock_main) cxx_test(gmock-cardinalities_test gmock_main) cxx_test(gmock_ex_test gmock_main) cxx_test(gmock-function-mocker_test gmock_main) cxx_test(gmock-internal-utils_test gmock_main) cxx_test(gmock-matchers-arithmetic_test gmock_main) cxx_test(gmock-matchers-comparisons_test gmock_main) cxx_test(gmock-matchers-containers_test gmock_main) cxx_test(gmock-matchers-misc_test gmock_main) cxx_test(gmock-more-actions_test gmock_main) cxx_test(gmock-nice-strict_test gmock_main) cxx_test(gmock-port_test gmock_main) cxx_test(gmock-spec-builders_test gmock_main) cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) cxx_test(gmock_test gmock_main) if (DEFINED GTEST_HAS_PTHREAD) cxx_test(gmock_stress_test gmock) endif() # gmock_all_test is commented to save time building and running tests. # Uncomment if necessary. # cxx_test(gmock_all_test gmock_main) endif() ``` -------------------------------- ### Documentation Generation (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Configures Doxygen for generating project documentation if the NOA_DOCS option is enabled. It specifies the Doxygen configuration file and the output directory for the generated website. ```cmake if(NOA_DOCS) noa_target_doxygen(CONFIG "${PROJECT_SOURCE_DIR}/doxygen/Doxyfile.in" OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/website") endif() ``` -------------------------------- ### Enable and Configure Tests (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Enables CMake's testing infrastructure and conditionally adds subdirectories for tests related to Hash, Flat Map, and Regex libraries. It also handles specific packaging tests based on sanitizer configurations. ```cmake if(NOA_TESTS AND NOA_GOOGLETEST) enable_testing() if(NOA_HASH) add_subdirectory(test/hash) endif() if(NOA_FLAT_MAP) add_subdirectory(test/flat_map) endif() if(NOA_REGEX) add_subdirectory(test/regex) endif() if(PROJECT_IS_TOP_LEVEL) # Otherwise we need the child project to link # against the sanitizers too. if(NOT NOA_ADDRESS_SANITIZER AND NOT NOA_UNDEFINED_SANITIZER) add_subdirectory(test/packaging) endif() endif() endif() ``` -------------------------------- ### Conditional Linking for QNX Systems Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googletest/googletest/CMakeLists.txt Conditionally links the 'regex' library to 'gtest' for QNX systems with version 7.1 or greater. ```cmake if(CMAKE_SYSTEM_NAME MATCHES "QNX" AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 7.1) target_link_libraries(gtest PUBLIC regex) endif() ``` -------------------------------- ### Configure Noa Regex Library Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/src/regex/CMakeLists.txt Defines the Noa library for regex functionality within the sourcemeta project. It specifies the namespace, project name, and folder location. The library is installed only if NOA_INSTALL is set to true. ```cmake noa_library(NAMESPACE sourcemeta PROJECT noa NAME regex FOLDER "Noa/Regex") if(NOA_INSTALL) noa_library_install(NAMESPACE sourcemeta PROJECT noa NAME regex) endif() target_link_libraries(sourcemeta_noa_regex INTERFACE Boost::regex) ``` -------------------------------- ### Add Benchmark Directory (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Conditionally adds the benchmark subdirectory for building performance benchmarks if the NOA_BENCHMARK and NOA_GOOGLEBENCHMARK options are enabled. ```cmake if(NOA_BENCHMARK AND NOA_GOOGLEBENCHMARK) add_subdirectory(benchmark) endif() ``` -------------------------------- ### Configure Sourcemeta Core Regex Library (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/src/core/regex/CMakeLists.txt Configures the sourcemeta_library for the core regex module. It specifies source files and links against the PCRE2 library for regular expression functionality. This configuration is part of the build system setup. ```cmake sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME regex SOURCES regex.cc preprocess.h) if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME regex) endif() target_link_libraries(sourcemeta_core_regex PRIVATE PCRE2::pcre2) ``` -------------------------------- ### Define Sourcemeta YAML Library (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/src/core/yaml/CMakeLists.txt Defines the Sourcemeta YAML library using CMake. It specifies the namespace, project, core name, private headers, and source files. The library is conditionally installed based on the SOURCEMETA_CORE_INSTALL flag. ```cmake sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME yaml PRIVATE_HEADERS error.h SOURCES yaml.cc) if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME yaml) endif() ``` -------------------------------- ### Code Quality Tools Configuration (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/CMakeLists.txt Sets up clang-format and clang-tidy checks for source files if the project is the top-level build. This enforces code style and helps identify potential code issues. ```cmake if(PROJECT_IS_TOP_LEVEL) noa_target_clang_format(SOURCES benchmark/*.h benchmark/*.cc src/*.h src/*.cc test/*.h test/*.cc) noa_target_clang_tidy(SOURCES src/*.h src/*.cc) endif() ``` -------------------------------- ### Manage Dependencies and Subdirectories (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/alterschema/CMakeLists.txt Finds required packages (Noa, JSONToolkit) and includes subdirectories for building specific components like the engine and linter. This orchestrates the build process based on selected options. ```cmake find_package(Noa REQUIRED) if(ALTERSCHEMA_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) configure_package_config_file( config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPATIBILITY SameMajorVersion) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" COMPONENT sourcemeta_alterschema_dev) endif() if(ALTERSCHEMA_ENGINE OR ALTERSCHEMA_LINTER) find_package(JSONToolkit REQUIRED) add_subdirectory(src/engine) endif() if(ALTERSCHEMA_LINTER) add_subdirectory(src/linter) endif() ``` -------------------------------- ### Build C++ Tests with Standard Flags (CMake) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googlemock/CMakeLists.txt This section details the CMake commands for building various C++ tests for Google Mock using standard compiler flags. It includes enabling testing and defining test executables like 'gmock-actions_test' linked against 'gmock_main'. ```cmake if (gmock_build_tests) enable_testing() if (MINGW OR CYGWIN) add_compile_options("-Wa,-mbig-obj") endif() cxx_test(gmock-actions_test gmock_main) cxx_test(gmock-cardinalities_test gmock_main) cxx_test(gmock_ex_test gmock_main) cxx_test(gmock-function-mocker_test gmock_main) cxx_test(gmock-internal-utils_test gmock_main) cxx_test(gmock-matchers-arithmetic_test gmock_main) cxx_test(gmock-matchers-comparisons_test gmock_main) cxx_test(gmock-matchers-containers_test gmock_main) cxx_test(gmock-matchers-misc_test gmock_main) cxx_test(gmock-more-actions_test gmock_main) cxx_test(gmock-nice-strict_test gmock_main) cxx_test(gmock-port_test gmock_main) cxx_test(gmock-spec-builders_test gmock_main) cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) cxx_test(gmock_test gmock_main) if (DEFINED GTEST_HAS_PTHREAD) cxx_test(gmock_stress_test gmock) endif() endif() ``` -------------------------------- ### Google Mock Library Definitions (MSVC) Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/core/vendor/googletest/googlemock/CMakeLists.txt Defines the 'gmock' and 'gmock_main' libraries for MSVC compilers. It uses strict compiler warnings and includes necessary source files. ```cmake if (MSVC) cxx_library(gmock "${cxx_strict}" "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc) cxx_library(gmock_main "${cxx_strict}" "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) endif() ``` -------------------------------- ### Dependency Management Option Source: https://github.com/sourcemeta/jsonbinpack/blob/main/vendor/noa/vendor/googlebenchmark/CMakeLists.txt Introduces the `BENCHMARK_DOWNLOAD_DEPENDENCIES` option, which allows CMake to download and build unmet dependencies if they are not found. This is useful for ensuring all necessary components are available for the build. ```cmake # Allow unmet dependencies to be met using CMake's ExternalProject mechanics, which # may require downloading the source code. option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF) ```