2016-11-11 13:55:55 +08:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
project(libpq VERSION 9.6.1 LANGUAGES C)
|
2016-11-17 16:20:16 +08:00
|
|
|
|
2018-03-24 01:01:07 +08:00
|
|
|
if(NOT CMAKE_SYSTEM_PROCESSOR)
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
|
|
|
endif()
|
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
find_package(OpenSSL REQUIRED)
|
2018-03-24 01:01:07 +08:00
|
|
|
find_program(PERL NAMES perl)
|
|
|
|
|
|
|
|
set(CMAKE_STATIC_LIBRARY_PREFIX)
|
|
|
|
set(CMAKE_SHARED_LIBRARY_PREFIX)
|
2016-11-16 11:44:53 +08:00
|
|
|
set(CMAKE_DEBUG_POSTFIX "d")
|
2018-03-24 01:01:07 +08:00
|
|
|
|
|
|
|
file(REMOVE
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/include/pg_config.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/include/pg_config_ext.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/include/pg_config_os.h
|
|
|
|
)
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
configure_file(src/include/pg_config.h.win32 include/pg_config.h)
|
|
|
|
configure_file(src/include/pg_config_ext.h.win32 include/pg_config_ext.h)
|
|
|
|
configure_file(src/include/port/win32.h include/pg_config_os.h)
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/pg_config_ext.h" "#include <stdint.h>\n#define PG_INT64_TYPE int64_t")
|
|
|
|
configure_file("${PORT_DIR}/pg_config.darwin.h" include/pg_config.h COPYONLY)
|
|
|
|
configure_file(src/include/port/darwin.h include/pg_config_os.h COPYONLY)
|
|
|
|
configure_file(src/backend/port/dynloader/darwin.h include/dynloader.h COPYONLY)
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/pg_config_ext.h" "#include <stdint.h>\n#define PG_INT64_TYPE int64_t")
|
|
|
|
configure_file(src/include/port/linux.h include/pg_config_os.h COPYONLY)
|
|
|
|
configure_file("${PORT_DIR}/pg_config.linux.h" include/pg_config.h COPYONLY)
|
|
|
|
configure_file(src/backend/port/dynloader/linux.h include/dynloader.h COPYONLY)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unknown system: ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
endif()
|
2018-03-13 22:32:27 +08:00
|
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/include/pg_config_paths.h "#define SYSCONFDIR \"\"")
|
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
set(INSTALL_INCLUDES ON CACHE BOOL "Install include files")
|
2018-03-13 22:32:27 +08:00
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
set(pg_port_src
|
|
|
|
src/port/pgstrcasecmp.c
|
|
|
|
src/port/pqsignal.c
|
|
|
|
src/port/thread.c
|
|
|
|
src/port/crypt.c
|
|
|
|
src/port/noblock.c
|
|
|
|
src/port/chklocale.c
|
|
|
|
src/port/snprintf.c
|
|
|
|
src/port/dirmod.c
|
|
|
|
src/port/pgsleep.c
|
|
|
|
src/port/open.c
|
|
|
|
src/port/system.c
|
|
|
|
)
|
2018-03-24 01:01:07 +08:00
|
|
|
if(WIN32)
|
|
|
|
list(APPEND pg_port_src
|
|
|
|
src/port/dirent.c
|
|
|
|
src/port/inet_aton.c
|
|
|
|
src/port/inet_net_ntop.c
|
|
|
|
src/port/win32error.c
|
|
|
|
src/port/win32setlocale.c
|
|
|
|
src/port/getaddrinfo.c
|
|
|
|
src/port/strlcpy.c
|
|
|
|
)
|
|
|
|
include_directories(src/include/port/win32 src/include/port/win32_msvc)
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
list(APPEND pg_port_src
|
|
|
|
src/port/strlcpy.c
|
2019-04-09 22:25:32 +08:00
|
|
|
src/port/inet_aton.c
|
|
|
|
src/port/inet_net_ntop.c
|
|
|
|
src/port/getpeereid.c
|
2018-03-24 01:01:07 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
set(pg_backend_src
|
|
|
|
src/backend/libpq/md5.c
|
|
|
|
src/backend/libpq/ip.c
|
|
|
|
src/backend/utils/mb/wchar.c
|
|
|
|
src/backend/utils/mb/encnames.c
|
|
|
|
)
|
2018-03-24 01:01:07 +08:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
list(APPEND pg_backend_src
|
|
|
|
src/backend/port/dynloader/linux.c
|
|
|
|
src/backend/port/sysv_sema.c
|
|
|
|
src/backend/port/sysv_shmem.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
if(NOT WIN32)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/utils/errcodes.h
|
|
|
|
COMMAND "${PERL}" "${CMAKE_CURRENT_SOURCE_DIR}/src/backend/utils/generate-errcodes.pl" "${CMAKE_CURRENT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_BINARY_DIR}/include/utils/errcodes.h"
|
|
|
|
VERBATIM
|
|
|
|
)
|
|
|
|
list(APPEND pg_backend_src
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/utils/errcodes.h
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
set(pg_libpq_src
|
|
|
|
src/interfaces/libpq/fe-auth.c
|
|
|
|
src/interfaces/libpq/fe-connect.c
|
|
|
|
src/interfaces/libpq/fe-exec.c
|
|
|
|
src/interfaces/libpq/fe-lobj.c
|
|
|
|
src/interfaces/libpq/fe-misc.c
|
|
|
|
src/interfaces/libpq/fe-print.c
|
|
|
|
src/interfaces/libpq/fe-protocol2.c
|
|
|
|
src/interfaces/libpq/fe-protocol3.c
|
|
|
|
src/interfaces/libpq/fe-secure-openssl.c
|
|
|
|
src/interfaces/libpq/fe-secure.c
|
|
|
|
src/interfaces/libpq/libpq-events.c
|
|
|
|
src/interfaces/libpq/pqexpbuffer.c
|
|
|
|
src/interfaces/libpq/libpq-dist.rc
|
|
|
|
)
|
2018-03-24 01:01:07 +08:00
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
list(APPEND pg_libpq_src
|
|
|
|
src/interfaces/libpq/pthread-win32.c
|
|
|
|
src/interfaces/libpq/win32.c
|
|
|
|
)
|
|
|
|
endif()
|
2016-11-11 13:55:55 +08:00
|
|
|
set(pg_libpq_interface
|
|
|
|
src/include/postgres_ext.h
|
2018-03-13 22:32:27 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/pg_config_ext.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/pg_config.h
|
2016-11-11 13:55:55 +08:00
|
|
|
src/interfaces/libpq/libpq-fe.h
|
2018-10-26 02:06:54 +08:00
|
|
|
src/interfaces/libpq/libpq-events.h
|
2018-03-24 01:01:07 +08:00
|
|
|
)
|
2016-11-17 16:01:38 +08:00
|
|
|
set(pg_libpq_catalog_interface
|
|
|
|
src/include/catalog/pg_type.h
|
|
|
|
src/include/catalog/genbki.h
|
|
|
|
)
|
2016-11-11 13:55:55 +08:00
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
2016-11-16 11:44:53 +08:00
|
|
|
set(CMAKE_DEBUG_POSTFIX "d")
|
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
2016-11-11 13:55:55 +08:00
|
|
|
add_library(libpq ${pg_port_src} ${pg_backend_src} ${pg_libpq_src})
|
2019-04-09 22:25:32 +08:00
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
target_compile_definitions(libpq PRIVATE -DFRONTEND -DENABLE_THREAD_SAFETY -DUSE_OPENSSL -D_CRT_SECURE_NO_WARNINGS)
|
2019-04-09 22:25:32 +08:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
target_compile_definitions(libpq PRIVATE -D_GNU_SOURCE)
|
|
|
|
endif()
|
|
|
|
|
2018-03-24 01:01:07 +08:00
|
|
|
target_link_libraries(libpq PRIVATE OpenSSL::SSL)
|
|
|
|
if(WIN32)
|
|
|
|
target_link_libraries(libpq PRIVATE ws2_32 secur32 advapi32 shell32)
|
|
|
|
endif()
|
|
|
|
target_include_directories(libpq PRIVATE src/include src/port ${CMAKE_CURRENT_BINARY_DIR}/include)
|
2016-11-17 01:12:04 +08:00
|
|
|
set_target_properties(libpq PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
2016-11-16 11:44:53 +08:00
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
install(TARGETS libpq
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
RUNTIME DESTINATION bin
|
2018-03-13 22:32:27 +08:00
|
|
|
)
|
|
|
|
|
2016-11-11 13:55:55 +08:00
|
|
|
if(INSTALL_INCLUDES)
|
|
|
|
install(FILES ${pg_libpq_interface} DESTINATION include)
|
2016-11-18 11:53:37 +08:00
|
|
|
install(DIRECTORY src/include/libpq DESTINATION include)
|
2016-11-17 16:01:38 +08:00
|
|
|
install(FILES ${pg_libpq_catalog_interface} DESTINATION include/catalog)
|
2018-10-26 02:06:54 +08:00
|
|
|
endif()
|