@@ -60,6 +60,31 @@ function(GET_PG_CONFIG var)
60
60
PARENT_SCOPE)
61
61
endfunction ()
62
62
63
+ # Search paths for Postgres binaries
64
+ if (WIN32 )
65
+ find_path (
66
+ PG_PATH postgres.exe
67
+ PATHS "C:/PostgreSQL" "C:/Program Files/PostgreSQL"
68
+ PATH_SUFFIXES bin 15/bin 16/bin
69
+ DOC "The path to a PostgreSQL installation" )
70
+ elseif (UNIX )
71
+ find_path (
72
+ PG_PATH postgres
73
+ PATHS $ENV{HOME} /opt/local/pgsql /usr/local/pgsql /usr/lib/postgresql
74
+ PATH_SUFFIXES bin 15/bin 16/bin
75
+ DOC "The path to a PostgreSQL installation" )
76
+ endif ()
77
+
78
+ find_program (
79
+ PG_CONFIG pg_config
80
+ HINTS ${PG_PATH}
81
+ PATH_SUFFIXES bin
82
+ DOC "The path to the pg_config of the PostgreSQL version to compile against" )
83
+
84
+ if (NOT PG_CONFIG)
85
+ message (FATAL_ERROR "Unable to find 'pg_config'" )
86
+ endif ()
87
+
63
88
configure_file ("version.config" "version.config" COPYONLY )
64
89
file (READ version .config VERSION_CONFIG)
65
90
@@ -95,6 +120,37 @@ endif()
95
120
# a hack to avoid change of SQL extschema variable
96
121
set (extschema "@extschema@" )
97
122
123
+ # Try to use the same compiler as Postgres to avoid mismatches and simplify
124
+ # configuration.
125
+ if (NOT DEFINED CMAKE_C_COMPILER)
126
+ get_pg_config(PG_CC --cc)
127
+
128
+ # The first word might be ccache or similar, so handle this.
129
+ string (REPLACE " " ";" PG_CC_LIST ${PG_CC} )
130
+ list (POP_FRONT PG_CC_LIST PG_CC_FIRST)
131
+ if (PG_CC_LIST)
132
+ # Got multi-word PG CC, treat the first word as ccache.
133
+ find_program (PG_CCACHE_FOUND ${PG_CC_FIRST} )
134
+ if ((NOT DEFINED CMAKE_C_COMPILER_LAUNCHER) AND PG_CCACHE_FOUND)
135
+ message (
136
+ STATUS
137
+ "Using ${PG_CCACHE_FOUND} as C compiler launcher based on pg_config CC"
138
+ )
139
+ set (CMAKE_C_COMPILER_LAUNCHER ${PG_CCACHE_FOUND} )
140
+ endif ()
141
+ set (PG_CC ${PG_CC_LIST} )
142
+ else ()
143
+ # Single-word CC.
144
+ set (PG_CC ${PG_CC_FIRST} )
145
+ endif ()
146
+
147
+ find_program (PG_CC_FOUND ${PG_CC} )
148
+ if (PG_CC_FOUND)
149
+ message (STATUS "Using ${PG_CC_FOUND} as CC based on pg_config CC" )
150
+ set (CMAKE_C_COMPILER ${PG_CC_FOUND} )
151
+ endif ()
152
+ endif ()
153
+
98
154
# Set project name, version, and language. Language needs to be set for compiler
99
155
# checks
100
156
project (
@@ -298,31 +354,6 @@ if(ENABLE_OPTIMIZER_DEBUG)
298
354
add_definitions (-DOPTIMIZER_DEBUG)
299
355
endif ()
300
356
301
- # Search paths for Postgres binaries
302
- if (WIN32 )
303
- find_path (
304
- PG_PATH postgres.exe
305
- PATHS "C:/PostgreSQL" "C:/Program Files/PostgreSQL"
306
- PATH_SUFFIXES bin 15/bin 16/bin
307
- DOC "The path to a PostgreSQL installation" )
308
- elseif (UNIX )
309
- find_path (
310
- PG_PATH postgres
311
- PATHS $ENV{HOME} /opt/local/pgsql /usr/local/pgsql /usr/lib/postgresql
312
- PATH_SUFFIXES bin 15/bin 16/bin
313
- DOC "The path to a PostgreSQL installation" )
314
- endif ()
315
-
316
- find_program (
317
- PG_CONFIG pg_config
318
- HINTS ${PG_PATH}
319
- PATH_SUFFIXES bin
320
- DOC "The path to the pg_config of the PostgreSQL version to compile against" )
321
-
322
- if (NOT PG_CONFIG)
323
- message (FATAL_ERROR "Unable to find 'pg_config'" )
324
- endif ()
325
-
326
357
find_package (Git)
327
358
328
359
# Check PostgreSQL version
0 commit comments