Skip to content

Commit

Permalink
Merge pull request #122 from Jacyking/master
Browse files Browse the repository at this point in the history
add pg ci
  • Loading branch information
Jacyking authored Oct 17, 2023
2 parents df5f9d7 + 7b4ae7c commit 0303216
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 243 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci-pgsql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI-PGSQL

on: [ push, pull_request ]

jobs:
build-and-test:

name: ${{ matrix.os }} (${{ matrix.configuration }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
configuration: [ Debug, Release ]
os: [ ubuntu-latest ] # macos-latest, ubuntu-latest, windows-latest

services:
postgres:
image: postgres
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: 123456
POSTGRES_DB: test_ormppdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Configure cmake
run: cmake -B${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DENABLE_PG=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{ matrix.configuration }}

- name: Test
working-directory: ${{github.workspace}}/build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest -C ${{ matrix.configuration }} -j `nproc` -V
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ include(cmake/develop.cmake)
include(cmake/platform.cmake)
include(cmake/dependency.cmake)

if (ENABLE_MYSQL)
if (ENABLE_PG)
include_directories(${PGSQL_INCLUDE_DIR} include)
elseif(ENABLE_MYSQL)
include_directories(${MYSQL_INCLUDE_DIR} include)
elseif(ENABLE_MARIADB)
include_directories(${MARIADB_INCLUDE_DIR} include)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<a href="https://github.com/qicosmos/ormpp/actions/workflows/ci-mysql.yml">
<img alt="ci-mysql" src="https://github.com/qicosmos/ormpp/actions/workflows/ci-mysql.yml/badge.svg?branch=master">
</a>
<a href="https://github.com/qicosmos/ormpp/actions/workflows/ci-pgsql.yml">
<img alt="ci-pgsql" src="https://github.com/qicosmos/ormpp/actions/workflows/ci-pgsql.yml/badge.svg?branch=master">
</a>
<a href="https://codecov.io/gh/qicosmos/ormpp">
<img alt="codecov" src="https://codecov.io/gh/qicosmos/ormpp/branch/master/graph/badge.svg">
</a>
Expand Down
1 change: 1 addition & 0 deletions cmake/develop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ endif()

option(ENABLE_PG "Enable pg" OFF)
if (ENABLE_PG)
include(cmake/pgsql.cmake)
message(STATUS "ENABLE_PG")
add_definitions(-DORMPP_ENABLE_PG)
endif()
Expand Down
58 changes: 58 additions & 0 deletions cmake/pgsql.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# - Find pq
# Find the native PGSQL includes and library
#
# PGSQL_INCLUDE_DIR - where to find libpq-fe.h, etc.
# PGSQL_LIBRARIES - List of libraries when using PGSQL.
# PGSQL_FOUND - True if PGSQL found.

IF (PGSQL_INCLUDE_DIR)
# Already in cache, be silent
SET(PGSQL_FIND_QUIETLY TRUE)
ENDIF (PGSQL_INCLUDE_DIR)

IF (WIN32)
FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h
$ENV{PROGRAMFILES}/PostgreSQL/*/include
$ENV{SYSTEMDRIVE}/PostgreSQL/*/include)
ELSE (WIN32)
FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h
/opt/homebrew/include/postgresql
/usr/local/include/postgresql
/usr/include/postgresql)
ENDIF(WIN32)

IF (WIN32)
SET(PGSQL_NAMES libpq)
FIND_LIBRARY(PGSQL_LIBRARY
NAMES ${PGSQL_NAMES}
PATHS $ENV{PROGRAMFILES}/PostgreSQL/*/lib
$ENV{SYSTEMDRIVE}/PostgreSQL/*/lib)
ELSE (WIN32)
SET(PGSQL_NAMES pq)
FIND_LIBRARY(PGSQL_LIBRARY
NAMES ${PGSQL_NAMES}
PATHS /usr/lib
/usr/local/lib
/opt/homebrew/lib)
ENDIF(WIN32)

IF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY)
SET(PGSQL_FOUND TRUE)
SET(PGSQL_LIBRARIES ${PGSQL_LIBRARY})
ELSE (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY)
SET(PGSQL_FOUND FALSE)
SET(PGSQL_LIBRARIES)
ENDIF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY)

IF (PGSQL_FOUND)
IF (NOT PGSQL_FIND_QUIETLY)
MESSAGE(STATUS "Found PGSQL: ${PGSQL_LIBRARY}")
ENDIF (NOT PGSQL_FIND_QUIETLY)
ELSE (PGSQL_FOUND)
IF (PGSQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for PGSQL libraries named ${PGSQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find PGSQL library")
ENDIF (PGSQL_FIND_REQUIRED)
ENDIF (PGSQL_FOUND)

MARK_AS_ADVANCED(PGSQL_LIBRARY PGSQL_INCLUDE_DIR)
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
status:
patch: off
project: off
20 changes: 7 additions & 13 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ set(ORMPP_EXAMPLE

add_executable(${PROJECT_NAME} ${ORMPP_EXAMPLE})

if (ENABLE_MYSQL)
if(ENABLE_PG)
target_link_libraries(${PROJECT_NAME} ${PGSQL_LIBRARY})
elseif(ENABLE_MYSQL)
target_link_libraries(${PROJECT_NAME} ${MYSQL_LIBRARY})
if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/MD")
if (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/MD")
endif()
endif()

if (ENABLE_MARIADB)
elseif(ENABLE_MARIADB)
target_link_libraries(${PROJECT_NAME} ${MARIADB_LIBRARY})
endif()

if (ENABLE_SQLITE3)
elseif(ENABLE_SQLITE3)
target_link_libraries(${PROJECT_NAME} sqlite3)
endif()

if (ENABLE_PG)
target_link_libraries(${PROJECT_NAME} pg)
endif()

install(TARGETS ${PROJECT_NAME} DESTINATION include)
Loading

0 comments on commit 0303216

Please sign in to comment.