-
Notifications
You must be signed in to change notification settings - Fork 243
/
config.cmake
154 lines (141 loc) · 4.68 KB
/
config.cmake
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function(detect_code_compiled code macro msg)
message(STATUS "Detecting ${msg}")
check_cxx_source_compiles("${code}" "${macro}" FAIL_REGEX "warning")
if(${macro})
message(STATUS "Detecting ${msg} - supported")
else()
message(STATUS "Detecting ${msg} - not supported")
endif()
endfunction(detect_code_compiled)
include(CheckIncludeFileCXX)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CMakeDetermineCompileFeatures)
include(CheckCXXSourceCompiles)
include(CMakeFindDependencyMacro)
if(NOT PostgreSQL_FOUND)
if(POLICY CMP0074)
cmake_policy(PUSH)
# CMP0074 is `OLD` by `cmake_minimum_required(VERSION 3.7)`,
# sets `NEW` to enable support CMake variable `PostgreSQL_ROOT`.
cmake_policy(SET CMP0074 NEW)
endif()
find_package(PostgreSQL)
if(POLICY CMP0074)
cmake_policy(POP)
endif()
endif()
if(NOT PostgreSQL_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PostgreSQL REQUIRED libpq)
endif()
check_function_exists("poll" PQXX_HAVE_POLL)
set(CMAKE_REQUIRED_LIBRARIES pq)
cmake_determine_compile_features(CXX)
cmake_policy(SET CMP0057 NEW)
# check_cxx_source_compiles requires CMAKE_REQUIRED_DEFINITIONS to specify
# compiling arguments.
# Wordaround: Push CMAKE_REQUIRED_DEFINITIONS
if(CMAKE_REQUIRED_DEFINITIONS)
set(def "${CMAKE_REQUIRED_DEFINITIONS}")
endif()
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION})
set(CMAKE_REQUIRED_QUIET ON)
try_compile(
PQXX_HAVE_GCC_PURE
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/gcc_pure.cxx)
try_compile(
PQXX_HAVE_GCC_VISIBILITY
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/gcc_visibility.cxx)
# C++20: Assume support.
try_compile(
PQXX_HAVE_LIKELY
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/likely.cxx)
try_compile(
PQXX_HAVE_CXA_DEMANGLE
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/cxa_demangle.cxx)
# C++20: Assume support.
try_compile(
PQXX_HAVE_CONCEPTS
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/concepts.cxx)
# C++20: Assume support.
try_compile(
PQXX_HAVE_SPAN
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/span.cxx)
try_compile(
PQXX_HAVE_CHARCONV_FLOAT
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/charconv_float.cxx)
try_compile(
PQXX_HAVE_CHARCONV_INT
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/charconv_int.cxx)
try_compile(
PQXX_HAVE_PATH
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/fs.cxx)
try_compile(
PQXX_HAVE_THREAD_LOCAL
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/thread_local.cxx)
try_compile(
PQXX_HAVE_SLEEP_FOR
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/sleep_for.cxx)
try_compile(
PQXX_HAVE_STRERROR_R
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/strerror_r.cxx)
try_compile(
PQXX_HAVE_STRERROR_S
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/strerror_s.cxx)
try_compile(
PQXX_HAVE_YEAR_MONTH_DAY
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/year_month_day.cxx)
# C++20: Assume support.
try_compile(
PQXX_HAVE_CMP
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/cmp.cxx)
try_compile(
need_fslib
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/need_fslib.cxx)
if(!need_fslib)
# TODO: This may work for gcc 8, but some clang versions may need -lc++fs.
link_libraries(stdc++fs)
endif()
# check_cxx_source_compiles requires CMAKE_REQUIRED_DEFINITIONS to specify
# compiling arguments.
# Workaround: Pop CMAKE_REQUIRED_DEFINITIONS
if(def)
set(CMAKE_REQUIRED_DEFINITIONS ${def})
unset(def CACHE)
else()
unset(CMAKE_REQUIRED_DEFINITIONS CACHE)
endif()
set(CMAKE_REQUIRED_QUIET OFF)
set(AC_CONFIG_H_IN "${PROJECT_SOURCE_DIR}/include/pqxx/config.h.in")
set(CM_CONFIG_H_IN "${PROJECT_BINARY_DIR}/include/pqxx/config_cmake.h.in")
set(CM_CONFIG_PUB "${PROJECT_BINARY_DIR}/include/pqxx/config-public-compiler.h")
set(CM_CONFIG_INT "${PROJECT_BINARY_DIR}/include/pqxx/config-internal-compiler.h")
set(CM_CONFIG_PQ "${PROJECT_BINARY_DIR}/include/pqxx/config-internal-libpq.h")
message(STATUS "Generating config.h")
file(WRITE "${CM_CONFIG_H_IN}" "")
file(STRINGS "${AC_CONFIG_H_IN}" lines)
foreach(line ${lines})
string(REGEX REPLACE "^#undef" "#cmakedefine" l "${line}")
file(APPEND "${CM_CONFIG_H_IN}" "${l}\n")
endforeach()
configure_file("${CM_CONFIG_H_IN}" "${CM_CONFIG_INT}" @ONLY)
configure_file("${CM_CONFIG_H_IN}" "${CM_CONFIG_PUB}" @ONLY)
configure_file("${CM_CONFIG_H_IN}" "${CM_CONFIG_PQ}" @ONLY)
message(STATUS "Generating config.h - done")