### Configure and Install Package Configuration Files Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Configures the main package configuration file and installs it along with the version file and find scripts. Ensure the installation destination is correctly set. ```cmake configure_package_config_file( ${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} PATH_VARS INCLUDE_INSTALL_DIR ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake # Install so it can be used in databentoConfig.cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findzstd.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) ``` -------------------------------- ### Install Databento C++ Library Locally Source: https://github.com/databento/databento-cpp/blob/main/README.md Build and install the databento-cpp library to a specified prefix (e.g., /usr) using CMake. This method is useful for system-wide installation or when not using FetchContent. ```sh git clone https://github.com/databento/databento-cpp cd databento-cpp cmake -S . -B build \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX='/usr' cmake --build build --target databento --parallel cmake --install build ``` -------------------------------- ### Install System and Version Headers Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Installs specific header files (system.hpp, version.hpp) into the project's include installation directory. ```cmake install( FILES ${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/system.hpp ${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp DESTINATION ${INCLUDE_INSTALL_DIR} ) ``` -------------------------------- ### Enable Examples in CMake Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Enables the building of examples for the project if the corresponding CMake variable is set. It also disables static analysis tools for examples and adds the examples subdirectory. ```cmake if(${PROJECT_NAME_UPPERCASE}_ENABLE_EXAMPLES) unset(CMAKE_CXX_CPPCHECK) # disable cppcheck for examples unset(CMAKE_CXX_CLANG_TIDY) # disable clang-tidy for examples message(STATUS "Build examples for the project.") add_subdirectory(examples) endif() ``` -------------------------------- ### Install Library Components Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Installs the project's targets, including libraries, archives, and headers, to standard installation directories. Conditional inclusion of external JSON and HTTP libraries is handled. ```cmake set(targets ${PROJECT_NAME}) if(NOT ${PROJECT_NAME_UPPERCASE}_USE_EXTERNAL_JSON) list(APPEND targets nlohmann_json) endif() if(NOT ${PROJECT_NAME_UPPERCASE}_USE_EXTERNAL_HTTPLIB) list(APPEND targets httplib) endif() include(GNUInstallDirs) install( TARGETS ${targets} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### Install Project License Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Installs the project's LICENSE file to the appropriate data directory for licenses. ```cmake install( FILES "LICENSE" DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/${PROJECT_NAME} ) ``` -------------------------------- ### Install Databento C++ Dependencies on macOS Source: https://github.com/databento/databento-cpp/blob/main/README.md Install necessary system dependencies for databento-cpp on macOS using Homebrew. Requires Homebrew to be installed. ```sh $ brew install openssl@3 zstd ``` -------------------------------- ### Set Properties for CMake Import Tests Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_import/CMakeLists.txt Sets properties for CMake import tests, defining setup and required fixtures for installation, configuration, and build steps. ```cmake set_tests_properties( cmake_import_install PROPERTIES FIXTURES_SETUP cmake_import ) set_tests_properties( cmake_import_configure PROPERTIES FIXTURES_SETUP cmake_import ) set_tests_properties( cmake_import_build PROPERTIES FIXTURES_REQUIRED cmake_import ) ``` -------------------------------- ### Install Project Include Directory Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Installs the project's public header files into the designated include directory, making them available for downstream projects. ```cmake set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) install( DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### Install Databento C++ Dependencies on Ubuntu Source: https://github.com/databento/databento-cpp/blob/main/README.md Install necessary system dependencies for databento-cpp on Ubuntu using apt. Requires root privileges. ```sh $ sudo apt update $ sudo apt install libssl-dev libzstd-dev ``` -------------------------------- ### Install Export CMake Package Configuration Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Installs the CMake export configuration file, which allows downstream projects to find and use the installed library via the specified namespace. ```cmake install( EXPORT ${PROJECT_NAME}Targets FILE ${PROJECT_NAME}Targets.cmake NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) ``` -------------------------------- ### Install Test Project with CMake Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_import/CMakeLists.txt Installs a test project using CMake. This command is typically used after building to stage the project for testing. ```cmake add_test( NAME cmake_import_install COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/pkg ) ``` -------------------------------- ### Fetch Live Trades with Databento C++ Source: https://github.com/databento/databento-cpp/blob/main/README.md Example C++ program to subscribe to live trades for ES mini futures for 10 seconds using the LiveThreaded client. Requires DATABENTO_API_KEY environment variable to be set. ```cpp #include #include #include #include #include namespace db = databento; int main() { db::PitSymbolMap symbol_mappings; auto client = db::LiveThreaded::Builder() .SetKeyFromEnv() .SetDataset(db::Dataset::GlbxMdp3) .BuildThreaded(); auto handler = [&symbol_mappings](const db::Record& rec) { symbol_mappings.OnRecord(rec); if (const auto* trade = rec.GetIf()) { std::cout << "Received trade for " << symbol_mappings[trade->hd.instrument_id] << ':' << *trade << '\n'; } return db::KeepGoing::Continue; }; client.Subscribe({"ES.FUT"}, db::Schema::Trades, db::SType::Parent); client.Start(handler); std::this_thread::sleep_for(std::chrono::seconds{10}); return 0; } ``` -------------------------------- ### Find and Link Databento C++ with CMake Source: https://github.com/databento/databento-cpp/blob/main/README.md After installing the databento-cpp library, use find_package to locate it and target_link_libraries to link it to your executable. ```cmake # CMakeLists.txt find_package(databento REQUIRED) target_link_libraries(example PRIVATE databento::databento) ``` -------------------------------- ### Find and Link Databento C++ Library with CMake Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_import/project/CMakeLists.txt Use `find_package` to locate the Databento library and `target_link_libraries` to link it to your executable. Ensure the Databento package is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.24) project(DummyImport LANGUAGES CXX) find_package(databento REQUIRED) add_executable(dummy main.cpp) target_link_libraries(dummy databento::databento) ``` -------------------------------- ### Generate Export Header Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Conditionally generates and installs an export header file if the `PROJECT_NAME_UPPERCASE_GENERATE_EXPORT_HEADER` variable is set. This is useful for defining exported symbols. ```cmake if(${PROJECT_NAME_UPPERCASE}_GENERATE_EXPORT_HEADER) include(GenerateExportHeader) generate_export_header(${PROJECT_NAME}) install( FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) message(STATUS "Generated the export header `${PROJECT_NAME}_export.h` and installed it.") endif() ``` -------------------------------- ### Fetch and Use databento-cpp with FetchContent Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_fetch_content/project/CMakeLists.txt This snippet configures CMake to fetch the databento-cpp project from its Git repository and makes it available for use. It then creates two executables, linking against the fetched library with and without its namespace. ```cmake cmake_minimum_required(VERSION 3.24) project(DummyImport LANGUAGES CXX) include(FetchContent) get_filename_component(GIT_REPOSITORY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE) FetchContent_Declare( databento GIT_REPOSITORY ${GIT_REPOSITORY_DIRECTORY} GIT_TAG HEAD ) FetchContent_MakeAvailable(databento) add_executable(with_namespace_target main.cpp) target_link_libraries(with_namespace_target databento::databento) add_executable(without_namespace_target main.cpp) target_link_libraries(without_namespace_target databento) ``` -------------------------------- ### Build Test Project with CMake Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_import/CMakeLists.txt Builds the test project using CMake. This command is executed after the project has been configured. ```cmake add_test( NAME cmake_import_build COMMAND ${CMAKE_COMMAND} --build . ) ``` -------------------------------- ### Integrate Databento C++ with CMake FetchContent Source: https://github.com/databento/databento-cpp/blob/main/README.md Use CMake FetchContent to easily embed the databento-cpp library into your project. Ensure your CMake version is at least 3.24. ```cmake cmake_minimum_required(VERSION 3.24) project(databento_example) include(FetchContent) FetchContent_Declare( databento GIT_REPOSITORY https://github.com/databento/databento-cpp GIT_TAG main ) FetchContent_MakeAvailable(databento) add_executable(example main.cpp) target_link_libraries(example PRIVATE databento::databento) ``` -------------------------------- ### Generate Package Version File Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Creates a basic package version file for CMake. Use this to define the version and compatibility of your package. ```cmake include(CMakePackageConfigHelpers) write_basic_package_version_file( ${PROJECT_NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY SameMinorVersion ) ``` -------------------------------- ### Configure Test Project with CMake Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_import/CMakeLists.txt Configures a test project using CMake. It specifies the generator, C++ compiler, and the directories for Databento and its dependencies (nlohmann_json, date, httplib). ```cmake add_test( NAME cmake_import_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -Ddatabento_DIR=${CMAKE_CURRENT_BINARY_DIR}/pkg/${CMAKE_INSTALL_LIBDIR}/cmake/databento -Dnlohmann_json_DIR=${nlohmann_json_BINARY_DIR} -Ddate_DIR=${CMAKE_CURRENT_BINARY_DIR}/pkg/${CMAKE_INSTALL_LIBDIR}/cmake/date -Dhttplib_DIR=${CMAKE_CURRENT_BINARY_DIR}/pkg/${CMAKE_INSTALL_LIBDIR}/cmake/httplib ${CMAKE_CURRENT_SOURCE_DIR}/project ) ``` -------------------------------- ### Configure cpp-httplib Dependency Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt This snippet configures the cpp-httplib dependency. It checks for an existing target, finds the package if not present, or uses FetchContent to download and build it. ```cmake # cpp-httplib if(${PROJECT_NAME_UPPERCASE}_USE_EXTERNAL_HTTPLIB) # Check if httplib target already exists if(TARGET httplib::httplib) get_target_property(HTTPLIB_SOURCE_DIR httplib::httplib SOURCE_DIR) message(STATUS "httplib::httplib already available as a target at ${HTTPLIB_SOURCE_DIR}") get_target_property(HTTPLIB_INCLUDE_DIRS httplib::httplib INTERFACE_INCLUDE_DIRECTORIES) if(HTTPLIB_INCLUDE_DIRS) message(STATUS "httplib::httplib include directories: ${HTTPLIB_INCLUDE_DIRS}") endif() else() find_package(httplib REQUIRED) endif() else() set(httplib_version 0.46.0) FetchContent_Declare( httplib URL https://github.com/yhirose/cpp-httplib/archive/refs/tags/v${httplib_version}.tar.gz DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) FetchContent_MakeAvailable(httplib) endif() ``` -------------------------------- ### Fetch Historical Trades in C++ Source: https://github.com/databento/databento-cpp/blob/main/README.md Fetches 10 minutes of historical trades for specified futures symbols. Requires setting the DATABENTO_API_KEY environment variable. ```cpp #include #include #include #include namespace db = databento; int main() { auto client = db::Historical::Builder().SetKey("$YOUR_API_KEY").Build(); auto store = client.TimeseriesGetRange( "GLBX.MDP3", {"2022-06-10T14:30", "2022-06-10T14:40"}, {"ESM2", "NQZ2"}, db::Schema::Trades); auto symbol_map = store.GetMetadata().CreateSymbolMap(); while (const auto* record = store.NextRecord()) { const auto& trade_msg = record->Get(); std::cout << "Received trade for " << symbol_map.At(trade_msg) << ": " << trade_msg << '\n'; } } ``` -------------------------------- ### Build CMake Test Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_fetch_content/CMakeLists.txt Defines a CMake test named 'cmake_fetch_content_build' to execute the build process for the project. This command is typically run after the configuration stage. ```cmake add_test( NAME cmake_fetch_content_build COMMAND ${CMAKE_COMMAND} --build . ) ``` -------------------------------- ### Configure nlohmann_json Dependency Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt This snippet shows how to configure the nlohmann_json dependency. It checks if the target already exists and uses it, otherwise it finds the package. If using FetchContent, it declares and makes the content available. ```cmake if(${PROJECT_NAME_UPPERCASE}_USE_EXTERNAL_JSON) # Check if json target already exists if(TARGET nlohmann_json::nlohmann_json) get_target_property(NLOHMANN_JSON_SOURCE_DIR nlohmann_json::nlohmann_json SOURCE_DIR) message(STATUS "nlohmann_json::nlohmann_json already available as a target at ${NLOHMANN_JSON_SOURCE_DIR}") get_target_property(NLOHMANN_JSON_INCLUDE_DIRS nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) if(NLOHMANN_JSON_INCLUDE_DIRS) message(STATUS "nlohmann_json::nlohmann_json include directories: ${NLOHMANN_JSON_INCLUDE_DIRS}") endif() else() find_package(nlohmann_json REQUIRED) endif() else() set(json_version 3.12.0) # Required to correctly install nlohmann_json set(JSON_Install ON) FetchContent_Declare( json URL https://github.com/nlohmann/json/releases/download/v${json_version}/json.tar.xz DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) FetchContent_MakeAvailable(json) # Ignore compiler warnings in headers add_system_include_property(nlohmann_json) endif() ``` -------------------------------- ### Configure CMake Test Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_fetch_content/CMakeLists.txt Defines a CMake test named 'cmake_fetch_content_configure' to set up the build environment. It specifies the generator, C++ compiler, and the source directory for the project. ```cmake add_test( NAME cmake_fetch_content_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/project ) if(DEFINED OPENSSL_ROOT_DIR) set_tests_properties( cmake_fetch_content_configure PROPERTIES ENVIRONMENT "OPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}" ) endif() ``` -------------------------------- ### Alias Library for Project Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Provides an alias for the project's library, allowing it to be referenced using a specific name in downstream projects. ```cmake add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) ``` -------------------------------- ### Set CMake Test Properties Source: https://github.com/databento/databento-cpp/blob/main/tests/cmake_fetch_content/CMakeLists.txt Configures properties for CMake tests, specifically setting up fixtures required for 'cmake_fetch_content_configure' and 'cmake_fetch_content_build' tests. This ensures necessary preconditions are met before test execution. ```cmake set_tests_properties( cmake_fetch_content_configure PROPERTIES FIXTURES_SETUP cmake_fetch_content ) set_tests_properties( cmake_fetch_content_build PROPERTIES FIXTURES_REQUIRED cmake_fetch_content ) ``` -------------------------------- ### Add clang-format Target Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Adds a target to the build system for formatting the project's code using clang-format. This can be invoked via `cmake --build build --target clang-format`. ```cmake add_clang_format_target() ``` -------------------------------- ### Platform-Specific Compile Definitions Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Adds the `NOMINMAX` compile definition when building on Windows. This is a common practice to avoid conflicts with Windows API macros. ```cmake if(WIN32) add_compile_definitions(NOMINMAX) endif() ``` -------------------------------- ### Enable Unit Testing in CMake Source: https://github.com/databento/databento-cpp/blob/main/CMakeLists.txt Enables unit testing for the project if the corresponding CMake variable is set. It also disables static analysis tools for tests and adds the tests subdirectory. ```cmake if(${PROJECT_NAME_UPPERCASE}_ENABLE_UNIT_TESTING) unset(CMAKE_CXX_CPPCHECK) # disable cppcheck for tests unset(CMAKE_CXX_CLANG_TIDY) # disable clang-tidy for tests enable_testing() message(STATUS "Build unit tests for the project.") add_subdirectory(tests) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.