### Build and Install oatpp-postgresql Source: https://github.com/oatpp/oatpp-postgresql/blob/master/README.md Instructions for building and installing the oatpp-postgresql library using CMake and Make. Requires the main oatpp module and PostgreSQL dev package. ```bash mkdir build && cd build cmake .. make install ``` -------------------------------- ### Connect to PostgreSQL Database Source: https://github.com/oatpp/oatpp-postgresql/blob/master/README.md Example C++ code demonstrating how to create a `DbClient` component for PostgreSQL. It involves setting up a `ConnectionProvider`, `ConnectionPool`, and `Executor`. ```cpp #include "db/MyClient.hpp" #include "oatpp-postgresql/orm.hpp" class AppComponent { public: /** * Create DbClient component. */ OATPP_CREATE_COMPONENT(std::shared_ptr, myDatabaseClient)([] { /* Create database-specific ConnectionProvider */ auto connectionProvider = std::make_shared(""); /* Create database-specific ConnectionPool */ auto connectionPool = oatpp::postgresql::ConnectionPool::createShared(connectionProvider, 10 /* max-connections */, std::chrono::seconds(5) /* connection TTL */); /* Create database-specific Executor */ auto executor = std::make_shared(connectionPool); /* Create MyClient database client */ return std::make_shared(executor); }()); }; ``` -------------------------------- ### Configure oatpp-postgresql Module Build Source: https://github.com/oatpp/oatpp-postgresql/blob/master/src/CMakeLists.txt Configures the CMake build for the oatpp-postgresql module. It defines the source files, sets C++ standard and extensions, links against the core oatpp library and PostgreSQL libraries, and specifies include directories. It also includes conditional compilation options for MSVC and handles module installation. ```CMake add_library(${OATPP_THIS_MODULE_NAME} oatpp-postgresql/mapping/type/Uuid.cpp oatpp-postgresql/mapping/type/Uuid.hpp oatpp-postgresql/mapping/Deserializer.cpp oatpp-postgresql/mapping/Deserializer.hpp oatpp-postgresql/mapping/Oid.hpp oatpp-postgresql/mapping/PgArray.cpp oatpp-postgresql/mapping/PgArray.hpp oatpp-postgresql/mapping/ResultMapper.cpp oatpp-postgresql/mapping/ResultMapper.hpp oatpp-postgresql/mapping/Serializer.cpp oatpp-postgresql/mapping/Serializer.hpp oatpp-postgresql/ql_template/Parser.cpp oatpp-postgresql/ql_template/Parser.hpp oatpp-postgresql/ql_template/TemplateValueProvider.cpp oatpp-postgresql/ql_template/TemplateValueProvider.hpp oatpp-postgresql/Connection.cpp oatpp-postgresql/Connection.hpp oatpp-postgresql/ConnectionProvider.cpp oatpp-postgresql/ConnectionProvider.hpp oatpp-postgresql/Executor.cpp oatpp-postgresql/Executor.hpp oatpp-postgresql/QueryResult.cpp oatpp-postgresql/QueryResult.hpp oatpp-postgresql/Types.hpp oatpp-postgresql/orm.hpp) set_target_properties(${OATPP_THIS_MODULE_NAME} PROPERTIES CXX_STANDARD 11 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON ) if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL) add_dependencies(${OATPP_THIS_MODULE_NAME} ${LIB_OATPP_EXTERNAL}) endif() target_link_oatpp(${OATPP_THIS_MODULE_NAME}) target_include_directories(${OATPP_THIS_MODULE_NAME} PUBLIC $ ${PostgreSQL_INCLUDE_DIRS} ) target_link_libraries(${OATPP_THIS_MODULE_NAME} PUBLIC ${PostgreSQL_LIBRARIES} ) if(MSVC) target_compile_options(${OATPP_THIS_MODULE_NAME} PRIVATE "/bigobj") endif() ####################################################################################################### ## install targets if(OATPP_INSTALL) include("../cmake/module-install.cmake") endif() ``` -------------------------------- ### CMake Configuration for oatpp-postgresql Source: https://github.com/oatpp/oatpp-postgresql/blob/master/test/CMakeLists.txt This CMake script defines the build process for the oatpp-postgresql module. It configures database connection details, sets up the `module-tests` executable with specified source files and C++ standard, manages dependencies, and links necessary libraries. ```cmake if(DEFINED ENV{PG_HOST}) set(POSTGRES_HOST $ENV{PG_HOST}) else() set(POSTGRES_HOST localhost) endif() message("POSTGRES_HOST=${POSTGRES_HOST}") add_definitions ( -DTEST_DB_URL="postgresql://postgres:db-pass@${POSTGRES_HOST}:5432/postgres" -DTEST_DB_MIGRATION="${CMAKE_CURRENT_SOURCE_DIR}/oatpp-postgresql/migration/" ) add_executable(module-tests oatpp-postgresql/ql_template/ParserTest.cpp oatpp-postgresql/ql_template/ParserTest.hpp oatpp-postgresql/types/ArrayTest.cpp oatpp-postgresql/types/ArrayTest.hpp oatpp-postgresql/types/FloatTest.cpp oatpp-postgresql/types/FloatTest.hpp oatpp-postgresql/types/InterpretationTest.cpp oatpp-postgresql/types/InterpretationTest.hpp oatpp-postgresql/types/IntTest.cpp oatpp-postgresql/types/IntTest.hpp oatpp-postgresql/types/CharacterTest.cpp oatpp-postgresql/types/CharacterTest.hpp oatpp-postgresql/tests.cpp ) set_target_properties(module-tests PROPERTIES CXX_STANDARD 11 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON ) target_include_directories(module-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL) add_dependencies(module-tests ${LIB_OATPP_EXTERNAL}) endif() add_dependencies(module-tests ${OATPP_THIS_MODULE_NAME}) target_link_oatpp(module-tests) target_link_libraries(module-tests PRIVATE ${OATPP_THIS_MODULE_NAME} ) ## TODO link dependencies here (if some) add_test(module-tests module-tests) ``` -------------------------------- ### oatpp-postgresql CMakeLists.txt Configuration Source: https://github.com/oatpp/oatpp-postgresql/blob/master/CMakeLists.txt This CMakeLists.txt file sets up the oatpp-postgresql module for building. It defines module metadata, handles dependency resolution for the oatpp framework and PostgreSQL libraries, and configures build options like shared libraries and testing. ```CMake cmake_minimum_required(VERSION 3.20) ################################################################################################### ## These variables are passed to oatpp-module-install.cmake script ## use these variables to configure module installation set(OATPP_THIS_MODULE_NAME oatpp-postgresql) ## name of the module (also name of folders in installation dirs) set(OATPP_THIS_MODULE_VERSION "1.4.0") ## version of the module (also sufix of folders in installation dirs) set(OATPP_THIS_MODULE_LIBRARIES oatpp-postgresql) ## list of libraries to find when find_package is called set(OATPP_THIS_MODULE_TARGETS oatpp-postgresql) ## list of targets to install set(OATPP_THIS_MODULE_DIRECTORIES oatpp-postgresql) ## list of directories to install ################################################################################################### project(${OATPP_THIS_MODULE_NAME} VERSION ${OATPP_THIS_MODULE_VERSION} LANGUAGES CXX ## HOMEPAGE_URL "https://github.com/oatpp/oatpp-postgresql" ## DESCRIPTION "Something about postgresql" ) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(OATPP_DIR_SRC "Path to oatpp module directory (sources)") option(OATPP_DIR_LIB "Path to directory with liboatpp (directory containing ex: liboatpp.so or liboatpp.dynlib)") option(OATPP_BUILD_TESTS "Build tests for this module" ON) option(OATPP_INSTALL "Install module binaries" ON) set(OATPP_MODULES_LOCATION "INSTALLED" CACHE STRING "Location where to find oatpp modules. can be [INSTALLED|EXTERNAL|CUSTOM]") ################################################################################################### ## get oatpp main module in specified location set(OATPP_MODULES_LOCATION_INSTALLED INSTALLED) set(OATPP_MODULES_LOCATION_EXTERNAL EXTERNAL) set(OATPP_MODULES_LOCATION_CUSTOM CUSTOM) if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_INSTALLED) message("Finding oatpp in location=INSTALLED") find_package(oatpp ${OATPP_THIS_MODULE_VERSION} REQUIRED) get_target_property(OATPP_INCLUDE oatpp::oatpp INTERFACE_INCLUDE_DIRECTORIES) message("OATPP_INCLUDE=${OATPP_INCLUDE}") get_target_property(OATPP_TEST_INCLUDE oatpp::oatpp-test INTERFACE_INCLUDE_DIRECTORIES) message("OATPP_TEST_INCLUDE=${OATPP_TEST_INCLUDE}") elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL) message("Finding oatpp in location=EXTERNAL") include(ExternalProject) set(MODULE_WAIT_DEPS ON) set(LIB_OATPP_EXTERNAL "lib_oatpp_external") ExternalProject_Add(${LIB_OATPP_EXTERNAL} GIT_REPOSITORY "https://github.com/oatpp/oatpp.git" GIT_TAG origin/master CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOATPP_INSTALL=OFF -DOATPP_BUILD_TESTS=OFF INSTALL_COMMAND cmake -E echo "SKIP INSTALL '${LIB_OATPP_EXTERNAL}'" ) ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} BINARY_DIR) set(OATPP_DIR_LIB ${BINARY_DIR}/src) ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} SOURCE_DIR) set(OATPP_DIR_SRC ${SOURCE_DIR}/src) message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'") message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'") elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_CUSTOM) message("Finding oatpp in location=CUSTOM") message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'") message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'") else() message("FATAL_ERROR Unknown location to find oatpp '${OATPP_MODULES_LOCATION}'") endif() if(OATPP_DIR_LIB) link_directories(${OATPP_DIR_LIB}) endif() ################################################################################################### ## get dependencies message("\n############################################################################") message("## ${OATPP_THIS_MODULE_NAME} module. Resolving dependencies...\n") set(PostgreSQL_ADDITIONAL_VERSIONS "17") find_package(PostgreSQL REQUIRED) message("PostgreSQL_INCLUDE_DIRS=${PostgreSQL_INCLUDE_DIRS}") message("PostgreSQL_LIBRARIES=${PostgreSQL_LIBRARIES}") message("PostgreSQL_TYPE_INCLUDE_DIR=${PostgreSQL_TYPE_INCLUDE_DIR}") message("PostgreSQL_VERSION_STRING=${PostgreSQL_VERSION_STRING}") message("\n############################################################################\n") ################################################################################################### ## define targets include(cmake/module-utils.cmake) add_subdirectory("src") if(OATPP_BUILD_TESTS) enable_testing() add_subdirectory("test") endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.