-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
82 lines (68 loc) · 2.15 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
cmake_minimum_required(VERSION 3.30)
project(pg_email_opt C)
set(CMAKE_C_STANDARD 11)
# Enable position independent code for shared library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Find PostgreSQL package
find_package(PostgreSQL 16 REQUIRED)
# Get PostgreSQL specific directories using pg_config
execute_process(
COMMAND pg_config --includedir-server
OUTPUT_VARIABLE PG_SERVER_INCLUDEDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND pg_config --pkglibdir
OUTPUT_VARIABLE PG_PKGLIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND pg_config --sharedir
OUTPUT_VARIABLE PG_SHAREDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Print found paths for verification
message(STATUS "PostgreSQL version: ${PostgreSQL_VERSION_STRING}")
message(STATUS "PostgreSQL server include dir: ${PG_SERVER_INCLUDEDIR}")
message(STATUS "PostgreSQL package lib dir: ${PG_PKGLIBDIR}")
message(STATUS "PostgreSQL share dir: ${PG_SHAREDIR}")
# Source files list
set(SOURCE_FILES
pg_email_opt.c
myutils/ip.c
myutils/domain.c
myutils/common.c
myutils/local.c
)
# Header files list
set(HEADER_FILES
myutils/local.h
myutils/domain.h
myutils/ip.h
myutils/common.h
)
# Create shared library (MODULE for PostgreSQL extension)
add_library(pg_email_opt MODULE ${SOURCE_FILES} ${HEADER_FILES})
# Set include directories
target_include_directories(pg_email_opt PRIVATE
${PostgreSQL_INCLUDE_DIRS}
${PG_SERVER_INCLUDEDIR}
${CMAKE_CURRENT_SOURCE_DIR} # Add current directory for myutils includes
)
# Link PostgreSQL libraries
target_link_libraries(pg_email_opt PRIVATE
${PostgreSQL_LIBRARIES}
)
# Add PostgreSQL specific compile definitions
target_compile_definitions(pg_email_opt PRIVATE
_GNU_SOURCE
)
# Set output directory
set_target_properties(pg_email_opt PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
# Set output properties for the library
set_target_properties(pg_email_opt PROPERTIES
PREFIX "" # Remove 'lib' prefix
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)