Skip to content

Commit

Permalink
cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
SunBeau committed Apr 29, 2024
1 parent 19da1a5 commit 7a954ab
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci-run-test-extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,21 @@ jobs:
cd tests/
make test
make test-ext
make clean
cd ../
make clean
- name: Cmake And make
working-directory: ${{ github.workspace }}
run: |
mkdir build/ && cd build/
cmake .. \
-DWITH_PGSQL=ON \
-DWITH_PGSQL_INCLUDE_DIR=/usr/include/postgresql \
-DWITH_PGSQL_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu
- name: Cmake Test
working-directory: ${{ github.workspace }}
run: |
cd build/
make test
31 changes: 28 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ IF (NOT CMAKE_USE_PTHREADS_INIT)
MESSAGE(FATAL_ERROR "Couldn't find pthreads.")
ENDIF()

IF(NOT "${WITH_PGSQL}" STREQUAL "")
message(STATUS "with_pgsql: ${WITH_PGSQL}")
# check "libpq-fe.h"
if(EXISTS "${WITH_PGSQL_INCLUDE_DIR}/libpq-fe.h")
message(STATUS "found 'libpq-fe.h' header.")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_PGSQL")
else()
message(FATAL_ERROR "Cannot find 'libpq-fe.h' header. Use '-DWITH_PGSQL_INCLUDE_DIR=DIR' to specify the directory where 'libpq-fe.h' is located.")
endif()

# check "libpq.so"
if(EXISTS "${WITH_PGSQL_LIBRARY_DIR}/libpq.so")
message(STATUS "found 'libpq.so' library.")
SET(QLIBC_LINK_LIBS "pq")
else()
message(FATAL_ERROR "Cannot find 'libpq.so' library. Use '-DWITH_PGSQL_LIBRARY_DIR=DIR' to specify the directory where 'libpq.so' is located.")
endif()
ENDIF()

SET(SRC_SUBPATHS
containers/*.c
utilities/*.c
Expand Down Expand Up @@ -80,20 +99,26 @@ FILE(GLOB_RECURSE SRC_LIB_EXT
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${qlibc_SOURCE_DIR}/lib)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${qlibc_SOURCE_DIR}/lib)

LIST(APPEND QLIBC_INCLUDE_DIRECTORIES ${qlibc_SOURCE_DIR}/src/internal)
LIST(APPEND QLIBC_INCLUDE_DIRECTORIES ${WITH_PGSQL_INCLUDE_DIR})
LIST(APPEND QLIBC_LINK_DIRECTORIES ${WITH_PGSQL_LIBRARY_DIR})

INCLUDE_DIRECTORIES(${QLIBC_INCLUDE_DIRECTORIES})
LINK_DIRECTORIES(${QLIBC_LINK_DIRECTORIES})

ADD_LIBRARY(qlibc-static STATIC ${SRC_LIB})
ADD_LIBRARY(qlibc SHARED ${SRC_LIB})
ADD_LIBRARY(qlibcext-static STATIC ${SRC_LIB_EXT})
ADD_LIBRARY(qlibcext SHARED ${SRC_LIB_EXT})

INCLUDE_DIRECTORIES(${qlibc_SOURCE_DIR}/src/internal)
TARGET_INCLUDE_DIRECTORIES(qlibc-static PUBLIC ${qlibc_SOURCE_DIR}/include/qlibc)
TARGET_INCLUDE_DIRECTORIES(qlibc PUBLIC ${qlibc_SOURCE_DIR}/include/qlibc)
TARGET_INCLUDE_DIRECTORIES(qlibcext-static PUBLIC ${qlibc_SOURCE_DIR}/include/qlibc)

TARGET_LINK_LIBRARIES(qlibc-static PRIVATE ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(qlibc PRIVATE ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(qlibcext-static PRIVATE ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(qlibcext PUBLIC qlibc)
TARGET_LINK_LIBRARIES(qlibcext-static PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${QLIBC_LINK_LIBS})
TARGET_LINK_LIBRARIES(qlibcext PUBLIC qlibc ${QLIBC_LINK_LIBS})

SET(QLIBC_HEADER "${qlibc_SOURCE_DIR}/include/qlibc")
INSTALL(DIRECTORY ${QLIBC_HEADER} DESTINATION include)
Expand Down
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ SET(test_list
test_qhash
)

IF(NOT "${WITH_PGSQL}" STREQUAL "")
LIST(APPEND test_list test_qdatabase_pgsql)
ENDIF()

SET(test_file_list
test_qhash_data_1.bin
test_qhash_data_2.bin
Expand Down

0 comments on commit 7a954ab

Please sign in to comment.