### Installation Configuration (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/CMakeLists.txt Configures the installation process, including setting RPATH on macOS for faster installation, installing the library, headers, and export files, and creating a package configuration file. ```cmake include(GNUInstallDirs) # Build targets with install rpath on Mac to dramatically speed up installation # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir) if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}") endif() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) endif() unset(isSystemDir) # Install library install(TARGETS InfluxDB EXPORT InfluxDBTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) # Create version file include(CMakePackageConfigHelpers) write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/InfluxDBConfigVersion.cmake" VERSION ${PACKAGE_VERSION} COMPATIBILITY AnyNewerVersion ) # Install headers install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(FILES ${PROJECT_BINARY_DIR}/src/InfluxDB/influxdb_export.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/InfluxDB") # Export targets install(EXPORT InfluxDBTargets FILE InfluxDBTargets.cmake NAMESPACE InfluxData:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/InfluxDB ) ``` -------------------------------- ### Build influxdb-cxx with CMake Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Steps to build the influxdb-cxx library using CMake. Requires CMake 3.12+ and a C++20 compiler. Installs the library system-wide. ```bash mkdir build && cd build cmake .. sudo make install ``` -------------------------------- ### Install CMake Configuration Files Source: https://github.com/offa/influxdb-cxx/blob/master/CMakeLists.txt Installs the generated InfluxDB CMake configuration files to the appropriate directory. These files, InfluxDBConfig.cmake and InfluxDBConfigVersion.cmake, are essential for CMake-based projects that depend on the InfluxDB C++ client library. They are installed into the lib/cmake/InfluxDB subdirectory. ```cmake install( FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/InfluxDBConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/InfluxDBConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/InfluxDB ) ``` -------------------------------- ### Basic Point Write to InfluxDB Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Example of writing a single data point to InfluxDB using the C++ client. It requires specifying the InfluxDB URI and constructing a Point object with fields and tags. ```cpp // Provide complete URI auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); influxdb->write(influxdb::Point{\"test\"} .addField(\"value\", 10) .addTag(\"host\", \"localhost\") ); ``` -------------------------------- ### Query Data from InfluxDB Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Example of querying data from InfluxDB using the C++ client. This functionality is available over HTTP only and returns a vector of Point objects. ```cpp // Available over HTTP only auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); /// Pass an IFQL to get list of points std::vector points = influxdb->query("SELECT * FROM test"); ``` -------------------------------- ### Configure Public and Private Include Directories (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Sets the include directories for the main InfluxDB library. Public include directories are accessible during the build and installation, while private ones are only for internal use. ```cmake target_include_directories(InfluxDB PUBLIC $ $ # for export header $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) ``` -------------------------------- ### Configure Package Configuration File with CMake Source: https://github.com/offa/influxdb-cxx/blob/master/CMakeLists.txt Configures the InfluxDB CMake package configuration file. This function generates the necessary CMake files (e.g., InfluxDBConfig.cmake) to allow other projects to find and use the installed InfluxDB C++ library. It specifies the input template, output file, installation destination, and path variables. ```cmake configure_package_config_file( cmake/InfluxDBConfig.cmake.in cmake/InfluxDBConfig.cmake INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/InfluxDB" PATH_VARS CMAKE_INSTALL_PREFIX ) ``` -------------------------------- ### Create InfluxDB v1.x Compatible User (Shell) Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Command to create a v1.x compatible user for InfluxDB v2.x, which is necessary for using the v1.x compatibility backend. Requires specifying read and write buckets, username, and password. ```sh influx v1 auth create --read-bucket ${BUCKET_ID} --write-bucket ${BUCKET_ID} --username ${USERNAME} --password ${PASSWORD} ``` -------------------------------- ### Execute InfluxDB Command Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Demonstrates executing a raw InfluxDB command using the C++ client. The response from the command is returned as a string. ```cpp auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); // Execute a command and receive it's response const auto response = influxdb->execute("SHOW DATABASES"); ``` -------------------------------- ### Project Definition and Options (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/CMakeLists.txt Defines the minimum CMake version, project name, version, and description. It also sets various build options like shared libraries, Boost support, testing, system tests, coverage, and warning flags. ```cmake cmake_minimum_required(VERSION 3.12.0) # disable testsuite when included # using add_subdirectory if(DEFINED PROJECT_NAME) set(INCLUDED_AS_SUBPROJECT ON) set(INFLUXCXX_TESTING OFF CACHE BOOL "testing not available in sub-project") set(INFLUXCXX_SYSTEMTEST OFF CACHE BOOL "system testing not available in sub-project") set(INFLUXCXX_COVERAGE OFF CACHE BOOL "coverage not available in sub-project") endif() option(BUILD_SHARED_LIBS "Build shared versions of libraries" ON) option(INFLUXCXX_WITH_BOOST "Build with Boost support enabled" ON) option(INFLUXCXX_TESTING "Enable testing for this component" ON) option(INFLUXCXX_SYSTEMTEST "Enable system tests" ON) option(INFLUXCXX_COVERAGE "Enable Coverage" OFF) option(INFLUXCXX_WERROR "Build with -Werror enabled (if supported)" ON) # Define project project(influxdb-cxx VERSION 0.8.0 DESCRIPTION "InfluxDB C++ client library" LANGUAGES CXX ) message(STATUS "~~~ ${PROJECT_NAME} v${PROJECT_VERSION} ~~~ ") # Add compiler flags for warnings if(NOT MSVC AND NOT INCLUDED_AS_SUBPROJECT) add_compile_options(-Wall -Wextra -pedantic -pedantic-errors $<$:-Werror> -Wshadow -Wold-style-cast -Wnull-dereference -Wnon-virtual-dtor -Woverloaded-virtual ) endif() set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # We explicitly export the public interface set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) include(GenerateExportHeader) # Set fPIC for all targets set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Set the default build type to "RelWithDebInfo" if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE ) endif() message(STATUS "Build Type : ${CMAKE_BUILD_TYPE}") message(STATUS "Boost support : ${INFLUXCXX_WITH_BOOST}") message(STATUS "Unit Tests : ${INFLUXCXX_TESTING}") message(STATUS "System Tests : ${INFLUXCXX_SYSTEMTEST}") message(STATUS "Werror : ${INFLUXCXX_WERROR}") # Add coverage flags if(INFLUXCXX_COVERAGE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") endif() ``` -------------------------------- ### Configure HTTP Transport with Timeout and Auth Token Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Shows advanced configuration for the HTTP transport using the InfluxDBBuilder. This allows setting timeouts and authentication tokens beyond what's available in the URI. ```cpp auto influxdb = InfluxDBBuilder::http("http://localhost:8086?db=test") .setTimeout(std::chrono::seconds{20}) .setAuthToken("") .connect(); ``` -------------------------------- ### Batch Point Write to InfluxDB Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Demonstrates writing points to InfluxDB in batches. Points are collected until a specified batch size is reached or explicitly flushed. ```cpp auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); // Write batches of 100 points influxdb->batchOf(100); for (;;) { influxdb->write(influxdb::Point{\"test\}.addField(\"value\", 10)); } ``` -------------------------------- ### Define Include Directories (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Sets up internal include directories for the project, including the current source directory, the project's include folder, and the build directory's source folder. These are used for library targets. ```cmake set(INTERNAL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/src ) ``` -------------------------------- ### Create Main InfluxDB Library (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Constructs the main InfluxDB library by combining the object files from InfluxDB-Core, InfluxDB-Internal, and InfluxDB-BoostSupport. It also defines an alias target for easier referencing. ```cmake add_library(InfluxDB $ $ $ ) add_library(InfluxData::InfluxDB ALIAS InfluxDB) ``` -------------------------------- ### CMake: Find Required Packages Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Finds and makes required packages like Catch2 for testing and trompeloeil for mocking available to the CMake build. ```cmake find_package(Catch2 REQUIRED) find_package(trompeloeil REQUIRED) ``` -------------------------------- ### Library Compilation and Testing (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/CMakeLists.txt Compiles the main library by adding the 'src' subdirectory and enables testing by adding the 'test' subdirectory if testing is enabled. ```cmake # Create library # note: BUILD_SHARED_LIBS specifies if static or shared # as boost is build without -fPIC, we cannot # statically link against it when building # influxdb as shared object add_subdirectory("src") #################################### # Tests #################################### if (INFLUXCXX_TESTING) enable_testing() add_subdirectory("test") endif() ``` -------------------------------- ### CMake: Create Custom Target for Running All Unit Tests Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Creates a custom target named `unittest` that executes all defined unit tests sequentially. It includes conditional execution for the Boost support test based on the platform. ```cmake add_custom_target(unittest PointTest COMMAND LineProtocolTest COMMAND InfluxDBTest COMMAND InfluxDBFactoryTest COMMAND ProxyTest COMMAND HttpTest COMMAND UriParserTest COMMAND NoBoostSupportTest COMMAND $<\>,$\>>:BoostSupportTest> COMMENT "Running unit tests\n\n" VERBATIM ) ``` -------------------------------- ### Handle Boost ASIO Null Dereference Warning (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Applies a workaround for a potential null-dereference warning in Boost ASIO for GCC versions greater than 12. This compiler flag is applied to specific source files. ```cmake if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "12") set_source_files_properties(UDP.cxx TCP.cxx UnixSocket.cxx PROPERTIES COMPILE_OPTIONS "-Wno-null-dereference") endif() ``` -------------------------------- ### Create Boost Support Library (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Defines an OBJECT library for Boost-specific support. It conditionally includes Boost-related source files based on the INFLUXCXX_WITH_BOOST variable. It also sets include directories and links against the date library and optionally Boost. ```cmake add_library(InfluxDB-BoostSupport OBJECT $<$>:NoBoostSupport.cxx> $<$:BoostSupport.cxx UDP.cxx TCP.cxx UnixSocket.cxx> ) target_include_directories(InfluxDB-BoostSupport PRIVATE ${INTERNAL_INCLUDE_DIRS}) target_link_libraries(InfluxDB-BoostSupport PRIVATE date::date) if (INFLUXCXX_WITH_BOOST) target_link_libraries(InfluxDB-BoostSupport PRIVATE Boost::boost) endif() ``` -------------------------------- ### Create Internal Library (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Defines an OBJECT library for internal functionalities, including LineProtocol, HTTP, and linking against the cpr library. It also sets internal include directories. ```cmake add_library(InfluxDB-Internal OBJECT LineProtocol.cxx HTTP.cxx) target_include_directories(InfluxDB-Internal PRIVATE ${INTERNAL_INCLUDE_DIRS}) target_link_libraries(InfluxDB-Internal PRIVATE cpr::cpr) ``` -------------------------------- ### Create Core Library (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Defines the core OBJECT library for InfluxDB, including main C++ files like InfluxDB.cxx and Point.cxx. It sets public include directories and links against the cpr library. ```cmake add_library(InfluxDB-Core OBJECT InfluxDB.cxx Point.cxx InfluxDBFactory.cxx InfluxDBBuilder.cxx Proxy.cxx ) target_include_directories(InfluxDB-Core PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/src ) target_link_libraries(InfluxDB-Core PRIVATE cpr::cpr) ``` -------------------------------- ### CMake: Add Unit Tests for InfluxDB Client Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Adds multiple unit tests for different components of the InfluxDB client library using the `add_unittest` function. Each test can have specific dependencies on other libraries. ```cmake add_unittest(PointTest DEPENDS InfluxDB) add_unittest(LineProtocolTest DEPENDS InfluxDB InfluxDB-Internal) add_unittest(InfluxDBTest DEPENDS InfluxDB) add_unittest(InfluxDBFactoryTest DEPENDS InfluxDB) add_unittest(ProxyTest DEPENDS InfluxDB) add_unittest(HttpTest DEPENDS InfluxDB-Core InfluxDB-Internal InfluxDB-BoostSupport CprMock Threads::Threads) add_unittest(UriParserTest) ``` -------------------------------- ### CMake: Define Unit Test Functionality Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Defines a reusable CMake function `add_unittest` to create executables for unit tests. It links against Catch2, trompeloeil, Threads, and project-specific libraries, setting include directories and registering the test. ```cmake function(add_unittest name) set(multiValueArgs DEPENDS) cmake_parse_arguments(TEST_OPTION "" "" ${multiValueArgs} ${ARGN}) add_executable(${name} ${name}.cxx) target_link_libraries(${name} PRIVATE ${TEST_OPTION_DEPENDS} Catch2::Catch2WithMain trompeloeil::trompeloeil Threads::Threads ) target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/mock ) add_test(NAME ${name} COMMAND ${name}) endfunction() ``` -------------------------------- ### Include influxdb-cxx in a CMake Project Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Demonstrates how to integrate the InfluxDB C++ library into a CMake project. It involves finding the package and linking the target library to your executable. ```cmake project(example) find_package(InfluxDB) add_executable(example-influx main.cpp) target_link_libraries(example-influx PRIVATE InfluxData::InfluxDB) ``` -------------------------------- ### Include influxdb-cxx as a Subdirectory in CMake Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Shows how to include the influxdb-cxx library as a subdirectory within your CMake project. This method links the library directly without a separate find_package call. ```cmake project(example) add_subdirectory(influxdb-cxx) add_executable(example-influx main.cpp) target_link_libraries(example-influx PRIVATE InfluxData::InfluxDB) ``` -------------------------------- ### CMake: Add Dependency for Boost Support Test to All Tests Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Ensures that the `unittest` target depends on the `BoostSupportTest` if Boost support is enabled, guaranteeing it runs when the `unittest` target is invoked. ```cmake if (INFLUXCXX_WITH_BOOST) add_dependencies(unittest BoostSupportTest) endif() ``` -------------------------------- ### Link Main Library Targets (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Specifies the libraries that the main InfluxDB library should link against, including cpr for HTTP requests and Threads for threading support. ```cmake target_link_libraries(InfluxDB PUBLIC cpr::cpr Threads::Threads ) ``` -------------------------------- ### CMake: Conditionally Include System Tests Subdirectory Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Includes the 'system' subdirectory for system tests if the `INFLUXCXX_SYSTEMTEST` variable is enabled. ```cmake if (INFLUXCXX_SYSTEMTEST) add_subdirectory(system) endif() ``` -------------------------------- ### Dependency Management (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/CMakeLists.txt Manages project dependencies by finding required packages like Threads and cpr, and conditionally finding Boost. It also includes a local cmake module directory and adds a third-party subdirectory. ```cmake list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") find_package(Threads REQUIRED) find_package(cpr REQUIRED) if (INFLUXCXX_WITH_BOOST) # Fixes warning when using boost from brew set(Boost_USE_MULTITHREADED TRUE) find_package(Boost REQUIRED) endif() add_subdirectory(3rd-party) ``` -------------------------------- ### CMake: Configure trompeloeil Dependency Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Configures the trompeloeil library, creating an imported target if it doesn't exist and linking it as an interface library. It also sets `NOMINMAX` for MSVC builds. ```cmake if (NOT TARGET trompeloeil::trompeloeil) add_library(trompeloeil::trompeloeil INTERFACE IMPORTED) target_link_libraries(trompeloeil::trompeloeil INTERFACE trompeloeil) endif() if (MSVC) target_compile_definitions(trompeloeil::trompeloeil INTERFACE NOMINMAX) endif() ``` -------------------------------- ### Flush Pending Batches in InfluxDB C++ Client Source: https://github.com/offa/influxdb-cxx/blob/master/README.md Shows how to manually flush any pending batches of points to InfluxDB. This is crucial to ensure all collected points are sent, especially before the client is destroyed. ```cpp auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); influxdb->batchOf(3); influxdb->write(influxdb::Point{\"test\}.addField(\"value\", 1)); influxdb->write(influxdb::Point{\"test\}.addField(\"value\", 2)); // Flush batches, both points are written influxdb->flushBatch(); ``` -------------------------------- ### CMake: Add Unit Test without Boost Support Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Adds a unit test specifically for the scenario where Boost support is not enabled. It explicitly sets the source file and links against the InfluxDB library. ```cmake add_unittest(NoBoostSupportTest) target_sources(NoBoostSupportTest PRIVATE ${PROJECT_SOURCE_DIR}/src/NoBoostSupport.cxx) target_link_libraries(NoBoostSupportTest PRIVATE InfluxDB) ``` -------------------------------- ### CMake: Add Mock Subdirectory Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Adds the 'mock' subdirectory to the build, likely containing mock implementations for dependencies used in testing. ```cmake add_subdirectory("mock") ``` -------------------------------- ### CMake: Conditionally Add Boost Support Unit Test Source: https://github.com/offa/influxdb-cxx/blob/master/test/CMakeLists.txt Conditionally adds a unit test for Boost support if the `INFLUXCXX_WITH_BOOST` variable is true. This test depends on Boost libraries and other InfluxDB components. ```cmake if (INFLUXCXX_WITH_BOOST) add_unittest(BoostSupportTest DEPENDS InfluxDB-BoostSupport InfluxDB Boost::boost date::date) endif() ``` -------------------------------- ### Set Library Version Information (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Configures the version and shared object version (SOVERSION) for the main InfluxDB library. It uses a major version variable to define these properties. ```cmake set(SO_VERSION_MAJOR 1) set_target_properties(InfluxDB PROPERTIES VERSION ${SO_VERSION_MAJOR}.0.0 SOVERSION ${SO_VERSION_MAJOR} ) ``` -------------------------------- ### Set C++ Standard Feature (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Ensures that the InfluxDB library is compiled with the C++ standard specified by the CMAKE_CXX_STANDARD variable, promoting modern C++ practices. ```cmake target_compile_features(InfluxDB PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) ``` -------------------------------- ### Generate Export Header (CMake) Source: https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt Generates an export header file for the InfluxDB library, which is crucial for defining symbols that will be exported from the shared library. ```cmake generate_export_header(InfluxDB EXPORT_FILE_NAME "${PROJECT_BINARY_DIR}/src/InfluxDB/influxdb_export.h") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.