WIP: About CMake v2

Started by YUriy Zhuravlevover 10 years ago160 messages
#1YUriy Zhuravlev
u.zhuravlev@postgrespro.ru

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

Old thread:
/messages/by-id/200812291325.13354.peter_e@gmx.net

The main argument against the "it's too hard". I'm right?

Thanks!
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: YUriy Zhuravlev (#1)
Re: WIP: About CMake v2

YUriy Zhuravlev wrote:

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

What's your motivation for doing so?

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Andres Freund
andres@anarazel.de
In reply to: Alvaro Herrera (#2)
Re: WIP: About CMake v2

On 2015-08-28 12:32:45 -0300, Alvaro Herrera wrote:

YUriy Zhuravlev wrote:

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

What's your motivation for doing so?

I definitely can see some advantages. Non-broken dependencies around
recursive make being a major one. But I'm also afraid it's a rather
large undertaking. There's a fair number of special kind of rules, and
we're probably not going to want to break pgxs for extensions.

I also have some doubts around the portability of cmake and it's
generated makefiles. We do support some odd platforms.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Andres Freund (#3)
Re: WIP: About CMake v2

Andres Freund wrote:

On 2015-08-28 12:32:45 -0300, Alvaro Herrera wrote:

YUriy Zhuravlev wrote:

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

What's your motivation for doing so?

I definitely can see some advantages. Non-broken dependencies around
recursive make being a major one. But I'm also afraid it's a rather
large undertaking. There's a fair number of special kind of rules, and
we're probably not going to want to break pgxs for extensions.

I also have some doubts around the portability of cmake and it's
generated makefiles. We do support some odd platforms.

If it allows us to get rid of our custom MSVC scripts, it's a huge
benefit, for sure -- that has been a huge pain in the neck since day
one.

Like you, I am also afraid it's a huge undertaking, but if Uri wants to
tackle it, we have that part covered. Experimentation until we get it
all correct is going to waste some of everybody's time, too, I'm sure.

I wonder about two other things: one is speed of the build (not that
currently it's all that great, given all the mess with recursive make
invocations, but perhaps it can be even worse); the other is how ugly
the generated files are going to be, and are we going to carry them in
our repo -- right now we only have configure, but are we going to keep
extra files to cope with builds in systems that don't have cmake
installed (as we cope with missing bison and flex)?

I sure would oppose something that looks as ugly as Automake makefiles.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Andres Freund
andres@anarazel.de
In reply to: Alvaro Herrera (#4)
Re: WIP: About CMake v2

On 2015-08-28 13:28:49 -0300, Alvaro Herrera wrote:

the other is how ugly the generated files are going to be, and are we
going to carry them in our repo -- right now we only have configure,
but are we going to keep extra files to cope with builds in systems
that don't have cmake installed (as we cope with missing bison and
flex)?

Apparently it's still unsupported to ship generated files - they contain
absolute paths and such. Personally I think that might be the
death-knell - I doubt that we want to have a full dependency on cmake on
every platform?

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#4)
Re: WIP: About CMake v2

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

I wonder about two other things: one is speed of the build (not that
currently it's all that great, given all the mess with recursive make
invocations, but perhaps it can be even worse); the other is how ugly
the generated files are going to be, and are we going to carry them in
our repo -- right now we only have configure, but are we going to keep
extra files to cope with builds in systems that don't have cmake
installed (as we cope with missing bison and flex)?

As near as I can tell, the generated files are platform-specific.
(They're certainly different for Unix and Windows; the overview
I'm looking at doesn't say in so many words whether they can vary
at a finer grain, but I bet they do.) So I'm afraid cmake would
likely become a build requirement, even for tarball users. That
is probably not a show-stopper, but it's a point against the idea.

I have no idea whether switching to cmake would be a good thing or not.
It's possible that it'd end up being even uglier than our current
autoconf+gmake+msvc-scripts mess ... although when phrased that way,
that sounds like a pretty low bar to clear. Anyway, if YUriy is willing
to do the preliminary investigation, let's see what he comes up with.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Christopher Browne
cbbrowne@gmail.com
In reply to: YUriy Zhuravlev (#1)
Re: WIP: About CMake v2

It's broadly interesting, but since it bakes in a build dependency on
CMake, there is some risk that the dependencies become an insurmountable
problem.

(Does CMake run on a VAX 11/780?? :-))

It is probably worth a try, to see what improvements arise, albeit with the
need to accept some risk of refusal of the change.

The experiment is most likely necessary: we won't know the benefits without
trying.

If the results represent little improvement, there will be little or no
appetite to jump through the dependency hoops needed to get the change
accepted.

On the other hand, if there are big gains, that encourages pushing thru the
dependency issues.
On Aug 28, 2015 10:45, "YUriy Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

Show quoted text

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

Old thread:
/messages/by-id/200812291325.13354.peter_e@gmx.net

The main argument against the "it's too hard". I'm right?

Thanks!
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Christopher Browne (#7)
Re: WIP: About CMake v2

Christopher Browne <cbbrowne@gmail.com> writes:

(Does CMake run on a VAX 11/780?? :-))

Yeah. I see the two major risks as being:

1. We limit ourselves to platforms that cmake works on.

2. We lose the ability to handle weird special-case tests that are
possible (if not necessarily pleasant) with autoconf/gmake.

I might be overly worried about #2 --- but the impression I have of cmake
is that they've spent lots of time on "make easy cases easy" and maybe not
enough on "make hard cases possible".

Anyway, we won't know unless somebody tries it. There will certainly be
some pluses and some minuses, and we'll have to decide whether the pluses
outweigh the minuses. I don't think we can tell that without a fairly
detailed attempt at making it work.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Gianni
nasus.maximos@gmail.com
In reply to: Alvaro Herrera (#4)
Re: WIP: About CMake v2

On Friday 28 August 2015 13:28:49 Alvaro Herrera wrote:

Andres Freund wrote:

On 2015-08-28 12:32:45 -0300, Alvaro Herrera wrote:

YUriy Zhuravlev wrote:

Hello Hackers

How would you react if I provided a patch which introduces a CMake
build
system?

What's your motivation for doing so?

I definitely can see some advantages. Non-broken dependencies around
recursive make being a major one. But I'm also afraid it's a rather
large undertaking. There's a fair number of special kind of rules, and
we're probably not going to want to break pgxs for extensions.

I also have some doubts around the portability of cmake and it's
generated makefiles. We do support some odd platforms.

If it allows us to get rid of our custom MSVC scripts, it's a huge
benefit, for sure -- that has been a huge pain in the neck since day
one.

As a user, I suffer a bit with the current build system when I try to build
libpq in MinGW. So, if moving to CMake means the build is more 'decoupled',
i.e. less inter-dependent modules, it would be great.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Christopher Browne (#7)
Re: WIP: About CMake v2

On Friday 28 August 2015 13:51:30 you wrote:

It's broadly interesting, but since it bakes in a build dependency on
CMake, there is some risk that the dependencies become an insurmountable
problem.

(Does CMake run on a VAX 11/780?? :-))

http://public.kitware.com/Bug/view.php?id=13605 you about this?

It is probably worth a try, to see what improvements arise, albeit with the
need to accept some risk of refusal of the change.

The experiment is most likely necessary: we won't know the benefits without
trying.

You right.

If the results represent little improvement, there will be little or no
appetite to jump through the dependency hoops needed to get the change
accepted.

On the other hand, if there are big gains, that encourages pushing thru the
dependency issues.

On Aug 28, 2015 10:45, "YUriy Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

Old thread:
/messages/by-id/200812291325.13354.peter_e@gmx.net

The main argument against the "it's too hard". I'm right?

Thanks!
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: YUriy Zhuravlev (#10)
Re: WIP: About CMake v2

YUriy Zhuravlev wrote:

On Friday 28 August 2015 13:51:30 you wrote:

It's broadly interesting, but since it bakes in a build dependency on
CMake, there is some risk that the dependencies become an insurmountable
problem.

(Does CMake run on a VAX 11/780?? :-))

http://public.kitware.com/Bug/view.php?id=13605 you about this?

Hmm, what this closed bug report says to me is that 1) cmake developers
take portability seriously, 2) all common and even some not-so-common
platforms are likely to be in hand already. Therefore, either we will
not find any portability problems, or fixing upstream those we do find
will not be terribly difficult.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Andres Freund
andres@anarazel.de
In reply to: Alvaro Herrera (#11)
Re: WIP: About CMake v2

On 2015-08-29 17:53:26 -0300, Alvaro Herrera wrote:

Therefore, either we will not find any portability problems, or fixing
upstream those we do find will not be terribly difficult.

Well, the difference to know is that we can't resolve that relatively
quickly ourselves, but that it'd rather require $whoever installing a
new version of cmake...

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#12)
Re: WIP: About CMake v2

Andres Freund <andres@anarazel.de> writes:

On 2015-08-29 17:53:26 -0300, Alvaro Herrera wrote:

Therefore, either we will not find any portability problems, or fixing
upstream those we do find will not be terribly difficult.

Well, the difference to know is that we can't resolve that relatively
quickly ourselves, but that it'd rather require $whoever installing a
new version of cmake...

Yup. So one of the things we'd want to establish is what's the minimum
version of cmake we're going to require, and which (hopefully old)
platforms will we be leaving out in the cold with that?

I suspect it's premature to try to decide that now, but it's certainly
a question to keep in mind.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#14Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#13)
Re: WIP: About CMake v2

Tom Lane wrote:

Andres Freund <andres@anarazel.de> writes:

On 2015-08-29 17:53:26 -0300, Alvaro Herrera wrote:

Therefore, either we will not find any portability problems, or fixing
upstream those we do find will not be terribly difficult.

Well, the difference to know is that we can't resolve that relatively
quickly ourselves, but that it'd rather require $whoever installing a
new version of cmake...

Yup. So one of the things we'd want to establish is what's the minimum
version of cmake we're going to require, and which (hopefully old)
platforms will we be leaving out in the cold with that?

Just for the record, in Debian land the versions shipped are thus:

oldoldstable (squeeze): 2.8.2 (has 2.8.9 available in squeeze-backports)
oldstable (wheezy): 2.8.9 (has 2.8.11 available in wheezy-backports)
stable (jessie): 3.0.2

VAX support was added in 2.8.11 (bug fixed in Oct. 2012).

I imagine that esoteric platforms are not going to have cmake at all and
are going to need their own installation anyway. Not sure if that's
going to be more onerous than the requirement to install GNU make.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#15Peter Eisentraut
peter_e@gmx.net
In reply to: YUriy Zhuravlev (#1)
Re: WIP: About CMake v2

On 8/28/15 10:14 AM, YUriy Zhuravlev wrote:

Hello Hackers

How would you react if I provided a patch which introduces a CMake build
system?

I would say, "Yay!".

I had that on my todo list, but I won't mind if someone else does it.
I've certainly "had it" with the current build system. ;-)

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#16Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#14)
Re: WIP: About CMake v2

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

I imagine that esoteric platforms are not going to have cmake at all and
are going to need their own installation anyway. Not sure if that's
going to be more onerous than the requirement to install GNU make.

If we get to the point where this is starting to look like a real
proposal, I'll try to install cmake from source on my buildfarm critters,
none of which have it ATM. And we'll need to get other buildfarm owners
to do likewise. So we'll be able to acquire data points on whether that's
a big problem or not.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#17YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: YUriy Zhuravlev (#1)
Re: WIP: About CMake v2

Thanks all hackers.
I have not heard of fundamental problems and continue its development. :)

--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#18Noah Misch
noah@leadboat.com
In reply to: Alvaro Herrera (#4)
Re: WIP: About CMake v2

On Fri, Aug 28, 2015 at 01:28:49PM -0300, Alvaro Herrera wrote:

If it allows us to get rid of our custom MSVC scripts, it's a huge
benefit, for sure -- that has been a huge pain in the neck since day
one.

Moreover, I suggest beginning with a patch that replaces the src/tools/msvc
build system with CMake. One can test almost all Windows configurations using
two machines, so author and reviewer can test most everything. src/tools/msvc
has more defects than the GNU make build system, so the minimum-quality
acceptable replacement is easier to deliver. With CMake driving all MSVC
builds, it would be much easier to gradually extend to other platforms.

Thanks,
nm

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#19Tom Lane
tgl@sss.pgh.pa.us
In reply to: Noah Misch (#18)
Re: WIP: About CMake v2

Noah Misch <noah@leadboat.com> writes:

On Fri, Aug 28, 2015 at 01:28:49PM -0300, Alvaro Herrera wrote:

If it allows us to get rid of our custom MSVC scripts, it's a huge
benefit, for sure -- that has been a huge pain in the neck since day
one.

Moreover, I suggest beginning with a patch that replaces the src/tools/msvc
build system with CMake. One can test almost all Windows configurations using
two machines, so author and reviewer can test most everything. src/tools/msvc
has more defects than the GNU make build system, so the minimum-quality
acceptable replacement is easier to deliver. With CMake driving all MSVC
builds, it would be much easier to gradually extend to other platforms.

mmm ... dunno about that plan. In the first place, you seem to be
recommending that YUriy incorporate all the deficiencies of src/tools/msvc
into his first draft and then hope somehow to fix them later. In the
second place, I think that the core problem here involves being sure
we can still cover all the portability issues that have been laboriously
hacked into the autoconf/gmake build system over nigh two decades.
Starting from a build system that was designed to cover exactly one target
platform, and has never been asked to do anything more than that, doesn't
sound like a recipe for success there.

Maybe you're right about how to approach this, but I wouldn't bet on it.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#20Robert Haas
robertmhaas@gmail.com
In reply to: Andres Freund (#3)
Re: WIP: About CMake v2

On Fri, Aug 28, 2015 at 11:39 AM, Andres Freund <andres@anarazel.de> wrote:

I definitely can see some advantages. Non-broken dependencies around
recursive make being a major one. But I'm also afraid it's a rather
large undertaking. There's a fair number of special kind of rules, and
we're probably not going to want to break pgxs for extensions.

Maybe we should merge all of the makefiles for subdirectories of
src/backend into a single makefile. The major disadvantage would be
that you couldn't rebuild a subdirectory any more by typing make -C
src/backend/executor or whatever. And I do do that sometimes, so
maybe it would be annoying, but presumably it would make the
dependency issues a lot easier to deal with.

I guess I'm a bit skeptical about the idea of porting to a new build
system. There's a good chance of replacing the problems we know about
with new problems that are no less serious, but merely unknown to us.
But I'm not going to stand here and hold my breath if everyone else
thinks it's a good idea.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#21Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#20)
Re: WIP: About CMake v2

Robert Haas <robertmhaas@gmail.com> writes:

I guess I'm a bit skeptical about the idea of porting to a new build
system. There's a good chance of replacing the problems we know about
with new problems that are no less serious, but merely unknown to us.
But I'm not going to stand here and hold my breath if everyone else
thinks it's a good idea.

FWIW, I'm also skeptical that this experiment will succeed. I think it
is worth trying ... but I'm by no means promising to buy into the result.

There is precedent for this sort of thing: mysql converted from
autoconf+gmake to cmake a few years back, and AFAIK they've not
regretted it. So that's a data point that a project of complexity
more or less similar to ours can make the change.

Where I do *not* want to end up is maintaining *three* build systems.
So I'll definitely resist any proposals to commit a partly-done cmake
conversion (which I fear might seem attractive at some point).

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#22Andres Freund
andres@anarazel.de
In reply to: Tom Lane (#21)
Re: WIP: About CMake v2

On 2015-09-01 10:05:44 -0400, Tom Lane wrote:

Where I do *not* want to end up is maintaining *three* build systems.
So I'll definitely resist any proposals to commit a partly-done cmake
conversion (which I fear might seem attractive at some point).

Enthusiastically seconded.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#23Noah Misch
noah@leadboat.com
In reply to: Tom Lane (#19)
Re: WIP: About CMake v2

On Tue, Sep 01, 2015 at 12:49:55AM -0400, Tom Lane wrote:

Noah Misch <noah@leadboat.com> writes:

On Fri, Aug 28, 2015 at 01:28:49PM -0300, Alvaro Herrera wrote:

If it allows us to get rid of our custom MSVC scripts, it's a huge
benefit, for sure -- that has been a huge pain in the neck since day
one.

Moreover, I suggest beginning with a patch that replaces the src/tools/msvc
build system with CMake. One can test almost all Windows configurations using
two machines, so author and reviewer can test most everything. src/tools/msvc
has more defects than the GNU make build system, so the minimum-quality
acceptable replacement is easier to deliver. With CMake driving all MSVC
builds, it would be much easier to gradually extend to other platforms.

mmm ... dunno about that plan. In the first place, you seem to be
recommending that YUriy incorporate all the deficiencies of src/tools/msvc
into his first draft and then hope somehow to fix them later.

No, src/tools/msvc is a poor source of implementation ideas. Implement the
CMake build in idiomatic CMake style. Write an initial patch sufficient so we
could delete src/tools/msvc in the same patch, and make little or no attempt
to cover other cases. That's my suggestion.

In the
second place, I think that the core problem here involves being sure
we can still cover all the portability issues that have been laboriously
hacked into the autoconf/gmake build system over nigh two decades.

I agree that the first patch should demonstrate the CMake programming
environment's sufficiency for open-ended portability adaptations. I doubt
demonstrating that requires actual porting to more than a platform or two.

Starting from a build system that was designed to cover exactly one target
platform, and has never been asked to do anything more than that, doesn't
sound like a recipe for success there.

Fair point. Perhaps replace src/tools/msvc completely and build+install on at
least one reasonable GNU/Linux configuration?

A monolithic patch replacing the GNU make build system with a CMake build
system sounds far too hard to write and review; we should expect to maintain
those two build systems in parallel for awhile. Reconciling the MSVC and GNU
make build systems is a chronic problem today, so it would be a big plus to
have no more than two of MSVC, GNU Make and CMake build systems to maintain.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#24Andres Freund
andres@anarazel.de
In reply to: Noah Misch (#23)
Re: WIP: About CMake v2

On 2015-09-01 10:32:39 -0400, Noah Misch wrote:

A monolithic patch replacing the GNU make build system with a CMake build
system sounds far too hard to write and review; we should expect to maintain
those two build systems in parallel for awhile.

I don't buy this. I don't think we're going to decide to switch to cmake
before seing how the gmake conversion will look like. Possibly the gmake
part doesn't have to be immediately committable when we replace msvc
with cmake, but I'll definitely want to see the benefit (i.e. see a
one-source-of-truth tree) before paying.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#25Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#24)
Re: WIP: About CMake v2

Andres Freund <andres@anarazel.de> writes:

On 2015-09-01 10:32:39 -0400, Noah Misch wrote:

A monolithic patch replacing the GNU make build system with a CMake build
system sounds far too hard to write and review; we should expect to maintain
those two build systems in parallel for awhile.

I don't buy this.

Me either. I think the odds would be better than 50-50 that we'd never
get past that stage, and we'd be left with a situation where we've still
got two build systems, only one of them is cmake not hand-rolled perl.

Now, maybe that's still an improvement over what we've got, but the
argument is significantly harder to make. We'd have bought into all of
cmake's disadvantages (whatever they prove to be) but we'd be missing
the main claimed advantage. Also, while src/tools/msvc certainly has
got limitations, it does get a fair amount of its info out of the
Makefiles; having to change it when you add a file or whatever is the
exception not the rule. A separate cmake build system would certainly
require maintenance *every* time we touch the Makefiles.

I would actually suggest that the cmake conversion would be better off
to ignore src/tools/msvc altogether to begin with. Build something that
can handle, say, the Linux build, and then stop and evaluate. If that
looks good then start extending to other platforms. If cmake is as nifty
as some folks claim, you might already have an 80%-working Windows build
at that point.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#26YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Tom Lane (#25)
Re: WIP: About CMake v2

On Tuesday 01 September 2015 11:46:05 you wrote:

I would actually suggest that the cmake conversion would be better off
to ignore src/tools/msvc altogether to begin with.

Build postgres by MSVC is important task for me. But Linux first of course.

A separate cmake build system would certainly
require maintenance *every* time we touch the Makefiles.

I can support the cmake build a separate git branch on github.
When we (and users) see that all is well then we will think when and how to
change GNUMake to CMake.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#27Greg Stark
stark@mit.edu
In reply to: Robert Haas (#20)
Re: WIP: About CMake v2

On Tue, Sep 1, 2015 at 2:41 PM, Robert Haas <robertmhaas@gmail.com> wrote:

Maybe we should merge all of the makefiles for subdirectories of
src/backend into a single makefile. The major disadvantage would be
that you couldn't rebuild a subdirectory any more by typing make -C
src/backend/executor or whatever. And I do do that sometimes, so
maybe it would be annoying, but presumably it would make the
dependency issues a lot easier to deal with.

Actually I think it's possible to cater to that use case though I've
never tried.

What I think does become difficult in this scenario are directories
that are built more than once, eg, for client and server side builds.
I guess you could still do it but it would require doubling up every
rule and creating lots of extra targets representing the two builds
since you can't just call make with different variables.

It is tempting and I've been wanting to evalangize this approach ever
since read http://aegis.sourceforge.net/auug97.pdf but I've never
actually had practical experience with it and iirc it's always this
scenario of wanting to compile submodules multiple times that blocked
using it.

--
greg

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#28Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Greg Stark (#27)
Re: WIP: About CMake v2

Greg Stark wrote:

It is tempting and I've been wanting to evalangize this approach ever
since read http://aegis.sourceforge.net/auug97.pdf but I've never
actually had practical experience with it and iirc it's always this
scenario of wanting to compile submodules multiple times that blocked
using it.

I actually played with that a bit awhile back, after seeing that paper
referenced the fourth or fifth time (meh). I converted a few of our
current subdir makefiles into "module.mk" files that were included
rather than recursed into; for instance optimizer/util/module.mk would
do this:

+OBJS += optimizer/util/clauses.o optimizer/util/joininfo.o optimizer/util/orclauses.o optimizer/util/pathnode.o optimizer/util/placeholder.o \
+       optimizer/util/plancat.o optimizer/util/predtest.o optimizer/util/relnode.o optimizer/util/restrictinfo.o optimizer/util/tlist.o optimizer/util/var.o

then the backend-level makefile would do this:

+include $(patsubst %,%/module.mk,$(NEWSUBDIRS))

where NEWSUBDIRS were the subdirs I had converted, so

NEWSUBDIRS = access optimizer

In turn, optimizer/module.mk would be this:

NEWSUBDIRS = geqo path plan prep util

include $(patsubst %,optimizer/%/module.mk,$(NEWSUBDIRS))

It seemed to work fine for the small subset that I changed; then I got
lazy and never got around to writing a macro to do the subdir makefile
conversion (and of course I wasn't going to do it by hand). Of course,
some things needs special treatment (postgres.bki, gram.c etc) which I
also never got around to even trying.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#29Noah Misch
noah@leadboat.com
In reply to: Tom Lane (#25)
Re: WIP: About CMake v2

On Tue, Sep 01, 2015 at 11:46:05AM -0400, Tom Lane wrote:

Andres Freund <andres@anarazel.de> writes:

On 2015-09-01 10:32:39 -0400, Noah Misch wrote:

A monolithic patch replacing the GNU make build system with a CMake build
system sounds far too hard to write and review; we should expect to maintain
those two build systems in parallel for awhile.

I don't buy this.

Me either.

Okay. If the author, reviewer(s) and committer deliver a correct monolithic
patch, I won't have anything to complain about. For the PostgreSQL hackers
not involved in this work, that outcome is better than my suggestion.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#30YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: YUriy Zhuravlev (#17)
Re: WIP: About CMake v2

Hello hackers.

News about CMake:
I built postgres, initdb, createdb, psql, pg_ctl using CMake.
After make install you can run initdb after run postgres after createdb and
use it by psql. Only for Linux now and realy bugy (and the code is very dirt)
but it work!
If someone wants to test or to help:
https://github.com/stalkerg/postgres_cmake

Thanks.

PS All define for pg_config.h generate and testing truly
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#31Michael Paquier
michael.paquier@gmail.com
In reply to: YUriy Zhuravlev (#30)
Re: WIP: About CMake v2

On Wed, Nov 25, 2015 at 1:35 AM, YUriy Zhuravlev <u.zhuravlev@postgrespro.ru

wrote:

News about CMake:
I built postgres, initdb, createdb, psql, pg_ctl using CMake.
After make install you can run initdb after run postgres after createdb and
use it by psql. Only for Linux now and realy bugy (and the code is very
dirt)
but it work!
If someone wants to test or to help:
https://github.com/stalkerg/postgres_cmake

PS All define for pg_config.h generate and testing truly

Thanks for sharing the progress! That's really something that would pay
long-term.
--
Michael

#32Craig Ringer
craig@2ndquadrant.com
In reply to: Tom Lane (#8)
Re: WIP: About CMake v2

On 29 August 2015 at 02:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Christopher Browne <cbbrowne@gmail.com> writes:

(Does CMake run on a VAX 11/780?? :-))

Yeah. I see the two major risks as being:

1. We limit ourselves to platforms that cmake works on.

2. We lose the ability to handle weird special-case tests that are
possible (if not necessarily pleasant) with autoconf/gmake.

I might be overly worried about #2 --- but the impression I have of cmake
is that they've spent lots of time on "make easy cases easy" and maybe not
enough on "make hard cases possible".

I would agree with that, and even go further to "make easy but common cases
ugly anyway".

I converted Scribus to CMake years ago as part of porting to Windows. It
promised to be a cleaner, nicer build system. It delivered in some ways and
was rather ugly in others.

Its configuration/scripting language feels like someone thought "hey, M4 is
horrible, lets make sure we keep that it-hurts-so-good feeling in our build
system too".

Many prewritten CMake modules fail to follow basic practices that make them
work anywhere but where the author wanted/needed. I rewrote pretty much
every CMake module I used in the build. That was years ago, mind, but I
haven't seen CMake exactly taking over the world since then.

For me CMake saved lots of pain on Windows, but added pain on Linux distros
and other platforms where I had to deal more directly with package naming
differences, path differences, etc. Maybe I was doing it wrong, or maybe
it's improved since.

To me, CMake is just another build system. It has some great features and
some truly awful ones, just like most others. It does have the major
advantage of working on Windows, but I'd want to know just how much of a
hit we were going to take on other platforms. If it breaks m68k netbsd I
really, really don't care, but platforms a sane person would use with a
modern Pg shouldn't be hurt in the name of making Windows nicer if it
doesn't actually gain real functionality.

A possible appeal of CMake to me is that we could more easily support
PGXS-like functionality sanely on Windows. It *really* sucks that we don't
have anything like that now, and how hard extensions are to build on
Windows. OTOH I think it's reasonably practical to use CMake to build a
"PGXS-alike" for windows that works with existing unmodified Pg installs of
existing versions... so the win isn't big.

Anyway, we won't know unless somebody tries it. There will certainly be

some pluses and some minuses, and we'll have to decide whether the pluses
outweigh the minuses. I don't think we can tell that without a fairly
detailed attempt at making it work.

I agree.

It's pretty much a case of "show us how it looks and we'll decide whether
to use your hours and hours of work or throw it away". Don't forget the
docs builds... unless of course the CMake conversion is also proposed to
come with a full conversion of the docs to a less prehistoric,
easier-to-work-with format. In which case you can quadruple the hours
you're gambling too.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#33YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Craig Ringer (#32)
Re: WIP: About CMake v2

On Wednesday 25 November 2015 13:27:33 you wrote:

That was years ago, mind, but I
haven't seen CMake exactly taking over the world since then.

KDE, MariaDB, neovim and etc. New projects usually selected CMake.

Many prewritten CMake modules fail to follow basic practices that make them
work anywhere but where the author wanted/needed.

Now everything is much better. And it is worth split "make" and configuration.
CMake better GNU Make and is similar to the m4 for configuring. But M4 older
and elaborated.

These are my feelings on the current work.

Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#34Craig Ringer
craig@2ndquadrant.com
In reply to: YUriy Zhuravlev (#33)
Re: WIP: About CMake v2

On 25 November 2015 at 17:41, YUriy Zhuravlev <u.zhuravlev@postgrespro.ru>
wrote:

Many prewritten CMake modules fail to follow basic practices that make

them

work anywhere but where the author wanted/needed.

Now everything is much better. And it is worth split "make" and
configuration.
CMake better GNU Make and is similar to the m4 for configuring. But M4
older
and elaborated.

These are my feelings on the current work.

That's great to hear. It's been a long while since I worked with it, and it
sounds like it's come a long way.

I'd be really happy to see a unified build system in Pg.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#35Euler Taveira
euler@timbira.com.br
In reply to: YUriy Zhuravlev (#30)
Re: WIP: About CMake v2

On 24-11-2015 13:35, YUriy Zhuravlev wrote:

News about CMake:
I built postgres, initdb, createdb, psql, pg_ctl using CMake.
After make install you can run initdb after run postgres after createdb and
use it by psql. Only for Linux now and realy bugy (and the code is very dirt)
but it work!
If someone wants to test or to help:
https://github.com/stalkerg/postgres_cmake

I give it a try. Nice WIP. IMHO you should try to support cmake version
that are available in the stable releases. Looking at [1]https://cmake.org/Wiki/CMake_Life_Cycle_Considerations, I think the
best choice is 2.8.11 (because it will cover Red Hat based distros and
also Debian based ones). Are you using a new feature from 3.1? I mean,
it should be nice to cover old stable releases, if it is possible.

[1]: https://cmake.org/Wiki/CMake_Life_Cycle_Considerations

--
Euler Taveira Timbira - http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#36YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Euler Taveira (#35)
Re: WIP: About CMake v2

On Thursday 26 November 2015 01:29:37 Euler Taveira wrote:

I give it a try. Nice WIP. IMHO you should try to support cmake version
that are available in the stable releases. Looking at [1], I think the
best choice is 2.8.11 (because it will cover Red Hat based distros and
also Debian based ones). Are you using a new feature from 3.1? I mean,
it should be nice to cover old stable releases, if it is possible.

Maybe you are right. But by the time I finish my work I think 3.0 will become
a standard. CMake is developing rapidly and soon will have version 3.4.1
And one more thing: a normal documentation came with 3.0. :)
But I try to check my code for 2.8.11, now I have 3.4.0 (latest for Gentoo).
Thanks.

--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#37Euler Taveira
euler@timbira.com.br
In reply to: YUriy Zhuravlev (#36)
Re: WIP: About CMake v2

On 26-11-2015 07:33, YUriy Zhuravlev wrote:

On Thursday 26 November 2015 01:29:37 Euler Taveira wrote:

I give it a try. Nice WIP. IMHO you should try to support cmake version
that are available in the stable releases. Looking at [1], I think the
best choice is 2.8.11 (because it will cover Red Hat based distros and
also Debian based ones). Are you using a new feature from 3.1? I mean,
it should be nice to cover old stable releases, if it is possible.

Maybe you are right. But by the time I finish my work I think 3.0 will become
a standard. CMake is developing rapidly and soon will have version 3.4.1
And one more thing: a normal documentation came with 3.0. :)
But I try to check my code for 2.8.11, now I have 3.4.0 (latest for Gentoo).

Have in mind that stable distros have a long cycle and are not released
soon. If you are planning your cmake work for 9.6 or even 9.7, it is
prudent to suport Red Hat 7 or Debian 8 because it will be a pain in the
neck to install a new cmake version just to compile postgres.

--
Euler Taveira Timbira - http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#38Tom Lane
tgl@sss.pgh.pa.us
In reply to: Euler Taveira (#37)
Re: WIP: About CMake v2

Euler Taveira <euler@timbira.com.br> writes:

On 26-11-2015 07:33, YUriy Zhuravlev wrote:

Maybe you are right. But by the time I finish my work I think 3.0 will become
a standard. CMake is developing rapidly and soon will have version 3.4.1
And one more thing: a normal documentation came with 3.0. :)
But I try to check my code for 2.8.11, now I have 3.4.0 (latest for Gentoo).

Have in mind that stable distros have a long cycle and are not released
soon. If you are planning your cmake work for 9.6 or even 9.7, it is
prudent to suport Red Hat 7 or Debian 8 because it will be a pain in the
neck to install a new cmake version just to compile postgres.

Not working with the cmake version shipped in current distributions would
almost certainly cause us to reject this patch. Adding a new build
dependency is bad enough; adding one that isn't easily available is a
show-stopper. You'd better think in terms of what's provided with RHEL6,
not RHEL7, as the minimum baseline on the Red Hat side. I'm not sure what
the oldest active LTS distribution is in the Debian world, but I'm pretty
sure it won't have cmake 3.

(FWIW, RHEL6 seems to be carrying 2.8.12 currently.)

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#39YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Tom Lane (#38)
Re: WIP: About CMake v2

On Thursday 26 November 2015 11:10:36 you wrote:

Adding a new build
dependency is bad enough; adding one that isn't easily available is a
show-stopper.

If someone decided to compile from source Postgres rather than install from
RPM then it will not be a problem as to build CMake.
On the one hand it is good that the GNU Make a stable and have not changed,
but it can not last forever.

It is possible to make support for CMake 2.6 but now is not the time when you
have to think about it. I'll come back to this when all the functionality will
work.

Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#40Andres Freund
andres@anarazel.de
In reply to: YUriy Zhuravlev (#39)
Re: WIP: About CMake v2

On 2015-11-26 19:22:23 +0300, YUriy Zhuravlev wrote:

On Thursday 26 November 2015 11:10:36 you wrote:

Adding a new build
dependency is bad enough; adding one that isn't easily available is a
show-stopper.

If someone decided to compile from source Postgres rather than install from
RPM then it will not be a problem as to build CMake.

Packages have to be built from something, and usually it's desirable
that all dependencies are from within the distribution.

I don't think you'll have much success pushing back on this.

It is possible to make support for CMake 2.6 but now is not the time when you
have to think about it. I'll come back to this when all the functionality will
work.

No point in doing any work if you don't agree with the basic prerequisites.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#41Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#40)
Re: WIP: About CMake v2

Andres Freund <andres@anarazel.de> writes:

On 2015-11-26 19:22:23 +0300, YUriy Zhuravlev wrote:

On Thursday 26 November 2015 11:10:36 you wrote:

Adding a new build dependency is bad enough; adding one that isn't
easily available is a show-stopper.

If someone decided to compile from source Postgres rather than install from
RPM then it will not be a problem as to build CMake.

Packages have to be built from something, and usually it's desirable
that all dependencies are from within the distribution.

Yeah. In particular, RPMs don't magically appear out of nowhere; somebody
has to build them, and more often than not, the somebody is subject to
distro packaging policy that says what build dependencies are allowed.

Red Hat certainly isn't ever going to ship a package that requires some
version of cmake that isn't what they ship in the particular distribution,
for example.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#42YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Andres Freund (#40)
Re: WIP: About CMake v2

On Thursday 26 November 2015 17:42:16 you wrote:

No point in doing any work if you don't agree with the basic prerequisites.

I meant that support for older versions of CMake I'll do when will implement
other functions.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#43Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#38)
Re: WIP: About CMake v2

Tom Lane wrote:

Not working with the cmake version shipped in current distributions would
almost certainly cause us to reject this patch. Adding a new build
dependency is bad enough; adding one that isn't easily available is a
show-stopper. You'd better think in terms of what's provided with RHEL6,
not RHEL7, as the minimum baseline on the Red Hat side. I'm not sure what
the oldest active LTS distribution is in the Debian world, but I'm pretty
sure it won't have cmake 3.

Current Debian Stable (wheezy) has cmake 3.0.2. Oldstable (jessie) has
2.8.4.

As for Ubuntu, according to https://wiki.ubuntu.com/LTS the oldest still
supported is 12.04 (Precise Pangolin) and they have 2.8.7:
http://packages.ubuntu.com/precise/cmake

For these systems, the CMake 2.8 functionality would be enough. No need
to go back to 2.6.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#44Euler Taveira
euler@timbira.com.br
In reply to: YUriy Zhuravlev (#42)
Re: WIP: About CMake v2

On 26-11-2015 14:06, YUriy Zhuravlev wrote:

On Thursday 26 November 2015 17:42:16 you wrote:

No point in doing any work if you don't agree with the basic prerequisites.

I meant that support for older versions of CMake I'll do when will implement
other functions.

I think you don't understand the point: start with the *right* cmake
version because you could have to redo (a lot of) your work or have your
patch rejected because you don't follow our advice.

--
Euler Taveira Timbira - http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#45Tom Lane
tgl@sss.pgh.pa.us
In reply to: Euler Taveira (#44)
Re: WIP: About CMake v2

Euler Taveira <euler@timbira.com.br> writes:

On 26-11-2015 14:06, YUriy Zhuravlev wrote:

I meant that support for older versions of CMake I'll do when will implement
other functions.

I think you don't understand the point: start with the *right* cmake
version because you could have to redo (a lot of) your work or have your
patch rejected because you don't follow our advice.

The way Yuriy wants to do it is not necessarily wrong. He might end up
with cleaner code if he starts by making a cmake-3 implementation and then
figures out how to back-port to cmake-2, rather than starting with the
more limited language to begin with.

Or maybe not. But I doubt it's open and shut.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#46Craig Ringer
craig@2ndquadrant.com
In reply to: Tom Lane (#45)
Re: WIP: About CMake v2

On 27 November 2015 at 12:39, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Euler Taveira <euler@timbira.com.br> writes:

On 26-11-2015 14:06, YUriy Zhuravlev wrote:

I meant that support for older versions of CMake I'll do when will

implement

other functions.

I think you don't understand the point: start with the *right* cmake
version because you could have to redo (a lot of) your work or have your
patch rejected because you don't follow our advice.

The way Yuriy wants to do it is not necessarily wrong. He might end up
with cleaner code if he starts by making a cmake-3 implementation and then
figures out how to back-port to cmake-2, rather than starting with the
more limited language to begin with.

Or maybe not. But I doubt it's open and shut.

One thing to consider: I can't imagine backporting this to all supported
back branches, it'd be a switch for the next release. Right?

That means he doesn't have to worry about what RH / Debian policy for their
old versions is. RH isn't going to release PostgreSQL 9.7 or whatever for
RHEL6, Debian isn't going to release it for Wheezy, etc.

We are. Or rather, the people within the community who perform the
thankless task of packaging are.

The people who need to be involved here are the PGDG package maintainers
for apt.postgresql.org and yum.postgresql.org. If you can convince them
that adding CMake 3.x as a build-dependency is acceptable and that it's
worth the pain/hassle required to ensure it's available you might avoid the
backport to CMake 2.8. Especially if someone else has already done the work
to backport CMake 3.x to wheezy, RHEL6 etc and there's a repo we can just
import the packages from or rebuild into PGDG.

A packaged version of the CMake needed will be vital for PGDG packages.
There's around about zero chance you'll get anywhere with the requirement
to hand-compile CMake to build packages. If you can't list it as a
build-depends and have the package fetched from a well-established repo
(PGDG, the distro repo, or distro official backports) I think you'd have to
support the older CMake instead.

Devrim at least has been fairly willing to backport packages and bundle
them into the PGDG repo when they're required to build newer versions of
things like PostGIS. Not without frustration and problems, though. I can't
say anything about the apt repo in this regard.

(I've CC'd Devrim)

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#47Tom Lane
tgl@sss.pgh.pa.us
In reply to: Craig Ringer (#46)
Re: WIP: About CMake v2

Craig Ringer <craig@2ndquadrant.com> writes:

One thing to consider: I can't imagine backporting this to all supported
back branches, it'd be a switch for the next release. Right?

Agreed.

That means he doesn't have to worry about what RH / Debian policy for their
old versions is. RH isn't going to release PostgreSQL 9.7 or whatever for
RHEL6, Debian isn't going to release it for Wheezy, etc.

Well, they won't if we make it impossible for them to do so.

More generally, I do not buy this argument for one second as a reason why
we can demand latest-and-greatest cmake, rather than something that's
likely to be readily available on a wide variety of platforms. Devrim is
not the only person in the world who will be needing to build PG on RHEL6,
or even older platforms.

If you take a close look at our build requirements, you will notice a
general distaste for insisting on latest anything. cmake is not going
to escape that project bias. Do you really think a project that still
works with C89, Perl 5.8.something, Python 2.3, bison 1.875, yadda yadda
is readily going to accept a patch that requires this year's cmake?
It would take a fairly impressive technical argument why working with
older cmakes is impossible/impractical before that will happen.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#48Michael Paquier
michael.paquier@gmail.com
In reply to: Craig Ringer (#46)
Re: WIP: About CMake v2

On Fri, Nov 27, 2015 at 2:50 PM, Craig Ringer <craig@2ndquadrant.com> wrote:

On 27 November 2015 at 12:39, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Euler Taveira <euler@timbira.com.br> writes:

On 26-11-2015 14:06, YUriy Zhuravlev wrote:

I meant that support for older versions of CMake I'll do when will
implement
other functions.

I think you don't understand the point: start with the *right* cmake
version because you could have to redo (a lot of) your work or have your
patch rejected because you don't follow our advice.

The way Yuriy wants to do it is not necessarily wrong. He might end up
with cleaner code if he starts by making a cmake-3 implementation and then
figures out how to back-port to cmake-2, rather than starting with the
more limited language to begin with.

Or maybe not. But I doubt it's open and shut.

One thing to consider: I can't imagine backporting this to all supported
back branches, it'd be a switch for the next release. Right?

That means he doesn't have to worry about what RH / Debian policy for their
old versions is. RH isn't going to release PostgreSQL 9.7 or whatever for
RHEL6, Debian isn't going to release it for Wheezy, etc.

We are. Or rather, the people within the community who perform the thankless
task of packaging are.

That's not only a problem related to packaging by pgdg maintainers or
the main Linux distributions. I think that you are forgetting people
who actually work on or compile the Postgres code on those platforms,
say because they for example need to perform performance test or
measurements particularly on such platforms based on customer
requirements, one possibility being to test different configure
options like bigger relation file blocks for example. It does not seem
acceptable to me to choose a minimal version of cmake without this
criteria taken into account.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#49YUriy Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Euler Taveira (#44)
Re: WIP: About CMake v2

On Thursday 26 November 2015 19:28:15 you wrote:

I think you don't understand the point: start with the *right* cmake
version because you could have to redo (a lot of) your work

Between versions CMake there is no fundamental difference.
On my laptop or desktop is already 3.4.0 (new KDE requires). At friends is
generally have the same all over 3.0.0. It is simply not convenient right now
(develop under 2.8).
But I try not to use 3.0 features. Later simply check will need to be 2.8.

Importantly do not forget CMake != GNU Make. CMake == autotools+gnumake.
New versions of CMake most fixes modules like FindBISON and etc. This
different philosophy.

Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#50Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: YUriy Zhuravlev (#1)
Re: WIP: About CMake v2

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master.
2. plpython2, plpython3, plperl, pltcl, plsql all work correctly (all tests
pass).
3. Works done for all contrib modules.
4. You can use gettext, .po->.mo will have converted by CMake.
5. All test pass under some Linux, FreeBSD, Solaris10 (on Sparc), Windows
MSVC 2015. MacOSX I think not big trouble too.
6. Prototype for PGXS (with MSVC support) done.

I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need tests
and small fixes. I can't develop and give guarantee without it.

I think this is very important work which makes it easier further support
Postgres but I can not do everything himself. It's physically impossible.

I think without community support I can't do significantly more.

Current version you can get here:
https://github.com/stalkerg/postgres_cmake

Thanks!
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#51Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Yury Zhuravlev (#50)
Re: WIP: About CMake v2

Yury Zhuravlev wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql all
work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo will
have converted by CMake. 5. All test pass under some Linux, FreeBSD,
Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big trouble too.
6. Prototype for PGXS (with MSVC support) done.

I just tried a standard build in Debian Jessie and it works nicely.
Well done! I think we should seriously consider this once 10 opens for
development.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#52Michael Paquier
michael.paquier@gmail.com
In reply to: Alvaro Herrera (#51)
Re: WIP: About CMake v2

On Thu, Jun 30, 2016 at 5:10 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Yury Zhuravlev wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql all
work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo will
have converted by CMake. 5. All test pass under some Linux, FreeBSD,
Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big trouble too.
6. Prototype for PGXS (with MSVC support) done.

Yeah! 6 would be really cool to have. Now that's doable with the perl
classes at disposition, but that's not really user-friendly.

I just tried a standard build in Debian Jessie and it works nicely.
Well done! I think we should seriously consider this once 10 opens for
development.

Yes! Heartfully agreed.

You have not tested with macOS, and so did I. With 10.11 with cmake
from brew I am getting this error at the first step:
-- Check flexible array support - yes with
CMake Error at cmake/RegressCheck.cmake:12 (elif):
Unknown CMake command "elif".
Call Stack (most recent call first):
CMakeLists.txt:782 (include)
$ cmake --version
cmake version 3.5.2
CMake suite maintained and supported by Kitware (kitware.com/cmake)

It would be nice to come as well with simpler steps than all this
mkdir build, etc stanza. Perhaps with a wrapper of some kind, in perl
that may be a good idea, though perl is not a hard requirement in
source tarballs, and on Windows/MSVC it is.
Regards,
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#53Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#52)
Re: WIP: About CMake v2

Michael Paquier wrote:

You have not tested with macOS, and so did I.

Thanks! I fixed this typo. But for XCode I see more corrections.
I will can fix it today or maybe tomorrow.

It would be nice to come as well with simpler steps than all this
mkdir build, etc stanza. Perhaps with a wrapper of some kind, in perl
that may be a good idea, though perl is not a hard requirement in
source tarballs, and on Windows/MSVC it is.

Only one extra phase (mkdir build). I think it's not so important.
For windows and macosx I used cmake GUI it's so easy.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#54Oleg Bartunov
obartunov@gmail.com
In reply to: Yury Zhuravlev (#50)
Re: WIP: About CMake v2

On Wed, Jun 29, 2016 at 7:23 PM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql all
work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo will
have converted by CMake. 5. All test pass under some Linux, FreeBSD,
Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big trouble too.
6. Prototype for PGXS (with MSVC support) done.
I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need tests and
small fixes. I can't develop and give guarantee without it.

can we use our buildfarm infrastructure for this, Andrew ?

I think this is very important work which makes it easier further support
Postgres but I can not do everything himself. It's physically impossible.

I think without community support I can't do significantly more.

Current version you can get here: https://github.com/stalkerg/postgres_cmake

Thanks!
--
Yury Zhuravlev

Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#55Andrew Dunstan
andrew@dunslane.net
In reply to: Oleg Bartunov (#54)
Re: WIP: About CMake v2

On 06/30/2016 06:26 AM, Oleg Bartunov wrote:

On Wed, Jun 29, 2016 at 7:23 PM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql all
work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo will
have converted by CMake. 5. All test pass under some Linux, FreeBSD,
Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big trouble too.
6. Prototype for PGXS (with MSVC support) done.
I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need tests and
small fixes. I can't develop and give guarantee without it.

can we use our buildfarm infrastructure for this, Andrew ?

When I get some time I intend to do some work with this to see what
might be involved in enabling this in the buildfarm. I imagine it will
probably involve something similar to the effort that moving to git
entailed.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#56Andrew Dunstan
andrew@dunslane.net
In reply to: Yury Zhuravlev (#53)
Re: WIP: About CMake v2

On 06/30/2016 03:13 AM, Yury Zhuravlev wrote:

Michael Paquier wrote:

You have not tested with macOS, and so did I.

Thanks! I fixed this typo. But for XCode I see more corrections. I
will can fix it today or maybe tomorrow.

It would be nice to come as well with simpler steps than all this
mkdir build, etc stanza. Perhaps with a wrapper of some kind, in perl
that may be a good idea, though perl is not a hard requirement in
source tarballs, and on Windows/MSVC it is.

Only one extra phase (mkdir build). I think it's not so important. For
windows and macosx I used cmake GUI it's so easy.

We need this to be scriptable, not using a GUI.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#57Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#56)
Re: WIP: About CMake v2

On Fri, Jul 1, 2016 at 5:19 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 06/30/2016 03:13 AM, Yury Zhuravlev wrote:

Only one extra phase (mkdir build). I think it's not so important. For
windows and macosx I used cmake GUI it's so easy.

We need this to be scriptable, not using a GUI.

Definitely agreed! Personally I am allergic to any kind of UIs for
development, and I am sure not to be the only one on this list.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#58Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#57)
Re: WIP: About CMake v2

Michael Paquier wrote:

Personally I am allergic to any kind of UIs for
development, and I am sure not to be the only one on this list.

Andrew Dunstan:

We need this to be scriptable, not using a GUI.

GUI is strong optional feature. Helpful for some tasks.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#59Dmitry Maslyuk
d.masluk@postgrespro.ru
In reply to: Yury Zhuravlev (#50)
Re: WIP: About CMake v2

Hi!

I think, we need simple configure script generator for backward
compatibility and easy using this build system.
Try playing with cmake build system under Win2008+MinGW. I plan to write
perl script for automatic build this
with depends.

On 29.06.2016 19:23, Yury Zhuravlev wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl,
plsql all work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext,
.po->.mo will have converted by CMake. 5. All test pass under some
Linux, FreeBSD, Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I
think not big trouble too. 6. Prototype for PGXS (with MSVC support)
done.
I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need
tests and small fixes. I can't develop and give guarantee without it.

I think this is very important work which makes it easier further
support Postgres but I can not do everything himself. It's physically
impossible.

I think without community support I can't do significantly more.

Current version you can get here:
https://github.com/stalkerg/postgres_cmake

Thanks!

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#60Christian Convey
christian.convey@gmail.com
In reply to: Dmitry Maslyuk (#59)
Re: WIP: About CMake v2

Hi Yury,

I'm interested in helping with your CMake effort. I don't have any
experience contributing to PG, but I do have some free time at the
moment. Please let me know if I can help.

I have an intermediate level of experience with CMake, Python, and
Bash scripting. My native environment is Mint 17.3 (i.e., Ubuntu
15.10), but I'd be happy to create additional VM's as needed. I'm
also happy to look into bugs on other systems (VMS, etc.) if I can get
SSH access.

Kind regards,
Christian Convey

On Fri, Jul 1, 2016 at 5:26 AM, Dmitry Maslyuk <d.masluk@postgrespro.ru> wrote:

Hi!

I think, we need simple configure script generator for backward
compatibility and easy using this build system.
Try playing with cmake build system under Win2008+MinGW. I plan to write
perl script for automatic build this
with depends.

On 29.06.2016 19:23, Yury Zhuravlev wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql
all work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo
will have converted by CMake. 5. All test pass under some Linux, FreeBSD,
Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big trouble too.
6. Prototype for PGXS (with MSVC support) done.
I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need tests
and small fixes. I can't develop and give guarantee without it.

I think this is very important work which makes it easier further support
Postgres but I can not do everything himself. It's physically impossible.

I think without community support I can't do significantly more.

Current version you can get here:
https://github.com/stalkerg/postgres_cmake

Thanks!

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#61Stefan Kaltenbrunner
stefan@kaltenbrunner.cc
In reply to: Yury Zhuravlev (#50)
Re: WIP: About CMake v2

On 06/29/2016 06:23 PM, Yury Zhuravlev wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql
all work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo
will have converted by CMake. 5. All test pass under some Linux,
FreeBSD, Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big
trouble too. 6. Prototype for PGXS (with MSVC support) done.
I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need tests
and small fixes. I can't develop and give guarantee without it.

I think this is very important work which makes it easier further
support Postgres but I can not do everything himself. It's physically
impossible.

I think without community support I can't do significantly more.

Current version you can get here:
https://github.com/stalkerg/postgres_cmake

hmm how do you actually want reports on how it works?

I just played with it on spoonbill (OpenBSD 5.3/sparc64) and got this:

CMake Error at CMakeLists.txt:1250 (file):
file does not recognize sub-command GENERATE

CMake Error at src/port/CMakeLists.txt:156 (target_compile_definitions):
Unknown CMake command "target_compile_definitions".

-- Configuring incomplete, errors occurred!

there is also a ton of stuff like:

Make Error: Internal CMake error, TryCompile generation of cmake failed
-- Looking for opterr - not found
-- Looking for optreset
CMake Error at CMakeLists.txt:10 (ADD_EXECUTABLE):
Target "cmTryCompileExec3458204847" links to item " m" which has
leading or
trailing whitespace. This is now an error according to policy CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed
-- Looking for optreset - not found
-- Looking for fseeko
CMake Error at CMakeLists.txt:10 (ADD_EXECUTABLE):
Target "cmTryCompileExec2628321539" links to item " m" which has
leading or
trailing whitespace. This is now an error according to policy CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed

which I have no idea whether they are an actual problem or just
"configure" noise

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#62Christian Convey
christian.convey@gmail.com
In reply to: Stefan Kaltenbrunner (#61)
Re: WIP: About CMake v2

Hi Stefan,

I think I've seen similar errors when a project's CMake files assumed
a newer version of CMake than the one being run.

Which version of CMake gave you those errors? (Sorry if you provided
that detail and I'm just missing it.)

Kind regards,
Christian

On Thu, Aug 18, 2016 at 2:45 PM, Stefan Kaltenbrunner
<stefan@kaltenbrunner.cc> wrote:

On 06/29/2016 06:23 PM, Yury Zhuravlev wrote:

Hello Hackers.

I decided to talk about the current state of the project:
1. Merge with 9.6 master. 2. plpython2, plpython3, plperl, pltcl, plsql
all work correctly (all tests pass).
3. Works done for all contrib modules. 4. You can use gettext, .po->.mo
will have converted by CMake. 5. All test pass under some Linux,
FreeBSD, Solaris10 (on Sparc), Windows MSVC 2015. MacOSX I think not big
trouble too. 6. Prototype for PGXS (with MSVC support) done.
I think is very big progress but I came across one problem.
I not have access to many OS and platforms. For each platform need tests
and small fixes. I can't develop and give guarantee without it.

I think this is very important work which makes it easier further
support Postgres but I can not do everything himself. It's physically
impossible.

I think without community support I can't do significantly more.

Current version you can get here:
https://github.com/stalkerg/postgres_cmake

hmm how do you actually want reports on how it works?

I just played with it on spoonbill (OpenBSD 5.3/sparc64) and got this:

CMake Error at CMakeLists.txt:1250 (file):
file does not recognize sub-command GENERATE

CMake Error at src/port/CMakeLists.txt:156 (target_compile_definitions):
Unknown CMake command "target_compile_definitions".

-- Configuring incomplete, errors occurred!

there is also a ton of stuff like:

Make Error: Internal CMake error, TryCompile generation of cmake failed
-- Looking for opterr - not found
-- Looking for optreset
CMake Error at CMakeLists.txt:10 (ADD_EXECUTABLE):
Target "cmTryCompileExec3458204847" links to item " m" which has
leading or
trailing whitespace. This is now an error according to policy CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed
-- Looking for optreset - not found
-- Looking for fseeko
CMake Error at CMakeLists.txt:10 (ADD_EXECUTABLE):
Target "cmTryCompileExec2628321539" links to item " m" which has
leading or
trailing whitespace. This is now an error according to policy CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed

which I have no idea whether they are an actual problem or just
"configure" noise

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#63Stefan Kaltenbrunner
stefan@kaltenbrunner.cc
In reply to: Christian Convey (#62)
Re: WIP: About CMake v2

On 08/18/2016 08:57 PM, Christian Convey wrote:

Hi Stefan,

I think I've seen similar errors when a project's CMake files assumed
a newer version of CMake than the one being run.

Which version of CMake gave you those errors? (Sorry if you provided
that detail and I'm just missing it.)

% cmake --version
cmake version 2.8.10.2

a quick look in the docs does not seem to reveal any kind of "minimum"
cmake version required - and the above is what is packaged as part of
openbsd 5.3 (which is outdated and unsupported upstream but it is
currently perfectly fine building all postgresql versions including
-HEAD and serving as a buildfarm member for years)

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#64Tom Lane
tgl@sss.pgh.pa.us
In reply to: Stefan Kaltenbrunner (#63)
Re: WIP: About CMake v2

Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:

On 08/18/2016 08:57 PM, Christian Convey wrote:

Which version of CMake gave you those errors? (Sorry if you provided
that detail and I'm just missing it.)

% cmake --version
cmake version 2.8.10.2

a quick look in the docs does not seem to reveal any kind of "minimum"
cmake version required - and the above is what is packaged as part of
openbsd 5.3 (which is outdated and unsupported upstream but it is
currently perfectly fine building all postgresql versions including
-HEAD and serving as a buildfarm member for years)

As an additional comment, I don't see us accepting a build system
that doesn't run on pretty old cmakes. We have never had a policy
of "latest and greatest is required" for *any* build support tool,
and cmake isn't likely to be given an exception.

BTW, I just noticed that cmake doesn't seem to be supplied as part of
Apple's dev tools, at least not up to current (El Capitan) releases.
That's going to be a rather large minus to be taken into account
whenever we make the go/no-go decision on this.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#65Christian Convey
christian.convey@gmail.com
In reply to: Stefan Kaltenbrunner (#63)
Re: WIP: About CMake v2

Hi Karl,

I'll need to let Yury answer your original question regarding the best
way to report CMake-related bugs.

Regarding the errors you're getting... I just looked at CMake's
online documentation regarding your "target_compile_definitions"
error.

From what I can tell, the "target_compile_definition" property was
introduced in CMake 2.8.11. It sounds like your version of CMake is
just a little too old.

Regarding how one can know the required CMake version: My modus
operandi for CMake projects in general is (1) read the project's
how-to-build docs, and if that's not heplful, (2) hope that the
project's CMake files contain a "cmake_minimum_required" call to give
me a clear error message. I didn't find any such indication in Yuri's
files, although perhaps I missed it.

Yury: Would it make sense to add a call to "cmake_minimum_required" in
one or more of your CMakeLists.txt files?

Kind regards,
Christian

On Thu, Aug 18, 2016 at 3:08 PM, Stefan Kaltenbrunner
<stefan@kaltenbrunner.cc> wrote:

On 08/18/2016 08:57 PM, Christian Convey wrote:

Hi Stefan,

I think I've seen similar errors when a project's CMake files assumed
a newer version of CMake than the one being run.

Which version of CMake gave you those errors? (Sorry if you provided
that detail and I'm just missing it.)

% cmake --version
cmake version 2.8.10.2

a quick look in the docs does not seem to reveal any kind of "minimum"
cmake version required - and the above is what is packaged as part of
openbsd 5.3 (which is outdated and unsupported upstream but it is
currently perfectly fine building all postgresql versions including
-HEAD and serving as a buildfarm member for years)

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#66Stefan Kaltenbrunner
stefan@kaltenbrunner.cc
In reply to: Christian Convey (#65)
Re: WIP: About CMake v2

On 08/18/2016 09:30 PM, Christian Convey wrote:

Hi Karl,

I'll need to let Yury answer your original question regarding the best
way to report CMake-related bugs.

Regarding the errors you're getting... I just looked at CMake's
online documentation regarding your "target_compile_definitions"
error.

From what I can tell, the "target_compile_definition" property was
introduced in CMake 2.8.11. It sounds like your version of CMake is
just a little too old.

Well - "too old" is a relative term - cmake 2.8.10 was released in only
october 2012 and cmake 2.8.11 in may 2013 so it is not even 4 years old,
the oldest currently supported (though for not much longer) postgresql
release 9.1 was released in september 2011 and 9.2 was also released
before october 2012.
So while Cmake compat might only make it for v10, I dont think that we
can depend on bleeding edge version like that for our buildtools...

Regarding how one can know the required CMake version: My modus
operandi for CMake projects in general is (1) read the project's
how-to-build docs, and if that's not heplful, (2) hope that the
project's CMake files contain a "cmake_minimum_required" call to give
me a clear error message. I didn't find any such indication in Yuri's
files, although perhaps I missed it.

Yury: Would it make sense to add a call to "cmake_minimum_required" in
one or more of your CMakeLists.txt files?

it would make sense nevertheless but I dont think that 2.8.11 is old
enough - looking at the release information and the feature compatibily
matrix it would seems we should more aim at something like 2.8.0 or 2.8.3...

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#67Christian Convey
christian.convey@gmail.com
In reply to: Tom Lane (#64)
Re: WIP: About CMake v2

Hi Tom,

Thanks for that information.

Is there some document I can read that explains which platform
versions (e.g., OpenBSD 5.3) are considered strongly supported?

I ask because I'm curious if/how someone in Yury's situation could
predict which minimum version of CMake must be supported in order for
his patch to be accepted. (And if he accepts my offer to pitch in,
I'll actually need that particular detail.)

Kind regards,
Christian

As an additional comment, I don't see us accepting a build system
that doesn't run on pretty old cmakes. We have never had a policy
of "latest and greatest is required" for *any* build support tool,
and cmake isn't likely to be given an exception.

BTW, I just noticed that cmake doesn't seem to be supplied as part of
Apple's dev tools, at least not up to current (El Capitan) releases.
That's going to be a rather large minus to be taken into account
whenever we make the go/no-go decision on this.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#68Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Stefan Kaltenbrunner (#66)
Re: WIP: About CMake v2

Stefan Kaltenbrunner wrote:

On 08/18/2016 09:30 PM, Christian Convey wrote:

Yury: Would it make sense to add a call to "cmake_minimum_required" in
one or more of your CMakeLists.txt files?

it would make sense nevertheless but I dont think that 2.8.11 is old
enough - looking at the release information and the feature compatibily
matrix it would seems we should more aim at something like 2.8.0 or 2.8.3...

Last year I checked versions installable in Debian:
/messages/by-id/20150829213631.GI2912@alvherre.pgsql
From that I would say that the maximum minimum is 2.8.2. Not sure if
there's any platform where 2.8.0 (released in 2009) or older would be
necessary.

For the record, IIRC the oldest Perl we support is something like 5.8.3
(released in 2004, bugfix release after 5.8.0 released in 2002)

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#69Stefan Kaltenbrunner
stefan@kaltenbrunner.cc
In reply to: Christian Convey (#67)
Re: WIP: About CMake v2

On 08/18/2016 09:42 PM, Christian Convey wrote:

Hi Tom,

Thanks for that information.

Is there some document I can read that explains which platform
versions (e.g., OpenBSD 5.3) are considered strongly supported?

well not sure we have very clear document on that - I would say that the
buildfarm is the most authoritative answer to that. So I think skimming
the buildfarm for the oldest and strangest platforms would be a good start.

I ask because I'm curious if/how someone in Yury's situation could
predict which minimum version of CMake must be supported in order for
his patch to be accepted. (And if he accepts my offer to pitch in,
I'll actually need that particular detail.)

well I personally think the level to meet would be that all the systems
on the buildfarm that can build -HEAD at the time the patch is proposed
for a commit should be able to build using the new system with whatever
cmake version is available in those by default (if it is at all).

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#70Christian Convey
christian.convey@gmail.com
In reply to: Stefan Kaltenbrunner (#66)
Re: WIP: About CMake v2

Hi Stefan,

Yury: Would it make sense to add a call to "cmake_minimum_required" in
one or more of your CMakeLists.txt files?

it would make sense nevertheless but I dont think that 2.8.11 is old
enough - looking at the release information and the feature compatibily
matrix it would seems we should more aim at something like 2.8.0 or 2.8.3...

I'm new to PG development, so I don't know what ideas the community is
open to. But I wonder if there's any merit to the following
approach...

* Allow the CMake-based build system to assume a fairly modern version
of CMake. (Maybe 2.8.12, or 3.0.)

* For systems where the minimum CMake version isn't readily available,
have an alternative build system which is just a simplistic Bash
script that naively performs a full build every time it's invoked.
The idea being that PG contributors are mostly the people who want
efficient rebuilds, and most/all of them could easily install that
minimal CMake version.

*IF* it proved possible to write a clear, maintainable Bash script for
that, perhaps that would eliminate most concerns about CMake not being
well-supported on uncommon platforms / platform versions.

- Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#71Stefan Kaltenbrunner
stefan@kaltenbrunner.cc
In reply to: Alvaro Herrera (#68)
Re: WIP: About CMake v2

On 08/18/2016 09:52 PM, Alvaro Herrera wrote:

Stefan Kaltenbrunner wrote:

On 08/18/2016 09:30 PM, Christian Convey wrote:

Yury: Would it make sense to add a call to "cmake_minimum_required" in
one or more of your CMakeLists.txt files?

it would make sense nevertheless but I dont think that 2.8.11 is old
enough - looking at the release information and the feature compatibily
matrix it would seems we should more aim at something like 2.8.0 or 2.8.3...

Last year I checked versions installable in Debian:
/messages/by-id/20150829213631.GI2912@alvherre.pgsql
From that I would say that the maximum minimum is 2.8.2. Not sure if
there's any platform where 2.8.0 (released in 2009) or older would be
necessary.

well we have for example a NetBSD 5.1 boxe (coypu) on the buildfarm that
have a software stack that is basically 2008/2009ish...
So 2.8.0-2.8.3 seems like a realistic target to me still

Stefan

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#72Christian Convey
christian.convey@gmail.com
In reply to: Stefan Kaltenbrunner (#69)
Re: WIP: About CMake v2

Hi Tom,

I ask because I'm curious if/how someone in Yury's situation could
predict which minimum version of CMake must be supported in order for
his patch to be accepted. (And if he accepts my offer to pitch in,
I'll actually need that particular detail.)

well I personally think the level to meet would be that all the systems
on the buildfarm that can build -HEAD at the time the patch is proposed
for a commit should be able to build using the new system with whatever
cmake version is available in those by default (if it is at all).

I see. In other projects I've worked on, the configuration of a build
farm has been driven by some list of platforms that were considered
important to support.

Is that the case here as well? I.e., is the build-farm population
just a convenient proxy for some other source of information regarding
what platforms are important?

Apologies if my questions are so basic that I can find the answers
elsewhere. I'll happily follow any RTFM links.

Thanks again,
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#73Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Christian Convey (#70)
Re: WIP: About CMake v2

Christian Convey wrote:

* Allow the CMake-based build system to assume a fairly modern version
of CMake. (Maybe 2.8.12, or 3.0.)

* For systems where the minimum CMake version isn't readily available,
have an alternative build system which is just a simplistic Bash
script that naively performs a full build every time it's invoked.
The idea being that PG contributors are mostly the people who want
efficient rebuilds, and most/all of them could easily install that
minimal CMake version.

*IF* it proved possible to write a clear, maintainable Bash script for
that, perhaps that would eliminate most concerns about CMake not being
well-supported on uncommon platforms / platform versions.

I think this "simplistic Bash script" is called "configure" and is
generated by autoconf from our configure.in. I don't think the word
"simplistic" describes it very well (nor does "maintainable").

I don't think we're interested in maintaining more build systems than we
already are. If cmake can replace the current MSVC tooling and
autoconf, all in one, my impression is that we're in. If we're
replacing two tools we've hammered pretty well over the years with two
tools that we haven't, I doubt we're interested.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#74Christian Convey
christian.convey@gmail.com
In reply to: Alvaro Herrera (#73)
Re: WIP: About CMake v2

I don't think we're interested in maintaining more build systems than we
already are. If cmake can replace the current MSVC tooling and
autoconf, all in one, my impression is that we're in. If we're
replacing two tools we've hammered pretty well over the years with two
tools that we haven't, I doubt we're interested.

Good to know, thanks.

- Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#75Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Christian Convey (#72)
Re: WIP: About CMake v2

Christian Convey wrote:

I see. In other projects I've worked on, the configuration of a build
farm has been driven by some list of platforms that were considered
important to support.

Build farm members are systems that somebody has seen as interesting
enough that they deserve enough effort to set up a buildfarm member for.
So the buildfarm roster *is* that list.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#76Andres Freund
andres@anarazel.de
In reply to: Christian Convey (#70)
Re: WIP: About CMake v2

On 2016-08-18 15:55:20 -0400, Christian Convey wrote:

* Allow the CMake-based build system to assume a fairly modern version
of CMake. (Maybe 2.8.12, or 3.0.)

* For systems where the minimum CMake version isn't readily available,
have an alternative build system which is just a simplistic Bash
script that naively performs a full build every time it's invoked.
The idea being that PG contributors are mostly the people who want
efficient rebuilds, and most/all of them could easily install that
minimal CMake version.

The benefit cmake brings to the table, from my pov, is that it allows to
get rid of somewhat a parallel buildsystem (msvc / windows, which
sources most of its information from the makefiles). If we continue to
have two, especially if they're entirely separate, I see little benefit
in this whole endeavor.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#77Christian Convey
christian.convey@gmail.com
In reply to: Stefan Kaltenbrunner (#69)
Re: WIP: About CMake v2

Hi Stefan,

I ask because I'm curious if/how someone in Yury's situation could
predict which minimum version of CMake must be supported in order for
his patch to be accepted. (And if he accepts my offer to pitch in,
I'll actually need that particular detail.)

well I personally think the level to meet would be that all the systems
on the buildfarm that can build -HEAD at the time the patch is proposed
for a commit should be able to build using the new system with whatever
cmake version is available in those by default (if it is at all).

What standard would you suggest for those platforms which don't have
an obvious default version of CMake?

I assume this includes all versions of Windows and of OS X, but
perhaps I'm misinformed.

Thanks,
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#78Tom Lane
tgl@sss.pgh.pa.us
In reply to: Christian Convey (#72)
Re: WIP: About CMake v2

Christian Convey <christian.convey@gmail.com> writes:

well I personally think the level to meet would be that all the systems
on the buildfarm that can build -HEAD at the time the patch is proposed
for a commit should be able to build using the new system with whatever
cmake version is available in those by default (if it is at all).

I see. In other projects I've worked on, the configuration of a build
farm has been driven by some list of platforms that were considered
important to support.

Is that the case here as well? I.e., is the build-farm population
just a convenient proxy for some other source of information regarding
what platforms are important?

To a large extent, the buildfarm population is interesting because those
machines represent platforms for which someone is willing to put their
money where their mouth is, ie go to the effort of maintaining a buildfarm
member. For those cases, we're likely to hear complaints if we break it.

There are also buildfarm members that are really only there as coal mine
canaries, that is, we don't want to break compatibility by accident ---
but if there were a good reason for it, we might be willing to throw those
platforms overboard. My HPPA/HPUX dinosaur is certainly in that category,
for example.

I do not think we have a project policy about where the dividing line
is, though.

BTW, Stefan's formulation supposes that on platforms where the vendor
didn't supply any version of cmake, we can tell people to install whatever
version we want. But that's assuming something not in evidence, namely
that cmake works on those platforms at all, in any version. We'll have
a lot of legwork to do to find out what platforms we are risking losing.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#79Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Christian Convey (#77)
Re: WIP: About CMake v2

On 8/18/16 4:23 PM, Christian Convey wrote:

What standard would you suggest for those platforms which don't have
an obvious default version of CMake?

In the olden days, when many platforms we supported didn't come with GNU
make or other GNU tools or even a compiler, we collected a lot of
practical information about where to get these things. You can see most
of that at
<https://www.postgresql.org/docs/devel/static/installation-platform-notes.html&gt;.

That's at least the spirit of things. I wouldn't worry about this so
much right now. Get it working first.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#80Michael Paquier
michael.paquier@gmail.com
In reply to: Tom Lane (#64)
Re: WIP: About CMake v2

On Fri, Aug 19, 2016 at 4:25 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

BTW, I just noticed that cmake doesn't seem to be supplied as part of
Apple's dev tools, at least not up to current (El Capitan) releases.
That's going to be a rather large minus to be taken into account
whenever we make the go/no-go decision on this.

Indeed. Now in order to test the patch on macos, one can depend on
brew's cmake. That's what I am doing.

I recall that a couple of releases before El Capitan (10.11), Lion and
Mountain Lion had a server edition that bundled Postgres natively.
Does this still exist for El Capitan? If yes, moving to cmake may
actually give an argument to those folks to begin to touch cmake and
integrate it natively... But as Apple is a fortress of secrecy that's
hard to tell.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#81Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Stefan Kaltenbrunner (#61)
Re: WIP: About CMake v2

Stefan Kaltenbrunner wrote:

hmm how do you actually want reports on how it works?

I just played with it on spoonbill (OpenBSD 5.3/sparc64) and got this:

CMake Error at CMakeLists.txt:1250 (file):
file does not recognize sub-command GENERATE

CMake Error at src/port/CMakeLists.txt:156 (target_compile_definitions):
Unknown CMake command "target_compile_definitions".

-- Configuring incomplete, errors occurred!

there is also a ton of stuff like:

Make Error: Internal CMake error, TryCompile generation of cmake failed
-- Looking for opterr - not found
-- Looking for optreset
CMake Error at CMakeLists.txt:10 (ADD_EXECUTABLE):
Target "cmTryCompileExec3458204847" links to item " m" which has
leading or
trailing whitespace. This is now an error according to policy CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed
-- Looking for optreset - not found
-- Looking for fseeko
CMake Error at CMakeLists.txt:10 (ADD_EXECUTABLE):
Target "cmTryCompileExec2628321539" links to item " m" which has
leading or
trailing whitespace. This is now an error according to policy CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed

which I have no idea whether they are an actual problem or just
"configure" noise

Can you send issue into github?
https://github.com/stalkerg/postgres_cmake/issues

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#82Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Christian Convey (#60)
Re: WIP: About CMake v2

Christian Convey wrote:

I'm interested in helping with your CMake effort. I don't have any
experience contributing to PG, but I do have some free time at the
moment. Please let me know if I can help.

I glad to hear it. I suppose you can just try build postgres and send all
problems to github tracker.
https://github.com/stalkerg/postgres_cmake/issues

Big thanks!

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#83Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Stefan Kaltenbrunner (#66)
Re: WIP: About CMake v2

Stefan Kaltenbrunner wrote:

On 08/18/2016 09:30 PM, Christian Convey wrote:

Hi Karl,

I'll need to let Yury answer your original question regarding the best
way to report CMake-related bugs.

Regarding the errors you're getting... I just looked at CMake's
online documentation regarding your "target_compile_definitions" ...

Well - "too old" is a relative term - cmake 2.8.10 was released in only
october 2012 and cmake 2.8.11 in may 2013 so it is not even 4 years old,
the oldest currently supported (though for not much longer) postgresql
release 9.1 was released in september 2011 and 9.2 was also released
before october 2012.
So while Cmake compat might only make it for v10, I dont think that we
can depend on bleeding edge version like that for our buildtools...

1. I don't know but nobody objections if we install latest CMake under
Windows or MacOSX but many if under Linux/*BSD. I have builded CMake
recently under old Solaris without any problems.

2. I use "graceful degradation" method and currently target is 3.0 version
BUT time to time I testing and backporting the code. I hope I can make all
features for 2.8.4 .

3. Please do not compare cmake and GNU Make. CMake it's like Autotools with
detect library scripts out the box. Every new version brings not only new
functions and syntax construction. Most fix in find_library scripts.
Besides you can't build project without gnu make, make, nmake, ninja and
etc because CMake generate files for another make systems. On this basis,
to CMake can not meet the same requirements for version as GNU Make. It is
quite another thing.

PS Special for Postgres in CMake 3.6 I implemented features for replace
gen_def.pl script under MSVC.
https://gitlab.kitware.com/cmake/cmake/merge_requests/29

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#84Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Andres Freund (#76)
Re: WIP: About CMake v2

Andres Freund wrote:

The benefit cmake brings to the table, from my pov, is that it allows to
get rid of somewhat a parallel buildsystem (msvc / windows, which
sources most of its information from the makefiles). If we continue to
have two, especially if they're entirely separate, I see little benefit
in this whole endeavor.

I fully agree with this. Although I still leave the probability that for a
while (couple of months) CMake will coexist with autoconf solely for
testing and verification.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#85Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Stefan Kaltenbrunner (#71)
Re: WIP: About CMake v2

Stefan Kaltenbrunner wrote:

well we have for example a NetBSD 5.1 boxe (coypu) on the buildfarm that
have a software stack that is basically 2008/2009ish...
So 2.8.0-2.8.3 seems like a realistic target to me still

You can install fresh CMake to NetBSD without big problems from source.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#86Christian Convey
christian.convey@gmail.com
In reply to: Yury Zhuravlev (#85)
Re: WIP: About CMake v2

Hi Yury,

On Fri, Aug 19, 2016 at 9:46 AM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Christian Convey wrote:

I'm interested in helping with your CMake effort. I don't have any
experience contributing to PG, but I do have some free time at the
moment. Please let me know if I can help.

I glad to hear it. I suppose you can just try build postgres and send all
problems to github tracker.
https://github.com/stalkerg/postgres_cmake/issues

Thanks, I'll be happy to do that. There's been a lot of discussion on
this thread regarding the minimum required CMake version. If you'd
like me to test with a particular version (or versions) of CMake,
please let me know.

- Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#87Christian Convey
christian.convey@gmail.com
In reply to: Christian Convey (#86)
Re: WIP: About CMake v2

Hi Yury,

I glad to hear it. I suppose you can just try build postgres and send all
problems to github tracker.
https://github.com/stalkerg/postgres_cmake/issues

FYI, I had success using your "postgres_cmake" repo. I tested it up
through "make check" and "make install".

Here are the details:

* postgres_cmake commit e7e75160d4533cd8caa9f3f0dd7b485dbd4e7bdf
* compiler = cc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
* cmake version = 3.5.3

Kind regards,
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#88Michael Paquier
michael.paquier@gmail.com
In reply to: Christian Convey (#87)
Re: WIP: About CMake v2

Yury,

On Mon, Aug 22, 2016 at 7:48 AM, Christian Convey
<christian.convey@gmail.com> wrote:

I glad to hear it. I suppose you can just try build postgres and send all
problems to github tracker.
https://github.com/stalkerg/postgres_cmake/issues

FYI, I had success using your "postgres_cmake" repo. I tested it up
through "make check" and "make install".

Here are the details:

* postgres_cmake commit e7e75160d4533cd8caa9f3f0dd7b485dbd4e7bdf
* compiler = cc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
* cmake version = 3.5.3

Could it be possible to get a refreshed patch on this thread for at
least the sake of the archives? I'd really like to see somehting
happening here and do some progress for this CF.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#89Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#88)
Re: WIP: About CMake v2

Michael Paquier wrote:

Could it be possible to get a refreshed patch on this thread for at
least the sake of the archives? I'd really like to see somehting
happening here and do some progress for this CF.

Sure, I will do it on Friday.
Today I finished mingw+msys support. (mingw without msys has not passed
some tests)
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#90Michael Paquier
michael.paquier@gmail.com
In reply to: Yury Zhuravlev (#89)
Re: WIP: About CMake v2

On Fri, Sep 16, 2016 at 4:38 AM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Michael Paquier wrote:

Could it be possible to get a refreshed patch on this thread for at
least the sake of the archives? I'd really like to see somehting
happening here and do some progress for this CF.

Sure, I will do it on Friday.
Today I finished mingw+msys support. (mingw without msys has not passed some
tests)

Okay. That sounds good to me. I don't recall what your patch is
exactly doing but could you still keep the vanilla Makefiles around?
This will reduce the diff of the patch, and we'd need anyway to keep
the former Makefile methods around until the buildfarm scripts are
updated, the animals do the switch and then get green. So a period
where both live in parallel is unavoidable.

I heard as well that MySQL is using cmake... It may be interesting to
see how they are integrating with it as a large project and avoid
their past mistakes.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#91Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#90)
Re: WIP: About CMake v2

On Fri, Sep 16, 2016 at 9:58 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Okay. That sounds good to me. I donas well a look around, and cmake really looks like a robust alternative to ./configure. Now I am aware of the fact that your patch recommends to build 't recall what your patch is
exactly doing but could you still keep the vanilla Makefiles around?
This will reduce the diff of the patch, and we'd need anyway to keep
the former Makefile methods around until the buildfarm scripts are
updated, the animals do the switch and then get green. So a period
where both live in parallel is unavoidable.

I heard as well that MySQL is using cmake... It may be interesting to
see how they are integrating with it as a large project and avoid
their past mistakes.

I could not resist so I just had a look at your patch. I had as well a
look around, and cmake really looks like a robust alternative to
./configure. In short, people doing now that:
./configure
make
make install
Would just do that:
cmake .
make
make install

I am no cmake guru yet, but VPATH builds are supported out of the box,
which is cool.

Your patch recommends to build with cmake after creating build/, now I
would expect most users to run cmake from the root folder. However
this causes all the Makefiles to get overwritten. As supporting all
platforms at once with cmake is going to be uncommitable, we are going
to need both methods able to live together for a while. Well, they can
coexist with this patch as long as cmake is not run from the root of
the code tree, which is acceptable for me as long as the switch is not
completed. However others may think differently on the matter.

Instead of getting support for all existing platforms, I would
recommend as well focusing only on one platform for the time being,
Linux, and get the work done correctly for that first. Once there is
something committed, we will be able to patch the buildfarm, and get
machines to switch to cmake one by one. After those are switched, we
could extend that. Another point of contention is support for
extensions. How long should we keep support for the existing PGXS? How
external extensions would compile with the new thing infrastructure?

Which brings me to another point, your patch is focused on features,
meaning that per-OS checks are all grouped by feature, but it may be a
good idea to split checks by OS if necessary, with for example
per-platform files and scripts in cmake/os/. And we could have just
something for Linux now.

A couple of issues I have noticed with your patch after a first set of tests:
- root's .gitignore needs to add entries for CMakeFiles and
cmake_install.cmake. You need as well to ignore CMakeCache
- A couple of headers are generated, like cubeparse.h (?)
- Currently a lot of users do things like that:
cd src/test/regress/ && make check
But this patch breaks that, and that's not cool. Recovery tests in
src/test/regress won't run either.

That's all I have for now. Looking forward to seeing some progress here.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#92Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#91)
Re: WIP: About CMake v2

Michael Paquier wrote:

Your patch recommends to build with cmake after creating build/, now I
would expect most users to run cmake from the root folder. However
this causes all the Makefiles to get overwritten. As supporting all
platforms at once with cmake is going to be uncommitable, we are going
to need both methods able to live together for a while. Well, they can
coexist with this patch as long as cmake is not run from the root of
the code tree, which is acceptable for me as long as the switch is not
completed. However others may think differently on the matter.

It's really a good point. Forbidden run cmake from root it is better
decision for me (of course for start).

Instead of getting support for all existing platforms, I would
recommend as well focusing only on one platform for the time being,
Linux, and get the work done correctly for that first. Once there is
something committed, we will be able to patch the buildfarm, and get
machines to switch to cmake one by one. After those are switched, we
could extend that.

You mean in first version of patch I can focus on Linux systems?

Another point of contention is support for
extensions. How long should we keep support for the existing PGXS? How
external extensions would compile with the new thing infrastructure?

As long as possible. I hope I can make PGXS Makefiles generator.

Which brings me to another point, your patch is focused on features,
meaning that per-OS checks are all grouped by feature, but it may be a
good idea to split checks by OS if necessary, with for example
per-platform files and scripts in cmake/os/. And we could have just
something for Linux now.

Currently I do not have a lot OS specific tests. All checks are doing in
same manner.

- root's .gitignore needs to add entries for CMakeFiles and
cmake_install.cmake. You need as well to ignore CMakeCache

Thanks I done this in last commit.

- A couple of headers are generated, like cubeparse.h (?)

Because BISON generate header by default. I suppose author of cube launched
bison by hand but I made it automatic.

- Currently a lot of users do things like that:
cd src/test/regress/ && make check
But this patch breaks that, and that's not cool. Recovery tests in
src/test/regress won't run either.

It seems restriction by design because in CMake you have only one enter
point.

That's all I have for now. Looking forward to seeing some progress here.

I merged master to my branch and I spent time to porting all changes. I
hope send patch in the weekend without terrible flaws.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#93Michael Paquier
michael.paquier@gmail.com
In reply to: Yury Zhuravlev (#92)
Re: WIP: About CMake v2

On Sat, Sep 17, 2016 at 1:40 AM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Michael Paquier wrote:
I merged master to my branch and I spent time to porting all changes. I hope
send patch in the weekend without terrible flaws.

By the way, I noticed that you did not register this patch in the current CF..
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#94Andres Freund
andres@anarazel.de
In reply to: Michael Paquier (#91)
Re: WIP: About CMake v2

Hi,

On 2016-09-16 22:33:50 +0900, Michael Paquier wrote:

As supporting all platforms at once with cmake is going to be
uncommitable, we are going to need both methods able to live together
for a while.

I very strongly disagree with this. It's way too likely that we end up
releasing with multiple buildsystems that way. I think we'll have to
require support for the most common OSs, and then fix up the fallout
afterwards.

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#95Michael Paquier
michael.paquier@gmail.com
In reply to: Andres Freund (#94)
Re: WIP: About CMake v2

On Sat, Sep 17, 2016 at 8:11 AM, Andres Freund <andres@anarazel.de> wrote:

Hi,

On 2016-09-16 22:33:50 +0900, Michael Paquier wrote:

As supporting all platforms at once with cmake is going to be
uncommitable, we are going to need both methods able to live together
for a while.

I very strongly disagree with this. It's way too likely that we end up
releasing with multiple buildsystems that way. I think we'll have to
require support for the most common OSs, and then fix up the fallout
afterwards.

Ok, then if we go through the hard method the switch patch had better
remove as well all the Makefiles in the tree and recommend cmake run
from base root as the default build method. By the way, there will be
a strong need for docs in the patch sooner or later...
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#96Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#93)
1 attachment(s)
Re: WIP: About CMake v2

Michael Paquier wrote:

On Sat, Sep 17, 2016 at 1:40 AM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Michael Paquier wrote:
I merged master to my branch and I spent time to porting all
changes. I hope
send patch in the weekend without terrible flaws.

By the way, I noticed that you did not register this patch in
the current CF..

Now, I published the first version of the patch.
This patch not ready for commit yet and all current task you can read here:
https://github.com/stalkerg/postgres_cmake/issues

I hope we realy close to end.

In this patch I forbade in-source build for avoid overwriting current
Makefiles.
We will can remove all Makefiles only after shall see in CMake. You don't
need support two system. During commitfests CMake build system will be
supported by me.

I need help with buildfarm because my knowledge of Perl is very bad
(thought about rewrite buildfarm to Python).

I hope for your support.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

cmake_v1.patchtext/x-patchDownload
diff --git a/.gitignore b/.gitignore
index 4976fd9..99c8297 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,8 @@ lib*.pc
 /Debug/
 /Release/
 /tmp_install/
+/CMakeCache.txt
+/CMakeFiles
+/cmake_install.cmake
+/install_manifest.txt
+/build
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..f9da88e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,1343 @@
+cmake_minimum_required(VERSION 2.8.4)
+
+project(Postgres C)
+
+include(CheckTypeSize)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckIncludeFiles)
+include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
+include(TestBigEndian)
+include(CheckStructHasMember)
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+	message(STATUS "${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}")
+	message(FATAL_ERROR "You must use another folder for build PostgreSQL")
+endif()
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+set(POSTGRES_MAJOR_VERSION 10)
+set(POSTGRES_MINOR_VERSION 0)
+set(POSTGRES_PATCH_VERSION 0)
+set(POSTGRES_VERSION
+  ${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.${POSTGRES_PATCH_VERSION})
+
+set(PG_VERSION "10devel")
+set(PG_VERSION_NUM 100000)
+set(PACKAGE_BUGREPORT "pgsql-bugs@postgresql.org")
+
+ # Offer the user the choice of overriding the installation directories
+set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
+set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
+set(INSTALL_INCLUDE_DIR include CACHE PATH
+  "Installation directory for header files")
+
+if(NOT PGBINDIR)
+	set(PGBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
+endif(NOT PGBINDIR)
+
+if(NOT PGSHAREDIR)
+	set(PGSHAREDIR "${CMAKE_INSTALL_PREFIX}/share/postgresql")
+endif(NOT PGSHAREDIR)
+
+if(NOT SYSCONFDIR)
+	set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
+endif(NOT SYSCONFDIR)
+
+if(NOT INCLUDEDIR)
+	set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT INCLUDEDIR)
+
+if(NOT PKGINCLUDEDIR)
+	set(PKGINCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT PKGINCLUDEDIR)
+
+if(NOT INCLUDEDIRSERVER)
+	set(INCLUDEDIRSERVER "${CMAKE_INSTALL_PREFIX}/include/server")
+endif(NOT INCLUDEDIRSERVER)
+
+if(MSVC)
+	if(NOT LIBDIR)
+		set(LIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+	endif(NOT LIBDIR)
+
+	if(NOT PKGLIBDIR)
+		set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+	endif(NOT PKGLIBDIR)
+else()
+	if(NOT LIBDIR)
+		set(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+	endif(NOT LIBDIR)
+
+	if(NOT PKGLIBDIR)
+		set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+	endif(NOT PKGLIBDIR)
+endif()
+
+if(NOT LOCALEDIR)
+	set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
+endif(NOT LOCALEDIR)
+
+if(NOT DOCDIR)
+	set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT DOCDIR)
+
+if(NOT HTMLDIR)
+	set(HTMLDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT HTMLDIR)
+
+if(NOT MANDIR)
+	set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
+endif(NOT MANDIR)
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+	set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+endif()
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|OpenBSD")
+	set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-x,-soname,")
+endif()
+
+if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-ignored-attributes")
+endif()
+
+if(MSVC)
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
+endif()
+
+test_big_endian(WORDS_BIGENDIAN)
+set(FIND_LIBRARY_USE_LIB64_PATHS ON)
+
+find_package(Perl REQUIRED)
+option(WITH_PERL "libperl is optional" ON)
+if(WITH_PERL)
+	find_package(PerlLibs)
+endif()
+if(PERLLIBS_FOUND)
+	EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts OUTPUT_VARIABLE PERL_CFLAGS)
+	EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts OUTPUT_VARIABLE PERL_LDFLAGS)
+	STRING(REGEX REPLACE "[\r\n]" " " PERL_CFLAGS ${PERL_CFLAGS})
+	STRING(REGEX REPLACE " +$" "" PERL_CFLAGS ${PERL_CFLAGS})
+	STRING(STRIP "${PERL_CFLAGS}" PERL_CFLAGS)
+	STRING(REGEX REPLACE "[\r\n]" " " PERL_LDFLAGS ${PERL_LDFLAGS})
+	STRING(REGEX REPLACE " +$" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+	STRING(REGEX REPLACE "-lperl" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+	if(MINGW AND NOT MSYS)
+		STRING(REGEX REPLACE "\\\\" "/" PERL_LDFLAGS ${PERL_LDFLAGS})
+	endif()
+	STRING(STRIP "${PERL_LDFLAGS}" PERL_LDFLAGS)
+endif()
+
+find_package(BISON REQUIRED)
+find_package(FLEX REQUIRED)
+find_package(Threads)
+
+option(WITH_OPENSSL "OPENSSL is optional" ON)
+if(WITH_OPENSSL)
+	find_package(OpenSSL)
+endif()
+find_package(ZLIB)
+
+option(WITH_PYTHON "Python is optional" ON)
+if(WITH_PYTHON)
+	find_package(PythonInterp)
+	find_package(PythonLibs)
+endif()
+find_package(SELinux)
+
+option(WITH_LIBXML "LIBXML is optional" ON)
+if(WITH_LIBXML)
+	find_package(LibXml2)
+	find_package(LibXslt)
+endif()
+
+option(WITH_TCL "TCL is optional" ON)
+if(WITH_TCL)
+	find_package(TCL)
+endif()
+find_package(LibSocket)
+
+option(USE_PAM "build with PAM support" OFF)
+if(USE_PAM)
+	find_library(PAM_LIB pam)
+	if(NOT PAM_LIB)
+		message(ERROR "library 'pam' is required for PAM")
+	endif()
+endif()
+
+option(USE_LDAP "build with LDAP support" OFF)
+if(USE_LDAP)
+	find_package(LDAP REQUIRED)
+endif()
+
+if(WIN32 OR MINGW)
+	set(NEED_REPL_SNPRINTF ON)
+else()
+	set(NEED_REPL_SNPRINTF OFF)
+endif()
+
+option(ENABLE_NLS "Define if you want National Language Support" OFF)
+if(ENABLE_NLS)
+	include(MakeNLS)
+	find_package(Gettext REQUIRED)
+	find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
+	if(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+		message(FATAL_ERROR "xgettext not found")
+	endif(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+	if(NOT NLS_LANGUAGES)
+		set(NLS_LANGUAGES "ko;cs;pt_BR;zh_CN;ru;fr;de;es;it;tr;ja;pl;zh_TW")
+	endif()
+
+	if(NOT NEED_REPL_SNPRINTF)
+		check_c_source_runs("
+			#include <stdio.h>
+			#include <string.h>
+
+			int main()
+			{
+			  char buf[100];
+
+			  /* can it swap arguments? */
+			  snprintf(buf, 100, \"%2\$d %1\$d\", 3, 4);
+			  if (strcmp(buf, \"4 3\") != 0)
+				return 1;
+			  return 0;
+			}
+		" SNPRINTF_ARG_CONTROL)
+		if(NOT SNPRINTF_ARG_CONTROL)
+			set(NEED_REPL_SNPRINTF ON)
+		endif()
+	endif()
+endif()
+
+option(ENABLE_GSS "Define to build with GSSAPI support." OFF)
+if(ENABLE_GSS)
+	check_include_files(gssapi/gssapi.h HAVE_GSSAPI_GSSAPI_H)
+	check_include_files(gssapi.h HAVE_GSSAPI_H)
+	set(PG_KRB_SRVTAB "FILE:${SYSCONFDIR}/krb5.keytab")
+	if(WIN32)
+		SET(GSS_LIBS "-lgssapi32")
+	else()
+		set(CMAKE_REQUIRED_LIBRARIES_OLD ${CMAKE_REQUIRED_LIBRARIES})
+		set(CMAKE_REQUIRED_LIBRARIES "-lgssapi_krb5")
+		check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+		if(NOT HAVE_GSS_INIT)
+			set(CMAKE_REQUIRED_LIBRARIES "-lgss")
+			check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+			if(NOT HAVE_GSS_INIT)
+				set(CMAKE_REQUIRED_LIBRARIES "-lgssapi -lkrb5 -lcrypto")
+				check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+			endif(NOT HAVE_GSS_INIT)
+		endif(NOT HAVE_GSS_INIT)
+		if(HAVE_GSS_INIT)
+			set(GSS_LIBS ${CMAKE_REQUIRED_LIBRARIES})
+		else()
+			message(FATAL_ERROR "Not found gss_init_sec_context function for GSSAPI")
+		endif()
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_OLD})
+	endif()
+else()
+	set(GSS_LIBS "")
+endif()
+
+option(USE_SYSTEMD "Define to build with systemd support" OFF)
+option(USE_BSD_AUTH "Define to build with BSD Authentication support" OFF)
+option(USE_ASSERT_CHECKING "Define to build with assertion checks." OFF)
+option(USE_BONJOUR "Define to build with Bonjour support." OFF)
+if(USE_BONJOUR)
+	check_include_files(dns_sd.h HAVE_DNS_SD_H)
+	if(NOT HAVE_DNS_SD_H)
+		message(FATAL_ERROR "header file <dns_sd.h> is required for Bonjour")
+	endif()
+endif()
+
+if(NOT MSVC)
+	find_library(DL_LIBRARIES NAMES dl)
+	find_library(M_LIB m)
+	if(NOT M_LIB)
+		set(M_LIB "")
+	endif()
+endif()
+
+if(NOT DL_LIBRARIES)
+	set(DL_LIBRARIES "")
+endif()
+
+if(LIBXML2_FOUND)
+	set(HAVE_LIBXML2 1)
+	set(USE_LIBXML 1)
+endif()
+
+if(LIBXSLT_FOUND)
+	set(HAVE_LIBXSLT 1)
+	set(USE_LIBXSLT 1)
+endif()
+
+if(ZLIB_FOUND)
+	set(HAVE_LIBZ 1)
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCC)
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.3 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.3)
+		# Disable strict-aliasing rules; needed for gcc 3.3+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+	endif()
+
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.4 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.4)
+		# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+	endif()
+
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+		# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexcess-precision=standard")
+	endif()
+
+	# Optimization flags for specific files that benefit from vectorization
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+		set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+	endif()
+
+	option(PROFILE_PID_DIR "Enable to allow profiling output to be saved separately for each process." OFF)
+endif()
+
+if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+	# Disable strict-aliasing rules; needed for gcc 3.3+
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+	# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+
+	# Optimization flags for specific files that benefit from vectorization
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+endif()
+
+if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
+	# Intel's compiler has a bug/misoptimization in checking for
+	# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mp1")
+	# Make sure strict aliasing is off (though this is said to be the default)
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+endif()
+
+check_symbol_exists(strlcpy "stdio.h;string.h" HAVE_DECL_STRLCPY)
+if(NOT HAVE_DECL_STRLCPY)
+	set(HAVE_DECL_STRLCPY 0)
+endif()
+check_symbol_exists(strlcat "stdio.h;string.h" HAVE_DECL_STRLCAT)
+if(NOT HAVE_DECL_STRLCAT)
+	set(HAVE_DECL_STRLCAT 0)
+endif()
+check_symbol_exists(snprintf "stdio.h;string.h" HAVE_DECL_SNPRINTF)
+if(NOT HAVE_DECL_SNPRINTF)
+	set(HAVE_DECL_SNPRINTF 0)
+endif()
+check_symbol_exists(vsnprintf "stdio.h;string.h" HAVE_DECL_VSNPRINTF)
+if(NOT HAVE_DECL_VSNPRINTF)
+	set(HAVE_DECL_VSNPRINTF 0)
+endif()
+check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV)
+check_symbol_exists(srandom "stdlib.h" HAVE_SRANDOM)
+
+# Test math functions
+check_symbol_exists(rint "math.h" HAVE_RINT)
+
+if(WIN32 AND NOT MINGW)
+	set(LIB_M "")
+else()
+	set(LIB_M m)
+endif()
+set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${LIB_M}")
+check_c_source_compiles("
+	#include <math.h>
+	double glob_double;
+	int main(void){
+		return isinf(glob_double) ? 0 : 1;
+	}
+" HAVE_ISINF)
+
+check_include_files(ieeefp.h HAVE_IEEEFP_H)
+if(NOT HAVE_IEEEFP_H)
+	set(HAVE_IEEEFP_H 0)
+else()
+	set(HAVE_IEEEFP_H 1)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ieeefp.h")
+endif()
+
+check_include_files(fp_class.h HAVE_FP_CLASS_H)
+if (HAVE_FP_CLASS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fp_class.h")
+endif()
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};float.h;math.h")
+
+# Need for isinf implementation
+check_function_exists(fpclass HAVE_FPCLASS)
+check_function_exists(fp_class HAVE_FP_CLASS)
+check_function_exists(fp_class_d HAVE_FP_CLASS_D)
+check_function_exists(class HAVE_CLASS)
+
+check_function_exists(getpeereid HAVE_GETPEEREID)
+check_function_exists(getpeerucred HAVE_GETPEERUCRED)
+check_function_exists(memmove HAVE_MEMMOVE)
+if(MSVC)
+	check_function_exists(_mbstowcs_l HAVE_MBSTOWCS_L)
+else()
+	check_function_exists(mbstowcs_l HAVE_MBSTOWCS_L)
+endif()
+
+check_function_exists(towlower HAVE_TOWLOWER)
+check_function_exists(wcstombs HAVE_WCSTOMBS)
+
+check_function_exists(mkdtemp HAVE_MKDTEMP)
+check_function_exists(mkstemp HAVE_MKSTEMP)
+check_function_exists(poll HAVE_POLL)
+
+check_function_exists(getrlimit HAVE_GETRLIMIT)
+check_function_exists(readlink HAVE_READLINK)
+check_function_exists(cbrt HAVE_CBRT)
+check_function_exists(pthread_is_threaded_np HAVE_PTHREAD_IS_THREADED_NP)
+check_function_exists(random HAVE_RANDOM)
+check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
+
+#So strange
+check_function_exists(pstat HAVE_PSTAT)
+
+check_include_files(ifaddrs.h HAVE_IFADDRS_H)
+if(HAVE_IFADDRS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ifaddrs.h")
+endif()
+check_function_exists(getifaddrs HAVE_GETIFADDRS)
+
+if(MSVC)
+	set(HAVE_MINIDUMP_TYPE 1)
+endif()
+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fcntl.h")
+	check_function_exists(posix_fadvise HAVE_DECL_POSIX_FADVISE)
+	if(HAVE_DECL_POSIX_FADVISE)
+		set(HAVE_POSIX_FADVISE 1)
+	endif()
+endif()
+
+find_library(CRYPT_LIB crypt)
+if(CRYPT_LIB)
+	set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${CRYPT_LIB}")
+endif()
+check_include_files(crypt.h HAVE_CRYPT_H)
+if(HAVE_CRYPT_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};crypt.h")
+endif()
+check_function_exists(crypt HAVE_CRYPT)
+
+check_include_files(unistd.h HAVE_UNISTD_H)
+if(HAVE_UNISTD_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};unistd.h")
+endif()
+check_function_exists(fdatasync HAVE_DECL_FDATASYNC)
+check_function_exists(sys_siglist HAVE_DECL_FDATASYNC)
+check_function_exists(setproctitle HAVE_SETPROCTITLE)
+check_function_exists(setsid HAVE_SETSID)
+if(HAVE_UNISTD_H)
+	check_symbol_exists(sys_siglist "signal.h;unistd.h" HAVE_DECL_SYS_SIGLIST)
+	check_symbol_exists(opterr "unistd.h" HAVE_INT_OPTERR)
+	check_symbol_exists(optreset "unistd.h" HAVE_INT_OPTRESET)
+else()
+	check_symbol_exists(sys_siglist "signal.h" HAVE_DECL_SYS_SIGLIST)
+endif()
+
+set(CMAKE_MACOSX_RPATH 1)
+#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+if(MSVC)
+	check_function_exists(_fseeki64 HAVE_FSEEKO)
+else()
+	check_function_exists(fseeko HAVE_FSEEKO)
+endif()
+
+if(NOT MSVC)
+	check_include_files(dlfcn.h HAVE_DLFCN_H)
+	if(HAVE_DLFCN_H)
+		set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};dlfcn.h")
+	endif()
+	set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARIES})
+	check_function_exists(dlopen HAVE_DLOPEN)
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES "")
+check_include_files(strings.h HAVE_STRINGS_H)
+check_include_files(string.h HAVE_STRING_H)
+if(HAVE_STRINGS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};strings.h")
+endif()
+if(HAVE_STRING_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};string.h")
+endif()
+check_function_exists(fls HAVE_FLS)
+
+check_include_files(getopt.h HAVE_GETOPT_H)
+if(HAVE_GETOPT_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};getopt.h")
+endif()
+
+check_function_exists(strtoll HAVE_STRTOLL)
+check_function_exists(strtoq HAVE_STRTOQ)
+check_function_exists(strtoull HAVE_STRTOULL)
+check_function_exists(strtouq HAVE_STRTOUQ)
+
+check_type_size("struct option" HAVE_STRUCT_OPTION)
+check_function_exists(getopt HAVE_GETOPT)
+check_function_exists(getopt_long HAVE_GETOPT_LONG)
+check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
+check_function_exists(getpwuid_r HAVE_GETPWUID_R)
+check_function_exists(strerror_r HAVE_STRERROR_R)
+check_function_exists(strerror HAVE_STRERROR)
+#I am not sure about this code.
+check_c_source_runs("
+#include <string.h>
+int main(void){
+#ifndef _AIX
+int strerror_r(int, char *, size_t);
+#else
+/* Older AIX has 'int' for the third argument so we don't test the args. */
+int strerror_r();
+#endif
+return 0;
+}
+" STRERROR_R_INT)
+
+check_c_source_runs("
+int main(void){
+int a = 0; int *p = &a; int r;
+ __asm__ __volatile__ (\" lwarx %0,0,%1,1\n\" : \"=&r\"(r) : \"r\"(p));
+return 0;
+}
+" HAVE_PPC_LWARX_MUTEX_HINT)
+
+check_c_source_runs("
+#include <machine/vmparam.h>
+#include <sys/exec.h>
+int main(void){
+PS_STRINGS->ps_nargvstr = 1;
+PS_STRINGS->ps_argvstr = \"foo\";
+return 0;
+}
+" HAVE_PS_STRINGS)
+
+check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
+if(HAVE_SYS_MMAN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/mman.h")
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -lrt")
+endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+check_function_exists(shm_open HAVE_SHM_OPEN)
+
+check_include_files(sys/time.h HAVE_SYS_TIME_H)
+check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
+if(HAVE_SYS_TIME_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/time.h")
+endif()
+if(HAVE_SYS_RESOURCE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/resource.h")
+endif()
+check_function_exists(getrusage HAVE_GETRUSAGE)
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+
+check_include_files(utime.h HAVE_UTIME_H)
+if(HAVE_UTIME_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};utime.h")
+endif()
+check_function_exists(utime HAVE_UTIME)
+check_function_exists(utimes HAVE_UTIMES)
+
+set(OLD_INCLUDES "${CMAKE_EXTRA_INCLUDE_FILES}")
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/in.h;arpa/inet.h")
+check_function_exists(inet_aton HAVE_INET_ATON)
+set(CMAKE_EXTRA_INCLUDE_FILES "${OLD_INCLUDES}")
+
+if(OPENSSL_FOUND)
+	set(USE_OPENSSL 1)
+	set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}")
+	set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
+	check_function_exists(SSL_get_current_compression HAVE_SSL_GET_CURRENT_COMPRESSION)
+endif(OPENSSL_FOUND)
+
+
+check_include_files(sys/un.h HAVE_SYS_UN_H)
+check_include_files(ucred.h HAVE_UCRED_H)
+check_include_files(sys/ucred.h HAVE_SYS_UCRED_H)
+check_include_files(sys/types.h HAVE_SYS_TYPES_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H)
+check_include_files(stdint.h HAVE_STDINT_H)
+
+check_include_files(sys/select.h HAVE_SYS_SELECT_H)
+check_include_files(sys/poll.h HAVE_SYS_POLL_H)
+check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
+check_include_files(sys/pstat.h HAVE_SYS_PSTAT_H)
+check_include_files(sys/tas.h HAVE_SYS_TAS_H)
+check_include_files(dld.h HAVE_DLD_H)
+check_include_files(langinfo.h HAVE_LANGINFO_H)
+check_include_files(poll.h HAVE_POLL_H)
+
+check_include_files(wchar.h HAVE_WCHAR_H)
+check_include_files(wctype.h HAVE_WCTYPE_H)
+check_include_files(winldap.h HAVE_WINLDAP_H)
+check_include_files(pwd.h HAVE_PWD_H)
+check_include_files(crtdefs.h HAVE_CRTDEFS_H)
+
+check_include_files(nbtool_config.h HAVE_NBTOOL_CONFIG_H)
+
+check_include_files(mbarrier.h HAVE_MBARRIER_H)
+check_include_files(atomic.h HAVE_ATOMIC_H)
+
+check_include_files(netinet/tcp.h HAVE_NETINET_TCP_H)
+check_include_files(net/if.h HAVE_NET_IF_H)
+
+check_include_files(pam/pam_appl.h HAVE_PAM_PAM_APPL_H)
+check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
+if(USE_PAM AND NOT (HAVE_PAM_PAM_APPL_H OR HAVE_SECURITY_PAM_APPL_H))
+	message(FATAL_ERROR "header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.")
+endif()
+
+check_include_files(syslog.h HAVE_SYSLOG)
+check_include_files(termios.h HAVE_TERMIOS_H)
+
+if(USE_SYSTEMD)
+	check_include_files(systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
+	if(NOT HAVE_SYSTEMD_SD_DAEMON_H)
+		message(FATAL_ERROR "header file <systemd/sd-daemon.h> is required for systemd support")
+	endif()
+endif()
+
+check_include_files(bsd_auth.h HAVE_BSD_AUTH_H)
+if(USE_BSD_AUTH AND NOT HAVE_BSD_AUTH_H)
+	message(FATAL_ERROR "header file <bsd_auth.h> is required for BSD Authentication support")
+endif()
+
+
+#Check ReadLine includes
+option(WITH_READLINE "do not use GNU Readline nor BSD Libedit for editing" ON)
+if(WITH_READLINE AND NOT MSVC)
+	find_package(Readline)
+	if(READLINE_FOUND)
+		#Sometimes for redline need curses
+		message(STATUS "Found Readline: ${READLINE_LIBRARY}")
+		find_package(Curses)
+		if(NOT CURSES_FOUND)
+			set(CURSES_NEED_NCURSES TRUE)
+		endif()
+		find_package(Curses)
+		check_include_files("stdio.h;readline.h" HAVE_READLINE_H)
+		check_include_files("stdio.h;history.h" HAVE_HISTORY_H)
+		check_include_files("stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H)
+		check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H)
+		check_include_files("stdio.h;editline/history.h" HAVE_EDITLINE_HISTORY_H)
+		check_include_files("stdio.h;editline/readline.h" HAVE_EDITLINE_READLINE_H)
+
+
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${READLINE_LIBRARY})
+		if(CURSES_FOUND)
+			set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CURSES_LIBRARIES})
+			set(READLINE_LIBRARY ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
+		endif()
+		check_function_exists(rl_completion_append_character HAVE_RL_COMPLETION_APPEND_CHARACTER)
+		check_function_exists(rl_completion_matches HAVE_RL_COMPLETION_MATCHES)
+		check_function_exists(rl_filename_completion_function HAVE_RL_FILENAME_COMPLETION_FUNCTION)
+		check_function_exists(rl_reset_screen_size HAVE_RL_RESET_SCREEN_SIZE)
+		check_function_exists(append_history HAVE_APPEND_HISTORY)
+		check_function_exists(history_truncate_file HAVE_HISTORY_TRUNCATE_FILE)
+	endif(READLINE_FOUND)
+endif()
+
+if(READLINE_FOUND)
+	set(HAVE_LIBREADLINE TRUE)
+else()
+	set(READLINE_LIBRARY "")
+	set(HAVE_LIBREADLINE FALSE)
+endif()
+
+check_include_files("sys/ipc.h" HAVE_SYS_IPC_H)
+check_include_files("sys/sem.h" HAVE_SYS_SEM_H)
+check_include_files("sys/shm.h" HAVE_SYS_SHM_H)
+check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+
+# Check if _GNU_SOURCE is available.
+check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
+check_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_DECL_F_FULLFSYNC)
+
+include(ReplacePython)
+include(CheckCpuID)
+include(CheckSSE42)
+
+if(MSVC)
+	if(HAVE__GET_CPUID OR HAVE__CPUID)
+		set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+	endif()
+else()
+	if(HAVE_SSE42 AND HAVE_SSE42_INTRINSICS)
+		set(USE_SSE42_CRC32C 1)
+	elseif(HAVE_SSE42_INTRINSICS AND (HAVE__GET_CPUID OR HAVE__CPUID))
+		set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+	else()
+		set(USE_SLICING_BY_8_CRC32C 1)
+	endif()
+endif()
+
+include(FuncAcceptArgtypes)
+include(CheckTypeAlignment)
+check_type_alignment(double ALIGNOF_DOUBLE)
+check_type_alignment(int ALIGNOF_INT)
+check_type_alignment(long ALIGNOF_LONG)
+check_type_alignment("long long int" ALIGNOF_LONG_LONG_INT)
+check_type_alignment(short ALIGNOF_SHORT)
+
+check_type_size(int64 HAVE_INT64)
+check_type_size(uint64 HAVE_UINT64)
+check_type_size(int8 HAVE_INT8)
+check_type_size(uint8 HAVE_UINT8)
+check_type_size("void *" VOID_POINTER_SIZE)
+math(EXPR VOID_POINTER_SIZE_BIT "${VOID_POINTER_SIZE}*8")
+check_type_size("long int" LONG_INT_SIZE)
+check_type_size("long long int" HAVE_LONG_LONG_INT)
+check_type_size("long" SIZEOF_LONG)
+check_type_size("size_t" SIZEOF_SIZE_T)
+check_type_size(__int128 PG_INT128_TYPE)
+if(PG_INT128_TYPE AND NOT WIN32)
+	set(HAVE_INT128 1)
+	set(PG_INT128_TYPE __int128)
+endif()
+
+check_include_files("locale.h" HAVE_LOCALE_H)
+check_include_files("xlocale.h" HAVE_XLOCALE_H)
+if(HAVE_LOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};locale.h")
+endif()
+check_type_size("locale_t" HAVE_LOCALE_T)
+if(NOT HAVE_LOCALE_T AND HAVE_XLOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+	check_type_size("locale_t" HAVE_LOCALE_T)
+	if(HAVE_LOCALE_T)
+		set(LOCALE_T_IN_XLOCALE 1)
+	else()
+		set(LOCALE_T_IN_XLOCALE 0)
+	endif()
+else()
+	set(LOCALE_T_IN_XLOCALE 0)
+endif()
+
+check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+#check_function_exists(wcstombs_l HAVE_WCSTOMBS_L)
+if(NOT HAVE_WCSTOMBS_L AND HAVE_XLOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+	check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+	if(HAVE_WCSTOMBS_L)
+		set(WCSTOMBS_L_IN_XLOCALE 1)
+	else()
+		set(WCSTOMBS_L_IN_XLOCALE 0)
+	endif()
+else()
+	set(WCSTOMBS_L_IN_XLOCALE 0)
+endif()
+
+if(LONG_INT_SIZE EQUAL 8)
+	set(PG_INT64_TYPE "long int")
+	set(HAVE_LONG_INT_64 ${LONG_INT_SIZE})
+else(LONG_INT_SIZE EQUAL 8)
+	if(HAVE_LONG_LONG_INT EQUAL 8)
+		set(PG_INT64_TYPE "long long int")
+		set(HAVE_LONG_LONG_INT_64 1)
+	else()
+		message(FATAL_ERROR "Cannot find a working 64-bit integer type.")
+	endif()
+endif(LONG_INT_SIZE EQUAL 8)
+
+message(STATUS "PG_INT64_TYPE: ${PG_INT64_TYPE} HAVE_LONG_INT_64: ${HAVE_LONG_INT_64}")
+# Compute maximum alignment of any basic type.
+# We assume long's alignment is at least as strong as char, short, or int;
+# but we must check long long (if it exists) and double.
+
+if(NOT MAXIMUM_ALIGNOF)
+	set(MAX_ALIGNOF ${ALIGNOF_LONG})
+	if(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+		set(MAX_ALIGNOF ${ALIGNOF_DOUBLE})
+	endif(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+	if(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+		set(MAX_ALIGNOF ${HAVE_LONG_LONG_INT_64})
+	endif(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+	if(MAX_ALIGNOF)
+		set(MAXIMUM_ALIGNOF ${MAX_ALIGNOF})
+	endif(MAX_ALIGNOF)
+endif(NOT MAXIMUM_ALIGNOF)
+message(STATUS "MAXIMUM_ALIGNOF ${MAXIMUM_ALIGNOF}")
+
+if(HAVE_LONG_LONG_INT_64)
+	if(NOT NEED_REPL_SNPRINTF)
+		include(CheckSnprintfLongLongIntModifier)
+		if(NOT LONG_LONG_INT_MODIFIER)
+			set(LONG_LONG_INT_MODIFIER "ll")
+			set(NEED_REPL_SNPRINTF ON)
+		endif(NOT LONG_LONG_INT_MODIFIER)
+	else(NOT NEED_REPL_SNPRINTF)
+		set(LONG_LONG_INT_MODIFIER "ll")
+	endif(NOT NEED_REPL_SNPRINTF)
+else(HAVE_LONG_LONG_INT_64)
+	set(LONG_LONG_INT_MODIFIER "l")
+endif(HAVE_LONG_LONG_INT_64)
+
+if(HAVE_LONG_LONG_INT_64)
+	message(STATUS "HAVE_LONG_LONG_INT_64 ${HAVE_LONG_LONG_INT_64}")
+endif()
+if(HAVE_LONG_LONG_INT_64)
+	include(CheckLLConstants)
+endif()
+
+#TODO: some strange here
+option(USE_FLOAT4_BYVAL "float4 values are passed by value" ON)
+if(USE_FLOAT4_BYVAL)
+	set(FLOAT4PASSBYVAL 1)
+else(USE_FLOAT4_BYVAL)
+	set(FLOAT4PASSBYVAL 0)
+endif(USE_FLOAT4_BYVAL)
+
+if(VOID_POINTER_SIZE EQUAL 8)
+	option(USE_FLOAT8_BYVAL "float8 values are passed by value" ON)
+else()
+	option(USE_FLOAT8_BYVAL "float8 values are passed by value" OFF)
+endif()
+if(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+	message(FATAL_ERROR "USE_FLOAT8_BYVAL is not supported on 32-bit platforms.")
+elseif(USE_FLOAT8_BYVAL AND VOID_POINTER_SIZE EQUAL 8)
+	set(FLOAT8PASSBYVAL 1)
+	set(USE_FLOAT8_BYVAL 1)
+else()
+	set(FLOAT8PASSBYVAL 0)
+	set(USE_FLOAT8_BYVAL 0)
+endif(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+
+if (_GNU_SOURCE)
+	add_definitions(-D_GNU_SOURCE)
+endif()
+if(Threads_FOUND)
+	set(ENABLE_THREAD_SAFETY 1)
+	set(THREADS_PREFER_PTHREAD_FLAG ON)
+	set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS")
+	if(THREADS_HAVE_PTHREAD_ARG)
+		set(PTHREAD_CFLAGS "${PTHREAD_CFLAGS} -pthread")
+	endif()
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PTHREAD_CFLAGS}")
+endif()
+
+set(PORT_DIR "${PROJECT_SOURCE_DIR}/src/port")
+set(PQ_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/libpq")
+set(MB_UTILS_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/utils/mb")
+
+
+set(fallback_SRCS "")
+
+if(NOT HAVE_DECL_STRLCPY)
+  set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcpy.c")
+endif(NOT HAVE_DECL_STRLCPY)
+
+if(NOT HAVE_DECL_STRLCAT)
+	set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcat.c")
+endif(NOT HAVE_DECL_STRLCAT)
+
+if(NOT HAVE_GETPEEREID)
+	set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/getpeereid.c")
+endif(NOT HAVE_GETPEEREID)
+
+set(TABLE_BLOCKSIZE 8 CACHE STRING "set table block size in kB")
+
+if(TABLE_BLOCKSIZE EQUAL 1)
+	set(BLCKSZ 1024)
+elseif(TABLE_BLOCKSIZE EQUAL 2)
+	set(BLCKSZ 2048)
+elseif(TABLE_BLOCKSIZE EQUAL 4)
+	set(BLCKSZ 4096)
+elseif(TABLE_BLOCKSIZE EQUAL 8)
+	set(BLCKSZ 8192)
+elseif(TABLE_BLOCKSIZE EQUAL 16)
+	set(BLCKSZ 16384)
+elseif(TABLE_BLOCKSIZE EQUAL 32)
+	set(BLCKSZ 32768)
+else(TABLE_BLOCKSIZE EQUAL 1)
+	message(FATAL_ERROR "Invalid block size. Allowed values are 1,2,4,8,16,32.")
+endif(TABLE_BLOCKSIZE EQUAL 1)
+
+message(STATUS "BLCKSZ - ${BLCKSZ}")
+
+set(SEGSIZE 1 CACHE STRING "set table segment size in GB")
+math(EXPR RELSEG_SIZE "(1024 / ${TABLE_BLOCKSIZE}) * ${SEGSIZE} * 1024")
+
+set(WAL_BLOCKSIZE 8 CACHE STRING "set WAL block size in kB")
+
+if(WAL_BLOCKSIZE EQUAL 1)
+	set(XLOG_BLCKSZ 1024)
+elseif(WAL_BLOCKSIZE EQUAL 2)
+	set(XLOG_BLCKSZ 2048)
+elseif(WAL_BLOCKSIZE EQUAL 4)
+	set(XLOG_BLCKSZ 4096)
+elseif(WAL_BLOCKSIZE EQUAL 8)
+	set(XLOG_BLCKSZ 8192)
+elseif(WAL_BLOCKSIZE EQUAL 16)
+	set(XLOG_BLCKSZ 16384)
+elseif(WAL_BLOCKSIZE EQUAL 32)
+	set(XLOG_BLCKSZ 32768)
+elseif(WAL_BLOCKSIZE EQUAL 64)
+	set(XLOG_BLCKSZ 65536)
+else(WAL_BLOCKSIZE EQUAL 1)
+	message(FATAL_ERROR "Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64.")
+endif(WAL_BLOCKSIZE EQUAL 1)
+
+message(STATUS "XLOG_BLCKSZ - ${XLOG_BLCKSZ}")
+
+set(WAL_SEGSIZE 16 CACHE STRING "set WAL segment size in MB")
+
+if (";1;2;4;8;16;32;64;" MATCHES ";${WAL_SEGSIZE};")
+	math(EXPR XLOG_SEG_SIZE "${WAL_SEGSIZE} * 1024 * 1024")
+else()
+	message(FATAL_ERROR "${WAL_SEGSIZE} Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.")
+endif()
+
+message(STATUS "XLOG_SEG_SIZE - ${XLOG_SEG_SIZE}")
+
+option(HAVE_ATOMICS "Define to ON if you want to use atomics if available." ON)
+
+if(HAVE_ATOMICS)
+	check_c_source_compiles("
+		int main(void){
+			char lock = 0;
+			__sync_lock_test_and_set(&lock, 1);
+			__sync_lock_release(&lock);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_CHAR_TAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int lock = 0;
+			__sync_lock_test_and_set(&lock, 1);
+			__sync_lock_release(&lock);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT32_TAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int val = 0;
+			__sync_val_compare_and_swap(&val, 0, 37);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT32_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			${PG_INT64_TYPE} lock = 0;
+			__sync_val_compare_and_swap(&lock, 0, (${PG_INT64_TYPE}) 37);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT64_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int val = 0;
+			int expect = 0;
+			__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+			return 0;
+		}
+	" HAVE_GCC__ATOMIC_INT32_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			${PG_INT64_TYPE} val = 0;
+			${PG_INT64_TYPE} expect = 0;
+			__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+			return 0;
+		}
+	" HAVE_GCC__ATOMIC_INT64_CAS)
+endif(HAVE_ATOMICS)
+
+check_c_source_runs("
+	int main(void){
+		static unsigned long int x = __builtin_bswap32(0xaabbccdd);
+		return 0;
+	}
+" HAVE__BUILTIN_BSWAP32)
+
+check_c_source_runs("
+	int main(void){
+		static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);
+		return 0;
+	}
+" HAVE__BUILTIN_BSWAP64)
+
+check_c_source_runs("
+	int main(void){
+		static int x; static int y[__builtin_constant_p(x) ? x : 1];
+		return 0;
+	}
+" HAVE__BUILTIN_CONSTANT_P)
+
+check_c_source_runs("
+	int main(void){
+		int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)];
+		return 0;
+	}
+" HAVE__BUILTIN_TYPES_COMPATIBLE_P)
+
+check_c_source_runs("
+	int main(void){
+		__builtin_unreachable();
+		return 0;
+	}
+" HAVE__BUILTIN_UNREACHABLE)
+
+check_c_source_runs("
+	int main(void){
+		{ _Static_assert(1, \"foo\"); }
+		return 0;
+	}
+" HAVE__STATIC_ASSERT)
+
+if(NOT PGPORT)
+	set(PGPORT 5432)
+endif(NOT PGPORT)
+
+include(CheckFlexibleArray)
+
+check_c_source_compiles("
+	#include <sys/time.h>
+	int main(void){
+		struct timeval *tp;
+		struct timezone *tzp;
+		gettimeofday(tp,tzp);
+		return 0;
+	}
+" GETTIMEOFDAY_2ARG)
+
+if(NOT GETTIMEOFDAY_2ARG)
+	set(GETTIMEOFDAY_1ARG 1)
+endif(NOT GETTIMEOFDAY_2ARG)
+
+check_c_source_compiles("
+	#include <time.h>
+	int main(void){
+		int res;
+	#ifndef __CYGWIN__
+		res = timezone / 60;
+	#else
+		res = _timezone / 60;
+	#endif
+		return 0;
+	}
+" HAVE_INT_TIMEZONE)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		printf(\"%s\", __func__);
+		return 0;
+	}
+" HAVE_FUNCNAME__FUNC)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		printf(\"%s\", __FUNCTION__);
+		return 0;
+	}
+" HAVE_FUNCNAME__FUNCTION)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		#define debug(...) fprintf(stderr, __VA_ARGS__)
+		debug(\"%s\", \"blarg\");
+		return 0;
+	}
+" HAVE__VA_ARGS)
+
+check_struct_has_member("struct tm" tm_zone "sys/types.h;time.h" HAVE_TM_ZONE LANGUAGE C)
+check_struct_has_member("struct tm" tm_gmtoff "sys/types.h;time.h" HAVE_STRUCT_TM_TM_ZONE LANGUAGE C)
+set(CMAKE_EXTRA_INCLUDE_FILES "time.h")
+check_type_size("*tzname" HAVE_TZNAME)
+
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+	set(CMAKE_REQUIRED_FLAGS "-Werror")
+endif()
+check_c_source_compiles("
+	extern int pgac_write(int ignore, const char *fmt,...) __attribute__((format(gnu_printf, 2, 3)));
+	int main(void){return 0;}
+" PG_PRINTF_ATTRIBUTE)
+
+if(PG_PRINTF_ATTRIBUTE)
+	set(PG_PRINTF_ATTRIBUTE gnu_printf)
+else(PG_PRINTF_ATTRIBUTE)
+	set(PG_PRINTF_ATTRIBUTE printf)
+endif(PG_PRINTF_ATTRIBUTE)
+
+if(NOT MEMSET_LOOP_LIMIT)
+	set(MEMSET_LOOP_LIMIT 1024)
+endif(NOT MEMSET_LOOP_LIMIT)
+
+
+if(WIN32 OR MINGW)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;winsock2.h;ws2tcpip.h")
+else()
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/socket.h;netdb.h")
+endif()
+
+check_type_size("struct addrinfo" HAVE_STRUCT_ADDRINFO)
+check_type_size("struct cmsgcred" HAVE_STRUCT_CMSGCRED)
+if(HAVE_STRUCT_ADDRINFO)
+	CHECK_STRUCT_HAS_MEMBER("struct addrinfo" sa_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_SA_LEN LANGUAGE C)
+	if(NOT (WIN32 OR MINGW))
+		set(HAVE_GETADDRINFO 1)
+	endif()
+endif(HAVE_STRUCT_ADDRINFO)
+
+check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
+if(HAVE_STRUCT_SOCKADDR_STORAGE)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN LANGUAGE C)
+endif(HAVE_STRUCT_SOCKADDR_STORAGE)
+
+# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
+if(HAVE_SYS_UN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/un.h")
+else(HAVE_SYS_UN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
+endif(HAVE_SYS_UN_H)
+check_type_size("struct sockaddr_un" HAVE_UNIX_SOCKETS)
+
+if(WIN32)
+	set(HAVE_IPV6 1)
+else()
+	set(CMAKE_EXTRA_INCLUDE_FILES "netinet/in.h")
+	check_type_size("struct sockaddr_in6" HAVE_IPV6)
+endif()
+
+set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/ipc.h;sys/sem.h")
+check_type_size("union semun" HAVE_UNION_SEMUN)
+
+check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
+
+check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
+
+if(WIN32 OR MINGW)
+	set(USE_WIN32_SEMAPHORES 1)
+	set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_sema.c")
+else(WIN32 OR MINGW)
+	if(USE_NAMED_POSIX_SEMAPHORES)
+		set(USE_NAMED_POSIX_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+	elseif(USE_UNNAMED_POSIX_SEMAPHORES)
+		set(USE_UNNAMED_POSIX_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+	else(USE_NAMED_POSIX_SEMAPHORES)
+		set(USE_SYSV_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_sema.c")
+	endif(USE_NAMED_POSIX_SEMAPHORES)
+endif(WIN32 OR MINGW)
+
+#Realy bad name for win32
+set(USE_SYSV_SHARED_MEMORY 1)
+if(WIN32 OR MINGW)
+	set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_shmem.c")
+else(WIN32 OR MINGW)
+	set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_shmem.c")
+endif(WIN32 OR MINGW)
+
+option(HAVE_SPINLOCKS "Define to ON if you have spinlocks." ON)
+
+
+option(USE_INTEGER_DATETIMES "Define to ON if you want 64-bit integer timestamp and interval support." ON)
+
+if(WIN32)
+	option(HAVE_SYMLINK "Define to ON if you have the `symlink' function." ON)
+else(WIN32)
+	set(HAVE_SYMLINK 1)
+endif(WIN32)
+
+option(PG_KRB_SRVNAM "Define to the name of the default PostgreSQL service principal in Kerberos (GSSAPI)." "postgres")
+
+#TODO: Need test this
+if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+	if(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+		set(TAS sunstudio_sparc.s)
+	else(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+		set(TAS sunstudio_x86.s)
+	endif(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+elseif(CMAKE_C_COMPILER_ID STREQUAL "HP-UX")
+	set(TAS hpux_hppa.s)
+else(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+	set(TAS dummy.s)
+endif(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+
+if(WIN32 OR MINGW)
+	set(CMAKE_EXTRA_INCLUDE_FILES
+		${CMAKE_EXTRA_INCLUDE_FILES}
+		windows.h
+		string.h
+		dbghelp.h
+	)
+	set(CMAKE_REQUIRED_DEFINITIONS "WIN32_LEAN_AND_MEAN")
+	check_type_size(MINIDUMP_TYPE NAVE_MINIDUMP_TYPE)
+endif(WIN32 OR MINGW)
+
+set(WIN32_STACK_RLIMIT 4194304)
+if(WIN32)
+	add_definitions(-DWIN32_STACK_RLIMIT=${WIN32_STACK_RLIMIT})
+endif()
+
+if(NEED_REPL_SNPRINTF)
+	option(USE_REPL_SNPRINTF "Use replacement snprintf() functions." ON)
+endif()
+
+include(GenDef)
+#Not work correctly for postgres see bug: 
+#https://gitlab.kitware.com/cmake/cmake/issues/16161
+#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+
+include(RegressCheck)
+
+# Need add sco and unixware?
+if(WIN32 OR MINGW)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/win32.h)
+elseif(APPLE)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/hpux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/newtbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/solaris.h)
+elseif(CYGWIN)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/cygwin.h)
+else(WIN32 OR MINGW)
+	message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+# Try make fake host tuple for regress and isolation tests
+if(MINGW AND VOID_POINTER_SIZE EQUAL 8)
+	set(HOST_TUPLE "x86_64-w64-mingw32")
+elseif(MINGW AND VOID_POINTER_SIZE EQUAL 4)
+	set(HOST_TUPLE "i686-pc-mingw32")
+elseif(CYGWIN)
+	set(HOST_TUPLE "i686-pc-cygwin")
+elseif(MSVC AND VOID_POINTER_SIZE EQUAL 4)
+	set(HOST_TUPLE "i686-pc-win32vc")
+else()
+	set(HOST_TUPLE ${CMAKE_HOST_SYSTEM})
+endif()
+
+set(WITH_UUID "OFF" CACHE STRING "type of uuid lib [bsd, e2fs, ossp]")
+if(WITH_UUID)
+	find_package(LibUUID)
+
+	if(WITH_UUID STREQUAL "bsd")
+		set(HAVE_UUID_BSD 1)
+		set(UUID_EXTRA_OBJS
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+		)
+	elseif(WITH_UUID STREQUAL "e2fs")
+		set(HAVE_UUID_E2FS 1)
+		set(UUID_EXTRA_OBJS
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+		)
+	elseif(WITH_UUID STREQUAL "ossp")
+		set(HAVE_UUID_OSSP 1)
+		set(UUID_EXTRA_OBJS "")
+	else()
+		message(WARNING "Not correct type of uuid lib:${WITH_UUID}")
+	endif()
+endif()
+
+file(GENERATE OUTPUT ${PROJECT_SOURCE_DIR}/src/include/pg_config_os.h
+	INPUT ${pgos_include_SRCS})
+
+if(MINGW OR MSVC)
+	include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32")
+endif()
+
+if(MSVC)
+	include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32_msvc")
+endif()
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_ext_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_ext.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_paths_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/port/pg_config_paths.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/PGXS.cmake.in"
+	"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake"
+	@ONLY
+)
+
+install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake
+		DESTINATION ${LIBDIR}/cmake)
+
+
+option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
+mark_as_advanced(CMAKE_USE_FOLDERS)
+
+macro(CMAKE_SET_TARGET_FOLDER tgt folder)
+	if(CMAKE_USE_FOLDERS)
+		set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+		if(MSVC AND TARGET ${tgt})
+			set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
+		endif()
+	else()
+		set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+	endif()
+endmacro()
+
+# Add sub-directories
+add_subdirectory(src)
+add_subdirectory(contrib)
+
+message(STATUS "------------------")
+message(STATUS "    Conclusion")
+message(STATUS "Host tuple: ${HOST_TUPLE}")
+message(STATUS "OpenSSL: ${OPENSSL_FOUND} version: ${OPENSSL_VERSION} libs: ${OPENSSL_LIBRARIES}")
+message(STATUS "Python: ${PYTHONINTERP_FOUND}")
+message(STATUS "PythonLibs: ${PYTHONLIBS_FOUND}")
+message(STATUS "PerlLibs: ${PERLLIBS_FOUND}")
+message(STATUS "LibXML2: ${LIBXML2_FOUND}")
+message(STATUS "LibXslt: ${LIBXSLT_FOUND}")
+message(STATUS "TCL: ${TCL_FOUND}")
+message(STATUS "PAM: ${PAM_LIB}")
+message(STATUS "------------------")
diff --git a/PGXS.cmake.in b/PGXS.cmake.in
new file mode 100644
index 0000000..01a1100
--- /dev/null
+++ b/PGXS.cmake.in
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 2.8)
+
+set(POSTGRES_MAJOR_VERSION "@POSTGRES_MAJOR_VERSION@")
+set(POSTGRES_MINOR_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_PATCH_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_VERSION "@POSTGRES_VERSION@")
+set(PG_VERSION "9.6devel")
+set(PG_VERSION_NUM 90600)
+
+set(PGBINDIR "@PGBINDIR@")
+set(PGSHAREDIR "@PGSHAREDIR@")
+set(SYSCONFDIR "@SYSCONFDIR@")
+set(INCLUDEDIR "@INCLUDEDIR@")
+set(PKGINCLUDEDIR "@PKGINCLUDEDIR@")
+set(INCLUDEDIRSERVER "@INCLUDEDIRSERVER@")
+set(LIBDIR "@LIBDIR@")
+set(PKGLIBDIR "@PKGLIBDIR@")
+set(LOCALEDIR "@LOCALEDIR@")
+set(DOCDIR "@DOCDIR@")
+set(HTMLDIR "@HTMLDIR@")
+set(MANDIR "@MANDIR@")
+
+
+set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+set(CMAKE_MACOSX_RPATH 1)
+
+set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
+set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "@CMAKE_SHARED_LIBRARY_SONAME_C_FLAG@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+
+include_directories(${INCLUDEDIRSERVER})
+link_directories(${LIBDIR})
+
+if(WIN32)
+	set(contrib_libs
+		port
+		pgcommon
+	)
+endif()
+
+if(MSVC)
+	set(contrib_libs
+		${contrib_libs}
+		postgres
+	)
+endif()
diff --git a/cmake/CheckCpuID.cmake b/cmake/CheckCpuID.cmake
new file mode 100644
index 0000000..3346302
--- /dev/null
+++ b/cmake/CheckCpuID.cmake
@@ -0,0 +1,17 @@
+CHECK_C_SOURCE_COMPILES("
+	#include <cpuid.h>
+	int main() {
+		unsigned int exx[4] = {0, 0, 0, 0};
+		__get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]);
+		return 0;
+	}
+" HAVE__GET_CPUID)
+
+CHECK_C_SOURCE_COMPILES("
+	#include <intrin.h>
+	int main() {
+		unsigned int exx[4] = {0, 0, 0, 0};
+		__cpuid(exx[0], 1);
+		return 0;
+	}
+" HAVE__CPUID)
diff --git a/cmake/CheckFlexibleArray.cmake b/cmake/CheckFlexibleArray.cmake
new file mode 100644
index 0000000..ce57aa4
--- /dev/null
+++ b/cmake/CheckFlexibleArray.cmake
@@ -0,0 +1,37 @@
+set(C99_C_FLAG_CANDIDATES
+   " "
+   "-std=c99"
+   "-std=gnu99"
+   "-c99"
+   "-AC99"
+   "-xc99=all"
+   "-qlanglvl=extc99"
+)
+
+message(STATUS "Check flexible array support")
+if(NOT MSVC)
+	foreach(FLAG ${C99_C_FLAG_CANDIDATES})
+		set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+		unset(FLEXIBLE_ARRAY_MEMBER CACHE)
+		CHECK_C_SOURCE_COMPILES("
+			int main(void){
+				int x = 10;
+				int y[x];
+				return 0;
+			}
+		" FLEXIBLE_ARRAY_MEMBER)
+		if(FLEXIBLE_ARRAY_MEMBER)
+			set(C99_C_FLAGS_INTERNAL "${FLAG}")
+			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
+			break()
+		endif(FLEXIBLE_ARRAY_MEMBER)
+	endforeach(FLAG ${C99_C_FLAG_CANDIDATES})
+endif()
+
+if(FLEXIBLE_ARRAY_MEMBER)
+	message(STATUS "Check flexible array support - yes with ${C99_C_FLAGS_INTERNAL}")
+	set(FLEXIBLE_ARRAY_MEMBER "")
+else(FLEXIBLE_ARRAY_MEMBER)
+	message(STATUS "Check flexible array support - no")
+	set(FLEXIBLE_ARRAY_MEMBER 1)
+endif(FLEXIBLE_ARRAY_MEMBER)
\ No newline at end of file
diff --git a/cmake/CheckLLConstants.cmake b/cmake/CheckLLConstants.cmake
new file mode 100644
index 0000000..68bf65f
--- /dev/null
+++ b/cmake/CheckLLConstants.cmake
@@ -0,0 +1,9 @@
+CHECK_C_SOURCE_COMPILES("
+	main() {
+		#define INT64CONST(x)  x##LL
+		long long int foo = INT64CONST(0x1234567890123456);
+		return 0;
+	}
+" HAVE_LL_CONSTANTS)
+
+message(STATUS "HAVE_LL_CONSTANTS ${HAVE_LL_CONSTANTS}")
\ No newline at end of file
diff --git a/cmake/CheckSSE42.cmake b/cmake/CheckSSE42.cmake
new file mode 100644
index 0000000..3fee3b4
--- /dev/null
+++ b/cmake/CheckSSE42.cmake
@@ -0,0 +1,30 @@
+foreach(FLAG ";-msse4.2")
+	unset(HAVE_SSE42_INTRINSICS CACHE)
+	set(CMAKE_REQUIRED_FLAGS ${FLAG})
+	check_c_source_runs("
+		#include <nmmintrin.h>
+		int main(void) {
+			unsigned int crc = 0;
+			crc = _mm_crc32_u8(crc, 0);
+			crc = _mm_crc32_u32(crc, 0);
+			/* return computed value, to prevent the above being optimized away */
+			return !(crc == 0);
+		}
+	" HAVE_SSE42_INTRINSICS)
+	if (HAVE_SSE42_INTRINSICS)
+		set(CFLAGS_SSE42 ${FLAG})
+		break()
+	endif()
+endforeach()
+
+message(STATUS "SSE4.2 flags: ${CFLAGS_SSE42}")
+set(CMAKE_REQUIRED_FLAGS ${CFLAGS_SSE42})
+check_c_source_compiles("
+	#ifndef __SSE4_2__
+	#error __SSE4_2__ not defined
+	#endif
+	int main(void){
+		return 0;
+	}
+" HAVE_SSE42)
+set(CMAKE_REQUIRED_FLAGS "")
diff --git a/cmake/CheckSnprintfLongLongIntModifier.cmake b/cmake/CheckSnprintfLongLongIntModifier.cmake
new file mode 100644
index 0000000..f076238
--- /dev/null
+++ b/cmake/CheckSnprintfLongLongIntModifier.cmake
@@ -0,0 +1,31 @@
+set(CMAKE_REQUIRED_INCLUDES "stdio.h")
+foreach(pgac_modifier "ll" "q" "I64")
+	unset(LONG_LONG_INT_MODIFIER CACHE)
+	CHECK_C_SOURCE_COMPILES("
+		typedef long long int ac_int64;
+
+		ac_int64 a = 20000001;
+		ac_int64 b = 40000005;
+
+		int does_int64_snprintf_work() {
+			ac_int64 c;
+			char buf[100];
+			if (sizeof(ac_int64) != 8)
+				return 0;	/* doesn't look like the right size */
+			
+			c = a * b;
+			snprintf(buf, 100, \"%${pgac_modifier}d\", c);
+			if (strcmp(buf, \"800000140000005\") != 0)
+				return 0;	/* either multiply or snprintf is busted */
+			return 1;
+		}
+		main() {
+			exit(! does_int64_snprintf_work());
+		}
+	" LONG_LONG_INT_MODIFIER)
+	if(LONG_LONG_INT_MODIFIER)
+		set(LONG_LONG_INT_MODIFIER ${pgac_modifier})
+		break()
+	endif(LONG_LONG_INT_MODIFIER)
+endforeach(pgac_modifier)
+message(STATUS "LONG_LONG_INT_MODIFIER ${LONG_LONG_INT_MODIFIER}")
\ No newline at end of file
diff --git a/cmake/CheckTypeAlignment.cmake b/cmake/CheckTypeAlignment.cmake
new file mode 100644
index 0000000..37cbb58
--- /dev/null
+++ b/cmake/CheckTypeAlignment.cmake
@@ -0,0 +1,29 @@
+macro(CHECK_TYPE_ALIGNMENT TYPE NAME)
+	if(NOT ${NAME})
+		message(STATUS "Check alignment of ${TYPE}")
+		
+		set(INCLUDE_HEADERS "#include <stddef.h>
+			#include <stdio.h>
+			#include <stdlib.h>")
+
+		if(HAVE_STDINT_H)
+			set(INCLUDE_HEADERS "${INCLUDE_HEADERS}\n#include <stdint.h>\n")
+		endif(HAVE_STDINT_H)
+
+		file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c"
+			"${INCLUDE_HEADERS}
+			int main(){
+				char diff;
+				struct foo {char a; ${TYPE} b;};
+				struct foo *p = (struct foo *) malloc(sizeof(struct foo));
+				diff = ((char *)&p->b) - ((char *)&p->a);
+				return diff;}
+		")
+
+		try_run(${NAME} COMPILE_RESULT "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
+			"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c")
+
+		message(STATUS "Check alignment of ${TYPE} - ${${NAME}}")
+
+	endif(NOT ${NAME})
+endmacro(CHECK_TYPE_ALIGNMENT TYPE NAME ALIGNOF_TYPE)
\ No newline at end of file
diff --git a/cmake/FindLDAP.cmake b/cmake/FindLDAP.cmake
new file mode 100644
index 0000000..8a5bc63
--- /dev/null
+++ b/cmake/FindLDAP.cmake
@@ -0,0 +1,41 @@
+# - Try to find the LDAP client libraries
+# Once done this will define
+#
+#  LDAP_FOUND - system has libldap
+#  LDAP_INCLUDE_DIR - the ldap include directory
+#  LDAP_LIBRARIES - libldap + liblber (if found) library
+#  LBER_LIBRARIES - liblber library
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+	# Already in cache, be silent
+	set(Ldap_FIND_QUIETLY TRUE)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(UNIX)
+	FIND_PATH(LDAP_INCLUDE_DIR ldap.h)
+	FIND_LIBRARY(LDAP_LIBRARIES NAMES ldap)
+	FIND_LIBRARY(LBER_LIBRARIES NAMES lber)
+
+else(UNIX)
+	FIND_PATH(LDAP_INCLUDE_DIR winldap.h)
+	FIND_LIBRARY(LDAP_LIBRARIES NAMES wldap32)
+endif(UNIX)
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+	set(LDAP_FOUND TRUE)
+	if(LBER_LIBRARIES)
+		set(LDAP_LIBRARIES ${LDAP_LIBRARIES} ${LBER_LIBRARIES})
+	endif(LBER_LIBRARIES)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(LDAP_FOUND)
+	if(NOT Ldap_FIND_QUIETLY)
+		message(STATUS "Found ldap: ${LDAP_LIBRARIES}")
+	endif(NOT Ldap_FIND_QUIETLY)
+else(LDAP_FOUND)
+	if (Ldap_FIND_REQUIRED)
+		message(FATAL_ERROR "Could NOT find ldap")
+	endif (Ldap_FIND_REQUIRED)
+endif(LDAP_FOUND)
+
+MARK_AS_ADVANCED(LDAP_INCLUDE_DIR LDAP_LIBRARIES LBER_LIBRARIES)
diff --git a/cmake/FindLibSocket.cmake b/cmake/FindLibSocket.cmake
new file mode 100644
index 0000000..148f4ec
--- /dev/null
+++ b/cmake/FindLibSocket.cmake
@@ -0,0 +1,11 @@
+find_library( LIBSOCKET_LIBRARY NAMES libsocket socket )
+mark_as_advanced( LIBSOCKET_LIBRARY )
+
+# handle the QUIETLY and REQUIRED arguments and set LIBSOCKET_FOUND to TRUE if
+# all listed variables are TRUE
+include( FindPackageHandleStandardArgs )
+FIND_PACKAGE_HANDLE_STANDARD_ARGS( LIBSOCKET DEFAULT_MSG LIBSOCKET_LIBRARY )
+
+if( LIBSOCKET_FOUND )
+	set( LIBSOCKET_LIBRARIES ${LIBSOCKET_LIBRARY} )
+endif( LIBSOCKET_FOUND )
diff --git a/cmake/FindLibUUID.cmake b/cmake/FindLibUUID.cmake
new file mode 100644
index 0000000..10626c5
--- /dev/null
+++ b/cmake/FindLibUUID.cmake
@@ -0,0 +1,50 @@
+# - Try to find LIBUUID
+# Find LIBUUID headers, libraries and the answer to all questions.
+#
+#  LIBUUID_FOUND               True if libuuid got found
+#  LIBUUID_INCLUDE_DIRS        Location of libuuid headers
+#  LIBUUID_LIBRARIES           List of libraries to use libuuid
+#
+# Copyright (c) 2008 Bjoern Ricks <bjoern.ricks@googlemail.com>
+#
+#  Redistribution and use is allowed according to the terms of the New
+#  BSD license.
+#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+INCLUDE(FindPkgConfig)
+
+IF(LibUUID_FIND_REQUIRED)
+	SET(_pkgconfig_REQUIRED "REQUIRED")
+ELSE(LibUUID_FIND_REQUIRED)
+	SET(_pkgconfig_REQUIRED "")
+ENDIF (LibUUID_FIND_REQUIRED)
+
+IF(LIBUUID_MIN_VERSION)
+	PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid>=${LIBUUID_MIN_VERSION})
+ELSE(LIBUUID_MIN_VERSION)
+	PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid)
+ENDIF(LIBUUID_MIN_VERSION)
+
+IF(NOT LIBUUID_FOUND)
+	FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
+	FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
+
+	# Report results
+	IF(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+		SET(LIBUUID_FOUND 1)
+		IF(NOT LIBUUID_FIND_QUIETLY)
+			MESSAGE(STATUS "Found libuuid: ${LIBUUID_LIBRARIES}")
+		ENDIF(NOT LIBUUID_FIND_QUIETLY)
+	ELSE(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+		IF(LIBUUID_FIND_REQUIRED)
+			MESSAGE(SEND_ERROR "Could NOT find libuuid")
+		ELSE(LIBUUID_FIND_REQUIRED)
+			IF(NOT LIBUUID_FIND_QUIETLY)
+				MESSAGE(STATUS "Could NOT find libuuid")
+			ENDIF(NOT LIBUUID_FIND_QUIETLY)
+		ENDIF (LIBUUID_FIND_REQUIRED)
+	ENDIF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+ENDIF(NOT LIBUUID_FOUND)
+
+MARK_AS_ADVANCED(LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS)
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
new file mode 100644
index 0000000..6603dbe
--- /dev/null
+++ b/cmake/FindReadline.cmake
@@ -0,0 +1,22 @@
+# from http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/FindReadline.cmake
+# http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/COPYING-CMAKE-SCRIPTS
+# --> BSD licensed
+#
+# GNU Readline library finder
+
+
+if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+	set(READLINE_FOUND TRUE)
+else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+	FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h
+		/usr/include/readline
+	)
+
+	FIND_LIBRARY(READLINE_LIBRARY NAMES readline PATHS
+		/opt/csw/lib/64/
+	)
+	include(FindPackageHandleStandardArgs)
+	FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
+
+	MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
+endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
diff --git a/cmake/FindSELinux.cmake b/cmake/FindSELinux.cmake
new file mode 100644
index 0000000..dd6e3ca
--- /dev/null
+++ b/cmake/FindSELinux.cmake
@@ -0,0 +1,55 @@
+# - Try to find the SELinux library
+# Once done this will define
+#
+#  SELINUX_FOUND - System has selinux
+#  SELINUX_INCLUDE_DIR - The selinux include directory
+#  SELINUX_LIBRARIES - The libraries needed to use selinux
+#  SELINUX_DEFINITIONS - Compiler switches required for using selinux
+
+#=============================================================================
+# Copyright 2010  Michael Leupold <lemma@confuego.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+IF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+	# in cache already
+	SET (SELinux_FIND_QUIETLY TRUE)
+ENDIF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+
+# TODO: This should be restricted to Linux only
+IF (NOT WIN32)
+	# use pkg-config to get the directories
+	FIND_PACKAGE (PkgConfig)
+	PKG_CHECK_MODULES (PC_SELINUX libselinux)
+	SET (SELINUX_DEFINITIONS ${PC_SELINUX_CFLAGS_OTHER})
+
+	FIND_PATH (SELINUX_INCLUDE_DIR selinux/selinux.h
+		HINTS
+		${PC_SELINUX_INCLUDEDIR}
+		${PC_SELINUX_INCLUDE_DIRS}
+	)
+
+	FIND_LIBRARY (SELINUX_LIBRARIES selinux libselinux
+		HINTS
+		${PC_SELINUX_LIBDIR}
+		${PC_SELINUX_LIBRARY_DIRS}
+	)
+
+	INCLUDE (FindPackageHandleStandardArgs)
+
+	# handle the QUIETLY and REQUIRED arguments and set SELINUX_FOUND
+	# to TRUE if all listed variables are TRUE
+	FIND_PACKAGE_HANDLE_STANDARD_ARGS (SELinux DEFAULT_MSG
+		SELINUX_INCLUDE_DIR
+		SELINUX_LIBRARIES
+	)
+
+	MARK_AS_ADVANCED (SELINUX_INCLUDE_DIR SELINUX_LIBRARIES)
+
+ENDIF (NOT WIN32)
diff --git a/cmake/FuncAcceptArgtypes.cmake b/cmake/FuncAcceptArgtypes.cmake
new file mode 100644
index 0000000..e333d69
--- /dev/null
+++ b/cmake/FuncAcceptArgtypes.cmake
@@ -0,0 +1,52 @@
+if(HAVE_SYS_TYPES_H)
+	set(INCLUDE_SYS_TYPES_H "#include <sys/types.h>")
+endif(HAVE_SYS_TYPES_H)
+
+if(HAVE_SYS_SOCKET_H)
+	set(INCLUDE_SYS_SOCKET_H "#include <sys/socket.h>")
+endif(HAVE_SYS_SOCKET_H)
+
+
+message(STATUS "Looking for accept function args")
+set(CMAKE_REQUIRED_QUIET 1)
+foreach(ac_cv_func_accept_return "int" "unsigned int PASCAL" "SOCKET WSAAPI")
+	foreach(ac_cv_func_accept_arg1 "unsigned int" "int" "SOCKET")
+		foreach(ac_cv_func_accept_arg2 "struct sockaddr *" "const struct sockaddr *" "void *")
+			foreach(ac_cv_func_accept_arg3 "int" "size_t" "socklen_t" "unsigned int" "void")
+				unset(AC_FUNC_ACCEPT CACHE)
+				CHECK_C_SOURCE_COMPILES("
+					${INCLUDE_SYS_TYPES_H}
+					${INCLUDE_SYS_SOCKET_H}
+					extern ${ac_cv_func_accept_return} accept (${ac_cv_func_accept_arg1}, ${ac_cv_func_accept_arg2}, ${ac_cv_func_accept_arg3} *);
+					int main(void){return 0;}
+				" AC_FUNC_ACCEPT)
+				if(AC_FUNC_ACCEPT)
+					set(ACCEPT_TYPE_RETURN ${ac_cv_func_accept_return})
+					set(ACCEPT_TYPE_ARG1 ${ac_cv_func_accept_arg1})
+					set(ACCEPT_TYPE_ARG2 ${ac_cv_func_accept_arg2})
+					set(ACCEPT_TYPE_ARG3 ${ac_cv_func_accept_arg3})
+					break()
+				endif(AC_FUNC_ACCEPT)
+			endforeach(ac_cv_func_accept_arg3)
+			if(AC_FUNC_ACCEPT)
+				break()
+			endif(AC_FUNC_ACCEPT)
+		endforeach(ac_cv_func_accept_arg2)
+		if(AC_FUNC_ACCEPT)
+			break()
+		endif(AC_FUNC_ACCEPT)
+	endforeach(ac_cv_func_accept_arg1)
+	if(AC_FUNC_ACCEPT)
+		break()
+	endif(AC_FUNC_ACCEPT)
+endforeach(ac_cv_func_accept_return)
+unset(CMAKE_REQUIRED_QUIET)
+
+if(NOT AC_FUNC_ACCEPT)
+	message(ERROR "could not determine argument types")
+endif(NOT AC_FUNC_ACCEPT)
+if(ACCEPT_TYPE_ARG3 STREQUAL "void")
+	set(ACCEPT_TYPE_ARG3 "int")
+endif()
+
+message(STATUS "Looking for accept function args - found ${ACCEPT_TYPE_RETURN}, ${ACCEPT_TYPE_ARG1}, ${ACCEPT_TYPE_ARG2}, ${ACCEPT_TYPE_ARG3} *")
diff --git a/cmake/GenDef.cmake b/cmake/GenDef.cmake
new file mode 100644
index 0000000..499b0bd
--- /dev/null
+++ b/cmake/GenDef.cmake
@@ -0,0 +1,12 @@
+macro(GEN_DEF NAME)
+	SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def\" ")
+	add_custom_command(
+		TARGET ${NAME}
+		PRE_LINK
+		#COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+		#OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+		COMMAND ${PERL_EXECUTABLE} ${PROJECT_SOURCE_DIR}/src/tools/msvc/gendef.pl ${CMAKE_CURRENT_BINARY_DIR}/$<$<BOOL:${CMAKE_BUILD_TYPE}>:${CMAKE_FILES_DIRECTORY}>${NAME}.dir/${CMAKE_CFG_INTDIR} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def ${CMAKE_VS_PLATFORM_NAME}
+		COMMENT " Gen defs "
+	)
+	set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def)
+endmacro(GEN_DEF NAME)
diff --git a/cmake/MakeNLS.cmake b/cmake/MakeNLS.cmake
new file mode 100644
index 0000000..c6db90d
--- /dev/null
+++ b/cmake/MakeNLS.cmake
@@ -0,0 +1,21 @@
+macro(MAKE_MO BIN_NAME LANGUAGES)
+	set(gmo_files "")
+	foreach(lang ${LANGUAGES})
+		if (NOT ";${NLS_LANGUAGES};" MATCHES ";${lang};")
+			continue()
+		endif()
+		set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo)
+		add_custom_command(OUTPUT ${_gmoFile}
+			COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} po/${lang}.po
+			WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+			DEPENDS po/${lang}.po
+		)
+		install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo DESTINATION share/locale/${lang}/LC_MESSAGES/ RENAME ${BIN_NAME}-${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.mo)
+		if(NOT TARGET pofiles)
+			add_custom_target(pofiles)
+		endif()
+		add_custom_target(${BIN_NAME}-mofile-${lang} ALL DEPENDS ${_gmoFile})
+		add_dependencies(pofiles ${BIN_NAME}-mofile-${lang})
+		set(gmo_files "${gmo_files};${_gmoFile}")
+	endforeach()
+endmacro()
diff --git a/cmake/RegressCheck.cmake b/cmake/RegressCheck.cmake
new file mode 100644
index 0000000..1770597
--- /dev/null
+++ b/cmake/RegressCheck.cmake
@@ -0,0 +1,168 @@
+set(tmp_check_folder ${CMAKE_BINARY_DIR}/src/test/regress/tmp_install)
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+	set(env_cmd
+		${CMAKE_COMMAND} -E env
+		"DYLD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+	)
+	set(tmp_env_cmd
+		${CMAKE_COMMAND} -E env
+		"DYLD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+	)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+	set(env_cmd
+		${CMAKE_COMMAND} -E env
+		"LIBPATH=$ENV{DESTDIR}${LIBDIR}:$LIBPATH"
+	)
+	set(tmp_env_cmd
+		${CMAKE_COMMAND} -E env
+		"LIBPATH=${tmp_check_folder}${LIBDIR}:$LIBPATH"
+	)
+else()
+	if (CMAKE_VERSION VERSION_GREATER "3.2.0")
+		set(env_cmd
+			${CMAKE_COMMAND} -E env
+			"LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH"
+		)
+		set(tmp_env_cmd
+			${CMAKE_COMMAND} -E env
+			"LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH"
+		)
+	else()
+		set(env_cmd
+			export "LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH" &&
+		)
+		set(tmp_env_cmd
+			export "LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH" &&
+		)
+	endif()
+endif()
+
+if(MSVC OR MSYS OR MINGW OR CMAKE_GENERATOR STREQUAL Xcode)
+	#Need rewrite
+	set(pre_pg_regress_check
+		${PGBINDIR}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_isolation_regress_check
+		${PGBINDIR}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+else(MSVC)
+	set(pre_pg_regress_check
+		${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_isolation_regress_check
+		${CMAKE_BINARY_DIR}/src/test/isolation/${CMAKE_INSTALL_CONFIG_NAME}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+endif()
+
+set(pg_regress_check
+	${env_cmd}
+	${pre_pg_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check
+	${env_cmd}
+	${pre_pg_isolation_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_isolation_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+if(MAX_CONNECTIONS)
+	set(MAXCONNOPT "${MAXCONNOPT} --max-connections=${MAX_CONNECTIONS}")
+endif()
+
+if(TEMP_CONFIG)
+	set(TEMP_CONF "${TEMP_CONF} --temp-config=${TEMP_CONFIG}")
+endif()
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	set(check_make_command "ninja")
+else()
+	set(check_make_command "make")
+endif()
+
+macro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	add_custom_target(${TARGET_NAME}_installcheck_tmp
+		COMMAND ${pg_regress_check_tmp} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+	
+	add_custom_target(${TARGET_NAME}_installcheck
+		COMMAND ${pg_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	if(CMAKE_GENERATOR STREQUAL "Ninja")
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${TARGET_NAME}_installcheck_tmp
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	else()
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+			COMMAND ${check_make_command} ${TARGET_NAME}_installcheck_tmp DESTDIR=${tmp_check_folder}
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	endif()
+	
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck "tests/install")
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	add_custom_target(${TARGET_NAME}_isolation_installcheck_tmp
+		COMMAND ${pg_isolation_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	add_custom_target(${TARGET_NAME}_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} ${TARGET_NAME}_isolation_installcheck_tmp DESTDIR=${tmp_check_folder}
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_isolation_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_installcheck_tmp PARENT_SCOPE)
+	set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_installcheck PARENT_SCOPE)
+	REGRESS_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
diff --git a/cmake/ReplacePython.cmake b/cmake/ReplacePython.cmake
new file mode 100644
index 0000000..f768307
--- /dev/null
+++ b/cmake/ReplacePython.cmake
@@ -0,0 +1,79 @@
+macro(replace_python2 input_file output_file)
+	file(READ ${input_file} tmp_string)
+	string(REGEX REPLACE
+		"except \([a-zA-Z\\.]*\), *\([a-zA-Z]*\):"
+		"except \\1 as \\2:"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"<type 'exceptions\\.\([a-zA-Z]*\)'>" "<class '\\1'>"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"<type 'long'>" "<class 'int'>"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([0-9][0-9]*\)L" "\\1"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([ [{]\)u\"" "\\1\""
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([ [{]\)u'" "\\1'"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"def next" "def __next__"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"LANGUAGE plpythonu" "LANGUAGE plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"LANGUAGE plpython2u" "LANGUAGE plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION \([^ ]*_\)+plpythonu" "EXTENSION \\1plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION plpythonu" "EXTENSION plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION \([^ ]*_\)+plpython2u" "EXTENSION \\1plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION plpython2u" "EXTENSION plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"installing required extension \"plpython2u\""
+		"installing required extension \"plpython3u\""
+		tmp_string
+		"${tmp_string}")
+	file(WRITE ${output_file} "${tmp_string}")
+endmacro()
+
+macro(replace_python_files r_regress_files)
+	file(MAKE_DIRECTORY sql/python3 expected/python3 results/python3)
+	set(adition_clean "")
+	set(regress_files3 "")
+	foreach(rfile ${r_regress_files})
+		replace_python2("sql/${rfile}.sql" "sql/python3/${rfile}.sql")
+		if(rfile STREQUAL "plpython_types")
+			replace_python2("expected/plpython_types_3.out" "expected/python3/${rfile}.out")
+		else()
+			replace_python2("expected/${rfile}.out" "expected/python3/${rfile}.out")
+		endif()
+		set(adition_clean "${adition_clean};sql/python3/${rfile}.sql;expected/python3/${rfile}.out;")
+		set(regress_files3 "${regress_files3};python3/${rfile}")
+	endforeach(rfile)
+	SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${adition_clean}")
+endmacro()
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt
new file mode 100644
index 0000000..7d25bf0
--- /dev/null
+++ b/contrib/CMakeLists.txt
@@ -0,0 +1,111 @@
+set(contrib_libs postgres)
+
+#TODO: need test under mingw or cygwin
+if(WIN32)
+	set(contrib_libs
+		port
+		pgcommon
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(contrib_libs
+		port
+		postgres
+		pgcommon_srv
+	)
+endif()
+
+set(contrib_check_targets "")
+set(contrib_installcheck_targets "")
+
+add_subdirectory(adminpack)
+add_subdirectory(auth_delay)
+add_subdirectory(auto_explain)
+add_subdirectory(btree_gin)
+add_subdirectory(btree_gist)
+add_subdirectory(bloom)
+add_subdirectory(chkpass)
+add_subdirectory(citext)
+add_subdirectory(cube)
+add_subdirectory(dblink)
+add_subdirectory(dict_int)
+add_subdirectory(dict_xsyn)
+add_subdirectory(earthdistance)
+add_subdirectory(file_fdw)
+add_subdirectory(fuzzystrmatch)
+add_subdirectory(hstore)
+if(PERLLIBS_FOUND)
+	add_subdirectory(hstore_plperl)
+endif()
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(hstore_plpython)
+endif()
+add_subdirectory(intarray)
+add_subdirectory(isn)
+add_subdirectory(lo)
+add_subdirectory(ltree)
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(ltree_plpython)
+endif()
+add_subdirectory(oid2name)
+add_subdirectory(pageinspect)
+add_subdirectory(passwordcheck)
+add_subdirectory(pg_buffercache)
+add_subdirectory(pg_freespacemap)
+add_subdirectory(pg_prewarm)
+add_subdirectory(pg_standby)
+add_subdirectory(pg_stat_statements)
+add_subdirectory(pg_trgm)
+add_subdirectory(pg_visibility)
+add_subdirectory(pgcrypto)
+add_subdirectory(pgrowlocks)
+add_subdirectory(pgstattuple)
+add_subdirectory(postgres_fdw)
+add_subdirectory(seg)
+if(SELINUX_LIBRARIES)
+	add_subdirectory(sepgsql)
+endif()
+add_subdirectory(spi)
+if(OPENSSL_FOUND)
+	add_subdirectory(sslinfo)
+endif()
+add_subdirectory(tablefunc)
+add_subdirectory(tcn)
+add_subdirectory(tsearch2)
+add_subdirectory(tsm_system_rows)
+add_subdirectory(tsm_system_time)
+add_subdirectory(unaccent)
+if(WITH_UUID)
+	add_subdirectory(uuid-ossp)
+endif()
+add_subdirectory(vacuumlo)
+if(LIBXML2_FOUND)
+	add_subdirectory(xml2)
+endif()
+
+add_custom_target(contrib_check
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+	COMMAND make install DESTDIR=${tmp_check_folder}
+	COMMAND make ${contrib_check_targets} DESTDIR=${tmp_check_folder}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+#Make chain for run tests in strict order
+#TODO: we can't run tests separately now
+set(first_element "")
+list(GET contrib_installcheck_targets 0 first_element)
+add_custom_target(contrib_installcheck
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+	DEPENDS tablespace-setup ${first_element}
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+set(last_element OFF)
+foreach(loop_var IN ITEMS ${contrib_installcheck_targets})
+	if(last_element)
+		add_dependencies(${last_element} ${loop_var})
+	endif()
+	set(last_element ${loop_var})
+endforeach()
diff --git a/contrib/adminpack/CMakeLists.txt b/contrib/adminpack/CMakeLists.txt
new file mode 100644
index 0000000..c1f5251
--- /dev/null
+++ b/contrib/adminpack/CMakeLists.txt
@@ -0,0 +1,27 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name adminpack)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
diff --git a/contrib/auth_delay/CMakeLists.txt b/contrib/auth_delay/CMakeLists.txt
new file mode 100644
index 0000000..b890114
--- /dev/null
+++ b/contrib/auth_delay/CMakeLists.txt
@@ -0,0 +1,27 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+	if(OPENSSL_FOUND)
+		include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	endif()
+endif()
+
+set(extension_name auth_delay)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/auto_explain/CMakeLists.txt b/contrib/auto_explain/CMakeLists.txt
new file mode 100644
index 0000000..11ca366
--- /dev/null
+++ b/contrib/auto_explain/CMakeLists.txt
@@ -0,0 +1,18 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name auto_explain)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
diff --git a/contrib/bloom/CMakeLists.txt b/contrib/bloom/CMakeLists.txt
new file mode 100644
index 0000000..634b3f9
--- /dev/null
+++ b/contrib/bloom/CMakeLists.txt
@@ -0,0 +1,35 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name bloom)
+
+add_library(${extension_name} MODULE
+	blcost.c
+	blinsert.c
+	blscan.c
+	blutils.c
+	blvacuum.c
+	blvalidate.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "bloom")
diff --git a/contrib/btree_gin/CMakeLists.txt b/contrib/btree_gin/CMakeLists.txt
new file mode 100644
index 0000000..de598d9
--- /dev/null
+++ b/contrib/btree_gin/CMakeLists.txt
@@ -0,0 +1,47 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name btree_gin)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regres_files
+	install_btree_gin
+	int2
+	int4
+	int8
+	float4
+	float8
+	money
+	oid
+	timestamp
+	timestamptz
+	time
+	timetz
+	date
+	interval
+	macaddr
+	inet
+	cidr
+	text
+	varchar
+	char
+	bytea
+	bit
+	varbit
+	numeric
+)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regres_files}")
diff --git a/contrib/btree_gist/CMakeLists.txt b/contrib/btree_gist/CMakeLists.txt
new file mode 100644
index 0000000..803cb0e
--- /dev/null
+++ b/contrib/btree_gist/CMakeLists.txt
@@ -0,0 +1,75 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name btree_gist)
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	btree_utils_num.c
+	btree_utils_var.c
+	btree_int2.c
+	btree_int4.c
+	btree_int8.c
+	btree_float4.c
+	btree_float8.c
+	btree_cash.c
+	btree_oid.c
+	btree_ts.c
+	btree_time.c
+	btree_date.c
+	btree_interval.c
+	btree_macaddr.c
+	btree_inet.c
+	btree_text.c
+	btree_bytea.c
+	btree_bit.c
+	btree_numeric.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+set(regres_files
+	init
+	int2
+	int4
+	int8
+	float4
+	float8
+	cash
+	oid
+	timestamp
+	timestamptz
+	time
+	timetz
+	date
+	interval
+	macaddr
+	inet
+	cidr
+	text
+	varchar
+	char
+	bytea
+	bit
+	varbit
+	numeric
+	not_equal
+)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regres_files}")
diff --git a/contrib/chkpass/CMakeLists.txt b/contrib/chkpass/CMakeLists.txt
new file mode 100644
index 0000000..6151b0e
--- /dev/null
+++ b/contrib/chkpass/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name chkpass)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/citext/CMakeLists.txt b/contrib/citext/CMakeLists.txt
new file mode 100644
index 0000000..3a0eb0e
--- /dev/null
+++ b/contrib/citext/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name citext)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "citext")
diff --git a/contrib/cube/CMakeLists.txt b/contrib/cube/CMakeLists.txt
new file mode 100644
index 0000000..9fafdea
--- /dev/null
+++ b/contrib/cube/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name cube)
+
+bison_target(CUBE_PARSER cubeparse.y ${CMAKE_CURRENT_SOURCE_DIR}/cubeparse.c)
+flex_target(CUBE_SCANNER cubescan.l  ${CMAKE_CURRENT_SOURCE_DIR}/cubescan.c)
+add_flex_bison_dependency(CUBE_SCANNER CUBE_PARSER)
+set_source_files_properties(${BISON_CUBE_PARSER_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${FLEX_CUBE_SCANNER_OUTPUTS})
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	${BISON_CUBE_PARSER_OUTPUTS}
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "cube")
diff --git a/contrib/dblink/CMakeLists.txt b/contrib/dblink/CMakeLists.txt
new file mode 100644
index 0000000..05507c4
--- /dev/null
+++ b/contrib/dblink/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name dblink)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files paths dblink)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/dict_int/CMakeLists.txt b/contrib/dict_int/CMakeLists.txt
new file mode 100644
index 0000000..5034d47
--- /dev/null
+++ b/contrib/dict_int/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name dict_int)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files dict_int)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/dict_xsyn/CMakeLists.txt b/contrib/dict_xsyn/CMakeLists.txt
new file mode 100644
index 0000000..f8335b6
--- /dev/null
+++ b/contrib/dict_xsyn/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name dict_xsyn)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	xsyn_sample.rules
+	DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regress_files dict_xsyn)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/earthdistance/CMakeLists.txt b/contrib/earthdistance/CMakeLists.txt
new file mode 100644
index 0000000..b4b4381
--- /dev/null
+++ b/contrib/earthdistance/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name earthdistance)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files earthdistance)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/file_fdw/CMakeLists.txt b/contrib/file_fdw/CMakeLists.txt
new file mode 100644
index 0000000..93c354a
--- /dev/null
+++ b/contrib/file_fdw/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name file_fdw)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files file_fdw)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/fuzzystrmatch/CMakeLists.txt b/contrib/fuzzystrmatch/CMakeLists.txt
new file mode 100644
index 0000000..6e21763
--- /dev/null
+++ b/contrib/fuzzystrmatch/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name fuzzystrmatch)
+
+add_library(${extension_name} MODULE ${extension_name}.c dmetaphone.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/hstore/CMakeLists.txt b/contrib/hstore/CMakeLists.txt
new file mode 100644
index 0000000..096e193
--- /dev/null
+++ b/contrib/hstore/CMakeLists.txt
@@ -0,0 +1,38 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name hstore)
+
+add_library(${extension_name} MODULE
+	hstore_io.c
+	hstore_op.c
+	hstore_gist.c
+	hstore_gin.c
+	hstore_compat.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	set_target_properties(${extension_name} PROPERTIES LINK_FLAGS -Wl,--out-implib=libmin${extension_name}.dll.a)
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/hstore_plperl/CMakeLists.txt b/contrib/hstore_plperl/CMakeLists.txt
new file mode 100644
index 0000000..ea738ed
--- /dev/null
+++ b/contrib/hstore_plperl/CMakeLists.txt
@@ -0,0 +1,38 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plperl"
+	"${PROJECT_SOURCE_DIR}/contrib/hstore"
+	${PERL_INCLUDE_PATH}
+)
+
+if(MINGW)
+	link_directories("${PROJECT_BINARY_DIR}/contrib/hstore")
+endif()
+set(extension_name hstore_plperl)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${PERL_LIBRARY} ${PERL_LDFLAGS})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	target_link_libraries(${extension_name} minhstore)
+	target_compile_definitions(${extension_name} PRIVATE -DPLPERL_HAVE_UID_GID)
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore_plperl)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/hstore_plpython/CMakeLists.txt b/contrib/hstore_plpython/CMakeLists.txt
new file mode 100644
index 0000000..fa67001
--- /dev/null
+++ b/contrib/hstore_plpython/CMakeLists.txt
@@ -0,0 +1,57 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plpython"
+	"${PROJECT_SOURCE_DIR}/contrib/hstore"
+	${PYTHON_INCLUDE_DIRS}
+)
+
+if(MINGW)
+	link_directories(
+		"${PROJECT_BINARY_DIR}/contrib/hstore"
+		"${PROJECT_BINARY_DIR}/src/pl/plpython"
+	)
+endif()
+
+set(extension_name hstore_plpython)
+
+add_library(${extension_name}${PYTHON_VERSION_MAJOR} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} ${contrib_libs} ${PYTHON_LIBRARIES})
+set_target_properties(${extension_name}${PYTHON_VERSION_MAJOR} PROPERTIES PREFIX "")
+add_dependencies(${extension_name}${PYTHON_VERSION_MAJOR} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} minhstore minplpython${PYTHON_VERSION_MAJOR})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name}${PYTHON_VERSION_MAJOR} contrib)
+endif()
+install(TARGETS ${extension_name}${PYTHON_VERSION_MAJOR}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	${extension_name}2u.control
+	${extension_name}2u--1.0.sql
+	${extension_name}3u.control
+	${extension_name}3u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore_plpython)
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${regress_files}")
+	set(regress_options
+		"--load-extension=hstore"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files3}")
+else()
+	set(regress_options
+		"--load-extension=hstore"
+		"--load-extension=plpythonu"
+		"--load-extension=hstore_plpythonu"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files}")
+endif()
diff --git a/contrib/intarray/CMakeLists.txt b/contrib/intarray/CMakeLists.txt
new file mode 100644
index 0000000..e5bee80
--- /dev/null
+++ b/contrib/intarray/CMakeLists.txt
@@ -0,0 +1,36 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name intarray)
+set(extension_lib_name _int)
+
+add_library(${extension_lib_name} MODULE
+	_int_bool.c
+	_int_gist.c
+	_int_op.c
+	_int_tool.c
+	_intbig_gist.c
+	_int_gin.c
+	_int_selfuncs.c
+)
+target_link_libraries(${extension_lib_name} ${contrib_libs})
+set_target_properties(${extension_lib_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_lib_name} postgres)
+if (MSVC)
+	gen_def(${extension_lib_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_lib_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ${extension_lib_name})
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/isn/CMakeLists.txt b/contrib/isn/CMakeLists.txt
new file mode 100644
index 0000000..9e19366
--- /dev/null
+++ b/contrib/isn/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name isn)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files isn)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/lo/CMakeLists.txt b/contrib/lo/CMakeLists.txt
new file mode 100644
index 0000000..0c7aab0
--- /dev/null
+++ b/contrib/lo/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name lo)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/ltree/CMakeLists.txt b/contrib/ltree/CMakeLists.txt
new file mode 100644
index 0000000..e097839
--- /dev/null
+++ b/contrib/ltree/CMakeLists.txt
@@ -0,0 +1,37 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name ltree)
+add_definitions(-DLOWER_NODE)
+
+add_library(${extension_name} MODULE
+	ltree_io.c
+	ltree_op.c
+	lquery_op.c
+	_ltree_op.c
+	crc32.c
+	ltxtquery_io.c
+	ltxtquery_op.c
+	ltree_gist.c
+	_ltree_gist.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ltree)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/ltree_plpython/CMakeLists.txt b/contrib/ltree_plpython/CMakeLists.txt
new file mode 100644
index 0000000..dd960aa
--- /dev/null
+++ b/contrib/ltree_plpython/CMakeLists.txt
@@ -0,0 +1,49 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plpython"
+	"${PROJECT_SOURCE_DIR}/contrib/ltree"
+	${PYTHON_INCLUDE_DIRS}
+)
+
+set(extension_name ltree_plpython)
+
+add_library(${extension_name}${PYTHON_VERSION_MAJOR} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} ${contrib_libs} ${PYTHON_LIBRARIES})
+set_target_properties(${extension_name}${PYTHON_VERSION_MAJOR} PROPERTIES PREFIX "")
+add_dependencies(${extension_name}${PYTHON_VERSION_MAJOR} postgres ltree)
+if (MSVC)
+	gen_def(${extension_name}${PYTHON_VERSION_MAJOR})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name}${PYTHON_VERSION_MAJOR} contrib)
+endif()
+install(TARGETS ${extension_name}${PYTHON_VERSION_MAJOR}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	${extension_name}2u.control
+	${extension_name}2u--1.0.sql
+	${extension_name}3u.control
+	${extension_name}3u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ltree_plpython)
+
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${regress_files}")
+	set(regress_options
+		"--load-extension=ltree"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files3}")
+else()
+	set(regress_options
+		"--load-extension=hstore"
+		"--load-extension=plpythonu"
+		"--load-extension=ltree"
+		"--load-extension=ltree_plpythonu"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files}")
+endif()
diff --git a/contrib/oid2name/CMakeLists.txt b/contrib/oid2name/CMakeLists.txt
new file mode 100644
index 0000000..3f1cefd
--- /dev/null
+++ b/contrib/oid2name/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name oid2name)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+
+if(MSVC OR MINGW)
+	target_link_libraries(${extension_name} pgcommon pq)
+endif()
+
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pageinspect/CMakeLists.txt b/contrib/pageinspect/CMakeLists.txt
new file mode 100644
index 0000000..3997184
--- /dev/null
+++ b/contrib/pageinspect/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pageinspect)
+
+add_library(${extension_name} MODULE
+	rawpage.c
+	heapfuncs.c
+	btreefuncs.c
+	fsmfuncs.c
+	brinfuncs.c
+	ginfuncs.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.5.sql
+	${extension_name}--1.4--1.5.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/passwordcheck/CMakeLists.txt b/contrib/passwordcheck/CMakeLists.txt
new file mode 100644
index 0000000..468e4e8
--- /dev/null
+++ b/contrib/passwordcheck/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name passwordcheck)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pg_buffercache/CMakeLists.txt b/contrib/pg_buffercache/CMakeLists.txt
new file mode 100644
index 0000000..4a99728
--- /dev/null
+++ b/contrib/pg_buffercache/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_buffercache)
+
+add_library(${extension_name} MODULE ${extension_name}_pages.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_freespacemap/CMakeLists.txt b/contrib/pg_freespacemap/CMakeLists.txt
new file mode 100644
index 0000000..0045ddc
--- /dev/null
+++ b/contrib/pg_freespacemap/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_freespacemap)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_prewarm/CMakeLists.txt b/contrib/pg_prewarm/CMakeLists.txt
new file mode 100644
index 0000000..8018abd
--- /dev/null
+++ b/contrib/pg_prewarm/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_prewarm)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_standby/CMakeLists.txt b/contrib/pg_standby/CMakeLists.txt
new file mode 100644
index 0000000..67305e9
--- /dev/null
+++ b/contrib/pg_standby/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_standby)
+
+add_executable(${extension_name} ${extension_name}.c)
+target_link_libraries(${extension_name} port pgcommon pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pg_stat_statements/CMakeLists.txt b/contrib/pg_stat_statements/CMakeLists.txt
new file mode 100644
index 0000000..ec6891f
--- /dev/null
+++ b/contrib/pg_stat_statements/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_stat_statements)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_trgm/CMakeLists.txt b/contrib/pg_trgm/CMakeLists.txt
new file mode 100644
index 0000000..d3bf9b0
--- /dev/null
+++ b/contrib/pg_trgm/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_trgm)
+
+add_library(${extension_name} MODULE
+	trgm_op.c
+	trgm_gist.c
+	trgm_gin.c
+	trgm_regexp.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.3.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files pg_trgm pg_word_trgm)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/pg_visibility/CMakeLists.txt b/contrib/pg_visibility/CMakeLists.txt
new file mode 100644
index 0000000..bc8db81
--- /dev/null
+++ b/contrib/pg_visibility/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_visibility)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pgcrypto/CMakeLists.txt b/contrib/pgcrypto/CMakeLists.txt
new file mode 100644
index 0000000..b4bfabd
--- /dev/null
+++ b/contrib/pgcrypto/CMakeLists.txt
@@ -0,0 +1,133 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+)
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+set(extension_name pgcrypto)
+
+set(pgcrypto_src
+	pgcrypto.c
+	px.c
+	px-hmac.c
+	px-crypt.c
+	crypt-gensalt.c
+	crypt-blowfish.c
+	crypt-des.c
+	crypt-md5.c
+	mbuf.c
+	pgp.c
+	pgp-armor.c
+	pgp-cfb.c
+	pgp-compress.c
+	pgp-decrypt.c
+	pgp-encrypt.c
+	pgp-info.c
+	pgp-mpi.c
+	pgp-pubdec.c
+	pgp-pubenc.c
+	pgp-pubkey.c
+	pgp-s2k.c
+	pgp-pgsql.c
+)
+
+set(regress_files
+	init
+	md5
+	sha1
+	hmac-md5
+	hmac-sha1
+	blowfish
+	rijndael
+	crypt-des
+	crypt-md5
+	crypt-blowfish
+	crypt-xdes
+	pgp-armor
+	pgp-decrypt
+	pgp-encrypt
+	pgp-pubkey-decrypt
+	pgp-pubkey-encrypt
+	pgp-info
+)
+
+if(OPENSSL_FOUND)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	set(pgcrypto_src ${pgcrypto_src} openssl.c pgp-mpi-openssl.c)
+	set(regress_files ${regress_files}
+		sha2
+		des
+		3des
+		cast5
+	)
+else()
+	add_executable(gen-rtab rijndael.c)
+	target_compile_definitions(gen-rtab PRIVATE -DPRINT_TABS)
+
+	add_custom_command(
+		DEPENDS gen-rtab
+		OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/rijndael.tbl
+		COMMAND gen-rtab > rijndael.tbl
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	set(pgcrypto_src ${pgcrypto_src}
+		md5.c
+		sha1.c
+		sha2.c
+		internal.c
+		internal-sha2.c
+		blf.c
+		rijndael.tbl
+		rijndael.c
+		fortuna.c
+		random.c
+		pgp-mpi-internal.c
+		imath.c
+	)
+	set(regress_files ${regress_files} sha2)
+endif()
+
+if(ZLIB_FOUND)
+	set(regress_files ${regress_files} pgp-compression)
+endif()
+
+add_library(${extension_name} MODULE ${pgcrypto_src})
+target_link_libraries(${extension_name}
+	${contrib_libs}
+)
+if(OPENSSL_FOUND)
+	target_link_libraries(${extension_name} ${OPENSSL_LIBRARIES})
+endif()
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+if(ZLIB_FOUND)
+	target_link_libraries(${extension_name} ${ZLIB_LIBRARIES})
+endif()
+if(WIN32)
+	target_link_libraries(${extension_name} ws2_32)
+endif()
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.3.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/pgcrypto/rijndael.c b/contrib/pgcrypto/rijndael.c
index 4adbcc1..af7b87c 100644
--- a/contrib/pgcrypto/rijndael.c
+++ b/contrib/pgcrypto/rijndael.c
@@ -78,8 +78,9 @@ static void gen_tabs(void);
 #endif
 
 #ifdef PRE_CALC_TABLES
-
-#include "rijndael.tbl"
+/* WRAP_INCLUDE for remove CMake circular dependency */
+#define WRAP_INCLUDE(x) x
+#include WRAP_INCLUDE("rijndael.tbl")
 #define tab_gen		1
 #else							/* !PRE_CALC_TABLES */
 
diff --git a/contrib/pgcrypto/rijndael.tbl b/contrib/pgcrypto/rijndael.tbl
index c7610c0..bc0a382 100644
--- a/contrib/pgcrypto/rijndael.tbl
+++ b/contrib/pgcrypto/rijndael.tbl
@@ -1133,6 +1133,7 @@ static const u4byte  il_tab[4][256] = {
 };
 
 static const u4byte rco_tab[10] = {
-  0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010,
+  0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 
   0x00000020, 0x00000040, 0x00000080, 0x0000001b, 0x00000036
 };
+
diff --git a/contrib/pgrowlocks/CMakeLists.txt b/contrib/pgrowlocks/CMakeLists.txt
new file mode 100644
index 0000000..ab294ce
--- /dev/null
+++ b/contrib/pgrowlocks/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pgrowlocks)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pgstattuple/CMakeLists.txt b/contrib/pgstattuple/CMakeLists.txt
new file mode 100644
index 0000000..5f0cac4
--- /dev/null
+++ b/contrib/pgstattuple/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pgstattuple)
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	pgstatindex.c
+	pgstatapprox.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files pgstattuple)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/postgres_fdw/CMakeLists.txt b/contrib/postgres_fdw/CMakeLists.txt
new file mode 100644
index 0000000..eb243ff
--- /dev/null
+++ b/contrib/postgres_fdw/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name postgres_fdw)
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	option.c
+	deparse.c
+	connection.c
+	shippable.c
+)
+target_link_libraries(${extension_name} ${contrib_libs} pq)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files postgres_fdw)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/seg/CMakeLists.txt b/contrib/seg/CMakeLists.txt
new file mode 100644
index 0000000..d464851
--- /dev/null
+++ b/contrib/seg/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name seg)
+
+bison_target(CUBE_PARSER segparse.y ${CMAKE_CURRENT_SOURCE_DIR}/segparse.c)
+flex_target(CUBE_SCANNER segscan.l  ${CMAKE_CURRENT_SOURCE_DIR}/segscan.c)
+add_flex_bison_dependency(CUBE_SCANNER CUBE_PARSER)
+set_source_files_properties(${BISON_CUBE_PARSER_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${FLEX_CUBE_SCANNER_OUTPUTS})
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	${BISON_CUBE_PARSER_OUTPUTS}
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files seg)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/sepgsql/CMakeLists.txt b/contrib/sepgsql/CMakeLists.txt
new file mode 100644
index 0000000..c44c78c
--- /dev/null
+++ b/contrib/sepgsql/CMakeLists.txt
@@ -0,0 +1,45 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name sepgsql)
+
+set(sepgsql_sql_output
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql.in
+	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	COMMAND sed 's,MODULE_PATHNAME,$$libdir/${extension_name},g' sepgsql.sql.in > ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_library(${extension_name} MODULE
+	hooks.c
+	selinux.c
+	uavc.c
+	label.c
+	dml.c
+	database.c
+	schema.c
+	relation.c
+	proc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+)
+target_link_libraries(${extension_name} ${contrib_libs} ${SELINUX_LIBRARIES})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	DESTINATION ${PGSHAREDIR}/contrib)
+
+#set(regress_files seg)
+#CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/spi/CMakeLists.txt b/contrib/spi/CMakeLists.txt
new file mode 100644
index 0000000..49bc5d7
--- /dev/null
+++ b/contrib/spi/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+
+set(modules_list 
+	autoinc
+	insert_username
+	moddatetime
+	refint
+	timetravel
+)
+
+foreach(loop_var IN ITEMS ${modules_list})
+	add_library(${loop_var} MODULE ${loop_var}.c)
+	target_compile_definitions(${loop_var} PRIVATE -DREFINT_VERBOSE)
+	target_link_libraries(${loop_var} ${contrib_libs})
+	set_target_properties(${loop_var} PROPERTIES PREFIX "")
+	add_dependencies(${loop_var} postgres)
+	if(MSVC)
+		gen_def(${loop_var})
+	endif()
+	if(NOT PGXS)
+		CMAKE_SET_TARGET_FOLDER(${loop_var} contrib/spi)
+	endif()
+	install(TARGETS ${loop_var}
+			RUNTIME DESTINATION ${PGBINDIR}
+			LIBRARY DESTINATION ${LIBDIR})
+	install(FILES ${loop_var}.control ${loop_var}--1.0.sql ${loop_var}--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+endforeach(loop_var)
diff --git a/contrib/sslinfo/CMakeLists.txt b/contrib/sslinfo/CMakeLists.txt
new file mode 100644
index 0000000..60d0a77
--- /dev/null
+++ b/contrib/sslinfo/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	${OPENSSL_INCLUDE_DIR}
+)
+
+set(extension_name sslinfo)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${OPENSSL_LIBRARIES})
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/tablefunc/CMakeLists.txt b/contrib/tablefunc/CMakeLists.txt
new file mode 100644
index 0000000..1c1550d
--- /dev/null
+++ b/contrib/tablefunc/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tablefunc)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tablefunc)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tcn/CMakeLists.txt b/contrib/tcn/CMakeLists.txt
new file mode 100644
index 0000000..87273a8
--- /dev/null
+++ b/contrib/tcn/CMakeLists.txt
@@ -0,0 +1,21 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tcn)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/tsearch2/CMakeLists.txt b/contrib/tsearch2/CMakeLists.txt
new file mode 100644
index 0000000..09e792c
--- /dev/null
+++ b/contrib/tsearch2/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsearch2)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsearch2)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tsm_system_rows/CMakeLists.txt b/contrib/tsm_system_rows/CMakeLists.txt
new file mode 100644
index 0000000..874b018
--- /dev/null
+++ b/contrib/tsm_system_rows/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsm_system_rows)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsm_system_rows)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tsm_system_time/CMakeLists.txt b/contrib/tsm_system_time/CMakeLists.txt
new file mode 100644
index 0000000..c723e1a
--- /dev/null
+++ b/contrib/tsm_system_time/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsm_system_time)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsm_system_time)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/unaccent/CMakeLists.txt b/contrib/unaccent/CMakeLists.txt
new file mode 100644
index 0000000..be6fa70
--- /dev/null
+++ b/contrib/unaccent/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name unaccent)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	${extension_name}.rules
+	DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regress_files unaccent)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/uuid-ossp/CMakeLists.txt b/contrib/uuid-ossp/CMakeLists.txt
new file mode 100644
index 0000000..4886f0f
--- /dev/null
+++ b/contrib/uuid-ossp/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+include_directories(${LIBUUID_INCLUDE_DIRS})
+include_directories("${PROJECT_SOURCE_DIR}/contrib/pgcrypto")
+
+set(extension_name uuid-ossp)
+
+add_library(${extension_name} MODULE ${extension_name}.c ${UUID_EXTRA_OBJS})
+target_link_libraries(${extension_name} ${contrib_libs} ${LIBUUID_LIBRARIES})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files uuid_ossp)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/uuid-ossp/uuid-ossp.c b/contrib/uuid-ossp/uuid-ossp.c
index 3e12bc4..39bf685 100644
--- a/contrib/uuid-ossp/uuid-ossp.c
+++ b/contrib/uuid-ossp/uuid-ossp.c
@@ -26,15 +26,7 @@
  */
 #define uuid_hash bsd_uuid_hash
 
-#ifdef HAVE_UUID_H
 #include <uuid.h>
-#endif
-#ifdef HAVE_OSSP_UUID_H
-#include <ossp/uuid.h>
-#endif
-#ifdef HAVE_UUID_UUID_H
-#include <uuid/uuid.h>
-#endif
 
 #undef uuid_hash
 
diff --git a/contrib/vacuumlo/CMakeLists.txt b/contrib/vacuumlo/CMakeLists.txt
new file mode 100644
index 0000000..e7b0481
--- /dev/null
+++ b/contrib/vacuumlo/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name vacuumlo)
+
+add_executable(${extension_name} ${extension_name}.c)
+target_link_libraries(${extension_name} port pgcommon pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/xml2/CMakeLists.txt b/contrib/xml2/CMakeLists.txt
new file mode 100644
index 0000000..4880422
--- /dev/null
+++ b/contrib/xml2/CMakeLists.txt
@@ -0,0 +1,40 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	${LIBXML2_INCLUDE_DIR}
+)
+
+if(LIBXSLT_FOUND)
+	include_directories(BEFORE ${LIBXSLT_INCLUDE_DIR})
+endif()
+
+set(extension_name xml2)
+set(extension_lib_name pgxml)
+
+add_library(${extension_lib_name} MODULE xpath.c xslt_proc.c)
+target_link_libraries(${extension_lib_name}
+	${contrib_libs}
+	${LIBXML2_LIBRARIES}
+)
+if(LIBXSLT_FOUND)
+	target_link_libraries(${extension_lib_name} ${LIBXSLT_LIBRARIES})
+endif()
+set_target_properties(${extension_lib_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_lib_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_lib_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files xml2)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..fc4f7bd
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,85 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(gen_errorcodes_depend
+	${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt
+	${PROJECT_SOURCE_DIR}/src/backend/utils/generate-errcodes.pl
+)
+set(gen_errorcodes_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/errcodes.h
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_errorcodes_depend}
+	OUTPUT ${gen_errorcodes_output}
+	COMMAND ${PERL_EXECUTABLE} generate-errcodes.pl errcodes.txt > ${gen_errorcodes_output}
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/backend/utils
+)
+
+add_custom_target(gen_errorcodes DEPENDS ${gen_errorcodes_output})
+
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${gen_errorcodes_output})
+
+set(PARSER_SCAN_FLEX_FLAGS, "-Cfe -p -p")
+bison_target(PARSER_GRAM
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.y
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+)
+flex_target(PARSER_SCAN
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.l
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+	${PARSER_SCAN_FLEX_FLAGS}
+)
+
+set_source_files_properties(${BISON_PARSER_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_PARSER_SCAN_OUTPUTS})
+
+add_custom_command(
+	MAIN_DEPENDENCY ${BISON_PARSER_GRAM_OUTPUTS}
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+	COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/src/backend/parser/gram.h ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+)
+
+add_custom_target(generate_parser_gram_h DEPENDS ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h)
+
+add_subdirectory(include)
+add_subdirectory(port)
+add_subdirectory(common)
+add_subdirectory(fe_utils)
+add_subdirectory(interfaces/libpq)
+add_subdirectory(interfaces/ecpg/pgtypeslib)
+add_subdirectory(interfaces/ecpg/ecpglib)
+add_subdirectory(interfaces/ecpg/compatlib)
+add_subdirectory(interfaces/ecpg/include)
+
+add_subdirectory(backend)
+add_subdirectory(timezone)
+add_subdirectory(test/regress)
+add_subdirectory(test/isolation)
+
+add_subdirectory(pl/plpgsql/src)
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(pl/plpython)
+endif()
+if(PERLLIBS_FOUND)
+	add_subdirectory(pl/plperl)
+endif()
+if(TCL_FOUND)
+	add_subdirectory(pl/tcl)
+endif()
+
+add_subdirectory(bin/initdb)
+add_subdirectory(bin/pg_archivecleanup)
+add_subdirectory(bin/pg_basebackup)
+add_subdirectory(bin/pg_config)
+add_subdirectory(bin/pg_controldata)
+add_subdirectory(bin/pg_ctl)
+add_subdirectory(bin/pg_dump)
+add_subdirectory(bin/pg_resetxlog)
+add_subdirectory(bin/pg_rewind)
+add_subdirectory(bin/pg_test_fsync)
+add_subdirectory(bin/pg_test_timing)
+add_subdirectory(bin/pg_upgrade)
+add_subdirectory(bin/pg_xlogdump)
+add_subdirectory(bin/pgbench)
+add_subdirectory(bin/psql)
+add_subdirectory(bin/scripts)
diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt
new file mode 100644
index 0000000..9633c6c
--- /dev/null
+++ b/src/backend/CMakeLists.txt
@@ -0,0 +1,1103 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+set(postgres_include_catalog "${PROJECT_SOURCE_DIR}/src/include/catalog")
+
+set(gen_fmgrtab_depend
+	utils/Gen_fmgrtab.pl
+	${CMAKE_CURRENT_SOURCE_DIR}/catalog/Catalog.pm
+	${postgres_include_catalog}/pg_proc.h
+)
+set(gen_fmgrtab_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/fmgroids.h
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/fmgrtab.c
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_fmgrtab_depend}
+	OUTPUT ${gen_fmgrtab_output}
+	COMMAND ${PERL_EXECUTABLE} -I${CMAKE_CURRENT_SOURCE_DIR}/catalog Gen_fmgrtab.pl ${postgres_include_catalog}/pg_proc.h
+	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/utils/fmgroids.h ${PROJECT_SOURCE_DIR}/src/include/utils/fmgroids.h
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
+)
+
+set(gen_probe_depend
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/Gen_dummy_probes.sed
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/probes.d
+)
+
+set(gen_probe_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/probes.h
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_probe_depend}
+	OUTPUT ${gen_probe_output}
+	COMMAND sed -f Gen_dummy_probes.sed probes.d >  ${gen_probe_output}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
+)
+
+flex_target(GUC_SCANNER utils/misc/guc-file.l  ${CMAKE_CURRENT_SOURCE_DIR}/utils/misc/guc-file.c)
+set_source_files_properties(utils/misc/guc.c PROPERTIES OBJECT_DEPENDS ${FLEX_GUC_SCANNER_OUTPUTS})
+
+if(WIN32 OR MINGW)
+	set(dynloader_SRCS port/dynloader/win32.c)
+	set(dynloader_H port/dynloader/win32.h)
+elseif(CYGWIN)
+	set(dynloader_SRCS port/dynloader/cygwin.c)
+	set(dynloader_H port/dynloader/cygwin.h)
+elseif(APPLE)
+	set(dynloader_SRCS port/dynloader/darwin.c)
+	set(dynloader_H port/dynloader/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(dynloader_SRCS port/dynloader/linux.c)
+	set(dynloader_H port/dynloader/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+	set(dynloader_SRCS port/dynloader/hpux.c)
+	set(dynloader_H port/dynloader/hpux.h)
+#TODO: FreeBSD, OpenBSD, NetBSD is equal loader
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+	set(dynloader_SRCS port/dynloader/freebsd.c)
+	set(dynloader_H port/dynloader/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+	set(dynloader_SRCS port/dynloader/openbsd.c)
+	set(dynloader_H port/dynloader/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+	set(dynloader_SRCS port/dynloader/netbsd.c)
+	set(dynloader_H port/dynloader/netbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(dynloader_SRCS port/dynloader/solaris.c)
+	set(dynloader_H port/dynloader/solaris.h)
+else(WIN32 OR MINGW)
+	message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+add_custom_command(
+	MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${dynloader_H}"
+	OUTPUT "${PROJECT_SOURCE_DIR}/src/include/dynloader.h"
+	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${dynloader_H} ${PROJECT_SOURCE_DIR}/src/include/dynloader.h
+)
+
+#Need for bin/pg_xlogdump
+set(access_rmgrdesc_SRC
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/brindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/clogdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/committsdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/dbasedesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/gindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/gistdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/hashdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/heapdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/mxactdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/nbtdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/relmapdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/replorigindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/seqdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/smgrdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/spgdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/standbydesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/tblspcdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/xactdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/xlogdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/genericdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/logicalmsgdesc.c
+)
+
+set(rmgrdesc_SRC
+	${access_rmgrdesc_SRC}
+	PARENT_SCOPE
+)
+
+set(access_SRCS
+	${gen_fmgrtab_output}
+	${gen_probe_output}
+	${PROJECT_SOURCE_DIR}/src/include/dynloader.h
+	${access_rmgrdesc_SRC}
+
+	access/brin/brin.c
+	access/brin/brin_pageops.c
+	access/brin/brin_revmap.c
+	access/brin/brin_tuple.c
+	access/brin/brin_xlog.c
+	access/brin/brin_minmax.c
+	access/brin/brin_inclusion.c
+	access/brin/brin_validate.c
+
+	access/common/heaptuple.c
+	access/common/indextuple.c
+	access/common/printtup.c
+	access/common/reloptions.c
+	access/common/scankey.c
+	access/common/tupconvert.c
+	access/common/tupdesc.c
+
+	access/gin/ginutil.c
+	access/gin/gininsert.c
+	access/gin/ginxlog.c
+	access/gin/ginentrypage.c
+	access/gin/gindatapage.c
+	access/gin/ginbtree.c
+	access/gin/ginscan.c
+	access/gin/ginget.c
+	access/gin/ginvacuum.c
+	access/gin/ginarrayproc.c
+	access/gin/ginbulk.c
+	access/gin/ginfast.c
+	access/gin/ginpostinglist.c
+	access/gin/ginlogic.c
+	access/gin/ginvalidate.c
+
+	access/gist/gist.c
+	access/gist/gistutil.c
+	access/gist/gistxlog.c
+	access/gist/gistvacuum.c
+	access/gist/gistget.c
+	access/gist/gistscan.c
+	access/gist/gistproc.c
+	access/gist/gistsplit.c
+	access/gist/gistbuild.c
+	access/gist/gistbuildbuffers.c
+	access/gist/gistvalidate.c
+
+	access/hash/hash.c
+	access/hash/hashfunc.c
+	access/hash/hashinsert.c
+	access/hash/hashovfl.c
+	access/hash/hashpage.c
+	access/hash/hashscan.c
+	access/hash/hashsearch.c
+	access/hash/hashsort.c
+	access/hash/hashutil.c
+	access/hash/hashvalidate.c
+
+	access/heap/heapam.c
+	access/heap/hio.c
+	access/heap/pruneheap.c
+	access/heap/rewriteheap.c
+	access/heap/syncscan.c
+	access/heap/tuptoaster.c
+	access/heap/visibilitymap.c
+
+	access/index/genam.c
+	access/index/indexam.c
+	access/index/amapi.c
+	access/index/amvalidate.c
+
+	access/nbtree/nbtcompare.c
+	access/nbtree/nbtinsert.c
+	access/nbtree/nbtpage.c
+	access/nbtree/nbtree.c
+	access/nbtree/nbtsearch.c
+	access/nbtree/nbtutils.c
+	access/nbtree/nbtsort.c
+	access/nbtree/nbtxlog.c
+	access/nbtree/nbtvalidate.c
+
+	access/spgist/spgutils.c
+	access/spgist/spginsert.c
+	access/spgist/spgscan.c
+	access/spgist/spgvacuum.c
+	access/spgist/spgdoinsert.c
+	access/spgist/spgxlog.c
+	access/spgist/spgtextproc.c
+	access/spgist/spgquadtreeproc.c
+	access/spgist/spgkdtreeproc.c
+	access/spgist/spgvalidate.c
+
+	access/tablesample/bernoulli.c
+	access/tablesample/system.c
+	access/tablesample/tablesample.c
+
+	access/transam/clog.c
+	access/transam/commit_ts.c
+	access/transam/multixact.c
+	access/transam/generic_xlog.c
+	access/transam/parallel.c
+	access/transam/rmgr.c
+	access/transam/slru.c
+	access/transam/subtrans.c
+	access/transam/timeline.c
+	access/transam/transam.c
+	access/transam/twophase.c
+	access/transam/twophase_rmgr.c
+	access/transam/varsup.c
+	access/transam/xact.c
+	access/transam/xlog.c
+	access/transam/xlogarchive.c
+	access/transam/xlogfuncs.c
+	access/transam/xloginsert.c
+	access/transam/xlogreader.c
+	access/transam/xlogutils.c
+)
+
+bison_target(BOOTSTRAP_PARSER bootstrap/bootparse.y ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/bootparse.c)
+flex_target(BOOTSTRAP_SCANNER bootstrap/bootscanner.l  ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/bootscanner.c)
+add_flex_bison_dependency(BOOTSTRAP_SCANNER BOOTSTRAP_PARSER)
+
+set_source_files_properties(bootstrap/bootparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_BOOTSTRAP_SCANNER_OUTPUTS})
+
+set(bootstrap_SRCS
+	bootstrap/bootstrap.c
+	${BISON_BOOTSTRAP_PARSER_OUTPUTS}
+)
+
+set_source_files_properties(
+	${BISON_BOOTSTRAP_PARSER_OUTPUTS}
+	PROPERTIES GENERATED TRUE
+)
+
+set(POSTGRES_BKI_SRCS
+	${postgres_include_catalog}/pg_proc.h
+	${postgres_include_catalog}/pg_type.h
+	${postgres_include_catalog}/pg_attribute.h
+	${postgres_include_catalog}/pg_class.h
+	${postgres_include_catalog}/pg_attrdef.h
+	${postgres_include_catalog}/pg_constraint.h
+	${postgres_include_catalog}/pg_inherits.h
+	${postgres_include_catalog}/pg_index.h
+	${postgres_include_catalog}/pg_operator.h
+	${postgres_include_catalog}/pg_opfamily.h
+	${postgres_include_catalog}/pg_opclass.h
+	${postgres_include_catalog}/pg_am.h
+	${postgres_include_catalog}/pg_amop.h
+	${postgres_include_catalog}/pg_amproc.h
+	${postgres_include_catalog}/pg_language.h
+	${postgres_include_catalog}/pg_largeobject_metadata.h
+	${postgres_include_catalog}/pg_largeobject.h
+	${postgres_include_catalog}/pg_aggregate.h
+	${postgres_include_catalog}/pg_statistic.h
+	${postgres_include_catalog}/pg_rewrite.h
+	${postgres_include_catalog}/pg_trigger.h
+	${postgres_include_catalog}/pg_event_trigger.h
+	${postgres_include_catalog}/pg_description.h
+	${postgres_include_catalog}/pg_cast.h
+	${postgres_include_catalog}/pg_enum.h
+	${postgres_include_catalog}/pg_namespace.h
+	${postgres_include_catalog}/pg_conversion.h
+	${postgres_include_catalog}/pg_depend.h
+	${postgres_include_catalog}/pg_database.h
+	${postgres_include_catalog}/pg_db_role_setting.h
+	${postgres_include_catalog}/pg_tablespace.h
+	${postgres_include_catalog}/pg_pltemplate.h
+	${postgres_include_catalog}/pg_authid.h
+	${postgres_include_catalog}/pg_auth_members.h
+	${postgres_include_catalog}/pg_shdepend.h
+	${postgres_include_catalog}/pg_shdescription.h
+	${postgres_include_catalog}/pg_ts_config.h
+	${postgres_include_catalog}/pg_ts_config_map.h
+	${postgres_include_catalog}/pg_ts_dict.h
+	${postgres_include_catalog}/pg_ts_parser.h
+	${postgres_include_catalog}/pg_ts_template.h
+	${postgres_include_catalog}/pg_extension.h
+	${postgres_include_catalog}/pg_foreign_data_wrapper.h
+	${postgres_include_catalog}/pg_foreign_server.h
+	${postgres_include_catalog}/pg_user_mapping.h
+	${postgres_include_catalog}/pg_foreign_table.h
+	${postgres_include_catalog}/pg_policy.h
+	${postgres_include_catalog}/pg_replication_origin.h
+	${postgres_include_catalog}/pg_default_acl.h
+	${postgres_include_catalog}/pg_init_privs.h
+	${postgres_include_catalog}/pg_seclabel.h
+	${postgres_include_catalog}/pg_shseclabel.h
+	${postgres_include_catalog}/pg_collation.h
+	${postgres_include_catalog}/pg_range.h
+	${postgres_include_catalog}/pg_transform.h
+	${postgres_include_catalog}/toasting.h
+	${postgres_include_catalog}/indexing.h
+)
+
+set(catalog_SRCS
+	catalog/catalog.c
+	catalog/dependency.c
+	catalog/heap.c
+	catalog/index.c
+	catalog/indexing.c
+	catalog/namespace.c
+	catalog/aclchk.c
+	catalog/objectaccess.c
+	catalog/objectaddress.c
+	catalog/pg_aggregate.c
+	catalog/pg_collation.c
+	catalog/pg_constraint.c
+	catalog/pg_conversion.c
+	catalog/pg_depend.c
+	catalog/pg_enum.c
+	catalog/pg_inherits.c
+	catalog/pg_largeobject.c
+	catalog/pg_namespace.c
+	catalog/pg_operator.c
+	catalog/pg_proc.c
+	catalog/pg_range.c
+	catalog/pg_db_role_setting.c
+	catalog/pg_shdepend.c
+	catalog/pg_type.c
+	catalog/storage.c
+	catalog/toasting.c
+)
+
+set(catalog_include
+	"-I${PROJECT_SOURCE_DIR}/src/backend/catalog"
+	"-I${PROJECT_SOURCE_DIR}/src/include/catalog"
+)
+
+add_custom_command(
+	DEPENDS ${POSTGRES_BKI_SRCS}
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h
+	COMMAND ${PERL_EXECUTABLE} genbki.pl ${catalog_include} --set-version=${POSTGRES_MAJOR_VERSION} ${POSTGRES_BKI_SRCS}
+	COMMAND ${CMAKE_COMMAND} -E copy schemapg.h ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/catalog
+)
+
+set_source_files_properties(utils/cache/relcache.c
+	PROPERTIES OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h)
+
+set(commands_SRCS
+	commands/aggregatecmds.c
+	commands/alter.c
+	commands/analyze.c
+	commands/async.c
+	commands/amcmds.c
+	commands/cluster.c
+	commands/comment.c
+	commands/collationcmds.c
+	commands/constraint.c
+	commands/conversioncmds.c
+	commands/copy.c
+	commands/createas.c
+	commands/dbcommands.c
+	commands/define.c
+	commands/discard.c
+	commands/dropcmds.c
+	commands/event_trigger.c
+	commands/explain.c
+	commands/extension.c
+	commands/foreigncmds.c
+	commands/functioncmds.c
+	commands/indexcmds.c
+	commands/lockcmds.c
+	commands/matview.c
+	commands/operatorcmds.c
+	commands/opclasscmds.c
+	commands/policy.c
+	commands/portalcmds.c
+	commands/prepare.c
+	commands/proclang.c
+	commands/schemacmds.c
+	commands/seclabel.c
+	commands/sequence.c
+	commands/tablecmds.c
+	commands/tablespace.c
+	commands/trigger.c
+	commands/tsearchcmds.c
+	commands/typecmds.c
+	commands/user.c
+	commands/vacuum.c
+	commands/vacuumlazy.c
+	commands/variable.c
+	commands/view.c
+)
+
+set(executor_SRCS
+	executor/execAmi.c
+	executor/execCurrent.c
+	executor/execGrouping.c
+	executor/execIndexing.c
+	executor/execJunk.c
+	executor/execMain.c
+	executor/execProcnode.c
+	executor/execParallel.c
+	executor/execQual.c
+	executor/execScan.c
+	executor/execTuples.c
+	executor/execUtils.c
+	executor/functions.c
+	executor/instrument.c
+	executor/tqueue.c
+	executor/nodeAppend.c
+	executor/nodeAgg.c
+	executor/nodeBitmapAnd.c
+	executor/nodeBitmapOr.c
+	executor/nodeBitmapHeapscan.c
+	executor/nodeBitmapIndexscan.c
+	executor/nodeCustom.c
+	executor/nodeHash.c
+	executor/nodeHashjoin.c
+	executor/nodeIndexscan.c
+	executor/nodeIndexonlyscan.c
+	executor/nodeLimit.c
+	executor/nodeLockRows.c
+	executor/nodeMaterial.c
+	executor/nodeMergeAppend.c
+	executor/nodeMergejoin.c
+	executor/nodeModifyTable.c
+	executor/nodeNestloop.c
+	executor/nodeFunctionscan.c
+	executor/nodeRecursiveunion.c
+	executor/nodeResult.c
+	executor/nodeSamplescan.c
+	executor/nodeSeqscan.c
+	executor/nodeSetOp.c
+	executor/nodeSort.c
+	executor/nodeUnique.c
+	executor/nodeValuesscan.c
+	executor/nodeCtescan.c
+	executor/nodeWorktablescan.c
+	executor/nodeGroup.c
+	executor/nodeGather.c
+	executor/nodeSubplan.c
+	executor/nodeSubqueryscan.c
+	executor/nodeTidscan.c
+	executor/nodeForeignscan.c
+	executor/nodeWindowAgg.c
+	executor/tstoreReceiver.c
+	executor/spi.c
+)
+
+set(lib_SRCS
+	lib/binaryheap.c
+	lib/bipartite_match.c
+	lib/hyperloglog.c
+	lib/ilist.c
+	lib/pairingheap.c
+	lib/rbtree.c
+	lib/stringinfo.c
+)
+
+if(OPENSSL_FOUND)
+	set(libpq_ssl_SRCS libpq/be-secure-openssl.c)
+endif(OPENSSL_FOUND)
+
+set(libpq_SRCS
+	libpq/be-fsstubs.c
+	libpq/be-secure.c
+	libpq/auth.c
+	libpq/crypt.c
+	libpq/hba.c
+	libpq/pqcomm.c
+	libpq/pqformat.c
+	libpq/pqmq.c
+	libpq/pqsignal.c
+	libpq/ifaddr.c
+	${libpq_ssl_SRCS}
+)
+
+set(utils_SRCS
+	utils/error/assert.c
+	utils/error/elog.c
+	utils/cache/attoptcache.c
+	utils/cache/catcache.c
+	utils/cache/evtcache.c
+	utils/cache/inval.c
+	utils/cache/plancache.c
+	utils/cache/relcache.c
+	utils/cache/relmapper.c
+	utils/cache/relfilenodemap.c
+	utils/cache/spccache.c
+	utils/cache/syscache.c
+	utils/cache/lsyscache.c
+	utils/cache/typcache.c
+	utils/cache/ts_cache.c
+	utils/mmgr/aset.c
+	utils/mmgr/mcxt.c
+	utils/mmgr/portalmem.c
+	utils/adt/acl.c
+	utils/adt/arrayfuncs.c
+	utils/adt/array_expanded.c
+	utils/adt/array_selfuncs.c
+	utils/adt/array_typanalyze.c
+	utils/adt/array_userfuncs.c
+	utils/adt/arrayutils.c
+	utils/adt/ascii.c
+	utils/adt/bool.c
+	utils/adt/cash.c
+	utils/adt/char.c
+	utils/adt/date.c
+	utils/adt/datetime.c
+	utils/adt/datum.c
+	utils/adt/dbsize.c
+	utils/adt/domains.c
+	utils/adt/encode.c
+	utils/adt/enum.c
+	utils/adt/expandeddatum.c
+	utils/adt/float.c
+	utils/adt/format_type.c
+	utils/adt/formatting.c
+	utils/adt/genfile.c
+	utils/adt/geo_ops.c
+	utils/adt/geo_selfuncs.c
+	utils/adt/geo_spgist.c
+	utils/adt/inet_cidr_ntop.c
+	utils/adt/inet_net_pton.c
+	utils/adt/int.c
+	utils/adt/int8.c
+	utils/adt/json.c
+	utils/adt/jsonb.c
+	utils/adt/jsonb_gin.c
+	utils/adt/jsonb_op.c
+	utils/adt/jsonb_util.c
+	utils/adt/jsonfuncs.c
+	utils/adt/like.c
+	#utils/adt/like_match.c
+	utils/adt/lockfuncs.c
+	utils/adt/mac.c
+	utils/adt/misc.c
+	utils/adt/nabstime.c
+	utils/adt/name.c
+	utils/adt/network.c
+	utils/adt/network_gist.c
+	utils/adt/network_selfuncs.c
+	utils/adt/numeric.c
+	utils/adt/numutils.c
+	utils/adt/oid.c
+	utils/adt/oracle_compat.c
+	utils/adt/orderedsetaggs.c
+	utils/adt/pg_locale.c
+	utils/adt/pg_lsn.c
+	utils/adt/pg_upgrade_support.c
+	utils/adt/pgstatfuncs.c
+	utils/adt/pseudotypes.c
+	utils/adt/quote.c
+	utils/adt/rangetypes.c
+	utils/adt/rangetypes_gist.c
+	utils/adt/rangetypes_selfuncs.c
+	utils/adt/rangetypes_spgist.c
+	utils/adt/rangetypes_typanalyze.c
+	utils/adt/regexp.c
+	utils/adt/regproc.c
+	utils/adt/ri_triggers.c
+	utils/adt/rowtypes.c
+	utils/adt/ruleutils.c
+	utils/adt/selfuncs.c
+	utils/adt/tid.c
+	utils/adt/timestamp.c
+	utils/adt/trigfuncs.c
+	utils/adt/tsginidx.c
+	utils/adt/tsgistidx.c
+	utils/adt/tsquery.c
+	utils/adt/tsquery_cleanup.c
+	utils/adt/tsquery_gist.c
+	utils/adt/tsquery_op.c
+	utils/adt/tsquery_rewrite.c
+	utils/adt/tsquery_util.c
+	utils/adt/tsrank.c
+	utils/adt/tsvector.c
+	utils/adt/tsvector_op.c
+	utils/adt/tsvector_parser.c
+	utils/adt/txid.c
+	utils/adt/uuid.c
+	utils/adt/varbit.c
+	utils/adt/varchar.c
+	utils/adt/varlena.c
+	utils/adt/amutils.c
+	utils/adt/version.c
+	utils/adt/windowfuncs.c
+	utils/adt/xid.c
+	utils/adt/xml.c
+	utils/adt/network_spgist.c
+	utils/fmgr/dfmgr.c
+	utils/fmgr/fmgr.c
+	utils/fmgr/funcapi.c
+	utils/hash/dynahash.c
+	utils/hash/hashfn.c
+	utils/hash/pg_crc.c
+	utils/init/globals.c
+	utils/init/miscinit.c
+	utils/init/postinit.c
+	utils/resowner/resowner.c
+	utils/sort/logtape.c
+	utils/sort/sortsupport.c
+	utils/sort/tuplesort.c
+	utils/sort/tuplestore.c
+	utils/time/combocid.c
+	utils/time/tqual.c
+	utils/time/snapmgr.c
+	utils/misc/guc.c
+	utils/misc/help_config.c
+	utils/misc/pg_rusage.c
+	utils/misc/pg_controldata.c
+	utils/misc/pg_config.c
+	utils/misc/ps_status.c
+	utils/misc/rls.c
+	utils/misc/sampling.c
+	utils/misc/superuser.c
+	utils/misc/timeout.c
+	utils/misc/tzparser.c
+	utils/mb/encnames.c
+	utils/mb/conv.c
+	utils/mb/mbutils.c
+	utils/mb/wchar.c
+	utils/mb/wstrcmp.c
+	utils/mb/wstrncmp.c
+)
+
+set(nodes_SRCS
+	nodes/nodeFuncs.c
+	nodes/nodes.c
+	nodes/list.c
+	nodes/bitmapset.c
+	nodes/tidbitmap.c
+	nodes/copyfuncs.c
+	nodes/equalfuncs.c
+	nodes/makefuncs.c
+	nodes/outfuncs.c
+	nodes/readfuncs.c
+	nodes/print.c
+	nodes/read.c
+	nodes/params.c
+	nodes/value.c
+	nodes/extensible.c
+)
+
+set(optimizer_SRCS
+	optimizer/geqo/geqo_copy.c
+	optimizer/geqo/geqo_eval.c
+	optimizer/geqo/geqo_main.c
+	optimizer/geqo/geqo_misc.c
+	optimizer/geqo/geqo_mutation.c
+	optimizer/geqo/geqo_pool.c
+	optimizer/geqo/geqo_random.c
+	optimizer/geqo/geqo_recombination.c
+	optimizer/geqo/geqo_selection.c
+	optimizer/geqo/geqo_erx.c
+	optimizer/geqo/geqo_pmx.c
+	optimizer/geqo/geqo_cx.c
+	optimizer/geqo/geqo_px.c
+	optimizer/geqo/geqo_ox1.c
+	optimizer/geqo/geqo_ox2.c
+	optimizer/path/allpaths.c
+	optimizer/path/clausesel.c
+	optimizer/path/costsize.c
+	optimizer/path/equivclass.c
+	optimizer/path/indxpath.c
+	optimizer/path/joinpath.c
+	optimizer/path/joinrels.c
+	optimizer/path/pathkeys.c
+	optimizer/path/tidpath.c
+	optimizer/plan/analyzejoins.c
+	optimizer/plan/createplan.c
+	optimizer/plan/initsplan.c
+	optimizer/plan/planagg.c
+	optimizer/plan/planmain.c
+	optimizer/plan/planner.c
+	optimizer/plan/setrefs.c
+	optimizer/plan/subselect.c
+	optimizer/prep/prepjointree.c
+	optimizer/prep/prepqual.c
+	optimizer/prep/prepsecurity.c
+	optimizer/prep/preptlist.c
+	optimizer/prep/prepunion.c
+	optimizer/util/clauses.c
+	optimizer/util/joininfo.c
+	optimizer/util/orclauses.c
+	optimizer/util/pathnode.c
+	optimizer/util/placeholder.c
+	optimizer/util/plancat.c
+	optimizer/util/predtest.c
+	optimizer/util/relnode.c
+	optimizer/util/restrictinfo.c
+	optimizer/util/tlist.c
+	optimizer/util/var.c
+)
+
+set(rewrite_SRCS
+	rewrite/rewriteRemove.c
+	rewrite/rewriteDefine.c
+	rewrite/rewriteHandler.c
+	rewrite/rewriteManip.c
+	rewrite/rewriteSupport.c
+	rewrite/rowsecurity.c
+)
+
+set(parser_SRCS
+	parser/analyze.c
+	#parser/gram.c
+	parser/parser.c
+	parser/parse_agg.c
+	parser/parse_clause.c
+	parser/parse_coerce.c
+	parser/parse_collate.c
+	parser/parse_cte.c
+	parser/parse_expr.c
+	parser/parse_func.c
+	parser/parse_node.c
+	parser/parse_oper.c
+	parser/parse_param.c
+	parser/parse_relation.c
+	parser/parse_target.c
+	parser/parse_type.c
+	parser/parse_utilcmd.c
+	parser/scansup.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+)
+
+set_source_files_properties(
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+	PROPERTIES GENERATED TRUE
+)
+
+set(tcop_SRCS
+	tcop/dest.c
+	tcop/fastpath.c
+	tcop/postgres.c
+	tcop/pquery.c
+	tcop/utility.c
+)
+
+set(tsearch_SRCS
+	tsearch/ts_locale.c
+	tsearch/ts_parse.c
+	tsearch/wparser.c
+	tsearch/wparser_def.c
+	tsearch/dict.c
+	tsearch/dict_simple.c
+	tsearch/dict_synonym.c
+	tsearch/dict_thesaurus.c
+	tsearch/dict_ispell.c
+	tsearch/regis.c
+	tsearch/spell.c
+	tsearch/to_tsany.c
+	tsearch/ts_selfuncs.c
+	tsearch/ts_typanalyze.c
+	tsearch/ts_utils.c
+)
+
+install(FILES
+			tsearch/dicts/ispell_sample.dict
+			tsearch/dicts/ispell_sample.affix
+			tsearch/dicts/hunspell_sample.affix
+			tsearch/dicts/hunspell_sample_long.affix
+			tsearch/dicts/hunspell_sample_long.dict
+			tsearch/dicts/hunspell_sample_num.affix
+			tsearch/dicts/hunspell_sample_num.dict
+			tsearch/dicts/synonym_sample.syn
+			tsearch/dicts/thesaurus_sample.ths
+		DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regex_SRCS
+	regex/regcomp.c
+	regex/regerror.c
+	regex/regexec.c
+	regex/regfree.c
+	regex/regprefix.c
+	regex/regexport.c
+)
+
+set(postmaster_SRCS
+	postmaster/autovacuum.c
+	postmaster/bgworker.c
+	postmaster/bgwriter.c
+	postmaster/checkpointer.c
+	postmaster/fork_process.c
+	postmaster/pgarch.c
+	postmaster/pgstat.c
+	postmaster/postmaster.c
+	postmaster/startup.c
+	postmaster/syslogger.c
+	postmaster/walwriter.c
+)
+
+if(WIN32 OR CYGWIN OR MINGW)
+	set(backend_port_win32_SRC
+		port/win32/timer.c
+		port/win32/socket.c
+		port/win32/signal.c
+		# I hope it is not necessary for modern MinGW
+		#port/win32/mingwcompat.c
+		port/win32/crashdump.c
+	)
+	if(NAVE_MINIDUMP_TYPE)
+		set(backend_port_win32_SRC
+			${backend_port_win32_SRC}
+			port/win32/crashdump.c
+		)
+	endif(NAVE_MINIDUMP_TYPE)
+endif()
+
+set(gen_lwlocknames_depend
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/generate-lwlocknames.pl
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.txt
+)
+
+set(gen_lwlocknames_output
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.c
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.h
+	${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+)
+
+
+add_custom_command(
+	OUTPUT ${gen_lwlocknames_output}
+	MAIN_DEPENDENCY ${gen_lwlocknames_depend}
+	COMMAND ${PERL_EXECUTABLE} generate-lwlocknames.pl lwlocknames.txt
+	COMMAND ${CMAKE_COMMAND} -E copy lwlocknames.h ${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr
+)
+
+set(backend_port_SRCS
+	port/atomics.c
+	port/tas/${TAS}
+	${backend_port_win32_SRC}
+	${backend_port_darwin_SRC}
+	${dynloader_SRCS}
+	${SEMA_IMPLEMENTATION}
+	${SHMEM_IMPLEMENTATION}
+)
+
+
+set(storage_SRCS
+	${gen_lwlocknames_output}
+	storage/buffer/buf_table.c
+	storage/buffer/buf_init.c
+	storage/buffer/bufmgr.c
+	storage/buffer/freelist.c
+	storage/buffer/localbuf.c
+	storage/file/fd.c
+	storage/file/buffile.c
+	storage/file/copydir.c
+	storage/file/reinit.c
+	storage/freespace/freespace.c
+	storage/freespace/fsmpage.c
+	storage/freespace/indexfsm.c
+	storage/ipc/dsm_impl.c
+	storage/ipc/dsm.c
+	storage/ipc/ipc.c
+	storage/ipc/ipci.c
+	storage/ipc/pmsignal.c
+	storage/ipc/procarray.c
+	storage/ipc/procsignal.c
+	storage/ipc/shmem.c
+	storage/ipc/shmqueue.c
+	storage/ipc/shm_mq.c
+	storage/ipc/shm_toc.c
+	storage/ipc/sinval.c
+	storage/ipc/sinvaladt.c
+	storage/ipc/standby.c
+	storage/ipc/latch.c
+	storage/large_object/inv_api.c
+	storage/lmgr/lmgr.c # Need some for check s_lock
+	storage/lmgr/lock.c
+	storage/lmgr/proc.c
+	storage/lmgr/deadlock.c
+	storage/lmgr/lwlock.c
+	storage/lmgr/spin.c
+	storage/lmgr/s_lock.c
+	storage/lmgr/predicate.c
+	storage/page/bufpage.c
+	storage/page/checksum.c
+	storage/page/itemptr.c
+	storage/smgr/md.c
+	storage/smgr/smgr.c
+	storage/smgr/smgrtype.c
+)
+
+if(NOT MSVC)
+	set_source_files_properties(storage/page/checksum.c
+		PROPERTIES COMPILE_FLAGS ${CFLAGS_VECTOR})
+endif()
+bison_target(REPL_GRAM
+	replication/repl_gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/repl_gram.c
+)
+flex_target(REPL_SCAN
+	replication/repl_scanner.l
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/repl_scanner.c
+)
+set_source_files_properties(${BISON_REPL_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_REPL_SCAN_OUTPUTS})
+
+bison_target(SYNC_GRAM
+	replication/syncrep_gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/syncrep_gram.c
+)
+flex_target(SYNC_SCAN
+	replication/syncrep_scanner.l
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/syncrep_scanner.c
+)
+set_source_files_properties(${BISON_SYNC_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_SYNC_SCAN_OUTPUTS})
+
+
+set(replication_SRCS
+	replication/walsender.c
+	replication/walreceiverfuncs.c
+	replication/walreceiver.c
+	replication/basebackup.c
+	replication/slot.c
+	replication/slotfuncs.c
+	replication/syncrep.c
+	replication/logical/decode.c
+	replication/logical/logical.c
+	replication/logical/logicalfuncs.c
+	replication/logical/reorderbuffer.c
+	replication/logical/origin.c
+	replication/logical/snapbuild.c
+	replication/logical/message.c
+	${BISON_REPL_GRAM_OUTPUTS}
+	${BISON_SYNC_GRAM_OUTPUTS}
+)
+
+set(timezone_SRCS
+	${PROJECT_SOURCE_DIR}/src/timezone/localtime.c
+	${PROJECT_SOURCE_DIR}/src/timezone/strftime.c
+	${PROJECT_SOURCE_DIR}/src/timezone/pgtz.c
+)
+
+add_custom_command(
+	OUTPUT "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c"
+	#MAIN_DEPENDENCY gen_qsort_tuple.pl
+	COMMAND ${PERL_EXECUTABLE} "gen_qsort_tuple.pl" > "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils/sort
+)
+
+set_source_files_properties(utils/sort/tuplesort.c
+	PROPERTIES OBJECT_DEPENDS "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c")
+
+set(postgres_SRCS
+	${storage_SRCS}
+	${access_SRCS}
+	${bootstrap_SRCS}
+	${commands_SRCS}
+	${catalog_SRCS}
+	${executor_SRCS}
+	foreign/foreign.c
+	${utils_SRCS}
+	${lib_SRCS}
+	${libpq_SRCS}
+	${nodes_SRCS}
+	${optimizer_SRCS}
+	${rewrite_SRCS}
+	${parser_SRCS}
+	${tcop_SRCS}
+	${tsearch_SRCS}
+	${regex_SRCS}
+	${postmaster_SRCS}
+	${backend_port_SRCS}
+	${replication_SRCS}
+	${timezone_SRCS}
+	main/main.c
+)
+
+if(OPENSSL_FOUND)
+	include_directories(BEFORE	${OPENSSL_INCLUDE_DIR})
+endif()
+if(LIBXML2_FOUND)
+	include_directories(BEFORE	${LIBXML2_INCLUDE_DIR})
+endif()
+#include_directories(BEFORE
+#	${OPENSSL_INCLUDE_DIR}
+#	${LIBXML2_INCLUDE_DIR}
+#)
+
+if(MSVC)
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:${WIN32_STACK_RLIMIT}")
+endif()
+
+if(MINGW OR CYGWIN)
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,${WIN32_STACK_RLIMIT} -Wl,--export-all-symbols")
+endif()
+
+add_executable(postgres
+	${postgres_SRCS}
+)
+
+target_link_libraries(postgres
+	pgcommon_srv
+	port_srv
+	pq
+	${READLINE_LIBRARY}
+	${CMAKE_THREAD_LIBS_INIT}
+	${DL_LIBRARIES}
+	${LIB_M}
+	${GSS_LIBS}
+)
+
+if(OPENSSL_FOUND)
+	target_link_libraries(postgres ${OPENSSL_LIBRARIES})
+endif()
+
+if(LIBXML2_FOUND)
+	target_link_libraries(postgres ${LIBXML2_LIBRARIES})
+endif()
+
+if(USE_PAM)
+	target_link_libraries(postgres ${PAM_LIB})
+endif()
+
+if(LDAP_FOUND)
+	target_link_libraries(postgres ${LBER_LIBRARIES})
+endif()
+
+add_dependencies(postgres gen_errorcodes generate_parser_gram_h)
+
+if(UNIX AND NOT APPLE)
+	target_link_libraries(postgres rt)
+endif()
+
+
+target_compile_definitions(postgres PRIVATE -DPG_KRB_SRVTAB="${PG_KRB_SRVTAB}")
+
+if(WIN32)
+	target_compile_definitions(postgres PRIVATE -DBUILDING_DLL -DEXEC_BACKEND)
+endif()
+
+if(MINGW)
+	set_target_properties(postgres PROPERTIES LINK_FLAGS -Wl,--out-implib=libpostgres.dll.a)
+endif()
+
+set_target_properties(postgres PROPERTIES ENABLE_EXPORTS 1)
+set_target_properties(postgres PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
+#Realy need?
+add_custom_target(duplicate_oids
+	COMMAND ${PERL_EXECUTABLE} ./duplicate_oids
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/include/catalog
+)
+
+add_library(pqwalreceiver MODULE
+	replication/libpqwalreceiver/libpqwalreceiver.c
+	${backend_port_win32_SRC}
+	${backend_port_darwin_SRC}
+)
+
+if(MSVC)
+	gen_def(pqwalreceiver)
+	gen_def(postgres)
+endif()
+
+if(WIN32)
+	target_link_libraries(pqwalreceiver postgres)
+endif()
+
+#Strange logic
+if(MINGW)
+	target_compile_definitions(pqwalreceiver PRIVATE -DBUILDING_DLL)
+endif()
+
+target_link_libraries(pqwalreceiver pq)
+
+install(TARGETS postgres pqwalreceiver
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(FILES
+	catalog/postgres.bki
+	catalog/postgres.description
+	catalog/postgres.shdescription
+	catalog/information_schema.sql
+	catalog/sql_features.txt
+	catalog/system_views.sql
+	libpq/pg_hba.conf.sample
+	libpq/pg_ident.conf.sample
+	utils/misc/postgresql.conf.sample
+DESTINATION ${PGSHAREDIR})
+
+add_subdirectory(utils/mb/conversion_procs)
+add_subdirectory(snowball)
+
+if(ENABLE_NLS)
+	MAKE_MO(postgres "de;es;fr;id;it;ja;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index d907e6b..1aad8f0 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -822,7 +822,7 @@ pg_GSS_recvauth(Port *port)
 			if (!kt_path ||
 				snprintf(kt_path, kt_len, "KRB5_KTNAME=%s",
 						 pg_krb_server_keyfile) != kt_len - 2 ||
-				putenv(kt_path) != 0)
+				pg_putenv_proxy(kt_path) != 0)
 			{
 				ereport(LOG,
 						(errcode(ERRCODE_OUT_OF_MEMORY),
diff --git a/src/backend/snowball/CMakeLists.txt b/src/backend/snowball/CMakeLists.txt
new file mode 100644
index 0000000..1299271
--- /dev/null
+++ b/src/backend/snowball/CMakeLists.txt
@@ -0,0 +1,126 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/snowball"
+	"${PROJECT_SOURCE_DIR}/src/include/snowball/libstemmer"
+)
+
+set(snow_languages
+	"danish\;danish"
+	"dutch\;dutch"
+	"english\;english"
+	"finnish\;finnish"
+	"french\;french"
+	"german\;german"
+	"hungarian\;hungarian"
+	"italian\;italian"
+	"norwegian\;norwegian"
+	"portuguese\;portuguese"
+	"romanian\;romanian"
+	"russian\;english"
+	"spanish\;spanish"
+	"swedish\;swedish"
+	"turkish\;turkish"
+)
+
+#Create snowball_create.sql
+file(STRINGS snowball.sql.in snowball_sql_tmpl NEWLINE_CONSUME)
+file(STRINGS snowball_func.sql.in snowball_func_sql_tmpl NEWLINE_CONSUME)
+
+file(WRITE "snowball_create.sql" ${snowball_func_sql_tmpl})
+
+foreach(pair_language ${snow_languages})
+	LIST(GET pair_language 0 lang)
+	LIST(GET pair_language 1 ascii_lang)
+	if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/stopwords/${lang}.stop")
+		set(stopwords ", StopWords=${lang}")
+	else()
+		set(stopwords "")
+	endif()
+	string(REPLACE "_LANGNAME_"
+		"${lang}" out_string
+		"${snowball_sql_tmpl}")
+	string(REPLACE "_DICTNAME_"
+		"${lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_CFGNAME_"
+		"${lang}" out_string
+		"${out_string}")
+	string(REPLACE "_ASCDICTNAME_"
+		"${ascii_lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_NONASCDICTNAME_"
+		"${lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_STOPWORDS_"
+		"${stopwords}" out_string
+		"${out_string}")
+	file(APPEND "snowball_create.sql" ${out_string})
+endforeach()
+
+
+set(snowball_SRCS
+	dict_snowball.c
+	libstemmer/api.c
+	libstemmer/utilities.c
+	libstemmer/stem_ISO_8859_1_danish.c
+	libstemmer/stem_ISO_8859_1_dutch.c
+	libstemmer/stem_ISO_8859_1_english.c
+	libstemmer/stem_ISO_8859_1_finnish.c
+	libstemmer/stem_ISO_8859_1_french.c
+	libstemmer/stem_ISO_8859_1_german.c
+	libstemmer/stem_ISO_8859_1_hungarian.c
+	libstemmer/stem_ISO_8859_1_italian.c
+	libstemmer/stem_ISO_8859_1_norwegian.c
+	libstemmer/stem_ISO_8859_1_porter.c
+	libstemmer/stem_ISO_8859_1_portuguese.c
+	libstemmer/stem_ISO_8859_1_spanish.c
+	libstemmer/stem_ISO_8859_1_swedish.c
+	libstemmer/stem_ISO_8859_2_romanian.c
+	libstemmer/stem_KOI8_R_russian.c
+	libstemmer/stem_UTF_8_danish.c
+	libstemmer/stem_UTF_8_dutch.c
+	libstemmer/stem_UTF_8_english.c
+	libstemmer/stem_UTF_8_finnish.c
+	libstemmer/stem_UTF_8_french.c
+	libstemmer/stem_UTF_8_german.c
+	libstemmer/stem_UTF_8_hungarian.c
+	libstemmer/stem_UTF_8_italian.c
+	libstemmer/stem_UTF_8_norwegian.c
+	libstemmer/stem_UTF_8_porter.c
+	libstemmer/stem_UTF_8_portuguese.c
+	libstemmer/stem_UTF_8_romanian.c
+	libstemmer/stem_UTF_8_russian.c
+	libstemmer/stem_UTF_8_spanish.c
+	libstemmer/stem_UTF_8_swedish.c
+	libstemmer/stem_UTF_8_turkish.c
+)
+
+add_library(dict_snowball MODULE ${snowball_SRCS})
+target_link_libraries(dict_snowball postgres)
+if (MSVC)
+	gen_def(dict_snowball)
+	target_link_libraries(dict_snowball pgcommon port)
+endif()
+set_target_properties(dict_snowball PROPERTIES PREFIX "")
+install(TARGETS dict_snowball
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(FILES snowball_create.sql
+		DESTINATION ${PGSHAREDIR})
+
+install(FILES
+		stopwords/danish.stop
+		stopwords/dutch.stop
+		stopwords/english.stop
+		stopwords/finnish.stop
+		stopwords/french.stop
+		stopwords/german.stop
+		stopwords/hungarian.stop
+		stopwords/italian.stop
+		stopwords/norwegian.stop
+		stopwords/portuguese.stop
+		stopwords/russian.stop
+		stopwords/spanish.stop
+		stopwords/swedish.stop
+		stopwords/turkish.stop
+		DESTINATION ${PGSHAREDIR}/tsearch_data)
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index a818023..5c26bf2 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -238,7 +238,7 @@ pg_perm_setlocale(int category, const char *locale)
 
 	snprintf(envbuf, LC_ENV_BUFSIZE - 1, "%s=%s", envvar, result);
 
-	if (putenv(envbuf))
+	if (pg_putenv_proxy(envbuf))
 		return NULL;
 
 	return result;
diff --git a/src/backend/utils/mb/conversion_procs/CMakeLists.txt b/src/backend/utils/mb/conversion_procs/CMakeLists.txt
new file mode 100644
index 0000000..008f58e
--- /dev/null
+++ b/src/backend/utils/mb/conversion_procs/CMakeLists.txt
@@ -0,0 +1,201 @@
+set(procs_list
+	ascii_and_mic
+	cyrillic_and_mic
+	euc_cn_and_mic
+	euc_jp_and_sjis
+	euc_kr_and_mic
+	euc_tw_and_big5
+	latin2_and_win1250
+	latin_and_mic
+	utf8_and_ascii
+	utf8_and_big5
+	utf8_and_cyrillic
+	utf8_and_euc_cn
+	utf8_and_euc_jp
+	utf8_and_euc_kr
+	utf8_and_euc_tw
+	utf8_and_gb18030
+	utf8_and_gbk
+	utf8_and_iso8859
+	utf8_and_iso8859_1
+	utf8_and_johab
+	utf8_and_sjis
+	utf8_and_win
+	utf8_and_uhc
+	utf8_and_euc2004
+	utf8_and_sjis2004
+	euc2004_sjis2004
+)
+
+# conversion_name source_encoding destination_encoding function object
+set(conversions_list
+	"ascii_to_mic\;SQL_ASCII\;MULE_INTERNAL\;ascii_to_mic\;ascii_and_mic"
+	"mic_to_ascii\;MULE_INTERNAL\;SQL_ASCII\;mic_to_ascii\;ascii_and_mic"
+	"koi8_r_to_mic\;KOI8R\;MULE_INTERNAL\;koi8r_to_mic\;cyrillic_and_mic"
+	"mic_to_koi8_r\;MULE_INTERNAL\;KOI8R\;mic_to_koi8r\;cyrillic_and_mic"
+	"iso_8859_5_to_mic\;ISO-8859-5\;MULE_INTERNAL\;iso_to_mic\;cyrillic_and_mic"
+	"mic_to_iso_8859_5\;MULE_INTERNAL\;ISO-8859-5\;mic_to_iso\;cyrillic_and_mic"
+	"windows_1251_to_mic\;WIN1251\;MULE_INTERNAL\;win1251_to_mic\;cyrillic_and_mic"
+	"mic_to_windows_1251\;MULE_INTERNAL\;WIN1251\;mic_to_win1251\;cyrillic_and_mic"
+	"windows_866_to_mic\;WIN866\;MULE_INTERNAL\;win866_to_mic\;cyrillic_and_mic"
+	"mic_to_windows_866\;MULE_INTERNAL\;WIN866\;mic_to_win866\;cyrillic_and_mic"
+	"koi8_r_to_windows_1251\;KOI8R\;WIN1251\;koi8r_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_koi8_r\;WIN1251\;KOI8R\;win1251_to_koi8r\;cyrillic_and_mic"
+	"koi8_r_to_windows_866\;KOI8R\;WIN866\;koi8r_to_win866\;cyrillic_and_mic"
+	"windows_866_to_koi8_r\;WIN866\;KOI8R\;win866_to_koi8r\;cyrillic_and_mic"
+	"windows_866_to_windows_1251\;WIN866\;WIN1251\;win866_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_windows_866\;WIN1251\;WIN866\;win1251_to_win866\;cyrillic_and_mic"
+	"iso_8859_5_to_koi8_r\;ISO-8859-5\;KOI8R\;iso_to_koi8r\;cyrillic_and_mic"
+	"koi8_r_to_iso_8859_5\;KOI8R\;ISO-8859-5\;koi8r_to_iso\;cyrillic_and_mic"
+	"iso_8859_5_to_windows_1251\;ISO-8859-5\;WIN1251\;iso_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_iso_8859_5\;WIN1251\;ISO-8859-5\;win1251_to_iso\;cyrillic_and_mic"
+	"iso_8859_5_to_windows_866\;ISO-8859-5\;WIN866\;iso_to_win866\;cyrillic_and_mic"
+	"windows_866_to_iso_8859_5\;WIN866\;ISO-8859-5\;win866_to_iso\;cyrillic_and_mic"
+	"euc_cn_to_mic\;EUC_CN\;MULE_INTERNAL\;euc_cn_to_mic\;euc_cn_and_mic"
+	"mic_to_euc_cn\;MULE_INTERNAL\;EUC_CN\;mic_to_euc_cn\;euc_cn_and_mic"
+	"euc_jp_to_sjis\;EUC_JP\;SJIS\;euc_jp_to_sjis\;euc_jp_and_sjis"
+	"sjis_to_euc_jp\;SJIS\;EUC_JP\;sjis_to_euc_jp\;euc_jp_and_sjis"
+	"euc_jp_to_mic\;EUC_JP\;MULE_INTERNAL\;euc_jp_to_mic\;euc_jp_and_sjis"
+	"sjis_to_mic\;SJIS\;MULE_INTERNAL\;sjis_to_mic\;euc_jp_and_sjis"
+	"mic_to_euc_jp\;MULE_INTERNAL\;EUC_JP\;mic_to_euc_jp\;euc_jp_and_sjis"
+	"mic_to_sjis\;MULE_INTERNAL\;SJIS\;mic_to_sjis\;euc_jp_and_sjis"
+	"euc_kr_to_mic\;EUC_KR\;MULE_INTERNAL\;euc_kr_to_mic\;euc_kr_and_mic"
+	"mic_to_euc_kr\;MULE_INTERNAL\;EUC_KR\;mic_to_euc_kr\;euc_kr_and_mic"
+	"euc_tw_to_big5\;EUC_TW\;BIG5\;euc_tw_to_big5\;euc_tw_and_big5"
+	"big5_to_euc_tw\;BIG5\;EUC_TW\;big5_to_euc_tw\;euc_tw_and_big5"
+	"euc_tw_to_mic\;EUC_TW\;MULE_INTERNAL\;euc_tw_to_mic\;euc_tw_and_big5"
+	"big5_to_mic\;BIG5\;MULE_INTERNAL\;big5_to_mic\;euc_tw_and_big5"
+	"mic_to_euc_tw\;MULE_INTERNAL\;EUC_TW\;mic_to_euc_tw\;euc_tw_and_big5"
+	"mic_to_big5\;MULE_INTERNAL\;BIG5\;mic_to_big5\;euc_tw_and_big5"
+	"iso_8859_2_to_mic\;LATIN2\;MULE_INTERNAL\;latin2_to_mic\;latin2_and_win1250"
+	"mic_to_iso_8859_2\;MULE_INTERNAL\;LATIN2\;mic_to_latin2\;latin2_and_win1250"
+	"windows_1250_to_mic\;WIN1250\;MULE_INTERNAL\;win1250_to_mic\;latin2_and_win1250"
+	"mic_to_windows_1250\;MULE_INTERNAL\;WIN1250\;mic_to_win1250\;latin2_and_win1250"
+	"iso_8859_2_to_windows_1250\;LATIN2\;WIN1250\;latin2_to_win1250\;latin2_and_win1250"
+	"windows_1250_to_iso_8859_2\;WIN1250\;LATIN2\;win1250_to_latin2\;latin2_and_win1250"
+	"iso_8859_1_to_mic\;LATIN1\;MULE_INTERNAL\;latin1_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_1\;MULE_INTERNAL\;LATIN1\;mic_to_latin1\;latin_and_mic"
+	"iso_8859_3_to_mic\;LATIN3\;MULE_INTERNAL\;latin3_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_3\;MULE_INTERNAL\;LATIN3\;mic_to_latin3\;latin_and_mic"
+	"iso_8859_4_to_mic\;LATIN4\;MULE_INTERNAL\;latin4_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_4\;MULE_INTERNAL\;LATIN4\;mic_to_latin4\;latin_and_mic"
+	"ascii_to_utf8\;SQL_ASCII\;UTF8\;ascii_to_utf8\;utf8_and_ascii"
+	"utf8_to_ascii\;UTF8\;SQL_ASCII\;utf8_to_ascii\;utf8_and_ascii"
+	"big5_to_utf8\;BIG5\;UTF8\;big5_to_utf8\;utf8_and_big5"
+	"utf8_to_big5\;UTF8\;BIG5\;utf8_to_big5\;utf8_and_big5"
+	"utf8_to_koi8_r\;UTF8\;KOI8R\;utf8_to_koi8r\;utf8_and_cyrillic"
+	"koi8_r_to_utf8\;KOI8R\;UTF8\;koi8r_to_utf8\;utf8_and_cyrillic"
+	"utf8_to_koi8_u\;UTF8\;KOI8U\;utf8_to_koi8u\;utf8_and_cyrillic"
+	"koi8_u_to_utf8\;KOI8U\;UTF8\;koi8u_to_utf8\;utf8_and_cyrillic"
+	"utf8_to_windows_866\;UTF8\;WIN866\;utf8_to_win\;utf8_and_win"
+	"windows_866_to_utf8\;WIN866\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_874\;UTF8\;WIN874\;utf8_to_win\;utf8_and_win"
+	"windows_874_to_utf8\;WIN874\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1250\;UTF8\;WIN1250\;utf8_to_win\;utf8_and_win"
+	"windows_1250_to_utf8\;WIN1250\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1251\;UTF8\;WIN1251\;utf8_to_win\;utf8_and_win"
+	"windows_1251_to_utf8\;WIN1251\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1252\;UTF8\;WIN1252\;utf8_to_win\;utf8_and_win"
+	"windows_1252_to_utf8\;WIN1252\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1253\;UTF8\;WIN1253\;utf8_to_win\;utf8_and_win"
+	"windows_1253_to_utf8\;WIN1253\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1254\;UTF8\;WIN1254\;utf8_to_win\;utf8_and_win"
+	"windows_1254_to_utf8\;WIN1254\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1255\;UTF8\;WIN1255\;utf8_to_win\;utf8_and_win"
+	"windows_1255_to_utf8\;WIN1255\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1256\;UTF8\;WIN1256\;utf8_to_win\;utf8_and_win"
+	"windows_1256_to_utf8\;WIN1256\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1257\;UTF8\;WIN1257\;utf8_to_win\;utf8_and_win"
+	"windows_1257_to_utf8\;WIN1257\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1258\;UTF8\;WIN1258\;utf8_to_win\;utf8_and_win"
+	"windows_1258_to_utf8\;WIN1258\;UTF8\;win_to_utf8\;utf8_and_win"
+	"euc_cn_to_utf8\;EUC_CN\;UTF8\;euc_cn_to_utf8\;utf8_and_euc_cn"
+	"utf8_to_euc_cn\;UTF8\;EUC_CN\;utf8_to_euc_cn\;utf8_and_euc_cn"
+	"euc_jp_to_utf8\;EUC_JP\;UTF8\;euc_jp_to_utf8\;utf8_and_euc_jp"
+	"utf8_to_euc_jp\;UTF8\;EUC_JP\;utf8_to_euc_jp\;utf8_and_euc_jp"
+	"euc_kr_to_utf8\;EUC_KR\;UTF8\;euc_kr_to_utf8\;utf8_and_euc_kr"
+	"utf8_to_euc_kr\;UTF8\;EUC_KR\;utf8_to_euc_kr\;utf8_and_euc_kr"
+	"euc_tw_to_utf8\;EUC_TW\;UTF8\;euc_tw_to_utf8\;utf8_and_euc_tw"
+	"utf8_to_euc_tw\;UTF8\;EUC_TW\;utf8_to_euc_tw\;utf8_and_euc_tw"
+	"gb18030_to_utf8\;GB18030\;UTF8\;gb18030_to_utf8\;utf8_and_gb18030"
+	"utf8_to_gb18030\;UTF8\;GB18030\;utf8_to_gb18030\;utf8_and_gb18030"
+	"gbk_to_utf8\;GBK\;UTF8\;gbk_to_utf8\;utf8_and_gbk"
+	"utf8_to_gbk\;UTF8\;GBK\;utf8_to_gbk\;utf8_and_gbk"
+	"utf8_to_iso_8859_2\;UTF8\;LATIN2\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_2_to_utf8\;LATIN2\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_3\;UTF8\;LATIN3\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_3_to_utf8\;LATIN3\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_4\;UTF8\;LATIN4\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_4_to_utf8\;LATIN4\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_9\;UTF8\;LATIN5\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_9_to_utf8\;LATIN5\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_10\;UTF8\;LATIN6\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_10_to_utf8\;LATIN6\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_13\;UTF8\;LATIN7\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_13_to_utf8\;LATIN7\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_14\;UTF8\;LATIN8\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_14_to_utf8\;LATIN8\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_15\;UTF8\;LATIN9\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_15_to_utf8\;LATIN9\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_16\;UTF8\;LATIN10\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_16_to_utf8\;LATIN10\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_5\;UTF8\;ISO-8859-5\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_5_to_utf8\;ISO-8859-5\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_6\;UTF8\;ISO-8859-6\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_6_to_utf8\;ISO-8859-6\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_7\;UTF8\;ISO-8859-7\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_7_to_utf8\;ISO-8859-7\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_8\;UTF8\;ISO-8859-8\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_8_to_utf8\;ISO-8859-8\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"iso_8859_1_to_utf8\;LATIN1\;UTF8\;iso8859_1_to_utf8\;utf8_and_iso8859_1"
+	"utf8_to_iso_8859_1\;UTF8\;LATIN1\;utf8_to_iso8859_1\;utf8_and_iso8859_1"
+	"johab_to_utf8\;JOHAB\;UTF8\;johab_to_utf8\;utf8_and_johab"
+	"utf8_to_johab\;UTF8\;JOHAB\;utf8_to_johab\;utf8_and_johab"
+	"sjis_to_utf8\;SJIS\;UTF8\;sjis_to_utf8\;utf8_and_sjis"
+	"utf8_to_sjis\;UTF8\;SJIS\;utf8_to_sjis\;utf8_and_sjis"
+	"uhc_to_utf8\;UHC\;UTF8\;uhc_to_utf8\;utf8_and_uhc"
+	"utf8_to_uhc\;UTF8\;UHC\;utf8_to_uhc\;utf8_and_uhc"
+	"euc_jis_2004_to_utf8\;EUC_JIS_2004\;UTF8\;euc_jis_2004_to_utf8\;utf8_and_euc2004"
+	"utf8_to_euc_jis_2004\;UTF8\;EUC_JIS_2004\;utf8_to_euc_jis_2004\;utf8_and_euc2004"
+	"shift_jis_2004_to_utf8\;SHIFT_JIS_2004\;UTF8\;shift_jis_2004_to_utf8\;utf8_and_sjis2004"
+	"utf8_to_shift_jis_2004\;UTF8\;SHIFT_JIS_2004\;utf8_to_shift_jis_2004\;utf8_and_sjis2004"
+	"euc_jis_2004_to_shift_jis_2004\;EUC_JIS_2004\;SHIFT_JIS_2004\;euc_jis_2004_to_shift_jis_2004\;euc2004_sjis2004"
+	"shift_jis_2004_to_euc_jis_2004\;SHIFT_JIS_2004\;EUC_JIS_2004\;shift_jis_2004_to_euc_jis_2004\;euc2004_sjis2004"
+)
+
+file(WRITE "conversion_create.sql" "")
+foreach(pair_conversion ${conversions_list})
+	LIST(GET pair_conversion 0 con_name)
+	LIST(GET pair_conversion 1 se)
+	LIST(GET pair_conversion 2 de)
+	LIST(GET pair_conversion 3 func)
+	LIST(GET pair_conversion 4 obj)
+	
+	file(APPEND "conversion_create.sql" "-- ${se} --> ${de}\n")
+	file(APPEND "conversion_create.sql" "CREATE OR REPLACE FUNCTION ${func} (INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) RETURNS VOID AS '$libdir/${obj}', '${func}' LANGUAGE C STRICT;\n")
+	file(APPEND "conversion_create.sql" "COMMENT ON FUNCTION ${func}(INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) IS 'internal conversion function for ${se} to ${de}';\n")
+	file(APPEND "conversion_create.sql" "DROP CONVERSION pg_catalog.${con_name};\n")
+	file(APPEND "conversion_create.sql" "CREATE DEFAULT CONVERSION pg_catalog.${con_name} FOR '${se}' TO '${de}' FROM ${func};\n")
+	file(APPEND "conversion_create.sql" "COMMENT ON CONVERSION pg_catalog.${con_name} IS 'conversion for ${se} to ${de}';\n")
+endforeach()
+
+foreach(loop_var IN ITEMS ${procs_list})
+	if(loop_var STREQUAL "euc_tw_and_big5")
+		add_library(${loop_var} MODULE ${loop_var}/${loop_var}.c ${loop_var}/big5.c)
+	else()
+		add_library(${loop_var} MODULE ${loop_var}/${loop_var}.c)
+	endif()
+	set_target_properties(${loop_var} PROPERTIES PREFIX "")
+	add_dependencies(${loop_var} gen_errorcodes)
+	target_link_libraries(${loop_var} postgres)
+	if(MSVC)
+		gen_def(${loop_var})
+	endif()
+	CMAKE_SET_TARGET_FOLDER(${loop_var} conversion_procs)
+	install(TARGETS ${loop_var}
+			RUNTIME DESTINATION ${PGBINDIR}
+			LIBRARY DESTINATION ${LIBDIR})
+endforeach(loop_var)
+
+install(FILES conversion_create.sql
+		DESTINATION ${PGSHAREDIR})
diff --git a/src/bin/initdb/CMakeLists.txt b/src/bin/initdb/CMakeLists.txt
new file mode 100644
index 0000000..52c3272
--- /dev/null
+++ b/src/bin/initdb/CMakeLists.txt
@@ -0,0 +1,35 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/timezone"
+)
+
+add_executable(initdb
+	initdb.c
+	findtimezone.c
+	"${PROJECT_SOURCE_DIR}/src/timezone/localtime.c"
+	"${PROJECT_SOURCE_DIR}/src/backend/utils/mb/encnames.c"
+)
+
+target_link_libraries(initdb
+	pgfeutils
+	pgcommon
+	port
+	pq
+	${GSS_LIBS}
+)
+
+if(UNIX AND NOT APPLE)
+	target_link_libraries(initdb rt)
+endif()
+
+target_compile_definitions(initdb PRIVATE -DFRONTEND)
+CMAKE_SET_TARGET_FOLDER(initdb bin)
+
+install(TARGETS initdb
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(initdb "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 3350e13..3ed89dc 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1496,10 +1496,10 @@ bootstrap_template1(void)
 	 * there doesn't seem to be any compelling reason to do that.
 	 */
 	snprintf(cmd, sizeof(cmd), "LC_COLLATE=%s", lc_collate);
-	putenv(pg_strdup(cmd));
+	pg_putenv_proxy(pg_strdup(cmd));
 
 	snprintf(cmd, sizeof(cmd), "LC_CTYPE=%s", lc_ctype);
-	putenv(pg_strdup(cmd));
+	pg_putenv_proxy(pg_strdup(cmd));
 
 	unsetenv("LC_ALL");
 
@@ -2757,7 +2757,7 @@ setup_pgdata(void)
 	 * have embedded spaces.
 	 */
 	pgdata_set_env = psprintf("PGDATA=%s", pg_data);
-	putenv(pgdata_set_env);
+	pg_putenv_proxy(pgdata_set_env);
 }
 
 
diff --git a/src/bin/pg_archivecleanup/CMakeLists.txt b/src/bin/pg_archivecleanup/CMakeLists.txt
new file mode 100644
index 0000000..7c79ac3
--- /dev/null
+++ b/src/bin/pg_archivecleanup/CMakeLists.txt
@@ -0,0 +1,20 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_archivecleanup pg_archivecleanup.c)
+
+target_link_libraries(pg_archivecleanup
+	port
+#	pq
+	pgcommon
+	${M_LIB}
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_archivecleanup bin)
+
+install(TARGETS pg_archivecleanup
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/pg_basebackup/CMakeLists.txt b/src/bin/pg_basebackup/CMakeLists.txt
new file mode 100644
index 0000000..a985e08
--- /dev/null
+++ b/src/bin/pg_basebackup/CMakeLists.txt
@@ -0,0 +1,51 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	${ZLIB_INCLUDE_DIRS}
+)
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+
+add_library(common_basebackup STATIC
+	receivelog.c
+	streamutil.c
+)
+
+target_link_libraries(common_basebackup
+	port
+	pq
+)
+
+set(basebackup_list 
+	pg_basebackup
+	pg_receivexlog
+	pg_recvlogical
+)
+
+foreach(loop_var IN ITEMS ${basebackup_list})
+	add_executable(${loop_var} ${loop_var}.c)
+
+	target_link_libraries(${loop_var}
+		pgfeutils
+		port
+		pq
+		pgcommon
+		${M_LIB}
+		common_basebackup
+	)
+	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
+	if(ZLIB_FOUND)
+		target_link_libraries(${loop_var} ${ZLIB_LIBRARIES})
+	endif()
+endforeach()
+
+install(TARGETS ${basebackup_list}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_basebackup "de;es;fr;it;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/bin/pg_config/CMakeLists.txt b/src/bin/pg_config/CMakeLists.txt
new file mode 100644
index 0000000..c9cb6e4
--- /dev/null
+++ b/src/bin/pg_config/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_config
+	pg_config.c
+)
+
+target_link_libraries(pg_config
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_config bin)
+
+install(TARGETS pg_config
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_config "cs;de;es;fr;it;ja;ko;nb;pl;pt_BR;ro;ru;sv;ta;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/bin/pg_controldata/CMakeLists.txt b/src/bin/pg_controldata/CMakeLists.txt
new file mode 100644
index 0000000..70a673c
--- /dev/null
+++ b/src/bin/pg_controldata/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_controldata
+	pg_controldata.c
+)
+
+target_link_libraries(pg_controldata
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_controldata bin)
+
+install(TARGETS pg_controldata
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_controldata "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_ctl/CMakeLists.txt b/src/bin/pg_ctl/CMakeLists.txt
new file mode 100644
index 0000000..8636d38
--- /dev/null
+++ b/src/bin/pg_ctl/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_ctl
+	pg_ctl.c
+)
+
+target_link_libraries(pg_ctl
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_ctl bin)
+
+install(TARGETS pg_ctl
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_ctl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index efc0729..7715081 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -902,7 +902,7 @@ do_start(void)
 
 		snprintf(env_var, sizeof(env_var), "PG_GRANDPARENT_PID=%d",
 				 (int) getppid());
-		putenv(env_var);
+		pg_putenv_proxy(env_var);
 	}
 #endif
 
@@ -2208,7 +2208,7 @@ main(int argc, char **argv)
 						pgdata_D = pg_strdup(optarg);
 						canonicalize_path(pgdata_D);
 						env_var = psprintf("PGDATA=%s", pgdata_D);
-						putenv(env_var);
+						pg_putenv_proxy(env_var);
 
 						/*
 						 * We could pass PGDATA just in an environment
diff --git a/src/bin/pg_dump/CMakeLists.txt b/src/bin/pg_dump/CMakeLists.txt
new file mode 100644
index 0000000..e0da845
--- /dev/null
+++ b/src/bin/pg_dump/CMakeLists.txt
@@ -0,0 +1,88 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	${ZLIB_INCLUDE_DIRS}
+)
+
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+add_library(libdump STATIC
+	pg_backup_archiver.c
+	pg_backup_db.c
+	pg_backup_custom.c
+	pg_backup_null.c
+	pg_backup_tar.c
+	pg_backup_directory.c
+	pg_backup_utils.c
+	parallel.c
+	compress_io.c
+	dumputils.c
+)
+
+add_executable(pg_dump
+	pg_dump.c
+	common.c
+	pg_dump_sort.c
+)
+
+target_link_libraries(pg_dump
+	libdump
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_dump bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_dump ${ZLIB_LIBRARIES})
+endif()
+
+add_executable(pg_restore
+	pg_restore.c
+)
+
+target_link_libraries(pg_restore
+	libdump
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_restore bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_restore ${ZLIB_LIBRARIES})
+endif()
+
+add_executable(pg_dumpall
+	pg_dumpall.c
+	dumputils.c
+)
+
+target_link_libraries(pg_dumpall
+	libdump
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_dumpall bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_dumpall ${ZLIB_LIBRARIES})
+endif()
+
+install(TARGETS pg_dump pg_restore pg_dumpall
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_dump "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/bin/pg_resetxlog/CMakeLists.txt b/src/bin/pg_resetxlog/CMakeLists.txt
new file mode 100644
index 0000000..e0d34ea
--- /dev/null
+++ b/src/bin/pg_resetxlog/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_resetxlog
+	pg_resetxlog.c
+)
+
+target_link_libraries(pg_resetxlog
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_resetxlog bin)
+
+install(TARGETS pg_resetxlog
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_resetxlog "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_rewind/CMakeLists.txt b/src/bin/pg_rewind/CMakeLists.txt
new file mode 100644
index 0000000..a81091f
--- /dev/null
+++ b/src/bin/pg_rewind/CMakeLists.txt
@@ -0,0 +1,37 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_rewind
+	pg_rewind.c
+	parsexlog.c
+	datapagemap.c
+	timeline.c
+	fetch.c
+	file_ops.c
+	copy_fetch.c
+	libpq_fetch.c
+	filemap.c
+	logging.c
+	${PROJECT_SOURCE_DIR}/src/backend/access/transam/xlogreader.c
+)
+
+target_link_libraries(pg_rewind
+	pgcommon
+	port
+	pq
+)
+
+target_compile_definitions(pg_rewind PRIVATE -DFRONTEND)
+
+CMAKE_SET_TARGET_FOLDER(pg_rewind bin)
+
+install(TARGETS pg_rewind
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_rewind "de;es;fr;it;ko;pl;ru;zh_CN")
+endif()
diff --git a/src/bin/pg_test_fsync/CMakeLists.txt b/src/bin/pg_test_fsync/CMakeLists.txt
new file mode 100644
index 0000000..4509380
--- /dev/null
+++ b/src/bin/pg_test_fsync/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_test_fsync
+	pg_test_fsync.c
+	
+)
+
+target_link_libraries(pg_test_fsync
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_test_fsync bin)
+
+install(TARGETS pg_test_fsync
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
diff --git a/src/bin/pg_test_timing/CMakeLists.txt b/src/bin/pg_test_timing/CMakeLists.txt
new file mode 100644
index 0000000..dce9232
--- /dev/null
+++ b/src/bin/pg_test_timing/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_test_timing
+	pg_test_timing.c
+	
+)
+
+target_link_libraries(pg_test_timing
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_test_timing bin)
+
+install(TARGETS pg_test_timing
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+
diff --git a/src/bin/pg_upgrade/CMakeLists.txt b/src/bin/pg_upgrade/CMakeLists.txt
new file mode 100644
index 0000000..cd9a902
--- /dev/null
+++ b/src/bin/pg_upgrade/CMakeLists.txt
@@ -0,0 +1,39 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_upgrade
+	check.c
+	controldata.c
+	dump.c
+	exec.c
+	file.c
+	function.c
+	info.c
+	option.c
+	parallel.c
+	pg_upgrade.c
+	relfilenode.c
+	server.c
+	tablespace.c
+	util.c
+	version.c 
+)
+
+target_link_libraries(pg_upgrade
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_upgrade bin)
+
+install(TARGETS pg_upgrade
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+
+
diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index 5b24ec0..3bf49fd 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -274,7 +274,7 @@ pg_putenv(const char *var, const char *val)
 		char	   *envstr;
 
 		envstr = psprintf("%s=%s", var, val);
-		putenv(envstr);
+		pg_putenv_proxy(envstr);
 
 		/*
 		 * Do not free envstr because it becomes part of the environment on
diff --git a/src/bin/pg_xlogdump/CMakeLists.txt b/src/bin/pg_xlogdump/CMakeLists.txt
new file mode 100644
index 0000000..f8b45a1
--- /dev/null
+++ b/src/bin/pg_xlogdump/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_xlogdump
+	${PROJECT_SOURCE_DIR}/src/backend/access/transam/xlogreader.c
+	pg_xlogdump.c
+	compat.c
+	rmgrdesc.c
+	${rmgrdesc_SRC}
+)
+
+target_link_libraries(pg_xlogdump
+	pgcommon
+	port
+	pq
+)
+
+target_compile_definitions(pg_xlogdump PRIVATE -DFRONTEND)
+
+CMAKE_SET_TARGET_FOLDER(pg_xlogdump bin)
+
+install(TARGETS pg_xlogdump
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/pgbench/CMakeLists.txt b/src/bin/pgbench/CMakeLists.txt
new file mode 100644
index 0000000..b10af2c
--- /dev/null
+++ b/src/bin/pgbench/CMakeLists.txt
@@ -0,0 +1,32 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+bison_target(PGBENCH_PARSER exprparse.y ${PROJECT_SOURCE_DIR}/src/bin/pgbench/exprparse.c)
+flex_target(PGBENCH_SCANNER exprscan.l  ${PROJECT_SOURCE_DIR}/src/bin/pgbench/exprscan.c)
+add_flex_bison_dependency(PGBENCH_SCANNER PGBENCH_PARSER)
+
+set_source_files_properties(exprparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_PGBENCH_SCANNER_OUTPUTS})
+
+add_executable(pgbench
+	pgbench.c
+	${BISON_PGBENCH_PARSER_OUTPUTS}
+)
+
+target_link_libraries(pgbench
+	pgfeutils
+	port
+	pq
+	pgcommon
+	${M_LIB}
+)
+
+add_dependencies(pgbench postgres)
+
+CMAKE_SET_TARGET_FOLDER(pgbench bin)
+
+install(TARGETS pgbench
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/psql/CMakeLists.txt b/src/bin/psql/CMakeLists.txt
new file mode 100644
index 0000000..ceccf23
--- /dev/null
+++ b/src/bin/psql/CMakeLists.txt
@@ -0,0 +1,72 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY create_help.pl
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/psql/sql_help.c ${PROJECT_SOURCE_DIR}/src/bin/psql/sql_help.h
+	COMMAND ${PERL_EXECUTABLE} create_help.pl ../../../doc/src/sgml/ref sql_help
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/psql
+)
+
+flex_target(SCANSLASH_SCAN
+	psqlscanslash.l
+	${CMAKE_CURRENT_SOURCE_DIR}/psqlscanslash.c
+)
+
+set(psql_SRCS
+	command.c
+	common.c
+	help.c
+	help.h
+	input.c
+	stringutils.c
+	mainloop.c
+	copy.c
+	copy.h
+	startup.c
+	prompt.c
+	variables.c
+	large_obj.c
+	describe.c
+	tab-complete.c
+	../pg_dump/dumputils.c
+	sql_help.c
+	crosstabview.c
+	${FLEX_SCANSLASH_SCAN_OUTPUTS}
+)
+
+add_executable(psql
+	${psql_SRCS}
+)
+
+target_link_libraries(psql
+	pgfeutils
+	pgcommon
+	port
+	pq
+	${READLINE_LIBRARY}
+	${CMAKE_THREAD_LIBS_INIT}
+)
+
+if(OPENSSL_FOUND)
+	target_link_libraries(psql ${OPENSSL_LIBRARIES})
+endif()
+if(NOT MSVC)
+	target_link_libraries(psql m)
+endif()
+
+add_dependencies(psql postgres)
+
+CMAKE_SET_TARGET_FOLDER(psql bin)
+
+install(TARGETS psql
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pslq "cs;de;es;fr;it;ja;pl;pt_BR;ru;zh_CN;zh_TW")
+endif()
+
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index a9a2fdb..a9e6dfa 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1350,7 +1350,7 @@ exec_command(const char *cmd,
 			char	   *newval;
 
 			newval = psprintf("%s=%s", envvar, envval);
-			putenv(newval);
+			pg_putenv_proxy(newval);
 			success = true;
 
 			/*
diff --git a/src/bin/scripts/CMakeLists.txt b/src/bin/scripts/CMakeLists.txt
new file mode 100644
index 0000000..c06548a
--- /dev/null
+++ b/src/bin/scripts/CMakeLists.txt
@@ -0,0 +1,89 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/bin/psql"
+)
+
+add_library(common_dump STATIC
+	common.c
+	${PROJECT_SOURCE_DIR}/src/bin/pg_dump/dumputils.c
+)
+
+add_library(common_print STATIC
+	common.c
+)
+
+set(common_libs
+	pgfeutils
+	pgcommon
+	port
+	pq
+	${LIB_M}
+)
+
+add_executable(createlang
+	createlang.c
+)
+
+target_link_libraries(createlang
+	common_print
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(createlang bin)
+
+add_executable(droplang
+	droplang.c
+)
+
+target_link_libraries(droplang
+	common_print
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(droplang bin)
+
+add_executable(pg_isready
+	pg_isready.c
+	common.c
+)
+
+target_link_libraries(pg_isready
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_isready bin)
+
+set(dump_modules_list 
+	createdb
+	createuser
+	dropdb
+	dropuser
+	clusterdb
+	vacuumdb
+	reindexdb
+)
+
+foreach(loop_var IN ITEMS ${dump_modules_list})
+	add_executable(${loop_var}
+		${loop_var}.c
+		${dump_parser_src}
+	)
+
+	target_link_libraries(${loop_var}
+		common_dump
+		${common_libs}
+	)
+
+	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
+endforeach()
+
+
+install(TARGETS ${dump_modules_list} createlang droplang pg_isready
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pgscripts "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
new file mode 100644
index 0000000..7a24165
--- /dev/null
+++ b/src/common/CMakeLists.txt
@@ -0,0 +1,48 @@
+set(pgcommon_srv_SRCS
+	exec.c
+	pg_lzcompress.c
+	pgfnames.c
+	psprintf.c
+	relpath.c
+	rmtree.c
+	string.c
+	username.c
+	wait_error.c
+	controldata_utils.c
+	config_info.c
+	keywords.c
+	md5.c
+	ip.c
+)
+
+set(pgcommon_SRCS
+	${pgcommon_srv_SRCS}
+	fe_memutils.c
+	restricted_token.c
+	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+)
+
+add_library(pgcommon_srv STATIC ${pgcommon_srv_SRCS})
+add_library(pgcommon STATIC ${pgcommon_SRCS})
+
+set_source_files_properties(
+	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+	PROPERTIES GENERATED TRUE
+)
+
+add_dependencies(pgcommon_srv generate_parser_gram_h)
+add_dependencies(pgcommon_srv gen_errorcodes)
+add_dependencies(pgcommon gen_errorcodes)
+
+target_compile_definitions(pgcommon PRIVATE -DFRONTEND)
+
+target_compile_definitions(pgcommon PRIVATE -DVAL_CPPFLAGS="${CMAKE_CXX_FLAGS}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_CFLAGS="${CMAKE_C_FLAGS} ${COMPILE_DEFINITIONS}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_CC="${CMAKE_C_COMPILER}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_LDFLAGS="${CMAKE_SHARED_LINKER_FLAGS}")
+
+# because port used in shared libraries
+set_property(TARGET pgcommon PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+
+install(TARGETS pgcommon
+		ARCHIVE DESTINATION ${LIBDIR})
diff --git a/src/common/exec.c b/src/common/exec.c
index a2de071..df2b675 100644
--- a/src/common/exec.c
+++ b/src/common/exec.c
@@ -586,7 +586,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
 		canonicalize_path(env_path + 12);
 		dup_path = strdup(env_path);
 		if (dup_path)
-			putenv(dup_path);
+			pg_putenv_proxy(dup_path);
 	}
 #endif
 
@@ -599,7 +599,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
 		canonicalize_path(env_path + 13);
 		dup_path = strdup(env_path);
 		if (dup_path)
-			putenv(dup_path);
+			pg_putenv_proxy(dup_path);
 	}
 }
 
diff --git a/src/common/restricted_token.c b/src/common/restricted_token.c
index d155b5e..2f3b429 100644
--- a/src/common/restricted_token.c
+++ b/src/common/restricted_token.c
@@ -163,7 +163,7 @@ get_restricted_token(const char *progname)
 
 		cmdline = pg_strdup(GetCommandLine());
 
-		putenv("PG_RESTRICT_EXEC=1");
+		pg_putenv_proxy("PG_RESTRICT_EXEC=1");
 
 		if ((restrictedToken = CreateRestrictedProcess(cmdline, &pi, progname)) == 0)
 		{
diff --git a/src/fe_utils/CMakeLists.txt b/src/fe_utils/CMakeLists.txt
new file mode 100644
index 0000000..6bf3fd3
--- /dev/null
+++ b/src/fe_utils/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/bin/psql"
+)
+
+set(psqlscan_flags, "-Cfe -p -p")
+
+flex_target(psqlscan
+	psqlscan.l
+	"${CMAKE_CURRENT_SOURCE_DIR}/psqlscan.c"
+	${psqlscan_flags}
+)
+
+add_library(pgfeutils STATIC
+	mbprint.c
+	print.c
+	psqlscan.c
+	simple_list.c
+	string_utils.c
+	${FLEX_psqlscan_OUTPUTS}
+)
diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt
new file mode 100644
index 0000000..c084822
--- /dev/null
+++ b/src/include/CMakeLists.txt
@@ -0,0 +1,78 @@
+set(INCLUDEDIR_INTERNAL ${PKGINCLUDEDIR}/internal)
+
+# These headers are needed by the public headers of the interfaces.
+install(FILES
+	postgres_ext.h
+	pg_config.h
+	pg_config_ext.h
+	pg_config_os.h
+	pg_config_manual.h
+	DESTINATION ${INCLUDEDIR})
+install(FILES
+	libpq/libpq-fs.h
+	DESTINATION ${INCLUDEDIR}/libpq)
+
+# These headers are needed by the not-so-public headers of the interfaces.
+install(FILES
+	c.h
+	port.h
+	postgres_fe.h
+	DESTINATION ${INCLUDEDIR_INTERNAL})
+install(FILES
+	libpq/pqcomm.h
+	DESTINATION ${INCLUDEDIR_INTERNAL}/libpq)
+
+# These headers are needed for server-side development
+set(SUBDIRS
+	access
+	bootstrap
+	catalog
+	commands
+	common
+	datatype
+	executor
+	foreign
+	lib
+	libpq
+	mb
+	nodes
+	optimizer
+	parser
+	postmaster
+	regex
+	replication
+	rewrite
+	storage
+	tcop
+	snowball
+	tsearch
+	utils
+	port
+	portability
+)
+
+install(FILES
+	c.h
+	dynloader.h
+	fmgr.h
+	funcapi.h
+	getaddrinfo.h
+	getopt_long.h
+	miscadmin.h
+	pg_config_ext.h
+	pg_config.h
+	pg_config_manual.h
+	pg_config_os.h
+	pg_getopt.h
+	pgstat.h
+	pgtar.h
+	pgtime.h
+	pg_trace.h
+	port.h
+	postgres_ext.h
+	postgres_fe.h
+	postgres.h
+	rusagestub.h
+	windowapi.h
+	DESTINATION ${INCLUDEDIRSERVER})
+install(DIRECTORY ${SUBDIRS} DESTINATION ${INCLUDEDIRSERVER})
diff --git a/src/include/c.h b/src/include/c.h
index 4ab3f80..1299e5c 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -317,8 +317,7 @@ typedef unsigned long long int uint64;
  *		There currently is only a limited support for the type. E.g. 128bit
  *		literals and snprintf are not supported; but math is.
  */
-#if defined(PG_INT128_TYPE)
-#define HAVE_INT128
+#if defined(HAVE_INT128)
 typedef PG_INT128_TYPE int128;
 typedef unsigned PG_INT128_TYPE uint128;
 #endif
diff --git a/src/include/pg_config_cmake.in b/src/include/pg_config_cmake.in
new file mode 100644
index 0000000..48685ae
--- /dev/null
+++ b/src/include/pg_config_cmake.in
@@ -0,0 +1,930 @@
+#ifndef AUTO_CONFIG_H
+#define AUTO_CONFIG_H
+
+/* Define to the type of arg 1 of 'accept' */
+#define ACCEPT_TYPE_ARG1 @ACCEPT_TYPE_ARG1@
+
+/* Define to the type of arg 2 of 'accept' */
+#define ACCEPT_TYPE_ARG2 @ACCEPT_TYPE_ARG2@
+
+/* Define to the type of arg 3 of 'accept' */
+#define ACCEPT_TYPE_ARG3 @ACCEPT_TYPE_ARG3@
+
+/* Define to the return type of 'accept' */
+#define ACCEPT_TYPE_RETURN @ACCEPT_TYPE_RETURN@
+
+/* The normal alignment of `double', in bytes. */
+#define ALIGNOF_DOUBLE @ALIGNOF_DOUBLE@
+
+/* The normal alignment of `int', in bytes. */
+#define ALIGNOF_INT @ALIGNOF_INT@
+
+/* The normal alignment of `long', in bytes. */
+#define ALIGNOF_LONG @ALIGNOF_LONG@
+
+/* The normal alignment of `long long int', in bytes. */
+#define ALIGNOF_LONG_LONG_INT @ALIGNOF_LONG_LONG_INT@
+
+/* The normal alignment of `short', in bytes. */
+#define ALIGNOF_SHORT @ALIGNOF_SHORT@
+
+/* Size of a disk block --- this also limits the size of a tuple. You can set
+   it bigger if you need bigger tuples (although TOAST should reduce the need
+   to have large tuples, since fields can be spread across multiple tuples).
+   BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is
+   currently 2^15 (32768). This is determined by the 15-bit widths of the
+   lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h).
+   Changing BLCKSZ requires an initdb. */
+#define BLCKSZ @BLCKSZ@
+
+/* Define to the default TCP port number on which the server listens and to
+   which clients will try to connect. This can be overridden at run-time, but
+   it's convenient if your clients have the right default compiled in.
+   (-DPGPORT=PORTNUM) */
+#define DEF_PGPORT @PGPORT@
+
+/* Define to the default TCP port number as a string constant. */
+#define DEF_PGPORT_STR "@PGPORT@"
+
+/* Define to build with GSSAPI support. */
+#cmakedefine ENABLE_GSS
+
+#cmakedefine ENABLE_NLS
+
+#cmakedefine ENABLE_THREAD_SAFETY 1
+
+/* Define to nothing if C supports flexible array members, and to 1 if it does
+   not. That way, with a declaration like `struct s { int n; double
+   d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99
+   compilers. When computing the size of such an object, don't use 'sizeof
+   (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)'
+   instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with
+   MSVC and with C++ compilers. */
+#define FLEXIBLE_ARRAY_MEMBER @FLEXIBLE_ARRAY_MEMBER@
+
+/* float4 values are passed by value if 'true', by reference if 'false' */
+#define FLOAT4PASSBYVAL @FLOAT4PASSBYVAL@
+
+/* float8, int8, and related values are passed by value if 'true', by
+   reference if 'false' */
+#define FLOAT8PASSBYVAL @FLOAT8PASSBYVAL@
+
+#cmakedefine GETTIMEOFDAY_1ARG
+
+#ifdef GETTIMEOFDAY_1ARG
+#	define gettimeofday(a,b) gettimeofday(a)
+#endif
+
+/* Define if you have the `append_history' function. */
+#cmakedefine HAVE_APPEND_HISTORY
+
+/* Define if you want to use atomics if available. */
+#cmakedefine HAVE_ATOMICS
+
+/* Define to 1 if you have the <atomic.h> header file. */
+#cmakedefine HAVE_ATOMIC_H 1
+
+/* Define if you have the `cbrt' function. */
+#cmakedefine HAVE_CBRT 1
+
+/* Define to 1 if you have the `class' function. */
+#cmakedefine HAVE_CLASS 1
+
+/* Define to 1 if you have the <crtdefs.h> header file. */
+#cmakedefine HAVE_CRTDEFS_H 1
+
+/* Define if you have the `crypt' function. */
+#cmakedefine HAVE_CRYPT
+
+/* Define if you have the <crypt.h> header file. */
+#cmakedefine HAVE_CRYPT_H
+
+/* Define to 1 if you have the declaration of `fdatasync' */
+#cmakedefine HAVE_DECL_FDATASYNC 1
+
+/* Define to 1 if you have the declaration of `F_FULLFSYNC' */
+#cmakedefine HAVE_DECL_F_FULLFSYNC 1
+
+/* Define to 1 if you have the declaration of `posix_fadvise' */
+#cmakedefine HAVE_DECL_POSIX_FADVISE 1
+
+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_SNPRINTF @HAVE_DECL_SNPRINTF@
+
+/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRLCAT @HAVE_DECL_STRLCAT@
+
+/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRLCPY @HAVE_DECL_STRLCPY@
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+   don't. */
+#cmakedefine HAVE_DECL_SYS_SIGLIST 1
+
+/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_VSNPRINTF @HAVE_DECL_VSNPRINTF@
+
+/* Define to 1 if you have the <dld.h> header file. */
+#cmakedefine HAVE_DLD_H
+
+/* Define to 1 if you have the `dlopen' function. */
+#cmakedefine HAVE_DLOPEN 1
+
+/* Define to 1 if you have the <editline/history.h> header file. */
+#cmakedefine HAVE_EDITLINE_HISTORY_H
+
+/* Define to 1 if you have the <editline/readline.h> header file. */
+#cmakedefine HAVE_EDITLINE_READLINE_H
+
+/* Define to 1 if you have the `fdatasync' function. */
+#cmakedefine HAVE_FDATASYNC 1
+
+/* Define to 1 if you have the `fls' function. */
+#cmakedefine HAVE_FLS
+
+/* Define to 1 if you have the `fpclass' function. */
+#cmakedefine HAVE_FPCLASS 1
+
+/* Define to 1 if you have the `fp_class' function. */
+#cmakedefine HAVE_FP_CLASS 1
+
+/* Define to 1 if you have the `fp_class_d' function. */
+#cmakedefine HAVE_FP_CLASS_D 1
+
+/* Define to 1 if you have the <fp_class.h> header file. */
+#cmakedefine HAVE_FP_CLASS_H 1
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#cmakedefine HAVE_FSEEKO 1
+
+/* Define to 1 if your compiler understands __func__. */
+#cmakedefine HAVE_FUNCNAME__FUNC
+
+/* Define to 1 if your compiler understands __FUNCTION__. */
+#cmakedefine HAVE_FUNCNAME__FUNCTION
+
+/* Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int). */
+#cmakedefine HAVE_GCC__ATOMIC_INT32_CAS 1
+
+/* Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).
+   */
+#cmakedefine HAVE_GCC__ATOMIC_INT64_CAS 1
+
+/* Define to 1 if you have __sync_lock_test_and_set(char *) and friends. */
+#cmakedefine HAVE_GCC__SYNC_CHAR_TAS 1
+
+/* Define to 1 if you have __sync_compare_and_swap(int *, int, int). */
+#cmakedefine HAVE_GCC__SYNC_INT32_CAS 1
+
+/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */
+#cmakedefine HAVE_GCC__SYNC_INT32_TAS 1
+
+/* Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64). */
+#cmakedefine HAVE_GCC__SYNC_INT64_CAS 1
+
+/* Define to 1 if you have the `getaddrinfo' function. */
+#cmakedefine HAVE_GETADDRINFO 1
+
+/* Define to 1 if you have the `gethostbyname_r' function. */
+#cmakedefine HAVE_GETHOSTBYNAME_R 1
+
+/* Define to 1 if you have the `getifaddrs' function. */
+#cmakedefine HAVE_GETIFADDRS 1
+
+/* Define to 1 if you have the `getopt' function. */
+#cmakedefine HAVE_GETOPT 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#cmakedefine HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
+#cmakedefine HAVE_GETOPT_LONG 1
+
+/* Define to 1 if you have the `getpeereid' function. */
+#cmakedefine HAVE_GETPEEREID 1
+
+/* Define to 1 if you have the `getpeerucred' function. */
+#cmakedefine HAVE_GETPEERUCRED 1
+
+/* Define to 1 if you have the `getpwuid_r' function. */
+#cmakedefine HAVE_GETPWUID_R 1
+
+/* Define to 1 if you have the `getrlimit' function. */
+#cmakedefine HAVE_GETRLIMIT 1
+
+/* Define to 1 if you have the `getrusage' function. */
+#cmakedefine HAVE_GETRUSAGE 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#cmakedefine HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+#cmakedefine HAVE_GSSAPI_GSSAPI_H 1
+
+/* Define to 1 if you have the <gssapi.h> header file. */
+#cmakedefine HAVE_GSSAPI_H 1
+
+/* Define to 1 if you have the <history.h> header file. */
+#cmakedefine HAVE_HISTORY_H 1
+
+/* Define to 1 if you have the `history_truncate_file' function. */
+#cmakedefine HAVE_HISTORY_TRUNCATE_FILE 1
+
+/* Define to 1 if you have the <ieeefp.h> header file. */
+#cmakedefine HAVE_IEEEFP_H @HAVE_IEEEFP_H@
+
+/* Define to 1 if you have the <ifaddrs.h> header file. */
+#cmakedefine HAVE_IFADDRS_H 1
+
+/* Define to 1 if you have the `inet_aton' function. */
+#cmakedefine HAVE_INET_ATON 1
+
+/* Define to 1 if the system has the type `int64'. */
+#cmakedefine HAVE_INT64 1
+
+/* Define to 1 if the system has the type `int8'. */
+#cmakedefine HAVE_INT8 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `intptr_t'. */
+/*#cmakedefine HAVE_INTPTR_T 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <inttypes.h> header file. */
+/*#cmakedefine HAVE_INTTYPES_H 1*/
+
+/* Define to 1 if you have the global variable 'int opterr'. */
+#cmakedefine HAVE_INT_OPTERR 1
+
+/* Define to 1 if you have the global variable 'int optreset'. */
+#cmakedefine HAVE_INT_OPTRESET 1
+
+/* Define to 1 if you have the global variable 'int timezone'. */
+#cmakedefine HAVE_INT_TIMEZONE 1
+
+/* Define to 1 if you have support for IPv6. */
+#cmakedefine HAVE_IPV6 1
+
+/* Define to 1 if you have isinf(). */
+#cmakedefine HAVE_ISINF 1
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#cmakedefine HAVE_LANGINFO_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <ldap.h> header file. */
+/*#cmakedefine HAVE_LDAP_H 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `crypto' library (-lcrypto). */
+/*#cmakedefine HAVE_LIBCRYPTO 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `ldap' library (-lldap). */
+/*#cmakedefine HAVE_LIBLDAP 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `ldap_r' library (-lldap_r). */
+/*#cmakedefine HAVE_LIBLDAP_R 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `m' library (-lm). */
+/*#cmakedefine HAVE_LIBM*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `pam' library (-lpam). */
+/*#cmakedefine HAVE_LIBPAM 1*/
+
+/* Define if you have a function readline library */
+#cmakedefine HAVE_LIBREADLINE 1
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `selinux' library (-lselinux). */
+/*#cmakedefine HAVE_LIBSELINUX 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `ssl' library (-lssl). */
+/*#cmakedefine HAVE_LIBSSL 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `wldap32' library (-lwldap32). */
+/*#cmakedefine HAVE_LIBWLDAP32 1*/
+
+/* Define to 1 if you have the `xml2' library (-lxml2). */
+#cmakedefine HAVE_LIBXML2 1
+
+/* Define to 1 if you have the `xslt' library (-lxslt). */
+#cmakedefine HAVE_LIBXSLT 1
+
+/* Define to 1 if you have the `z' library (-lz). */
+#cmakedefine HAVE_LIBZ 1
+
+/* Define to 1 if constants of type 'long long int' should have the suffix LL.
+   */
+#cmakedefine HAVE_LL_CONSTANTS 1
+
+/* Define to 1 if the system has the type `locale_t'. */
+#cmakedefine HAVE_LOCALE_T
+
+/* Define to 1 if `long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_INT_64 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if `long long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_LONG_INT_64 1
+
+/* Define to 1 if you have the <mbarrier.h> header file. */
+#cmakedefine HAVE_MBARRIER_H 1
+
+/* Define to 1 if you have the `mbstowcs_l' function. */
+#cmakedefine HAVE_MBSTOWCS_L 1
+
+/* Define to 1 if you have the `memmove' function. */
+#cmakedefine HAVE_MEMMOVE 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <memory.h> header file. */
+/*#cmakedefine HAVE_MEMORY_H 1*/
+
+/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
+#cmakedefine HAVE_MINIDUMP_TYPE 1
+
+/* Define to 1 if you have the `mkdtemp' function. */
+#cmakedefine HAVE_MKDTEMP 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <netinet/in.h> header file. */
+/*#cmakedefine HAVE_NETINET_IN_H 1*/
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#cmakedefine HAVE_NETINET_TCP_H 1
+
+/* Define to 1 if you have the <net/if.h> header file. */
+#cmakedefine HAVE_NET_IF_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <ossp/uuid.h> header file. */
+/*#cmakedefine HAVE_OSSP_UUID_H 1*/
+
+/* Define to 1 if you have the <pam/pam_appl.h> header file. */
+#cmakedefine HAVE_PAM_PAM_APPL_H 1
+
+/* Define to 1 if you have the `poll' function. */
+#cmakedefine HAVE_POLL 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+#cmakedefine HAVE_POLL_H 1
+
+/* Define to 1 if you have the `posix_fadvise' function. */
+#cmakedefine HAVE_POSIX_FADVISE 1
+
+/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */
+#cmakedefine HAVE_PPC_LWARX_MUTEX_HINT 1
+
+/* Define to 1 if you have the `pstat' function. */
+#cmakedefine HAVE_PSTAT 1
+
+/* Define to 1 if the PS_STRINGS thing exists. */
+#cmakedefine HAVE_PS_STRINGS 1
+
+/* TODO BUT DO NOT NEED:Define if you have POSIX threads libraries and header files. */
+/*#cmakedefine HAVE_PTHREAD 1*/
+
+/* Define to 1 if you have the `pthread_is_threaded_np' function. */
+#cmakedefine HAVE_PTHREAD_IS_THREADED_NP 1
+
+/* TODO BUT DO NOT NEED:Have PTHREAD_PRIO_INHERIT. */
+/*#cmakedefine HAVE_PTHREAD_PRIO_INHERIT 1*/
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#cmakedefine HAVE_PWD_H 1
+
+/* Define to 1 if you have the `random' function. */
+#cmakedefine HAVE_RANDOM 1
+
+/* Define to 1 if you have the <readline.h> header file. */
+#cmakedefine HAVE_READLINE_H 1
+
+/* Define to 1 if you have the <readline/history.h> header file. */
+#cmakedefine HAVE_READLINE_HISTORY_H 1
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#cmakedefine HAVE_READLINE_READLINE_H 1
+
+/* Define to 1 if you have the `readlink' function. */
+#cmakedefine HAVE_READLINK 1
+
+/* Define to 1 if you have the `rint' function. */
+#cmakedefine HAVE_RINT 1
+
+/* Define to 1 if you have the global variable
+   'rl_completion_append_character'. */
+#cmakedefine HAVE_RL_COMPLETION_APPEND_CHARACTER 1
+
+/* Define to 1 if you have the `rl_completion_matches' function. */
+#cmakedefine HAVE_RL_COMPLETION_MATCHES 1
+
+/* Define to 1 if you have the `rl_filename_completion_function' function. */
+#cmakedefine HAVE_RL_FILENAME_COMPLETION_FUNCTION 1
+
+/* Define to 1 if you have the `rl_reset_screen_size' function. */
+#cmakedefine HAVE_RL_RESET_SCREEN_SIZE 1
+
+/* Define to 1 if you have the <security/pam_appl.h> header file. */
+#cmakedefine HAVE_SECURITY_PAM_APPL_H 1
+
+/* Define to 1 if you have the `setproctitle' function. */
+#cmakedefine HAVE_SETPROCTITLE 1
+
+/* Define to 1 if you have the `setsid' function. */
+#cmakedefine HAVE_SETSID 1
+
+/* Define to 1 if you have the `shm_open' function. */
+#cmakedefine HAVE_SHM_OPEN 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `snprintf' function. */
+/*#cmakedefine HAVE_SNPRINTF 1*/
+
+/* Define to 1 if you have spinlocks. */
+#cmakedefine HAVE_SPINLOCKS 1
+
+/* Define to 1 if you have the `srandom' function. */
+#cmakedefine HAVE_SRANDOM 1
+
+/* Define to 1 if you have the `SSL_get_current_compression' function. */
+#cmakedefine HAVE_SSL_GET_CURRENT_COMPRESSION 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <stdlib.h> header file. */
+/*#cmakedefine HAVE_STDLIB_H 1*/
+
+/* Define to 1 if you have the `strerror' function. */
+#cmakedefine HAVE_STRERROR 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `strlcat' function. */
+/*#cmakedefine HAVE_STRLCAT 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `strlcpy' function. */
+/*#cmakedefine HAVE_STRLCPY 1*/
+
+/* Define to 1 if you have the `strtoll' function. */
+#cmakedefine HAVE_STRTOLL 1
+
+/* Define to 1 if you have the `strtoq' function. */
+#cmakedefine HAVE_STRTOQ 1
+
+/* Define to 1 if you have the `strtoull' function. */
+#cmakedefine HAVE_STRTOULL 1
+
+/* Define to 1 if you have the `strtouq' function. */
+#cmakedefine HAVE_STRTOUQ 1
+
+/* Define to 1 if the system has the type `struct addrinfo'. */
+#cmakedefine HAVE_STRUCT_ADDRINFO 1
+
+/* Define to 1 if the system has the type `struct cmsgcred'. */
+#cmakedefine HAVE_STRUCT_CMSGCRED 1
+
+/* Define to 1 if the system has the type `struct option'. */
+#cmakedefine HAVE_STRUCT_OPTION 1
+
+/* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
+
+/* Define to 1 if the system has the type `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE 1
+
+/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
+
+/* Define to 1 if `ss_len' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
+
+/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY 1
+
+/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#cmakedefine HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define to 1 if you have the `symlink' function. */
+#cmakedefine HAVE_SYMLINK 1
+
+/* Define to 1 if you have the `sync_file_range' function. */
+#cmakedefine HAVE_SYNC_FILE_RANGE 1
+
+/* Define to 1 if you have the syslog interface. */
+#cmakedefine HAVE_SYSLOG 1
+
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#cmakedefine HAVE_SYS_EPOLL_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/ipc.h> header file. */
+#cmakedefine HAVE_SYS_IPC_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#cmakedefine HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/pstat.h> header file. */
+#cmakedefine HAVE_SYS_PSTAT_H 1
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#cmakedefine HAVE_SYS_RESOURCE_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#cmakedefine HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/sem.h> header file. */
+#cmakedefine HAVE_SYS_SEM_H 1
+
+/* Define to 1 if you have the <sys/shm.h> header file. */
+#cmakedefine HAVE_SYS_SHM_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#cmakedefine HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+#cmakedefine HAVE_SYS_SOCKIO_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/tas.h> header file. */
+#cmakedefine HAVE_SYS_TAS_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#cmakedefine HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/ucred.h> header file. */
+#cmakedefine HAVE_SYS_UCRED_H 1
+
+/* Define to 1 if you have the <sys/un.h> header file. */
+#cmakedefine HAVE_SYS_UN_H 1
+
+/* Define to 1 if you have the <termios.h> header file. */
+#cmakedefine HAVE_TERMIOS_H 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#cmakedefine HAVE_TM_ZONE 1
+
+/* Define to 1 if you have the `towlower' function. */
+#cmakedefine HAVE_TOWLOWER 1
+
+/* Define to 1 if you have the external array `tzname'. */
+#cmakedefine HAVE_TZNAME 1
+
+/* Define to 1 if you have the <ucred.h> header file. */
+#cmakedefine HAVE_UCRED_H 1
+
+/* Define to 1 if the system has the type `uint64'. */
+#cmakedefine HAVE_UINT64 1
+
+/* Define to 1 if the system has the type `uint8'. */
+#cmakedefine HAVE_UINT8 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `uintptr_t'. */
+/*#cmakedefine HAVE_UINTPTR_T 1*/
+
+/* Define to 1 if the system has the type `union semun'. */
+#cmakedefine HAVE_UNION_SEMUN 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/* Define to 1 if you have unix sockets. */
+#cmakedefine HAVE_UNIX_SOCKETS 1
+
+/* Define to 1 if you have the `unsetenv' function. */
+#cmakedefine HAVE_UNSETENV 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `unsigned long long int'. */
+/*#cmakedefine HAVE_UNSIGNED_LONG_LONG_INT 1*/
+
+/* Define to 1 if you have the `utime' function. */
+#cmakedefine HAVE_UTIME 1
+
+/* Define to 1 if you have the `utimes' function. */
+#cmakedefine HAVE_UTIMES 1
+
+/* Define to 1 if you have the <utime.h> header file. */
+#cmakedefine HAVE_UTIME_H 1
+
+/* Define to 1 if you have BSD UUID support. */
+#cmakedefine HAVE_UUID_BSD 1
+
+/* Define to 1 if you have E2FS UUID support. */
+#cmakedefine HAVE_UUID_E2FS 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <uuid.h> header file. */
+/*#cmakedefine HAVE_UUID_H 1*/
+
+/* Define to 1 if you have OSSP UUID support. */
+#cmakedefine HAVE_UUID_OSSP 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <uuid/uuid.h> header file. */
+/*#cmakedefine HAVE_UUID_UUID_H 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `vsnprintf' function. */
+/*#cmakedefine HAVE_VSNPRINTF 1*/
+
+/* Define to 1 if you have the <wchar.h> header file. */
+#cmakedefine HAVE_WCHAR_H 1
+
+/* Define to 1 if you have the `wcstombs' function. */
+#cmakedefine HAVE_WCSTOMBS 1
+
+/* Define to 1 if you have the `wcstombs_l' function. */
+#cmakedefine HAVE_WCSTOMBS_L 1
+
+/* Define to 1 if you have the <wctype.h> header file. */
+#cmakedefine HAVE_WCTYPE_H 1
+
+/* Define to 1 if you have the <winldap.h> header file. */
+#cmakedefine HAVE_WINLDAP_H 1
+
+/* Define to 1 if your compiler understands __builtin_bswap32. */
+#cmakedefine HAVE__BUILTIN_BSWAP32 1
+
+/* Define to 1 if your compiler understands __builtin_bswap64. */
+#cmakedefine HAVE__BUILTIN_BSWAP64 1
+
+/* Define to 1 if your compiler understands __builtin_constant_p. */
+#cmakedefine HAVE__BUILTIN_CONSTANT_P 1
+
+/* Define to 1 if your compiler understands __builtin_types_compatible_p. */
+#cmakedefine HAVE__BUILTIN_TYPES_COMPATIBLE_P 1
+
+/* Define to 1 if your compiler understands __builtin_unreachable. */
+#cmakedefine HAVE__BUILTIN_UNREACHABLE 1
+
+/* Define to 1 if you have __cpuid. */
+#cmakedefine HAVE__CPUID 1
+
+/* Define to 1 if you have __cpuid. */
+#cmakedefine HAVE__GET_CPUID 1
+
+/* Define to 1 if your compiler understands _Static_assert. */
+#cmakedefine HAVE__STATIC_ASSERT 1
+
+/* Define to 1 if your compiler understands __VA_ARGS__ in macros. */
+#cmakedefine HAVE__VA_ARGS 1
+
+/* Define to the appropriate snprintf length modifier for 64-bit ints. */
+#define INT64_MODIFIER "@LONG_LONG_INT_MODIFIER@"
+
+/* Define to 1 if `locale_t' requires <xlocale.h>. */
+#cmakedefine LOCALE_T_IN_XLOCALE 1
+
+/* Define as the maximum alignment requirement of any C data type. */
+#define MAXIMUM_ALIGNOF @MAXIMUM_ALIGNOF@
+
+/* Define bytes to use libc memset(). */
+#define MEMSET_LOOP_LIMIT @MEMSET_LOOP_LIMIT@
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
+
+/* TODO BUT DO NOT NEED:Define to the full name of this package. */
+/*#define PACKAGE_NAME "@PACKAGE_NAME@"*/
+
+/* TODO:Define to the full name and version of this package. */
+/*#define PACKAGE_STRING "@PACKAGE_STRING@"*/
+
+/* TODO BUT DO NOT NEED:Define to the one symbol short name of this package. */
+/*#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"*/
+
+/* TODO BUT DO NOT NEED:Define to the home page for this package. */
+/*#define PACKAGE_URL "@PACKAGE_URL@"*/
+
+/* TODO BUT DO NOT NEED:Define to the version of this package. */
+/*#define PACKAGE_VERSION "@PACKAGE_VERSION@"*/
+
+/* Define to the name of a signed 128-bit integer type. */
+#define PG_INT128_TYPE @PG_INT128_TYPE@
+
+/* Define to the name of a signed 64-bit integer type. */
+#define PG_INT64_TYPE @PG_INT64_TYPE@
+
+/* Define to the name of the default PostgreSQL service principal in Kerberos
+   (GSSAPI). */
+#define PG_KRB_SRVNAM "@PG_KRB_SRVNAM@"
+
+/* PostgreSQL major version as a string */
+#define PG_MAJORVERSION "@POSTGRES_MAJOR_VERSION@"
+
+/* Define to gnu_printf if compiler supports it, else printf. */
+#define PG_PRINTF_ATTRIBUTE @PG_PRINTF_ATTRIBUTE@
+
+/* PostgreSQL version as a string */
+#define PG_VERSION "@PG_VERSION@"
+
+/* PostgreSQL version as a number */
+#define PG_VERSION_NUM @PG_VERSION_NUM@
+
+/* A string containing the version number, platform, and C compiler */
+#define PG_VERSION_STR "PostgreSQL @PG_VERSION@ on @CMAKE_SYSTEM_NAME@, compiled by @CMAKE_C_COMPILER_ID@, @VOID_POINTER_SIZE_BIT@-bit"
+
+/* Define to 1 to allow profiling output to be saved separately for each
+   process. */
+#cmakedefine PROFILE_PID_DIR 1
+
+/* TODO BUT DO NOT NEED:Define to necessary symbol if this constant uses a non-standard name on
+   your system. */
+/*#cmakedefine PTHREAD_CREATE_JOINABLE*/
+
+/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus,
+   the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger
+   than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be
+   less than your OS' limit on file size. This is often 2 GB or 4GB in a
+   32-bit operating system, unless you have large file support enabled. By
+   default, we make the limit 1 GB to avoid any possible integer-overflow
+   problems within the OS. A limit smaller than necessary only means we divide
+   a large relation into more chunks than necessary, so it seems best to err
+   in the direction of a small limit. A power-of-2 value is recommended to
+   save a few cycles in md.c, but is not absolutely required. Changing
+   RELSEG_SIZE requires an initdb. */
+#define RELSEG_SIZE @RELSEG_SIZE@
+
+/* The size of `long', as computed by sizeof. */
+#define SIZEOF_LONG @SIZEOF_LONG@
+
+/* TODO BUT DO NOT NEED:The size of `off_t', as computed by sizeof. */
+/*#define SIZEOF_OFF_T @SIZEOF_OFF_T@*/
+
+/* The size of `size_t', as computed by sizeof. */
+#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@
+
+/* The size of `void *', as computed by sizeof. */
+#define SIZEOF_VOID_P @CMAKE_SIZEOF_VOID_P@
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the ANSI C header files. */
+/*#cmakedefine STDC_HEADERS 1*/
+
+/* Define to 1 if strerror_r() returns a int. */
+#cmakedefine STRERROR_R_INT 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if your <sys/time.h> declares `struct tm'. */
+/*#cmakedefine TM_IN_SYS_TIME 1*/
+
+/* Define to 1 to build with assertion checks. (--enable-cassert) */
+#cmakedefine USE_ASSERT_CHECKING 1
+
+/* Define to 1 to build with Bonjour support. (--with-bonjour) */
+#cmakedefine USE_BONJOUR 1
+
+/* Define to 1 to build with BSD Authentication support. (--with-bsd-auth) */
+#cmakedefine USE_BSD_AUTH 1
+
+/* Define to 1 if you want float4 values to be passed by value. */
+#cmakedefine USE_FLOAT4_BYVAL 1
+
+/* Define to 1 if you want float8, int8, etc values to be passed by value. */
+#cmakedefine USE_FLOAT8_BYVAL 1
+
+/* Define to 1 if you want 64-bit integer timestamp and interval support. */
+#cmakedefine USE_INTEGER_DATETIMES 1
+
+/* Define to 1 to build with LDAP support. (--with-ldap) */
+#cmakedefine USE_LDAP 1
+
+/* Define to 1 to build with XML support. (-DWITH_LIBXML) */
+#cmakedefine USE_LIBXML 1
+
+/* Define to 1 to use XSLT support when building contrib/xml2. */
+#cmakedefine USE_LIBXSLT 1
+
+/* Define to select named POSIX semaphores. */
+#cmakedefine USE_NAMED_POSIX_SEMAPHORES 1
+
+/* Define to build with OpenSSL support. (--with-openssl) */
+#cmakedefine USE_OPENSSL 1
+
+/* Define to 1 to build with PAM support. (--with-pam) */
+#cmakedefine USE_PAM 1
+
+/* Use replacement snprintf() functions. */
+#cmakedefine USE_REPL_SNPRINTF 1
+
+/* Define to 1 to use Intel SSE 4.2 CRC instructions with a runtime check. */
+#cmakedefine USE_SLICING_BY_8_CRC32C 1
+
+/* Define to 1 use Intel SSE 4.2 CRC instructions. */
+#cmakedefine USE_SSE42_CRC32C 1
+
+/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */
+#cmakedefine USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1
+
+/* Define to build with systemd support. (--with-systemd) */
+#cmakedefine USE_SYSTEMD
+
+/* Define to select SysV-style semaphores. */
+#cmakedefine USE_SYSV_SEMAPHORES
+
+/* Define to select SysV-style shared memory. */
+#cmakedefine USE_SYSV_SHARED_MEMORY
+
+/* Define to select unnamed POSIX semaphores. */
+#cmakedefine USE_UNNAMED_POSIX_SEMAPHORES
+
+/* Define to select Win32-style semaphores. */
+#cmakedefine USE_WIN32_SEMAPHORES
+
+/* TODO BUT DO NOT NEED:Define to select Win32-style shared memory. */
+/*#cmakedefine USE_WIN32_SHARED_MEMORY*/
+
+/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
+#cmakedefine WCSTOMBS_L_IN_XLOCALE 1
+
+/* NOT NEED:Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+/*#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+#  undef WORDS_BIGENDIAN
+# endif
+#endif*/
+
+/* Size of a WAL file block. This need have no particular relation to BLCKSZ.
+   XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O,
+   XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O
+   buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb.
+   */
+#define XLOG_BLCKSZ @XLOG_BLCKSZ@
+
+/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2
+   and larger than XLOG_BLCKSZ (preferably, a great deal larger than
+   XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */
+#define XLOG_SEG_SIZE @XLOG_SEG_SIZE@
+
+/* TODO BUT DO NOT NEED:Number of bits in a file offset, on hosts where this is settable. */
+/*#undef _FILE_OFFSET_BITS*/
+
+/* TODO BUT DO NOT NEED:Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/*#undef _LARGEFILE_SOURCE*/
+
+/* TODO BUT DO NOT NEED:Define for large files, on AIX-style hosts. */
+/*#undef _LARGE_FILES*/
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#undef inline
+#endif
+
+/* Define to the type of a signed integer type wide enough to hold a pointer,
+   if such a type exists, and if the system does not define it. */
+/*#undef intptr_t*/
+
+/* Define to empty if the C compiler does not understand signed types. */
+/*#undef signed*/
+
+/* Define to the type of an unsigned integer type wide enough to hold a
+   pointer, if such a type exists, and if the system does not define it. */
+/*#undef uintptr_t*/
+
+#cmakedefine HAVE_INT128
+
+#ifdef WIN32
+#undef PG_INT128_TYPE
+#endif
+
+#define LONG_LONG_INT_MODIFIER @LONG_LONG_INT_MODIFIER@
+
+#define POSTGRES_MAJOR_VERSION @POSTGRES_MAJOR_VERSION@
+
+#define POSTGRES_MINOR_VERSION @POSTGRES_MINOR_VERSION@
+
+#define POSTGRES_PATCH_VERSION @POSTGRES_PATCH_VERSION@
+
+#ifdef __APPLE__
+#	if __BIG_ENDIAN
+#		define WORDS_BIGENDIAN 1
+#	endif
+#else
+#cmakedefine WORDS_BIGENDIAN 1
+#endif
+
+#define DLSUFFIX "@CMAKE_SHARED_MODULE_SUFFIX@"
+
+#cmakedefine HAVE_MKSTEMP 1
+
+#cmakedefine HAVE_NBTOOL_CONFIG_H 1
+
+/*#include "@pgos_include_SRCS@"*/
+
+#endif  // AUTO_CONFIG_H
diff --git a/src/include/pg_config_ext_cmake.in b/src/include/pg_config_ext_cmake.in
new file mode 100644
index 0000000..a73f04b
--- /dev/null
+++ b/src/include/pg_config_ext_cmake.in
@@ -0,0 +1 @@
+#define PG_INT64_TYPE @PG_INT64_TYPE@
\ No newline at end of file
diff --git a/src/include/pg_config_paths_cmake.in b/src/include/pg_config_paths_cmake.in
new file mode 100644
index 0000000..f1b3c08
--- /dev/null
+++ b/src/include/pg_config_paths_cmake.in
@@ -0,0 +1,12 @@
+#define PGBINDIR "@PGBINDIR@"
+#define PGSHAREDIR "@PGSHAREDIR@"
+#define SYSCONFDIR "@SYSCONFDIR@" 
+#define INCLUDEDIR "@INCLUDEDIR@"
+#define PKGINCLUDEDIR "@PKGINCLUDEDIR@"
+#define INCLUDEDIRSERVER "@INCLUDEDIRSERVER@"
+#define LIBDIR "@LIBDIR@"
+#define PKGLIBDIR "@PKGLIBDIR@"
+#define LOCALEDIR "@LOCALEDIR@"
+#define DOCDIR "@DOCDIR@"
+#define HTMLDIR "@HTMLDIR@"
+#define MANDIR "@MANDIR@"
\ No newline at end of file
diff --git a/src/include/port.h b/src/include/port.h
index b81fa4a..dd63c44 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -470,4 +470,7 @@ extern char *escape_single_quotes_ascii(const char *src);
 /* port/wait_error.c */
 extern char *wait_result_to_str(int exit_status);
 
+extern int pg_putenv_proxy(char *envval);
+
+
 #endif   /* PG_PORT_H */
diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index 4453c90..2c30268 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -418,7 +418,6 @@ extern void pgwin32_unsetenv(const char *);
 extern int	pgwin32_is_service(void);
 extern int	pgwin32_is_admin(void);
 
-#define putenv(x) pgwin32_putenv(x)
 #define unsetenv(x) pgwin32_unsetenv(x)
 
 /* Things that exist in MingW headers, but need to be added to MSVC & BCC */
diff --git a/src/interfaces/ecpg/compatlib/CMakeLists.txt b/src/interfaces/ecpg/compatlib/CMakeLists.txt
new file mode 100644
index 0000000..3214951
--- /dev/null
+++ b/src/interfaces/ecpg/compatlib/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+set(ecpg_compat_SRC
+	informix.c
+)
+if(USE_REPL_SNPRINTF)
+	set(ecpg_compat_SRC
+		${ecpg_compat_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+add_library(ecpg_compat SHARED ${ecpg_compat_SRC})
+if (MSVC)
+	gen_def(ecpg_compat)
+endif()
+target_link_libraries(ecpg_compat ${LIB_M} pgtypes pq ecpg)
+target_compile_definitions(ecpg_compat PRIVATE -DFRONTEND)
+set_target_properties(ecpg_compat PROPERTIES VERSION "3.8")
+
+install(TARGETS ecpg_compat
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/interfaces/ecpg/ecpglib/CMakeLists.txt b/src/interfaces/ecpg/ecpglib/CMakeLists.txt
new file mode 100644
index 0000000..158ec62
--- /dev/null
+++ b/src/interfaces/ecpg/ecpglib/CMakeLists.txt
@@ -0,0 +1,76 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+set(ecpg_SRC
+	execute.c
+	typename.c
+	descriptor.c
+	sqlda.c
+	data.c
+	error.c
+	prepare.c
+	memory.c
+	connect.c
+	misc.c
+	${PROJECT_SOURCE_DIR}/src/port/path.c
+	${PROJECT_SOURCE_DIR}/src/port/pgstrcasecmp.c
+)
+
+if(USE_REPL_SNPRINTF)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/rint.c
+	)
+endif()
+
+if(NOT HAVE_DECL_STRLCPY)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/strlcpy.c
+	)
+endif()
+
+if(NOT HAVE_ISINF)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/isinf.c
+	)
+endif()
+
+if(WIN32)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/win32setlocale.c
+	)
+else()
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/thread.c
+	)
+endif()
+
+add_library(ecpg SHARED ${ecpg_SRC})
+if (MSVC)
+	gen_def(ecpg)
+endif()
+target_link_libraries(ecpg ${LIB_M} pgtypes pq)
+target_compile_definitions(ecpg PRIVATE -DFRONTEND)
+set_target_properties(ecpg PROPERTIES VERSION "6.8")
+
+install(TARGETS ecpg
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(ecpg "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;tr;zh_CN")
+endif()
diff --git a/src/interfaces/ecpg/include/CMakeLists.txt b/src/interfaces/ecpg/include/CMakeLists.txt
new file mode 100644
index 0000000..63c42e8
--- /dev/null
+++ b/src/interfaces/ecpg/include/CMakeLists.txt
@@ -0,0 +1,25 @@
+set(INCLUDEDIR_INTERNAL ${PKGINCLUDEDIR}/internal)
+
+install(FILES
+	ecpgerrno.h
+	ecpglib.h
+	ecpgtype.h
+	sqlca.h
+	sql3types.h
+	ecpg_informix.h
+	pgtypes_error.h
+	pgtypes_numeric.h
+	pgtypes_timestamp.h
+	pgtypes_date.h
+	pgtypes_interval.h
+	sqlda.h
+	sqlda-compat.h
+	sqlda-native.h
+	ecpg_config.h
+	DESTINATION ${INCLUDEDIR})
+
+install(FILES
+	datetime.h
+	decimal.h
+	sqltypes.h
+	DESTINATION ${PKGINCLUDEDIR}/informix/esql)
diff --git a/src/interfaces/ecpg/include/ecpg_config_cmake.in b/src/interfaces/ecpg/include/ecpg_config_cmake.in
new file mode 100644
index 0000000..1f3fcb8
--- /dev/null
+++ b/src/interfaces/ecpg/include/ecpg_config_cmake.in
@@ -0,0 +1,19 @@
+/* Define to 1 if the system has the type `int64'. */
+#cmakedefine HAVE_INT64 1
+
+/* Define to 1 if `long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_INT_64 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if `long long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_LONG_INT_64 1
+
+/* Define to 1 if you want 64-bit integer timestamp and interval support.
+   (--enable-integer-datetimes) */
+#cmakedefine USE_INTEGER_DATETIMES 1
+
+/* Define to 1 to build client libraries as thread-safe code.
+ *    (--enable-thread-safety) */
+#cmakedefine ENABLE_THREAD_SAFETY 1
diff --git a/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt b/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt
new file mode 100644
index 0000000..a36ddca
--- /dev/null
+++ b/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt
@@ -0,0 +1,41 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+)
+set(pgtypes_SRC
+	numeric.c
+	datetime.c
+	common.c
+	dt_common.c
+	timestamp.c
+	interval.c
+	${PROJECT_SOURCE_DIR}/src/port/pgstrcasecmp.c
+)
+if(USE_REPL_SNPRINTF)
+	set(pgtypes_SRC
+		${pgtypes_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(pgtypes_SRC
+		${pgtypes_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/rint.c
+	)
+endif()
+
+add_library(pgtypes SHARED ${pgtypes_SRC})
+if (MSVC)
+	gen_def(pgtypes)
+endif()
+
+target_link_libraries(pgtypes ${LIB_M})
+target_compile_definitions(pgtypes PRIVATE -DFRONTEND)
+set_target_properties(pgtypes PROPERTIES VERSION "3.7")
+
+
+install(TARGETS pgtypes
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/interfaces/libpq/CMakeLists.txt b/src/interfaces/libpq/CMakeLists.txt
new file mode 100644
index 0000000..8afcc6c
--- /dev/null
+++ b/src/interfaces/libpq/CMakeLists.txt
@@ -0,0 +1,108 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+)
+
+if(USE_OPENSSL)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	set(pq_ssl_SRCS fe-secure-openssl.c)
+endif(USE_OPENSSL)
+
+set(pq_SRCS
+	fe-auth.c
+	fe-connect.c
+	fe-exec.c
+	fe-misc.c
+	fe-print.c
+	fe-lobj.c
+	fe-protocol2.c
+	fe-protocol3.c
+	pqexpbuffer.c
+	fe-secure.c
+	libpq-events.c
+
+	${PORT_DIR}/chklocale.c
+	${PORT_DIR}/inet_net_ntop.c
+	${PORT_DIR}/noblock.c
+	${PORT_DIR}/pgstrcasecmp.c
+	${PORT_DIR}/pqsignal.c
+	${PORT_DIR}/thread.c
+
+	${PROJECT_SOURCE_DIR}/src/common/ip.c
+	${PROJECT_SOURCE_DIR}/src/common/md5.c
+	${MB_UTILS_BACKEND_DIR}/encnames.c
+	${MB_UTILS_BACKEND_DIR}/wchar.c
+
+	${fallback_SRCS}
+	${pq_ssl_SRCS}
+)
+
+if(USE_REPL_SNPRINTF)
+	set(pq_SRCS ${pq_SRCS} ${PORT_DIR}/snprintf.c)
+endif()
+
+set(RES_FILES "")
+if(WIN32)
+	set(pq_SRCS ${pq_SRCS}
+		win32.c
+		${PORT_DIR}/win32error.c
+		${PORT_DIR}/win32setlocale.c
+		${PORT_DIR}/pgsleep.c
+		${PORT_DIR}/open.c
+		${PORT_DIR}/system.c
+		${PORT_DIR}/inet_aton.c
+		${PORT_DIR}/thread.c
+		${PORT_DIR}/getaddrinfo.c
+	)
+	if (Threads_FOUND)
+		set(pq_SRCS ${pq_SRCS} pthread-win32.c)
+	endif()
+	set(RES_FILES "libpq.rc")
+	set(CMAKE_RC_COMPILER_INIT windres)
+	ENABLE_LANGUAGE(RC)
+	SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
+endif()
+
+add_library(pq SHARED ${pq_SRCS} ${RES_FILES})
+target_link_libraries(pq
+	${CMAKE_THREAD_LIBS_INIT}
+	${LIBSOCKET_LIBRARIES}
+	${GSS_LIBS}
+)
+if(USE_OPENSSL)
+	target_link_libraries(pq ${OPENSSL_LIBRARIES})
+endif()
+if (MSVC)
+	gen_def(pq)
+endif()
+if(CRYPT_LIB)
+	target_link_libraries(pq ${CRYPT_LIB})
+endif()
+if(WIN32)
+	target_link_libraries(pq
+		#port
+		Secur32
+		ws2_32
+	)
+endif()
+
+if(LDAP_FOUND)
+	target_link_libraries(pq ${LDAP_LIBRARIES})
+endif()
+
+if(USE_OPENSSL)
+	target_include_directories(pq PUBLIC ${OPENSSL_INCLUDE_DIR})
+endif()
+
+
+target_compile_definitions(pq PRIVATE -DFRONTEND -DUNSAFE_STAT_OK)
+install(TARGETS pq
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(libpq "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;tr;zh_CN;zh_TW")
+endif()
+
+#TODO 
+#set_target_properties(pq PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.list")
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 9668b52..06964c6 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -28,6 +28,7 @@
 #include "pg_config_paths.h"
 
 #ifdef WIN32
+#include <WS2tcpip.h>
 #include "win32.h"
 #ifdef _WIN32_IE
 #undef _WIN32_IE
diff --git a/src/pl/plperl/CMakeLists.txt b/src/pl/plperl/CMakeLists.txt
new file mode 100644
index 0000000..ba73e7c
--- /dev/null
+++ b/src/pl/plperl/CMakeLists.txt
@@ -0,0 +1,100 @@
+if(WIN32)
+	add_definitions(-DPLPERL_HAVE_UID_GID)
+endif()
+
+execute_process(
+	COMMAND ${PERL_EXECUTABLE} -e "use List::Util qw(first); print first { -r \"$_/ExtUtils/xsubpp\" } @INC"
+	OUTPUT_VARIABLE XSUBPPDIR
+)
+execute_process(
+	COMMAND ${PERL_EXECUTABLE} -V:usemultiplicity
+	OUTPUT_VARIABLE PERL_MULTIPLICITY
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/SPI.c"
+	MAIN_DEPENDENCY SPI.xs plperl_helpers.h
+	COMMAND ${PERL_EXECUTABLE} ${XSUBPPDIR}/ExtUtils/xsubpp -typemap ${PERL_PRIVLIB}/ExtUtils/typemap SPI.xs > "${CMAKE_CURRENT_SOURCE_DIR}/SPI.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/Util.c"
+	MAIN_DEPENDENCY Util.xs plperl_helpers.h
+	COMMAND ${PERL_EXECUTABLE} ${XSUBPPDIR}/ExtUtils/xsubpp -typemap ${PERL_PRIVLIB}/ExtUtils/typemap Util.xs > "${CMAKE_CURRENT_SOURCE_DIR}/Util.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	MAIN_DEPENDENCY plc_perlboot.pl plc_trusted.pl
+	COMMAND ${PERL_EXECUTABLE} text2macro.pl "--strip='^(\\#.*|\\s*)$$'" plc_perlboot.pl plc_trusted.pl > "${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	MAIN_DEPENDENCY plperl_opmask.pl
+	COMMAND ${PERL_EXECUTABLE} plperl_opmask.pl "${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plname "plperl")
+
+set(plperl_SRCS
+	"${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	"${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	plperl.c
+	SPI.c
+	Util.c
+)
+
+include_directories(${PERL_INCLUDE_PATH})
+add_library(${plname} MODULE ${plperl_SRCS})
+target_link_libraries(${plname} postgres ${PERL_LIBRARY} ${PERL_LDFLAGS})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} port)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+		plperl.control
+		plperl--1.0.sql
+		plperl--unpackaged--1.0.sql
+		plperlu.control
+		plperlu--1.0.sql
+		plperlu--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	plperl.h
+	ppport.h
+	DESTINATION ${INCLUDEDIRSERVER})
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB} --load-extension=plperl --load-extension=plperlu)
+set(plregres_files
+	plperl
+	plperl_lc
+	plperl_trigger
+	plperl_shared
+	plperl_elog
+	plperl_util
+	plperl_init
+	plperlu
+	plperl_array
+)
+
+if(PERL_MULTIPLICITY STREQUAL "usemultiplicity='define'")
+	set(plregres_files ${plregres_files} plperl_plperlu)
+endif()
+
+REGRESS_CHECK(plperl "${REGRESS_OPTS}" "${plregres_files}")
+
+if(ENABLE_NLS)
+	MAKE_MO(plperl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;sv;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/pl/plpgsql/src/CMakeLists.txt b/src/pl/plpgsql/src/CMakeLists.txt
new file mode 100644
index 0000000..29efb6a
--- /dev/null
+++ b/src/pl/plpgsql/src/CMakeLists.txt
@@ -0,0 +1,37 @@
+BISON_TARGET(PLPGSQL_PARSER pl_gram.y ${CMAKE_CURRENT_SOURCE_DIR}/pl_gram.c COMPILE_FLAGS "-d")
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/plerrcodes.h"
+	MAIN_DEPENDENCY generate-plerrcodes.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-plerrcodes.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/plerrcodes.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plpgsql_SRCS
+	pl_handler.c
+	pl_comp.c
+	plerrcodes.h
+	pl_exec.c
+	pl_funcs.c
+	pl_scanner.c
+	${BISON_PLPGSQL_PARSER_OUTPUT_SOURCE}
+)
+
+add_library(plpgsql MODULE ${plpgsql_SRCS})
+target_link_libraries(plpgsql postgres)
+if (MSVC)
+	gen_def(plpgsql)
+	target_link_libraries(plpgsql port pgcommon)
+endif()
+set_target_properties(plpgsql PROPERTIES PREFIX "")
+add_dependencies(plpgsql postgres)
+
+install(TARGETS plpgsql
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+
+if(ENABLE_NLS)
+	MAKE_MO(plpgsql "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;zh_CN;zh_TW")
+endif()
diff --git a/src/pl/plpython/CMakeLists.txt b/src/pl/plpython/CMakeLists.txt
new file mode 100644
index 0000000..e443e81
--- /dev/null
+++ b/src/pl/plpython/CMakeLists.txt
@@ -0,0 +1,92 @@
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	MAIN_DEPENDENCY generate-spiexceptions.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-spiexceptions.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plname "plpython${PYTHON_VERSION_MAJOR}")
+
+set(plpython_SRCS
+	"${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	plpy_cursorobject.c
+	plpy_elog.c
+	plpy_exec.c
+	plpy_main.c
+	plpy_planobject.c
+	plpy_plpymodule.c
+	plpy_procedure.c
+	plpy_resultobject.c
+	plpy_spi.c
+	plpy_subxactobject.c
+	plpy_typeio.c
+	plpy_util.c
+)
+
+include_directories(${PYTHON_INCLUDE_DIRS})
+add_library(${plname} MODULE ${plpython_SRCS})
+target_link_libraries(${plname} postgres ${PYTHON_LIBRARIES})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} port)
+endif()
+if(MINGW)
+	set_target_properties(${plname} PROPERTIES LINK_FLAGS -Wl,--out-implib=libmin${plname}.dll.a)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	plpython2u.control
+	plpython2u--1.0.sql
+	plpython2u--unpackaged--1.0.sql
+	plpython3u.control
+	plpython3u--1.0.sql
+	plpython3u--unpackaged--1.0.sql
+	plpythonu.control
+	plpythonu--1.0.sql
+	plpythonu--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB})
+if (PYTHON_VERSION_MAJOR EQUAL 2)
+	set(REGRESS_OPTS ${REGRESS_OPTS} --load-extension=plpythonu)
+endif()
+
+set(plregres_files
+	plpython_schema
+	plpython_populate
+	plpython_test
+	plpython_do
+	plpython_global
+	plpython_import
+	plpython_spi
+	plpython_newline
+	plpython_void
+	plpython_params
+	plpython_setof
+	plpython_record
+	plpython_trigger
+	plpython_types
+	plpython_error
+	plpython_unicode
+	plpython_quote
+	plpython_composite
+	plpython_subtransaction
+	plpython_drop
+)
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${plregres_files}")
+	REGRESS_CHECK(plpython "${REGRESS_OPTS}" "${regress_files3}")
+else()
+	REGRESS_CHECK(plpython "${REGRESS_OPTS}" "${plregres_files}")
+endif()
+
+if(ENABLE_NLS)
+	MAKE_MO(plpython "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/pl/tcl/CMakeLists.txt b/src/pl/tcl/CMakeLists.txt
new file mode 100644
index 0000000..b75d44f
--- /dev/null
+++ b/src/pl/tcl/CMakeLists.txt
@@ -0,0 +1,49 @@
+set(plname "pltcl")
+
+include_directories(${TCL_INCLUDE_PATH})
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h"
+	MAIN_DEPENDENCY generate-pltclerrcodes.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-pltclerrcodes.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(gen_pltclerrcodes DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h")
+
+add_library(${plname} MODULE
+	pltcl.c
+)
+
+target_link_libraries(${plname} postgres ${TCL_LIBRARY})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} port)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres gen_pltclerrcodes)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+		${plname}.control
+		${plname}--1.0.sql
+		${plname}--unpackaged--1.0.sql
+		${plname}u.control
+		${plname}u--1.0.sql
+		${plname}u--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB} --load-extension=pltcl)
+set(plregres_files
+	pltcl_setup
+	pltcl_queries
+	pltcl_unicode
+)
+REGRESS_CHECK(pltcl "${REGRESS_OPTS}" "${plregres_files}")
+
+if(ENABLE_NLS)
+	MAKE_MO(pltcl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/port/CMakeLists.txt b/src/port/CMakeLists.txt
new file mode 100644
index 0000000..eae5a31
--- /dev/null
+++ b/src/port/CMakeLists.txt
@@ -0,0 +1,165 @@
+if(USE_SSE42_CRC32C)
+	SET(PG_CRC32C_OBJS pg_crc32c_sse42.c)
+elseif(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK)
+	SET(PG_CRC32C_OBJS
+		pg_crc32c_sse42.c
+		pg_crc32c_sb8.c
+		pg_crc32c_choose.c
+	)
+elseif(USE_SLICING_BY_8_CRC32C)
+	SET(PG_CRC32C_OBJS pg_crc32c_sb8.c)
+endif()
+
+set_source_files_properties(pg_crc32c_sse42.c PROPERTIES COMPILE_FLAGS "${CFLAGS_SSE42}")
+
+set(port_SRCS
+	chklocale.c
+	erand48.c
+	inet_net_ntop.c
+	noblock.c
+	path.c
+	pgcheckdir.c
+	pgmkdirp.c
+	pgsleep.c
+	pgstrcasecmp.c
+	pqsignal.c
+	qsort.c
+	qsort_arg.c
+	quotes.c
+	sprompt.c
+	tar.c
+	thread.c
+	pg_putenv_proxy.c
+	${fallback_SRCS}
+	${PG_CRC32C_OBJS}
+)
+
+if(NOT HAVE_FLS)
+	set(port_SRCS
+		${port_SRCS}
+		fls.c
+	)
+endif(NOT HAVE_FLS)
+
+if(NOT HAVE_ISINF)
+	set(port_SRCS
+		${port_SRCS}
+		isinf.c
+	)
+endif()
+
+if(NOT HAVE_MKDTEMP)
+	set(port_SRCS
+		${port_SRCS}
+		mkdtemp.c
+	)
+endif()
+
+if(NOT HAVE_GETOPT)
+	set(port_SRCS
+		${port_SRCS}
+		getopt.c
+	)
+endif()
+
+if(NOT (HAVE_STRUCT_OPTION AND HAVE_GETOPT_LONG))
+	set(port_SRCS
+		${port_SRCS}
+		getopt_long.c
+	)
+endif()
+
+if(NOT HAVE_GETTIMEOFDAY)
+	set(port_SRCS
+		${port_SRCS}
+		gettimeofday.c
+	)
+endif()
+
+if(NOT HAVE_INET_ATON)
+	set(port_SRCS
+		${port_SRCS}
+		inet_aton.c
+	)
+endif()
+
+if(NOT HAVE_RANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		random.c
+	)
+endif()
+
+if(NOT HAVE_SRANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		srandom.c
+	)
+endif()
+
+if(USE_REPL_SNPRINTF)
+	set(port_SRCS
+		${port_SRCS}
+		snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(port_SRCS
+		${port_SRCS}
+		rint.c
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(port_SRCS
+		${port_SRCS}
+		dirmod.c
+		kill.c
+		open.c
+		getrusage.c
+		system.c
+		win32security.c
+		win32env.c
+		win32error.c
+		win32setlocale.c
+	)
+endif()
+
+if(MSVC)
+	set(port_SRCS
+		${port_SRCS}
+		dirent.c
+	)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	# Solaris' getopt() doesn't do what we want for long options, so always use
+	# our version on that platform.
+	set(port_SRCS
+		${port_SRCS}
+		getopt.c
+	)
+endif()
+
+if(NOT HAVE_CRYPT)
+	set(port_SRCS
+		${port_SRCS}
+		crypt.c
+	)
+endif()
+
+add_library(port_srv STATIC ${port_SRCS})
+add_library(port STATIC ${port_SRCS})
+
+add_dependencies(port_srv gen_errorcodes)
+add_dependencies(port gen_errorcodes)
+
+# because port used in shared libraries
+set_property(TARGET port PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+
+
+target_compile_definitions(port PRIVATE -DFRONTEND)
+set_source_files_properties(thread.c PROPERTIES COMPILE_FLAGS ${PTHREAD_CFLAGS})
+install(TARGETS port
+		ARCHIVE DESTINATION ${LIBDIR})
diff --git a/src/port/Makefile b/src/port/Makefile
index bc9b63a..40dcdab 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -33,7 +33,7 @@ LIBS += $(PTHREAD_LIBS)
 OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
 	noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o \
 	pgstrcasecmp.o pqsignal.o \
-	qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o
+	qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o pg_putenv_proxy.o
 
 # foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
 OBJS_SRV = $(OBJS:%.o=%_srv.o)
diff --git a/src/port/pg_putenv_proxy.c b/src/port/pg_putenv_proxy.c
new file mode 100644
index 0000000..ae10852
--- /dev/null
+++ b/src/port/pg_putenv_proxy.c
@@ -0,0 +1,26 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_putenv_proxy.c
+ *	  pg_putenv_proxy for putenv
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ *	  src/port/pg_putenv_proxy.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "c.h"
+
+int
+pg_putenv_proxy(char *envval)
+{
+#ifdef WIN32
+	return pgwin32_putenv(envval);
+#else
+	return putenv(envval);
+#endif
+}
\ No newline at end of file
diff --git a/src/port/unsetenv.c b/src/port/unsetenv.c
index bb7ab43..0c66ef3 100644
--- a/src/port/unsetenv.c
+++ b/src/port/unsetenv.c
@@ -44,7 +44,7 @@ unsetenv(const char *name)
 
 	/* Override the existing setting by forcibly defining the var */
 	sprintf(envstr, "%s=", name);
-	putenv(envstr);
+	pg_putenv_proxy(envstr);
 
 	/* Now we can clobber the variable definition this way: */
 	strcpy(envstr, "=");
@@ -53,5 +53,5 @@ unsetenv(const char *name)
 	 * This last putenv cleans up if we have multiple zero-length names as a
 	 * result of unsetting multiple things.
 	 */
-	putenv(envstr);
+	pg_putenv_proxy(envstr);
 }
diff --git a/src/test/isolation/CMakeLists.txt b/src/test/isolation/CMakeLists.txt
new file mode 100644
index 0000000..2b13ee4
--- /dev/null
+++ b/src/test/isolation/CMakeLists.txt
@@ -0,0 +1,64 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/test/regress"
+)
+
+add_executable(pg_isolation_regress
+	${PROJECT_SOURCE_DIR}/src/test/regress/pg_regress.c
+	isolation_main.c
+)
+
+target_link_libraries(pg_isolation_regress
+	pq
+	pgcommon
+	port
+)
+
+target_compile_definitions(pg_isolation_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}"
+)
+
+bison_target(SPEC_PARSER specparse.y ${CMAKE_CURRENT_SOURCE_DIR}/specparse.c)
+flex_target(SPEC_SCANNER specscanner.l  ${CMAKE_CURRENT_SOURCE_DIR}/specscanner.c)
+add_flex_bison_dependency(SPEC_SCANNER SPEC_PARSER)
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/specparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_SPEC_SCANNER_OUTPUTS})
+
+add_executable(isolationtester
+	isolationtester.c
+	${BISON_SPEC_PARSER_OUTPUTS}
+)
+
+target_link_libraries(isolationtester
+	pgcommon
+	port
+	pq
+)
+
+add_custom_target(isolation_check
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+	COMMAND make install DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+	COMMAND make isolation_installcheck_tmp DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+add_custom_target(isolation_installcheck
+	COMMAND ${pg_isolation_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/isolation_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(isolation_installcheck_tmp
+	COMMAND ${pg_isolation_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/isolation_schedule --dlpath=${CMAKE_CURRENT_BINARY_DIR}/tmp_install${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+install(TARGETS isolationtester
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(TARGETS pg_isolation_regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/test/regress/CMakeLists.txt b/src/test/regress/CMakeLists.txt
new file mode 100644
index 0000000..fdc1fc2
--- /dev/null
+++ b/src/test/regress/CMakeLists.txt
@@ -0,0 +1,81 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/port"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_regress
+	pg_regress.c
+	pg_regress_main.c
+)
+
+target_link_libraries(pg_regress
+	pq
+	pgcommon
+	port
+)
+
+target_compile_definitions(pg_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}")
+
+
+add_library(regress MODULE regress.c)
+#target_link_libraries(regress
+#	pq
+#)
+if (MSVC)
+	gen_def(regress)
+endif()
+
+if(MSVC OR MINGW)
+	target_link_libraries(regress postgres port pgcommon)
+endif()
+
+set_target_properties(regress PROPERTIES PREFIX "")
+add_dependencies(regress postgres)
+
+add_custom_target(tablespace-setup
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ./testtablespace
+	COMMAND ${CMAKE_COMMAND} -E make_directory ./testtablespace
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install ${check_make_command} install
+		COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/ ${check_make_command} installcheck_tmp
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} install DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} installcheck_tmp DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+
+add_custom_target(installcheck
+	COMMAND ${pg_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/parallel_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(installcheck_tmp
+	COMMAND ${pg_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/parallel_schedule --dlpath=${CMAKE_CURRENT_BINARY_DIR}/tmp_install${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+install(TARGETS pg_regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(TARGETS regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 14c87c9..f34f32a 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -712,7 +712,7 @@ doputenv(const char *var, const char *val)
 	char	   *s;
 
 	s = psprintf("%s=%s", var, val);
-	putenv(s);
+	pg_putenv_proxy(s);
 }
 
 /*
@@ -721,7 +721,7 @@ doputenv(const char *var, const char *val)
 static void
 initialize_environment(void)
 {
-	putenv("PGAPPNAME=pg_regress");
+	pg_putenv_proxy("PGAPPNAME=pg_regress");
 
 	if (nolocale)
 	{
@@ -744,7 +744,7 @@ initialize_environment(void)
 		 * variables unset; see PostmasterMain().
 		 */
 #if defined(WIN32) || defined(__CYGWIN__) || defined(__darwin__)
-		putenv("LANG=C");
+		pg_putenv_proxy("LANG=C");
 #endif
 	}
 
@@ -756,7 +756,7 @@ initialize_environment(void)
 	 */
 	unsetenv("LANGUAGE");
 	unsetenv("LC_ALL");
-	putenv("LC_MESSAGES=C");
+	pg_putenv_proxy("LC_MESSAGES=C");
 
 	/*
 	 * Set encoding as requested
@@ -769,8 +769,8 @@ initialize_environment(void)
 	/*
 	 * Set timezone and datestyle for datetime-related tests
 	 */
-	putenv("PGTZ=PST8PDT");
-	putenv("PGDATESTYLE=Postgres, MDY");
+	pg_putenv_proxy("PGTZ=PST8PDT");
+	pg_putenv_proxy("PGDATESTYLE=Postgres, MDY");
 
 	/*
 	 * Likewise set intervalstyle to ensure consistent results.  This is a bit
@@ -786,7 +786,7 @@ initialize_environment(void)
 			old_pgoptions = "";
 		new_pgoptions = psprintf("PGOPTIONS=%s %s",
 								 old_pgoptions, my_pgoptions);
-		putenv(new_pgoptions);
+		pg_putenv_proxy(new_pgoptions);
 	}
 
 	if (temp_instance)
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index e7826a4..b38e361 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -853,7 +853,7 @@ regress_putenv(PG_FUNCTION_ARGS)
 	envbuf = text_to_cstring((text *) PG_GETARG_POINTER(0));
 	MemoryContextSwitchTo(oldcontext);
 
-	if (putenv(envbuf) != 0)
+	if (pg_putenv_proxy(envbuf) != 0)
 		elog(ERROR, "could not set environment variable: %m");
 
 	PG_RETURN_VOID();
diff --git a/src/timezone/CMakeLists.txt b/src/timezone/CMakeLists.txt
new file mode 100644
index 0000000..4f60ce9
--- /dev/null
+++ b/src/timezone/CMakeLists.txt
@@ -0,0 +1,76 @@
+#TODO compile timezones
+
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+
+
+set(tzdata 
+	${CMAKE_CURRENT_SOURCE_DIR}/data/africa
+	${CMAKE_CURRENT_SOURCE_DIR}/data/antarctica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/asia
+	${CMAKE_CURRENT_SOURCE_DIR}/data/australasia
+	${CMAKE_CURRENT_SOURCE_DIR}/data/europe
+	${CMAKE_CURRENT_SOURCE_DIR}/data/northamerica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/southamerica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/pacificnew
+	${CMAKE_CURRENT_SOURCE_DIR}/data/etcetera
+	${CMAKE_CURRENT_SOURCE_DIR}/data/factory
+	${CMAKE_CURRENT_SOURCE_DIR}/data/backward
+	${CMAKE_CURRENT_SOURCE_DIR}/data/systemv
+)
+
+add_executable(zic
+	zic.c
+)
+target_link_libraries(zic
+	port
+)
+
+if(MSVC)
+	foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
+		string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
+		set_target_properties(zic PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+		set_target_properties(zic PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+		set_target_properties(zic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+	endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
+endif(MSVC)
+
+
+install(FILES 
+	tznames/Africa.txt
+	tznames/America.txt
+	tznames/Antarctica.txt
+	tznames/Asia.txt
+	tznames/Atlantic.txt
+	tznames/Australia.txt
+	tznames/Etc.txt
+	tznames/Europe.txt
+	tznames/Indian.txt
+	tznames/Pacific.txt
+	tznames/Default
+	tznames/Australia
+	tznames/India
+DESTINATION ${PGSHAREDIR}/timezonesets)
+
+function(JOIN VALUES GLUE OUTPUT)
+  string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
+  string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
+  set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
+endfunction()
+
+if(MINGW)
+	string(SUBSTRING ${PGSHAREDIR} 2 -1 PGSHAREDIR_ZIC)
+else()
+	set(PGSHAREDIR_ZIC ${PGSHAREDIR})
+endif()
+
+JOIN("${tzdata}" " " tzdata_string)
+install(
+	CODE "message('${CMAKE_CURRENT_BINARY_DIR}/zic${CMAKE_EXECUTABLE_SUFFIX} \$ENV{DESTDIR}${PGSHAREDIR_ZIC}/timezone -p US/Eastern ${tzdata_string}')"
+	CODE "execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/zic${CMAKE_EXECUTABLE_SUFFIX} -d \"\$ENV{DESTDIR}${PGSHAREDIR_ZIC}/timezone\" -p \"US/Eastern\" ${tzdata_string})"
+)
+
diff --git a/src/timezone/Makefile b/src/timezone/Makefile
index bed5727..348c79e 100644
--- a/src/timezone/Makefile
+++ b/src/timezone/Makefile
@@ -54,6 +54,7 @@ zic: $(ZICOBJS) | submake-libpgport
 
 install: all installdirs
 ifeq (,$(with_system_tzdata))
+	echo "-d '$(DESTDIR)$(datadir)/timezone' -p '$(POSIXRULES)' $(TZDATAFILES)"
 	$(ZIC) -d '$(DESTDIR)$(datadir)/timezone' -p '$(POSIXRULES)' $(TZDATAFILES)
 endif
 	$(MAKE) -C tznames $@
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index a6c43c2..e35ed5a 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -154,23 +154,21 @@ sub usage
 }
 
 usage()
-  unless scalar(@ARGV) == 2
-	  && (   ($ARGV[0] =~ /\\([^\\]+$)/)
-		  && ($ARGV[1] eq 'Win32' || $ARGV[1] eq 'x64'));
-my $defname  = uc $1;
-my $deffile  = "$ARGV[0]/$defname.def";
-my $platform = $ARGV[1];
+  unless scalar(@ARGV) == 3
+	  && ($ARGV[2] eq 'Win32' || $ARGV[2] eq 'x64');
+my $deffile  = $ARGV[1];
+my $platform = $ARGV[2];
 
 # if the def file exists and is newer than all input object files, skip
 # its creation
 if (-f $deffile
 	&& (-M $deffile > max(map { -M } <$ARGV[0]/*.obj>)))
 {
-	print "Not re-generating $defname.DEF, file already exists.\n";
+	print "Not re-generating .DEF, file already exists.\n";
 	exit(0);
 }
 
-print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
+print "Generating .DEF from directory $ARGV[0], platform $platform\n";
 
 my %def = ();
 
#97Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Andres Freund (#94)
Re: WIP: About CMake v2

Andres Freund wrote:

It's way too likely that we end up
releasing with multiple buildsystems that way.

If we fail in the CMake integration we can easily remove all CMake files
before code freeze.
I hope step by step CMake integration better way for current situation.
But I do not insist, just I trying to find the easiest way.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#98Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#91)
Re: WIP: About CMake v2

On 9/16/16 9:33 AM, Michael Paquier wrote:

I am no cmake guru yet, but VPATH builds are supported out of the box,
which is cool.

Your patch recommends to build with cmake after creating build/, now I
would expect most users to run cmake from the root folder.

My understanding is that cmake strongly recommends building in a
separate directory, which is usually a subdirectory named something like
"build". So the above is likely going to be the standard workflow.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#99Stas Kelvich
s.kelvich@postgrespro.ru
In reply to: Yury Zhuravlev (#96)
Re: WIP: About CMake v2

On 17 Sep 2016, at 20:21, Yury Zhuravlev <u.zhuravlev@postgrespro.ru> wrote:

Michael Paquier wrote:

On Sat, Sep 17, 2016 at 1:40 AM, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Michael Paquier wrote:
I merged master to my branch and I spent time to porting all changes. I hope
send patch in the weekend without terrible flaws.

By the way, I noticed that you did not register this patch in the current CF..

Now, I published the first version of the patch. This patch not ready for commit yet and all current task you can read here:
https://github.com/stalkerg/postgres_cmake/issues

I hope we realy close to end.
In this patch I forbade in-source build for avoid overwriting current Makefiles. We will can remove all Makefiles only after shall see in CMake. You don't need support two system. During commitfests CMake build system will be supported by me.
I need help with buildfarm because my knowledge of Perl is very bad (thought about rewrite buildfarm to Python).

I hope for your support.

Tried to generate Xcode project out of cmake, build fails on genbki.pl: can't locate Catalog.pm (which itself lives in src/backend/catalog/Catalog.pm)

--
Stas Kelvich
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#100Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Stas Kelvich (#99)
Re: WIP: About CMake v2

Stas Kelvich wrote:

On 17 Sep 2016, at 20:21, Yury Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:

Michael Paquier wrote: ...

Tried to generate Xcode project out of cmake, build fails on
genbki.pl: can't locate Catalog.pm (which itself lives in
src/backend/catalog/Catalog.pm)

Can you try again? On my Xcode 7.3 / ElCapitan everything is working
correctly.
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#101Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Stas Kelvich (#99)
Re: WIP: About CMake v2

Stas Kelvich wrote:

Tried to generate Xcode project out of cmake, build fails on
genbki.pl: can't locate Catalog.pm (which itself lives in
src/backend/catalog/Catalog.pm)

Thanks again! I have corrected your issue.
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#102Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Yury Zhuravlev (#96)
Re: WIP: About CMake v2

On 9/17/16 1:21 PM, Yury Zhuravlev wrote:

Now, I published the first version of the patch.

I tried this out. Because of some file moves in initdb and
pg_basebackup, the build fails:

[ 74%] Linking C executable initdb
Undefined symbols for architecture x86_64:
"_fsync_pgdata", referenced from:
_main in initdb.c.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [src/bin/initdb/CMakeFiles/initdb.dir/build.make:177:
src/bin/initdb/initdb] Error 1
make[1]: *** [CMakeFiles/Makefile2:2893:
src/bin/initdb/CMakeFiles/initdb.dir/all] Error 2
make: *** [Makefile:128: all] Error 2

Please submit an updated patch.

I suggest you use git format-patch to produce patches. This is easier
to apply, especially when there are a lot of new files involved. Also
use the git facilities to check for whitespace errors.

Please supply some documentation, such as

- what are the basic commands
- how to set include/library paths, choose configure options
- how to set CFLAGS
- how to see raw build commands
- what are the targets for all/world/check/docs etc.
- explain directory structure

I suggest for now you could put this into a README.cmake file in your
patch. We don't need to commit it that way, but it would help in the
meantime.

When I run cmake without options, it seems to do opportunistic feature
checking. For example, it turns on OpenSSL or Python support if it can
find it, otherwise it turns it off. We need this to be deterministic.
Without options, choose the basic feature set, require all other
features to be turned on explicitly, fail if they can't be found.
Whatever the Autoconf-based build does now has been fairly deliberately
tuned, so there should be very little reason to deviate from that.

The Python check appears to be picking up pieces from two different
Python installations:

-- Found PythonInterp: /usr/local/bin/python (found version "2.7.12")
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.10")

The check results otherwise look OK, but I'm a bit confused about the
order. It checks for some functions before all the header files are
checked for. Is that intentional?

There are a number of changes in .[ch] and .pl files that are unclear
and not explained. Please explain them. You can also submit separate
preliminary patches if you need to do some refactoring. Ultimately, I
would expect this patch not to require C code changes.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#103Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Peter Eisentraut (#102)
Re: WIP: About CMake v2

Hello.

Peter Eisentraut wrote:

I tried this out. Because of some file moves in initdb and
pg_basebackup, the build fails:

Yes, I need rebase patch to latest master. I do it as soon as possible.
Also I have some new achievements.

I suggest you use git format-patch to produce patches. This is easier
to apply, especially when there are a lot of new files involved. Also
use the git facilities to check for whitespace errors.

I agree.

I suggest for now you could put this into a README.cmake file in your
patch. We don't need to commit it that way, but it would help in the
meantime.

Good idea, currently I write all documentation on github. I will try to
move it to patch.

When I run cmake without options, it seems to do opportunistic feature
checking. For example, it turns on OpenSSL or Python support if it can
find it, otherwise it turns it off. We need this to be deterministic.
Without options, choose the basic feature set, require all other
features to be turned on explicitly, fail if they can't be found.
Whatever the Autoconf-based build does now has been fairly deliberately
tuned, so there should be very little reason to deviate from that.

This approach I see only in Postgres project and not fully understood.
Can you explain me more what reasons led to this approach?
Not big deal to make behavior like postgres Autoconf but I think it's
important clear view here.

The Python check appears to be picking up pieces from two different
Python installations:

Ooops you right. For Python detecting I use standard CMake module and
his behavior depending on CMake version. We should really careful here.

The check results otherwise look OK, but I'm a bit confused about the
order. It checks for some functions before all the header files are
checked for. Is that intentional?

I have plans to change order checks.

There are a number of changes in .[ch] and .pl files that are unclear
and not explained. Please explain them. You can also submit separate
preliminary patches if you need to do some refactoring. Ultimately, I
would expect this patch not to require C code changes.

I suppose separate patches with comments will be best way. I will do it.
I think we can talks about details after that.

Big thanks for your remarks it's very important for me and this "small"
project.
I will try to do all tasks quickly.

Best regards.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#104Craig Ringer
craig.ringer@2ndquadrant.com
In reply to: Yury Zhuravlev (#103)
Re: WIP: About CMake v2

On 9 Nov. 2016 06:37, "Yury Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

When I run cmake without options, it seems to do opportunistic feature
checking. For example, it turns on OpenSSL or Python support if it can
find it, otherwise it turns it off. We need this to be deterministic.
Without options, choose the basic feature set, require all other
features to be turned on explicitly, fail if they can't be found.
Whatever the Autoconf-based build does now has been fairly deliberately
tuned, so there should be very little reason to deviate from that.

This approach I see only in Postgres project and not fully understood.
Can you explain me more what reasons led to this approach?

It's predictable. The default has the same result for everyone. I quite
like it myself.

#105Michael Paquier
michael.paquier@gmail.com
In reply to: Craig Ringer (#104)
Re: WIP: About CMake v2

On Wed, Nov 9, 2016 at 7:54 AM, Craig Ringer
<craig.ringer@2ndquadrant.com> wrote:

On 9 Nov. 2016 06:37, "Yury Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

This approach I see only in Postgres project and not fully understood.
Can you explain me more what reasons led to this approach?

It's predictable. The default has the same result for everyone. I quite like
it myself.

+1. Let's tell to the system what we want him to do and not let him
guess what we'd like to be done or it will get harder to test and
develop code for all kind of code paths with #ifdef's. That's one step
away from Skynet.
-- 
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#106Craig Ringer
craig.ringer@2ndquadrant.com
In reply to: Michael Paquier (#105)
Re: WIP: About CMake v2

On 9 November 2016 at 10:12, Michael Paquier <michael.paquier@gmail.com> wrote:

On Wed, Nov 9, 2016 at 7:54 AM, Craig Ringer
<craig.ringer@2ndquadrant.com> wrote:

On 9 Nov. 2016 06:37, "Yury Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

This approach I see only in Postgres project and not fully understood.
Can you explain me more what reasons led to this approach?

It's predictable. The default has the same result for everyone. I quite like
it myself.

+1. Let's tell to the system what we want him to do and not let him
guess what we'd like to be done or it will get harder to test and
develop code for all kind of code paths with #ifdef's. That's one step
away from Skynet.

Er... ok then. (Backs away slowly).

More seriously, I like it for development where a stable and
predictable default is great.

For users it slightly sucks, as most users will want us to find
whatever is on the system without being manually told to enable each
feature. "Of course I want SSL, I have openssl installed don't I?"
It's not like we require users to specify --enable-largefile
--enable-atomics --enable-getopt --enable-ipv6 .... we do detect a
lot automatically.

So personally I think it'd be fine if a cmake build defaulted to
finding and using what it could, but offered a --minimal mode or
whatever that gets us just core postgres + whatever we enable
explicitly. But our current behaviour is OK too.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#107Tom Lane
tgl@sss.pgh.pa.us
In reply to: Craig Ringer (#104)
Re: WIP: About CMake v2

Craig Ringer <craig.ringer@2ndquadrant.com> writes:

On 9 Nov. 2016 06:37, "Yury Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

This approach I see only in Postgres project and not fully understood.
Can you explain me more what reasons led to this approach?

It's predictable. The default has the same result for everyone. I quite
like it myself.

It's advantageous from a packaging standpoint, precisely because it's
predictable: either you get the set of features you expect, or you get
a build failure. Years ago we were more on the "opportunistic" side
of things, and we had problems with packages sometimes silently losing
features. A pretty-recent example is that OpenSSL changed their APIs
in 1.1.0 so that our configure probe failed. With an opportunistic
approach, that would have meant builds silently going from "ssl yes"
to "ssl no". That's not good.

So this is really not open for negotiation. As Peter said upthread,
what we are looking for in a CMake reimplementation is that it behaves
exactly like the Autoconf version does. To the extent that you are unable
or unwilling to duplicate that behavior, you increase the odds that
we'll reject this work.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#108Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Tom Lane (#107)
Re: WIP: About CMake v2

Tom Lane wrote:

So this is really not open for negotiation. As Peter said upthread,
what we are looking for in a CMake reimplementation is that it behaves
exactly like the Autoconf version does. To the extent that you are unable
or unwilling to duplicate that behavior, you increase the odds that
we'll reject this work.

Who asking about negotiation? I just wanted an explanation for the clear
understanding and nothing more.
Now I know about reasons. Thanks.

regards
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#109Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Craig Ringer (#106)
Re: WIP: About CMake v2

Craig Ringer wrote:

So personally I think it'd be fine if a cmake build defaulted to
finding and using what it could, but offered a --minimal mode or
whatever that gets us just core postgres + whatever we enable
explicitly. But our current behaviour is OK too.

To me it's best way. But I'm not sure what Tom Lane will accept this.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#110Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Craig Ringer (#106)
Re: WIP: About CMake v2

Craig Ringer wrote:

So personally I think it'd be fine if a cmake build defaulted to
finding and using what it could, but offered a --minimal mode or
whatever that gets us just core postgres + whatever we enable
explicitly. But our current behaviour is OK too.

To me it's best way. But I'm not sure what Tom Lane will accept this.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#111Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Yury Zhuravlev (#110)
Re: WIP: About CMake v2

On 11/11/16 08:15, Yury Zhuravlev wrote:

Craig Ringer wrote:

So personally I think it'd be fine if a cmake build defaulted to
finding and using what it could, but offered a --minimal mode or
whatever that gets us just core postgres + whatever we enable
explicitly. But our current behaviour is OK too.

To me it's best way. But I'm not sure what Tom Lane will accept this.

I just had a play with this patch - nice! (ok so it needs a fix so that
the compile completes as mentioned prev).

I would recommend making it behave as Tom suggested. *Then* add an
--autodetect or similar option that makes
behave in the 'finding and using what it could' manner as a 2nd patch.

regards

Mark

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#112Tom Lane
tgl@sss.pgh.pa.us
In reply to: Mark Kirkwood (#111)
Re: WIP: About CMake v2

Mark Kirkwood <mark.kirkwood@catalyst.net.nz> writes:

I would recommend making it behave as Tom suggested. *Then* add an
--autodetect or similar option that makes
behave in the 'finding and using what it could' manner as a 2nd patch.

An "--autodetect" switch would be fine with me. I just don't want it
to behave that way by default, because then you get into the unexpected
results problem.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#113Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Peter Eisentraut (#102)
1 attachment(s)
Re: WIP: About CMake v2

I had a bit a play around to see if I could get this building properly
again with v10 (i.e master). I've attached a minimal *incremental* patch
that needs to be applied after v1. This gets everything under the src
tree building (added the new file_utils.c and reordered some link libs
and removed some duplicates).

I haven't made any changes with respect to it trying to detect and build
everything. One added nit I see is that unless I'm missing something
there appears to be no way to stop it trying to build all the
contribs...so an option to enable/disable their build is needed.

To make it display what options there are I use:

$ mkdir build; cd build ; cmake .. -LH

And to do a build that works:

$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/pgsql/10 -DWITH_PERL=OFF
-DWITH_OPENSSL=OFF -DWITH_PYTHON=OFF

With reference to Tom's comments, I'm thinking that these should all
default to 'OFF' plus an additional variable WITH_CONTRIB (or similar)
should default to OFF too.

regards

Mark

Show quoted text

On 09/11/16 08:37, Peter Eisentraut wrote:

On 9/17/16 1:21 PM, Yury Zhuravlev wrote:

Now, I published the first version of the patch.

I tried this out. Because of some file moves in initdb and
pg_basebackup, the build fails:

[ 74%] Linking C executable initdb
Undefined symbols for architecture x86_64:
"_fsync_pgdata", referenced from:
_main in initdb.c.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [src/bin/initdb/CMakeFiles/initdb.dir/build.make:177:
src/bin/initdb/initdb] Error 1
make[1]: *** [CMakeFiles/Makefile2:2893:
src/bin/initdb/CMakeFiles/initdb.dir/all] Error 2
make: *** [Makefile:128: all] Error 2

Please submit an updated patch.

I suggest you use git format-patch to produce patches. This is easier
to apply, especially when there are a lot of new files involved. Also
use the git facilities to check for whitespace errors.

Please supply some documentation, such as

- what are the basic commands
- how to set include/library paths, choose configure options
- how to set CFLAGS
- how to see raw build commands
- what are the targets for all/world/check/docs etc.
- explain directory structure

I suggest for now you could put this into a README.cmake file in your
patch. We don't need to commit it that way, but it would help in the
meantime.

When I run cmake without options, it seems to do opportunistic feature
checking. For example, it turns on OpenSSL or Python support if it can
find it, otherwise it turns it off. We need this to be deterministic.
Without options, choose the basic feature set, require all other
features to be turned on explicitly, fail if they can't be found.
Whatever the Autoconf-based build does now has been fairly deliberately
tuned, so there should be very little reason to deviate from that.

The Python check appears to be picking up pieces from two different
Python installations:

-- Found PythonInterp: /usr/local/bin/python (found version "2.7.12")
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.10")

The check results otherwise look OK, but I'm a bit confused about the
order. It checks for some functions before all the header files are
checked for. Is that intentional?

There are a number of changes in .[ch] and .pl files that are unclear
and not explained. Please explain them. You can also submit separate
preliminary patches if you need to do some refactoring. Ultimately, I
would expect this patch not to require C code changes.

Attachments:

cmake_v1_1.patchtext/x-patch; name=cmake_v1_1.patchDownload
diff --git a/src/bin/pg_archivecleanup/CMakeLists.txt b/src/bin/pg_archivecleanup/CMakeLists.txt
index 7c79ac3..06d7be4 100644
--- a/src/bin/pg_archivecleanup/CMakeLists.txt
+++ b/src/bin/pg_archivecleanup/CMakeLists.txt
@@ -7,9 +7,8 @@ include_directories(BEFORE
 add_executable(pg_archivecleanup pg_archivecleanup.c)
 
 target_link_libraries(pg_archivecleanup
-	port
-#	pq
 	pgcommon
+	port
 	${M_LIB}
 )
 
diff --git a/src/bin/pg_basebackup/CMakeLists.txt b/src/bin/pg_basebackup/CMakeLists.txt
index a985e08..a9bdd66 100644
--- a/src/bin/pg_basebackup/CMakeLists.txt
+++ b/src/bin/pg_basebackup/CMakeLists.txt
@@ -12,9 +12,12 @@ endif()
 add_library(common_basebackup STATIC
 	receivelog.c
 	streamutil.c
+	walmethods.c
 )
 
 target_link_libraries(common_basebackup
+	pgfeutils
+	pgcommon
 	port
 	pq
 )
@@ -29,12 +32,8 @@ foreach(loop_var IN ITEMS ${basebackup_list})
 	add_executable(${loop_var} ${loop_var}.c)
 
 	target_link_libraries(${loop_var}
-		pgfeutils
-		port
-		pq
-		pgcommon
-		${M_LIB}
 		common_basebackup
+		${M_LIB}
 	)
 	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
 	if(ZLIB_FOUND)
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 7a24165..9338482 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -18,6 +18,7 @@ set(pgcommon_srv_SRCS
 set(pgcommon_SRCS
 	${pgcommon_srv_SRCS}
 	fe_memutils.c
+	file_utils.c
 	restricted_token.c
 	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
 )
#114Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Peter Eisentraut (#102)
Re: WIP: About CMake v2

Yeah, there seems to be a lot of these. Looking through them almost all
concern the addition of piece of code to wrap putenv. e.g:

--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1350,7 +1350,7 @@ exec_command(const char *cmd,
                         char       *newval;
                         newval = psprintf("%s=%s", envvar, envval);
-                       putenv(newval);
+                       pg_putenv_proxy(newval);
                         success = true;

/*

Where pg_putenv_proxy either calls putenv or pgwin32_putenv (the latter
on windows I'd guess). I wonder if this could have been avoided, since
the original code handles this sort of thing. There are also some minor
- and not immediately obvious - changes to a number of macros in various
includes...If I'm feeling keen I'll experiment to see how far I can get
without any source changes at all.

regards

Mark

On 09/11/16 08:37, Peter Eisentraut wrote:

There are a number of changes in .[ch] and .pl files that are unclear
and not explained. Please explain them. You can also submit separate
preliminary patches if you need to do some refactoring. Ultimately, I
would expect this patch not to require C code changes.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#115Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Mark Kirkwood (#114)
1 attachment(s)
Re: WIP: About CMake v2

Actually, it was not that tricky to separate out the cmake only changes,
and test this on unmodified sources. It appears to work fine for me -
passes 'make check' (needs the v1_1 incremental patch applied of
course). The Patch is attached. I wonder if the original had some
changes for building under latest Windows...(I'm using Ubuntu 16.10,
with cmake 3.5).

regards

Mark

Show quoted text

On 16/11/16 16:00, Mark Kirkwood wrote:

Yeah, there seems to be a lot of these. Looking through them almost
all concern the addition of piece of code to wrap putenv. e.g:

--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1350,7 +1350,7 @@ exec_command(const char *cmd,
char       *newval;
newval = psprintf("%s=%s", envvar, envval);
-                       putenv(newval);
+                       pg_putenv_proxy(newval);
success = true;

/*

Where pg_putenv_proxy either calls putenv or pgwin32_putenv (the
latter on windows I'd guess). I wonder if this could have been
avoided, since the original code handles this sort of thing. There are
also some minor - and not immediately obvious - changes to a number of
macros in various includes...If I'm feeling keen I'll experiment to
see how far I can get without any source changes at all.

regards

Mark

On 09/11/16 08:37, Peter Eisentraut wrote:

There are a number of changes in .[ch] and .pl files that are unclear
and not explained. Please explain them. You can also submit separate
preliminary patches if you need to do some refactoring. Ultimately, I
would expect this patch not to require C code changes.

Attachments:

cmake_v1_minimal.patchtext/x-patch; name=cmake_v1_minimal.patchDownload
diff --git a/.gitignore b/.gitignore
index 4976fd9..99c8297 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,8 @@ lib*.pc
 /Debug/
 /Release/
 /tmp_install/
+/CMakeCache.txt
+/CMakeFiles
+/cmake_install.cmake
+/install_manifest.txt
+/build
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..f9da88e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,1343 @@
+cmake_minimum_required(VERSION 2.8.4)
+
+project(Postgres C)
+
+include(CheckTypeSize)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckIncludeFiles)
+include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
+include(TestBigEndian)
+include(CheckStructHasMember)
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+	message(STATUS "${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}")
+	message(FATAL_ERROR "You must use another folder for build PostgreSQL")
+endif()
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+set(POSTGRES_MAJOR_VERSION 10)
+set(POSTGRES_MINOR_VERSION 0)
+set(POSTGRES_PATCH_VERSION 0)
+set(POSTGRES_VERSION
+  ${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.${POSTGRES_PATCH_VERSION})
+
+set(PG_VERSION "10devel")
+set(PG_VERSION_NUM 100000)
+set(PACKAGE_BUGREPORT "pgsql-bugs@postgresql.org")
+
+ # Offer the user the choice of overriding the installation directories
+set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
+set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
+set(INSTALL_INCLUDE_DIR include CACHE PATH
+  "Installation directory for header files")
+
+if(NOT PGBINDIR)
+	set(PGBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
+endif(NOT PGBINDIR)
+
+if(NOT PGSHAREDIR)
+	set(PGSHAREDIR "${CMAKE_INSTALL_PREFIX}/share/postgresql")
+endif(NOT PGSHAREDIR)
+
+if(NOT SYSCONFDIR)
+	set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
+endif(NOT SYSCONFDIR)
+
+if(NOT INCLUDEDIR)
+	set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT INCLUDEDIR)
+
+if(NOT PKGINCLUDEDIR)
+	set(PKGINCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT PKGINCLUDEDIR)
+
+if(NOT INCLUDEDIRSERVER)
+	set(INCLUDEDIRSERVER "${CMAKE_INSTALL_PREFIX}/include/server")
+endif(NOT INCLUDEDIRSERVER)
+
+if(MSVC)
+	if(NOT LIBDIR)
+		set(LIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+	endif(NOT LIBDIR)
+
+	if(NOT PKGLIBDIR)
+		set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+	endif(NOT PKGLIBDIR)
+else()
+	if(NOT LIBDIR)
+		set(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+	endif(NOT LIBDIR)
+
+	if(NOT PKGLIBDIR)
+		set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+	endif(NOT PKGLIBDIR)
+endif()
+
+if(NOT LOCALEDIR)
+	set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
+endif(NOT LOCALEDIR)
+
+if(NOT DOCDIR)
+	set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT DOCDIR)
+
+if(NOT HTMLDIR)
+	set(HTMLDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT HTMLDIR)
+
+if(NOT MANDIR)
+	set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
+endif(NOT MANDIR)
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+	set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+endif()
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|OpenBSD")
+	set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-x,-soname,")
+endif()
+
+if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-ignored-attributes")
+endif()
+
+if(MSVC)
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
+endif()
+
+test_big_endian(WORDS_BIGENDIAN)
+set(FIND_LIBRARY_USE_LIB64_PATHS ON)
+
+find_package(Perl REQUIRED)
+option(WITH_PERL "libperl is optional" ON)
+if(WITH_PERL)
+	find_package(PerlLibs)
+endif()
+if(PERLLIBS_FOUND)
+	EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts OUTPUT_VARIABLE PERL_CFLAGS)
+	EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts OUTPUT_VARIABLE PERL_LDFLAGS)
+	STRING(REGEX REPLACE "[\r\n]" " " PERL_CFLAGS ${PERL_CFLAGS})
+	STRING(REGEX REPLACE " +$" "" PERL_CFLAGS ${PERL_CFLAGS})
+	STRING(STRIP "${PERL_CFLAGS}" PERL_CFLAGS)
+	STRING(REGEX REPLACE "[\r\n]" " " PERL_LDFLAGS ${PERL_LDFLAGS})
+	STRING(REGEX REPLACE " +$" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+	STRING(REGEX REPLACE "-lperl" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+	if(MINGW AND NOT MSYS)
+		STRING(REGEX REPLACE "\\\\" "/" PERL_LDFLAGS ${PERL_LDFLAGS})
+	endif()
+	STRING(STRIP "${PERL_LDFLAGS}" PERL_LDFLAGS)
+endif()
+
+find_package(BISON REQUIRED)
+find_package(FLEX REQUIRED)
+find_package(Threads)
+
+option(WITH_OPENSSL "OPENSSL is optional" ON)
+if(WITH_OPENSSL)
+	find_package(OpenSSL)
+endif()
+find_package(ZLIB)
+
+option(WITH_PYTHON "Python is optional" ON)
+if(WITH_PYTHON)
+	find_package(PythonInterp)
+	find_package(PythonLibs)
+endif()
+find_package(SELinux)
+
+option(WITH_LIBXML "LIBXML is optional" ON)
+if(WITH_LIBXML)
+	find_package(LibXml2)
+	find_package(LibXslt)
+endif()
+
+option(WITH_TCL "TCL is optional" ON)
+if(WITH_TCL)
+	find_package(TCL)
+endif()
+find_package(LibSocket)
+
+option(USE_PAM "build with PAM support" OFF)
+if(USE_PAM)
+	find_library(PAM_LIB pam)
+	if(NOT PAM_LIB)
+		message(ERROR "library 'pam' is required for PAM")
+	endif()
+endif()
+
+option(USE_LDAP "build with LDAP support" OFF)
+if(USE_LDAP)
+	find_package(LDAP REQUIRED)
+endif()
+
+if(WIN32 OR MINGW)
+	set(NEED_REPL_SNPRINTF ON)
+else()
+	set(NEED_REPL_SNPRINTF OFF)
+endif()
+
+option(ENABLE_NLS "Define if you want National Language Support" OFF)
+if(ENABLE_NLS)
+	include(MakeNLS)
+	find_package(Gettext REQUIRED)
+	find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
+	if(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+		message(FATAL_ERROR "xgettext not found")
+	endif(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+	if(NOT NLS_LANGUAGES)
+		set(NLS_LANGUAGES "ko;cs;pt_BR;zh_CN;ru;fr;de;es;it;tr;ja;pl;zh_TW")
+	endif()
+
+	if(NOT NEED_REPL_SNPRINTF)
+		check_c_source_runs("
+			#include <stdio.h>
+			#include <string.h>
+
+			int main()
+			{
+			  char buf[100];
+
+			  /* can it swap arguments? */
+			  snprintf(buf, 100, \"%2\$d %1\$d\", 3, 4);
+			  if (strcmp(buf, \"4 3\") != 0)
+				return 1;
+			  return 0;
+			}
+		" SNPRINTF_ARG_CONTROL)
+		if(NOT SNPRINTF_ARG_CONTROL)
+			set(NEED_REPL_SNPRINTF ON)
+		endif()
+	endif()
+endif()
+
+option(ENABLE_GSS "Define to build with GSSAPI support." OFF)
+if(ENABLE_GSS)
+	check_include_files(gssapi/gssapi.h HAVE_GSSAPI_GSSAPI_H)
+	check_include_files(gssapi.h HAVE_GSSAPI_H)
+	set(PG_KRB_SRVTAB "FILE:${SYSCONFDIR}/krb5.keytab")
+	if(WIN32)
+		SET(GSS_LIBS "-lgssapi32")
+	else()
+		set(CMAKE_REQUIRED_LIBRARIES_OLD ${CMAKE_REQUIRED_LIBRARIES})
+		set(CMAKE_REQUIRED_LIBRARIES "-lgssapi_krb5")
+		check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+		if(NOT HAVE_GSS_INIT)
+			set(CMAKE_REQUIRED_LIBRARIES "-lgss")
+			check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+			if(NOT HAVE_GSS_INIT)
+				set(CMAKE_REQUIRED_LIBRARIES "-lgssapi -lkrb5 -lcrypto")
+				check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+			endif(NOT HAVE_GSS_INIT)
+		endif(NOT HAVE_GSS_INIT)
+		if(HAVE_GSS_INIT)
+			set(GSS_LIBS ${CMAKE_REQUIRED_LIBRARIES})
+		else()
+			message(FATAL_ERROR "Not found gss_init_sec_context function for GSSAPI")
+		endif()
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_OLD})
+	endif()
+else()
+	set(GSS_LIBS "")
+endif()
+
+option(USE_SYSTEMD "Define to build with systemd support" OFF)
+option(USE_BSD_AUTH "Define to build with BSD Authentication support" OFF)
+option(USE_ASSERT_CHECKING "Define to build with assertion checks." OFF)
+option(USE_BONJOUR "Define to build with Bonjour support." OFF)
+if(USE_BONJOUR)
+	check_include_files(dns_sd.h HAVE_DNS_SD_H)
+	if(NOT HAVE_DNS_SD_H)
+		message(FATAL_ERROR "header file <dns_sd.h> is required for Bonjour")
+	endif()
+endif()
+
+if(NOT MSVC)
+	find_library(DL_LIBRARIES NAMES dl)
+	find_library(M_LIB m)
+	if(NOT M_LIB)
+		set(M_LIB "")
+	endif()
+endif()
+
+if(NOT DL_LIBRARIES)
+	set(DL_LIBRARIES "")
+endif()
+
+if(LIBXML2_FOUND)
+	set(HAVE_LIBXML2 1)
+	set(USE_LIBXML 1)
+endif()
+
+if(LIBXSLT_FOUND)
+	set(HAVE_LIBXSLT 1)
+	set(USE_LIBXSLT 1)
+endif()
+
+if(ZLIB_FOUND)
+	set(HAVE_LIBZ 1)
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCC)
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.3 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.3)
+		# Disable strict-aliasing rules; needed for gcc 3.3+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+	endif()
+
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.4 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.4)
+		# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+	endif()
+
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+		# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexcess-precision=standard")
+	endif()
+
+	# Optimization flags for specific files that benefit from vectorization
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+		set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+	endif()
+
+	option(PROFILE_PID_DIR "Enable to allow profiling output to be saved separately for each process." OFF)
+endif()
+
+if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+	# Disable strict-aliasing rules; needed for gcc 3.3+
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+	# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+
+	# Optimization flags for specific files that benefit from vectorization
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+endif()
+
+if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
+	# Intel's compiler has a bug/misoptimization in checking for
+	# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mp1")
+	# Make sure strict aliasing is off (though this is said to be the default)
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+endif()
+
+check_symbol_exists(strlcpy "stdio.h;string.h" HAVE_DECL_STRLCPY)
+if(NOT HAVE_DECL_STRLCPY)
+	set(HAVE_DECL_STRLCPY 0)
+endif()
+check_symbol_exists(strlcat "stdio.h;string.h" HAVE_DECL_STRLCAT)
+if(NOT HAVE_DECL_STRLCAT)
+	set(HAVE_DECL_STRLCAT 0)
+endif()
+check_symbol_exists(snprintf "stdio.h;string.h" HAVE_DECL_SNPRINTF)
+if(NOT HAVE_DECL_SNPRINTF)
+	set(HAVE_DECL_SNPRINTF 0)
+endif()
+check_symbol_exists(vsnprintf "stdio.h;string.h" HAVE_DECL_VSNPRINTF)
+if(NOT HAVE_DECL_VSNPRINTF)
+	set(HAVE_DECL_VSNPRINTF 0)
+endif()
+check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV)
+check_symbol_exists(srandom "stdlib.h" HAVE_SRANDOM)
+
+# Test math functions
+check_symbol_exists(rint "math.h" HAVE_RINT)
+
+if(WIN32 AND NOT MINGW)
+	set(LIB_M "")
+else()
+	set(LIB_M m)
+endif()
+set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${LIB_M}")
+check_c_source_compiles("
+	#include <math.h>
+	double glob_double;
+	int main(void){
+		return isinf(glob_double) ? 0 : 1;
+	}
+" HAVE_ISINF)
+
+check_include_files(ieeefp.h HAVE_IEEEFP_H)
+if(NOT HAVE_IEEEFP_H)
+	set(HAVE_IEEEFP_H 0)
+else()
+	set(HAVE_IEEEFP_H 1)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ieeefp.h")
+endif()
+
+check_include_files(fp_class.h HAVE_FP_CLASS_H)
+if (HAVE_FP_CLASS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fp_class.h")
+endif()
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};float.h;math.h")
+
+# Need for isinf implementation
+check_function_exists(fpclass HAVE_FPCLASS)
+check_function_exists(fp_class HAVE_FP_CLASS)
+check_function_exists(fp_class_d HAVE_FP_CLASS_D)
+check_function_exists(class HAVE_CLASS)
+
+check_function_exists(getpeereid HAVE_GETPEEREID)
+check_function_exists(getpeerucred HAVE_GETPEERUCRED)
+check_function_exists(memmove HAVE_MEMMOVE)
+if(MSVC)
+	check_function_exists(_mbstowcs_l HAVE_MBSTOWCS_L)
+else()
+	check_function_exists(mbstowcs_l HAVE_MBSTOWCS_L)
+endif()
+
+check_function_exists(towlower HAVE_TOWLOWER)
+check_function_exists(wcstombs HAVE_WCSTOMBS)
+
+check_function_exists(mkdtemp HAVE_MKDTEMP)
+check_function_exists(mkstemp HAVE_MKSTEMP)
+check_function_exists(poll HAVE_POLL)
+
+check_function_exists(getrlimit HAVE_GETRLIMIT)
+check_function_exists(readlink HAVE_READLINK)
+check_function_exists(cbrt HAVE_CBRT)
+check_function_exists(pthread_is_threaded_np HAVE_PTHREAD_IS_THREADED_NP)
+check_function_exists(random HAVE_RANDOM)
+check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
+
+#So strange
+check_function_exists(pstat HAVE_PSTAT)
+
+check_include_files(ifaddrs.h HAVE_IFADDRS_H)
+if(HAVE_IFADDRS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ifaddrs.h")
+endif()
+check_function_exists(getifaddrs HAVE_GETIFADDRS)
+
+if(MSVC)
+	set(HAVE_MINIDUMP_TYPE 1)
+endif()
+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fcntl.h")
+	check_function_exists(posix_fadvise HAVE_DECL_POSIX_FADVISE)
+	if(HAVE_DECL_POSIX_FADVISE)
+		set(HAVE_POSIX_FADVISE 1)
+	endif()
+endif()
+
+find_library(CRYPT_LIB crypt)
+if(CRYPT_LIB)
+	set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${CRYPT_LIB}")
+endif()
+check_include_files(crypt.h HAVE_CRYPT_H)
+if(HAVE_CRYPT_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};crypt.h")
+endif()
+check_function_exists(crypt HAVE_CRYPT)
+
+check_include_files(unistd.h HAVE_UNISTD_H)
+if(HAVE_UNISTD_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};unistd.h")
+endif()
+check_function_exists(fdatasync HAVE_DECL_FDATASYNC)
+check_function_exists(sys_siglist HAVE_DECL_FDATASYNC)
+check_function_exists(setproctitle HAVE_SETPROCTITLE)
+check_function_exists(setsid HAVE_SETSID)
+if(HAVE_UNISTD_H)
+	check_symbol_exists(sys_siglist "signal.h;unistd.h" HAVE_DECL_SYS_SIGLIST)
+	check_symbol_exists(opterr "unistd.h" HAVE_INT_OPTERR)
+	check_symbol_exists(optreset "unistd.h" HAVE_INT_OPTRESET)
+else()
+	check_symbol_exists(sys_siglist "signal.h" HAVE_DECL_SYS_SIGLIST)
+endif()
+
+set(CMAKE_MACOSX_RPATH 1)
+#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+if(MSVC)
+	check_function_exists(_fseeki64 HAVE_FSEEKO)
+else()
+	check_function_exists(fseeko HAVE_FSEEKO)
+endif()
+
+if(NOT MSVC)
+	check_include_files(dlfcn.h HAVE_DLFCN_H)
+	if(HAVE_DLFCN_H)
+		set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};dlfcn.h")
+	endif()
+	set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARIES})
+	check_function_exists(dlopen HAVE_DLOPEN)
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES "")
+check_include_files(strings.h HAVE_STRINGS_H)
+check_include_files(string.h HAVE_STRING_H)
+if(HAVE_STRINGS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};strings.h")
+endif()
+if(HAVE_STRING_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};string.h")
+endif()
+check_function_exists(fls HAVE_FLS)
+
+check_include_files(getopt.h HAVE_GETOPT_H)
+if(HAVE_GETOPT_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};getopt.h")
+endif()
+
+check_function_exists(strtoll HAVE_STRTOLL)
+check_function_exists(strtoq HAVE_STRTOQ)
+check_function_exists(strtoull HAVE_STRTOULL)
+check_function_exists(strtouq HAVE_STRTOUQ)
+
+check_type_size("struct option" HAVE_STRUCT_OPTION)
+check_function_exists(getopt HAVE_GETOPT)
+check_function_exists(getopt_long HAVE_GETOPT_LONG)
+check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
+check_function_exists(getpwuid_r HAVE_GETPWUID_R)
+check_function_exists(strerror_r HAVE_STRERROR_R)
+check_function_exists(strerror HAVE_STRERROR)
+#I am not sure about this code.
+check_c_source_runs("
+#include <string.h>
+int main(void){
+#ifndef _AIX
+int strerror_r(int, char *, size_t);
+#else
+/* Older AIX has 'int' for the third argument so we don't test the args. */
+int strerror_r();
+#endif
+return 0;
+}
+" STRERROR_R_INT)
+
+check_c_source_runs("
+int main(void){
+int a = 0; int *p = &a; int r;
+ __asm__ __volatile__ (\" lwarx %0,0,%1,1\n\" : \"=&r\"(r) : \"r\"(p));
+return 0;
+}
+" HAVE_PPC_LWARX_MUTEX_HINT)
+
+check_c_source_runs("
+#include <machine/vmparam.h>
+#include <sys/exec.h>
+int main(void){
+PS_STRINGS->ps_nargvstr = 1;
+PS_STRINGS->ps_argvstr = \"foo\";
+return 0;
+}
+" HAVE_PS_STRINGS)
+
+check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
+if(HAVE_SYS_MMAN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/mman.h")
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -lrt")
+endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+check_function_exists(shm_open HAVE_SHM_OPEN)
+
+check_include_files(sys/time.h HAVE_SYS_TIME_H)
+check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
+if(HAVE_SYS_TIME_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/time.h")
+endif()
+if(HAVE_SYS_RESOURCE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/resource.h")
+endif()
+check_function_exists(getrusage HAVE_GETRUSAGE)
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+
+check_include_files(utime.h HAVE_UTIME_H)
+if(HAVE_UTIME_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};utime.h")
+endif()
+check_function_exists(utime HAVE_UTIME)
+check_function_exists(utimes HAVE_UTIMES)
+
+set(OLD_INCLUDES "${CMAKE_EXTRA_INCLUDE_FILES}")
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/in.h;arpa/inet.h")
+check_function_exists(inet_aton HAVE_INET_ATON)
+set(CMAKE_EXTRA_INCLUDE_FILES "${OLD_INCLUDES}")
+
+if(OPENSSL_FOUND)
+	set(USE_OPENSSL 1)
+	set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}")
+	set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
+	check_function_exists(SSL_get_current_compression HAVE_SSL_GET_CURRENT_COMPRESSION)
+endif(OPENSSL_FOUND)
+
+
+check_include_files(sys/un.h HAVE_SYS_UN_H)
+check_include_files(ucred.h HAVE_UCRED_H)
+check_include_files(sys/ucred.h HAVE_SYS_UCRED_H)
+check_include_files(sys/types.h HAVE_SYS_TYPES_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H)
+check_include_files(stdint.h HAVE_STDINT_H)
+
+check_include_files(sys/select.h HAVE_SYS_SELECT_H)
+check_include_files(sys/poll.h HAVE_SYS_POLL_H)
+check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
+check_include_files(sys/pstat.h HAVE_SYS_PSTAT_H)
+check_include_files(sys/tas.h HAVE_SYS_TAS_H)
+check_include_files(dld.h HAVE_DLD_H)
+check_include_files(langinfo.h HAVE_LANGINFO_H)
+check_include_files(poll.h HAVE_POLL_H)
+
+check_include_files(wchar.h HAVE_WCHAR_H)
+check_include_files(wctype.h HAVE_WCTYPE_H)
+check_include_files(winldap.h HAVE_WINLDAP_H)
+check_include_files(pwd.h HAVE_PWD_H)
+check_include_files(crtdefs.h HAVE_CRTDEFS_H)
+
+check_include_files(nbtool_config.h HAVE_NBTOOL_CONFIG_H)
+
+check_include_files(mbarrier.h HAVE_MBARRIER_H)
+check_include_files(atomic.h HAVE_ATOMIC_H)
+
+check_include_files(netinet/tcp.h HAVE_NETINET_TCP_H)
+check_include_files(net/if.h HAVE_NET_IF_H)
+
+check_include_files(pam/pam_appl.h HAVE_PAM_PAM_APPL_H)
+check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
+if(USE_PAM AND NOT (HAVE_PAM_PAM_APPL_H OR HAVE_SECURITY_PAM_APPL_H))
+	message(FATAL_ERROR "header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.")
+endif()
+
+check_include_files(syslog.h HAVE_SYSLOG)
+check_include_files(termios.h HAVE_TERMIOS_H)
+
+if(USE_SYSTEMD)
+	check_include_files(systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
+	if(NOT HAVE_SYSTEMD_SD_DAEMON_H)
+		message(FATAL_ERROR "header file <systemd/sd-daemon.h> is required for systemd support")
+	endif()
+endif()
+
+check_include_files(bsd_auth.h HAVE_BSD_AUTH_H)
+if(USE_BSD_AUTH AND NOT HAVE_BSD_AUTH_H)
+	message(FATAL_ERROR "header file <bsd_auth.h> is required for BSD Authentication support")
+endif()
+
+
+#Check ReadLine includes
+option(WITH_READLINE "do not use GNU Readline nor BSD Libedit for editing" ON)
+if(WITH_READLINE AND NOT MSVC)
+	find_package(Readline)
+	if(READLINE_FOUND)
+		#Sometimes for redline need curses
+		message(STATUS "Found Readline: ${READLINE_LIBRARY}")
+		find_package(Curses)
+		if(NOT CURSES_FOUND)
+			set(CURSES_NEED_NCURSES TRUE)
+		endif()
+		find_package(Curses)
+		check_include_files("stdio.h;readline.h" HAVE_READLINE_H)
+		check_include_files("stdio.h;history.h" HAVE_HISTORY_H)
+		check_include_files("stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H)
+		check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H)
+		check_include_files("stdio.h;editline/history.h" HAVE_EDITLINE_HISTORY_H)
+		check_include_files("stdio.h;editline/readline.h" HAVE_EDITLINE_READLINE_H)
+
+
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${READLINE_LIBRARY})
+		if(CURSES_FOUND)
+			set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CURSES_LIBRARIES})
+			set(READLINE_LIBRARY ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
+		endif()
+		check_function_exists(rl_completion_append_character HAVE_RL_COMPLETION_APPEND_CHARACTER)
+		check_function_exists(rl_completion_matches HAVE_RL_COMPLETION_MATCHES)
+		check_function_exists(rl_filename_completion_function HAVE_RL_FILENAME_COMPLETION_FUNCTION)
+		check_function_exists(rl_reset_screen_size HAVE_RL_RESET_SCREEN_SIZE)
+		check_function_exists(append_history HAVE_APPEND_HISTORY)
+		check_function_exists(history_truncate_file HAVE_HISTORY_TRUNCATE_FILE)
+	endif(READLINE_FOUND)
+endif()
+
+if(READLINE_FOUND)
+	set(HAVE_LIBREADLINE TRUE)
+else()
+	set(READLINE_LIBRARY "")
+	set(HAVE_LIBREADLINE FALSE)
+endif()
+
+check_include_files("sys/ipc.h" HAVE_SYS_IPC_H)
+check_include_files("sys/sem.h" HAVE_SYS_SEM_H)
+check_include_files("sys/shm.h" HAVE_SYS_SHM_H)
+check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+
+# Check if _GNU_SOURCE is available.
+check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
+check_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_DECL_F_FULLFSYNC)
+
+include(ReplacePython)
+include(CheckCpuID)
+include(CheckSSE42)
+
+if(MSVC)
+	if(HAVE__GET_CPUID OR HAVE__CPUID)
+		set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+	endif()
+else()
+	if(HAVE_SSE42 AND HAVE_SSE42_INTRINSICS)
+		set(USE_SSE42_CRC32C 1)
+	elseif(HAVE_SSE42_INTRINSICS AND (HAVE__GET_CPUID OR HAVE__CPUID))
+		set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+	else()
+		set(USE_SLICING_BY_8_CRC32C 1)
+	endif()
+endif()
+
+include(FuncAcceptArgtypes)
+include(CheckTypeAlignment)
+check_type_alignment(double ALIGNOF_DOUBLE)
+check_type_alignment(int ALIGNOF_INT)
+check_type_alignment(long ALIGNOF_LONG)
+check_type_alignment("long long int" ALIGNOF_LONG_LONG_INT)
+check_type_alignment(short ALIGNOF_SHORT)
+
+check_type_size(int64 HAVE_INT64)
+check_type_size(uint64 HAVE_UINT64)
+check_type_size(int8 HAVE_INT8)
+check_type_size(uint8 HAVE_UINT8)
+check_type_size("void *" VOID_POINTER_SIZE)
+math(EXPR VOID_POINTER_SIZE_BIT "${VOID_POINTER_SIZE}*8")
+check_type_size("long int" LONG_INT_SIZE)
+check_type_size("long long int" HAVE_LONG_LONG_INT)
+check_type_size("long" SIZEOF_LONG)
+check_type_size("size_t" SIZEOF_SIZE_T)
+check_type_size(__int128 PG_INT128_TYPE)
+if(PG_INT128_TYPE AND NOT WIN32)
+	set(HAVE_INT128 1)
+	set(PG_INT128_TYPE __int128)
+endif()
+
+check_include_files("locale.h" HAVE_LOCALE_H)
+check_include_files("xlocale.h" HAVE_XLOCALE_H)
+if(HAVE_LOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};locale.h")
+endif()
+check_type_size("locale_t" HAVE_LOCALE_T)
+if(NOT HAVE_LOCALE_T AND HAVE_XLOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+	check_type_size("locale_t" HAVE_LOCALE_T)
+	if(HAVE_LOCALE_T)
+		set(LOCALE_T_IN_XLOCALE 1)
+	else()
+		set(LOCALE_T_IN_XLOCALE 0)
+	endif()
+else()
+	set(LOCALE_T_IN_XLOCALE 0)
+endif()
+
+check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+#check_function_exists(wcstombs_l HAVE_WCSTOMBS_L)
+if(NOT HAVE_WCSTOMBS_L AND HAVE_XLOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+	check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+	if(HAVE_WCSTOMBS_L)
+		set(WCSTOMBS_L_IN_XLOCALE 1)
+	else()
+		set(WCSTOMBS_L_IN_XLOCALE 0)
+	endif()
+else()
+	set(WCSTOMBS_L_IN_XLOCALE 0)
+endif()
+
+if(LONG_INT_SIZE EQUAL 8)
+	set(PG_INT64_TYPE "long int")
+	set(HAVE_LONG_INT_64 ${LONG_INT_SIZE})
+else(LONG_INT_SIZE EQUAL 8)
+	if(HAVE_LONG_LONG_INT EQUAL 8)
+		set(PG_INT64_TYPE "long long int")
+		set(HAVE_LONG_LONG_INT_64 1)
+	else()
+		message(FATAL_ERROR "Cannot find a working 64-bit integer type.")
+	endif()
+endif(LONG_INT_SIZE EQUAL 8)
+
+message(STATUS "PG_INT64_TYPE: ${PG_INT64_TYPE} HAVE_LONG_INT_64: ${HAVE_LONG_INT_64}")
+# Compute maximum alignment of any basic type.
+# We assume long's alignment is at least as strong as char, short, or int;
+# but we must check long long (if it exists) and double.
+
+if(NOT MAXIMUM_ALIGNOF)
+	set(MAX_ALIGNOF ${ALIGNOF_LONG})
+	if(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+		set(MAX_ALIGNOF ${ALIGNOF_DOUBLE})
+	endif(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+	if(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+		set(MAX_ALIGNOF ${HAVE_LONG_LONG_INT_64})
+	endif(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+	if(MAX_ALIGNOF)
+		set(MAXIMUM_ALIGNOF ${MAX_ALIGNOF})
+	endif(MAX_ALIGNOF)
+endif(NOT MAXIMUM_ALIGNOF)
+message(STATUS "MAXIMUM_ALIGNOF ${MAXIMUM_ALIGNOF}")
+
+if(HAVE_LONG_LONG_INT_64)
+	if(NOT NEED_REPL_SNPRINTF)
+		include(CheckSnprintfLongLongIntModifier)
+		if(NOT LONG_LONG_INT_MODIFIER)
+			set(LONG_LONG_INT_MODIFIER "ll")
+			set(NEED_REPL_SNPRINTF ON)
+		endif(NOT LONG_LONG_INT_MODIFIER)
+	else(NOT NEED_REPL_SNPRINTF)
+		set(LONG_LONG_INT_MODIFIER "ll")
+	endif(NOT NEED_REPL_SNPRINTF)
+else(HAVE_LONG_LONG_INT_64)
+	set(LONG_LONG_INT_MODIFIER "l")
+endif(HAVE_LONG_LONG_INT_64)
+
+if(HAVE_LONG_LONG_INT_64)
+	message(STATUS "HAVE_LONG_LONG_INT_64 ${HAVE_LONG_LONG_INT_64}")
+endif()
+if(HAVE_LONG_LONG_INT_64)
+	include(CheckLLConstants)
+endif()
+
+#TODO: some strange here
+option(USE_FLOAT4_BYVAL "float4 values are passed by value" ON)
+if(USE_FLOAT4_BYVAL)
+	set(FLOAT4PASSBYVAL 1)
+else(USE_FLOAT4_BYVAL)
+	set(FLOAT4PASSBYVAL 0)
+endif(USE_FLOAT4_BYVAL)
+
+if(VOID_POINTER_SIZE EQUAL 8)
+	option(USE_FLOAT8_BYVAL "float8 values are passed by value" ON)
+else()
+	option(USE_FLOAT8_BYVAL "float8 values are passed by value" OFF)
+endif()
+if(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+	message(FATAL_ERROR "USE_FLOAT8_BYVAL is not supported on 32-bit platforms.")
+elseif(USE_FLOAT8_BYVAL AND VOID_POINTER_SIZE EQUAL 8)
+	set(FLOAT8PASSBYVAL 1)
+	set(USE_FLOAT8_BYVAL 1)
+else()
+	set(FLOAT8PASSBYVAL 0)
+	set(USE_FLOAT8_BYVAL 0)
+endif(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+
+if (_GNU_SOURCE)
+	add_definitions(-D_GNU_SOURCE)
+endif()
+if(Threads_FOUND)
+	set(ENABLE_THREAD_SAFETY 1)
+	set(THREADS_PREFER_PTHREAD_FLAG ON)
+	set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS")
+	if(THREADS_HAVE_PTHREAD_ARG)
+		set(PTHREAD_CFLAGS "${PTHREAD_CFLAGS} -pthread")
+	endif()
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PTHREAD_CFLAGS}")
+endif()
+
+set(PORT_DIR "${PROJECT_SOURCE_DIR}/src/port")
+set(PQ_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/libpq")
+set(MB_UTILS_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/utils/mb")
+
+
+set(fallback_SRCS "")
+
+if(NOT HAVE_DECL_STRLCPY)
+  set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcpy.c")
+endif(NOT HAVE_DECL_STRLCPY)
+
+if(NOT HAVE_DECL_STRLCAT)
+	set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcat.c")
+endif(NOT HAVE_DECL_STRLCAT)
+
+if(NOT HAVE_GETPEEREID)
+	set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/getpeereid.c")
+endif(NOT HAVE_GETPEEREID)
+
+set(TABLE_BLOCKSIZE 8 CACHE STRING "set table block size in kB")
+
+if(TABLE_BLOCKSIZE EQUAL 1)
+	set(BLCKSZ 1024)
+elseif(TABLE_BLOCKSIZE EQUAL 2)
+	set(BLCKSZ 2048)
+elseif(TABLE_BLOCKSIZE EQUAL 4)
+	set(BLCKSZ 4096)
+elseif(TABLE_BLOCKSIZE EQUAL 8)
+	set(BLCKSZ 8192)
+elseif(TABLE_BLOCKSIZE EQUAL 16)
+	set(BLCKSZ 16384)
+elseif(TABLE_BLOCKSIZE EQUAL 32)
+	set(BLCKSZ 32768)
+else(TABLE_BLOCKSIZE EQUAL 1)
+	message(FATAL_ERROR "Invalid block size. Allowed values are 1,2,4,8,16,32.")
+endif(TABLE_BLOCKSIZE EQUAL 1)
+
+message(STATUS "BLCKSZ - ${BLCKSZ}")
+
+set(SEGSIZE 1 CACHE STRING "set table segment size in GB")
+math(EXPR RELSEG_SIZE "(1024 / ${TABLE_BLOCKSIZE}) * ${SEGSIZE} * 1024")
+
+set(WAL_BLOCKSIZE 8 CACHE STRING "set WAL block size in kB")
+
+if(WAL_BLOCKSIZE EQUAL 1)
+	set(XLOG_BLCKSZ 1024)
+elseif(WAL_BLOCKSIZE EQUAL 2)
+	set(XLOG_BLCKSZ 2048)
+elseif(WAL_BLOCKSIZE EQUAL 4)
+	set(XLOG_BLCKSZ 4096)
+elseif(WAL_BLOCKSIZE EQUAL 8)
+	set(XLOG_BLCKSZ 8192)
+elseif(WAL_BLOCKSIZE EQUAL 16)
+	set(XLOG_BLCKSZ 16384)
+elseif(WAL_BLOCKSIZE EQUAL 32)
+	set(XLOG_BLCKSZ 32768)
+elseif(WAL_BLOCKSIZE EQUAL 64)
+	set(XLOG_BLCKSZ 65536)
+else(WAL_BLOCKSIZE EQUAL 1)
+	message(FATAL_ERROR "Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64.")
+endif(WAL_BLOCKSIZE EQUAL 1)
+
+message(STATUS "XLOG_BLCKSZ - ${XLOG_BLCKSZ}")
+
+set(WAL_SEGSIZE 16 CACHE STRING "set WAL segment size in MB")
+
+if (";1;2;4;8;16;32;64;" MATCHES ";${WAL_SEGSIZE};")
+	math(EXPR XLOG_SEG_SIZE "${WAL_SEGSIZE} * 1024 * 1024")
+else()
+	message(FATAL_ERROR "${WAL_SEGSIZE} Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.")
+endif()
+
+message(STATUS "XLOG_SEG_SIZE - ${XLOG_SEG_SIZE}")
+
+option(HAVE_ATOMICS "Define to ON if you want to use atomics if available." ON)
+
+if(HAVE_ATOMICS)
+	check_c_source_compiles("
+		int main(void){
+			char lock = 0;
+			__sync_lock_test_and_set(&lock, 1);
+			__sync_lock_release(&lock);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_CHAR_TAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int lock = 0;
+			__sync_lock_test_and_set(&lock, 1);
+			__sync_lock_release(&lock);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT32_TAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int val = 0;
+			__sync_val_compare_and_swap(&val, 0, 37);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT32_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			${PG_INT64_TYPE} lock = 0;
+			__sync_val_compare_and_swap(&lock, 0, (${PG_INT64_TYPE}) 37);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT64_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int val = 0;
+			int expect = 0;
+			__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+			return 0;
+		}
+	" HAVE_GCC__ATOMIC_INT32_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			${PG_INT64_TYPE} val = 0;
+			${PG_INT64_TYPE} expect = 0;
+			__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+			return 0;
+		}
+	" HAVE_GCC__ATOMIC_INT64_CAS)
+endif(HAVE_ATOMICS)
+
+check_c_source_runs("
+	int main(void){
+		static unsigned long int x = __builtin_bswap32(0xaabbccdd);
+		return 0;
+	}
+" HAVE__BUILTIN_BSWAP32)
+
+check_c_source_runs("
+	int main(void){
+		static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);
+		return 0;
+	}
+" HAVE__BUILTIN_BSWAP64)
+
+check_c_source_runs("
+	int main(void){
+		static int x; static int y[__builtin_constant_p(x) ? x : 1];
+		return 0;
+	}
+" HAVE__BUILTIN_CONSTANT_P)
+
+check_c_source_runs("
+	int main(void){
+		int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)];
+		return 0;
+	}
+" HAVE__BUILTIN_TYPES_COMPATIBLE_P)
+
+check_c_source_runs("
+	int main(void){
+		__builtin_unreachable();
+		return 0;
+	}
+" HAVE__BUILTIN_UNREACHABLE)
+
+check_c_source_runs("
+	int main(void){
+		{ _Static_assert(1, \"foo\"); }
+		return 0;
+	}
+" HAVE__STATIC_ASSERT)
+
+if(NOT PGPORT)
+	set(PGPORT 5432)
+endif(NOT PGPORT)
+
+include(CheckFlexibleArray)
+
+check_c_source_compiles("
+	#include <sys/time.h>
+	int main(void){
+		struct timeval *tp;
+		struct timezone *tzp;
+		gettimeofday(tp,tzp);
+		return 0;
+	}
+" GETTIMEOFDAY_2ARG)
+
+if(NOT GETTIMEOFDAY_2ARG)
+	set(GETTIMEOFDAY_1ARG 1)
+endif(NOT GETTIMEOFDAY_2ARG)
+
+check_c_source_compiles("
+	#include <time.h>
+	int main(void){
+		int res;
+	#ifndef __CYGWIN__
+		res = timezone / 60;
+	#else
+		res = _timezone / 60;
+	#endif
+		return 0;
+	}
+" HAVE_INT_TIMEZONE)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		printf(\"%s\", __func__);
+		return 0;
+	}
+" HAVE_FUNCNAME__FUNC)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		printf(\"%s\", __FUNCTION__);
+		return 0;
+	}
+" HAVE_FUNCNAME__FUNCTION)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		#define debug(...) fprintf(stderr, __VA_ARGS__)
+		debug(\"%s\", \"blarg\");
+		return 0;
+	}
+" HAVE__VA_ARGS)
+
+check_struct_has_member("struct tm" tm_zone "sys/types.h;time.h" HAVE_TM_ZONE LANGUAGE C)
+check_struct_has_member("struct tm" tm_gmtoff "sys/types.h;time.h" HAVE_STRUCT_TM_TM_ZONE LANGUAGE C)
+set(CMAKE_EXTRA_INCLUDE_FILES "time.h")
+check_type_size("*tzname" HAVE_TZNAME)
+
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+	set(CMAKE_REQUIRED_FLAGS "-Werror")
+endif()
+check_c_source_compiles("
+	extern int pgac_write(int ignore, const char *fmt,...) __attribute__((format(gnu_printf, 2, 3)));
+	int main(void){return 0;}
+" PG_PRINTF_ATTRIBUTE)
+
+if(PG_PRINTF_ATTRIBUTE)
+	set(PG_PRINTF_ATTRIBUTE gnu_printf)
+else(PG_PRINTF_ATTRIBUTE)
+	set(PG_PRINTF_ATTRIBUTE printf)
+endif(PG_PRINTF_ATTRIBUTE)
+
+if(NOT MEMSET_LOOP_LIMIT)
+	set(MEMSET_LOOP_LIMIT 1024)
+endif(NOT MEMSET_LOOP_LIMIT)
+
+
+if(WIN32 OR MINGW)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;winsock2.h;ws2tcpip.h")
+else()
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/socket.h;netdb.h")
+endif()
+
+check_type_size("struct addrinfo" HAVE_STRUCT_ADDRINFO)
+check_type_size("struct cmsgcred" HAVE_STRUCT_CMSGCRED)
+if(HAVE_STRUCT_ADDRINFO)
+	CHECK_STRUCT_HAS_MEMBER("struct addrinfo" sa_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_SA_LEN LANGUAGE C)
+	if(NOT (WIN32 OR MINGW))
+		set(HAVE_GETADDRINFO 1)
+	endif()
+endif(HAVE_STRUCT_ADDRINFO)
+
+check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
+if(HAVE_STRUCT_SOCKADDR_STORAGE)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN LANGUAGE C)
+endif(HAVE_STRUCT_SOCKADDR_STORAGE)
+
+# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
+if(HAVE_SYS_UN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/un.h")
+else(HAVE_SYS_UN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
+endif(HAVE_SYS_UN_H)
+check_type_size("struct sockaddr_un" HAVE_UNIX_SOCKETS)
+
+if(WIN32)
+	set(HAVE_IPV6 1)
+else()
+	set(CMAKE_EXTRA_INCLUDE_FILES "netinet/in.h")
+	check_type_size("struct sockaddr_in6" HAVE_IPV6)
+endif()
+
+set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/ipc.h;sys/sem.h")
+check_type_size("union semun" HAVE_UNION_SEMUN)
+
+check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
+
+check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
+
+if(WIN32 OR MINGW)
+	set(USE_WIN32_SEMAPHORES 1)
+	set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_sema.c")
+else(WIN32 OR MINGW)
+	if(USE_NAMED_POSIX_SEMAPHORES)
+		set(USE_NAMED_POSIX_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+	elseif(USE_UNNAMED_POSIX_SEMAPHORES)
+		set(USE_UNNAMED_POSIX_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+	else(USE_NAMED_POSIX_SEMAPHORES)
+		set(USE_SYSV_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_sema.c")
+	endif(USE_NAMED_POSIX_SEMAPHORES)
+endif(WIN32 OR MINGW)
+
+#Realy bad name for win32
+set(USE_SYSV_SHARED_MEMORY 1)
+if(WIN32 OR MINGW)
+	set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_shmem.c")
+else(WIN32 OR MINGW)
+	set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_shmem.c")
+endif(WIN32 OR MINGW)
+
+option(HAVE_SPINLOCKS "Define to ON if you have spinlocks." ON)
+
+
+option(USE_INTEGER_DATETIMES "Define to ON if you want 64-bit integer timestamp and interval support." ON)
+
+if(WIN32)
+	option(HAVE_SYMLINK "Define to ON if you have the `symlink' function." ON)
+else(WIN32)
+	set(HAVE_SYMLINK 1)
+endif(WIN32)
+
+option(PG_KRB_SRVNAM "Define to the name of the default PostgreSQL service principal in Kerberos (GSSAPI)." "postgres")
+
+#TODO: Need test this
+if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+	if(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+		set(TAS sunstudio_sparc.s)
+	else(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+		set(TAS sunstudio_x86.s)
+	endif(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+elseif(CMAKE_C_COMPILER_ID STREQUAL "HP-UX")
+	set(TAS hpux_hppa.s)
+else(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+	set(TAS dummy.s)
+endif(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+
+if(WIN32 OR MINGW)
+	set(CMAKE_EXTRA_INCLUDE_FILES
+		${CMAKE_EXTRA_INCLUDE_FILES}
+		windows.h
+		string.h
+		dbghelp.h
+	)
+	set(CMAKE_REQUIRED_DEFINITIONS "WIN32_LEAN_AND_MEAN")
+	check_type_size(MINIDUMP_TYPE NAVE_MINIDUMP_TYPE)
+endif(WIN32 OR MINGW)
+
+set(WIN32_STACK_RLIMIT 4194304)
+if(WIN32)
+	add_definitions(-DWIN32_STACK_RLIMIT=${WIN32_STACK_RLIMIT})
+endif()
+
+if(NEED_REPL_SNPRINTF)
+	option(USE_REPL_SNPRINTF "Use replacement snprintf() functions." ON)
+endif()
+
+include(GenDef)
+#Not work correctly for postgres see bug: 
+#https://gitlab.kitware.com/cmake/cmake/issues/16161
+#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+
+include(RegressCheck)
+
+# Need add sco and unixware?
+if(WIN32 OR MINGW)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/win32.h)
+elseif(APPLE)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/hpux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/newtbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/solaris.h)
+elseif(CYGWIN)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/cygwin.h)
+else(WIN32 OR MINGW)
+	message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+# Try make fake host tuple for regress and isolation tests
+if(MINGW AND VOID_POINTER_SIZE EQUAL 8)
+	set(HOST_TUPLE "x86_64-w64-mingw32")
+elseif(MINGW AND VOID_POINTER_SIZE EQUAL 4)
+	set(HOST_TUPLE "i686-pc-mingw32")
+elseif(CYGWIN)
+	set(HOST_TUPLE "i686-pc-cygwin")
+elseif(MSVC AND VOID_POINTER_SIZE EQUAL 4)
+	set(HOST_TUPLE "i686-pc-win32vc")
+else()
+	set(HOST_TUPLE ${CMAKE_HOST_SYSTEM})
+endif()
+
+set(WITH_UUID "OFF" CACHE STRING "type of uuid lib [bsd, e2fs, ossp]")
+if(WITH_UUID)
+	find_package(LibUUID)
+
+	if(WITH_UUID STREQUAL "bsd")
+		set(HAVE_UUID_BSD 1)
+		set(UUID_EXTRA_OBJS
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+		)
+	elseif(WITH_UUID STREQUAL "e2fs")
+		set(HAVE_UUID_E2FS 1)
+		set(UUID_EXTRA_OBJS
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+		)
+	elseif(WITH_UUID STREQUAL "ossp")
+		set(HAVE_UUID_OSSP 1)
+		set(UUID_EXTRA_OBJS "")
+	else()
+		message(WARNING "Not correct type of uuid lib:${WITH_UUID}")
+	endif()
+endif()
+
+file(GENERATE OUTPUT ${PROJECT_SOURCE_DIR}/src/include/pg_config_os.h
+	INPUT ${pgos_include_SRCS})
+
+if(MINGW OR MSVC)
+	include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32")
+endif()
+
+if(MSVC)
+	include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32_msvc")
+endif()
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_ext_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_ext.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_paths_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/port/pg_config_paths.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/PGXS.cmake.in"
+	"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake"
+	@ONLY
+)
+
+install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake
+		DESTINATION ${LIBDIR}/cmake)
+
+
+option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
+mark_as_advanced(CMAKE_USE_FOLDERS)
+
+macro(CMAKE_SET_TARGET_FOLDER tgt folder)
+	if(CMAKE_USE_FOLDERS)
+		set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+		if(MSVC AND TARGET ${tgt})
+			set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
+		endif()
+	else()
+		set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+	endif()
+endmacro()
+
+# Add sub-directories
+add_subdirectory(src)
+add_subdirectory(contrib)
+
+message(STATUS "------------------")
+message(STATUS "    Conclusion")
+message(STATUS "Host tuple: ${HOST_TUPLE}")
+message(STATUS "OpenSSL: ${OPENSSL_FOUND} version: ${OPENSSL_VERSION} libs: ${OPENSSL_LIBRARIES}")
+message(STATUS "Python: ${PYTHONINTERP_FOUND}")
+message(STATUS "PythonLibs: ${PYTHONLIBS_FOUND}")
+message(STATUS "PerlLibs: ${PERLLIBS_FOUND}")
+message(STATUS "LibXML2: ${LIBXML2_FOUND}")
+message(STATUS "LibXslt: ${LIBXSLT_FOUND}")
+message(STATUS "TCL: ${TCL_FOUND}")
+message(STATUS "PAM: ${PAM_LIB}")
+message(STATUS "------------------")
diff --git a/PGXS.cmake.in b/PGXS.cmake.in
new file mode 100644
index 0000000..01a1100
--- /dev/null
+++ b/PGXS.cmake.in
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 2.8)
+
+set(POSTGRES_MAJOR_VERSION "@POSTGRES_MAJOR_VERSION@")
+set(POSTGRES_MINOR_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_PATCH_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_VERSION "@POSTGRES_VERSION@")
+set(PG_VERSION "9.6devel")
+set(PG_VERSION_NUM 90600)
+
+set(PGBINDIR "@PGBINDIR@")
+set(PGSHAREDIR "@PGSHAREDIR@")
+set(SYSCONFDIR "@SYSCONFDIR@")
+set(INCLUDEDIR "@INCLUDEDIR@")
+set(PKGINCLUDEDIR "@PKGINCLUDEDIR@")
+set(INCLUDEDIRSERVER "@INCLUDEDIRSERVER@")
+set(LIBDIR "@LIBDIR@")
+set(PKGLIBDIR "@PKGLIBDIR@")
+set(LOCALEDIR "@LOCALEDIR@")
+set(DOCDIR "@DOCDIR@")
+set(HTMLDIR "@HTMLDIR@")
+set(MANDIR "@MANDIR@")
+
+
+set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+set(CMAKE_MACOSX_RPATH 1)
+
+set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
+set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "@CMAKE_SHARED_LIBRARY_SONAME_C_FLAG@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+
+include_directories(${INCLUDEDIRSERVER})
+link_directories(${LIBDIR})
+
+if(WIN32)
+	set(contrib_libs
+		port
+		pgcommon
+	)
+endif()
+
+if(MSVC)
+	set(contrib_libs
+		${contrib_libs}
+		postgres
+	)
+endif()
diff --git a/cmake/CheckCpuID.cmake b/cmake/CheckCpuID.cmake
new file mode 100644
index 0000000..3346302
--- /dev/null
+++ b/cmake/CheckCpuID.cmake
@@ -0,0 +1,17 @@
+CHECK_C_SOURCE_COMPILES("
+	#include <cpuid.h>
+	int main() {
+		unsigned int exx[4] = {0, 0, 0, 0};
+		__get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]);
+		return 0;
+	}
+" HAVE__GET_CPUID)
+
+CHECK_C_SOURCE_COMPILES("
+	#include <intrin.h>
+	int main() {
+		unsigned int exx[4] = {0, 0, 0, 0};
+		__cpuid(exx[0], 1);
+		return 0;
+	}
+" HAVE__CPUID)
diff --git a/cmake/CheckFlexibleArray.cmake b/cmake/CheckFlexibleArray.cmake
new file mode 100644
index 0000000..ce57aa4
--- /dev/null
+++ b/cmake/CheckFlexibleArray.cmake
@@ -0,0 +1,37 @@
+set(C99_C_FLAG_CANDIDATES
+   " "
+   "-std=c99"
+   "-std=gnu99"
+   "-c99"
+   "-AC99"
+   "-xc99=all"
+   "-qlanglvl=extc99"
+)
+
+message(STATUS "Check flexible array support")
+if(NOT MSVC)
+	foreach(FLAG ${C99_C_FLAG_CANDIDATES})
+		set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+		unset(FLEXIBLE_ARRAY_MEMBER CACHE)
+		CHECK_C_SOURCE_COMPILES("
+			int main(void){
+				int x = 10;
+				int y[x];
+				return 0;
+			}
+		" FLEXIBLE_ARRAY_MEMBER)
+		if(FLEXIBLE_ARRAY_MEMBER)
+			set(C99_C_FLAGS_INTERNAL "${FLAG}")
+			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
+			break()
+		endif(FLEXIBLE_ARRAY_MEMBER)
+	endforeach(FLAG ${C99_C_FLAG_CANDIDATES})
+endif()
+
+if(FLEXIBLE_ARRAY_MEMBER)
+	message(STATUS "Check flexible array support - yes with ${C99_C_FLAGS_INTERNAL}")
+	set(FLEXIBLE_ARRAY_MEMBER "")
+else(FLEXIBLE_ARRAY_MEMBER)
+	message(STATUS "Check flexible array support - no")
+	set(FLEXIBLE_ARRAY_MEMBER 1)
+endif(FLEXIBLE_ARRAY_MEMBER)
\ No newline at end of file
diff --git a/cmake/CheckLLConstants.cmake b/cmake/CheckLLConstants.cmake
new file mode 100644
index 0000000..68bf65f
--- /dev/null
+++ b/cmake/CheckLLConstants.cmake
@@ -0,0 +1,9 @@
+CHECK_C_SOURCE_COMPILES("
+	main() {
+		#define INT64CONST(x)  x##LL
+		long long int foo = INT64CONST(0x1234567890123456);
+		return 0;
+	}
+" HAVE_LL_CONSTANTS)
+
+message(STATUS "HAVE_LL_CONSTANTS ${HAVE_LL_CONSTANTS}")
\ No newline at end of file
diff --git a/cmake/CheckSSE42.cmake b/cmake/CheckSSE42.cmake
new file mode 100644
index 0000000..3fee3b4
--- /dev/null
+++ b/cmake/CheckSSE42.cmake
@@ -0,0 +1,30 @@
+foreach(FLAG ";-msse4.2")
+	unset(HAVE_SSE42_INTRINSICS CACHE)
+	set(CMAKE_REQUIRED_FLAGS ${FLAG})
+	check_c_source_runs("
+		#include <nmmintrin.h>
+		int main(void) {
+			unsigned int crc = 0;
+			crc = _mm_crc32_u8(crc, 0);
+			crc = _mm_crc32_u32(crc, 0);
+			/* return computed value, to prevent the above being optimized away */
+			return !(crc == 0);
+		}
+	" HAVE_SSE42_INTRINSICS)
+	if (HAVE_SSE42_INTRINSICS)
+		set(CFLAGS_SSE42 ${FLAG})
+		break()
+	endif()
+endforeach()
+
+message(STATUS "SSE4.2 flags: ${CFLAGS_SSE42}")
+set(CMAKE_REQUIRED_FLAGS ${CFLAGS_SSE42})
+check_c_source_compiles("
+	#ifndef __SSE4_2__
+	#error __SSE4_2__ not defined
+	#endif
+	int main(void){
+		return 0;
+	}
+" HAVE_SSE42)
+set(CMAKE_REQUIRED_FLAGS "")
diff --git a/cmake/CheckSnprintfLongLongIntModifier.cmake b/cmake/CheckSnprintfLongLongIntModifier.cmake
new file mode 100644
index 0000000..f076238
--- /dev/null
+++ b/cmake/CheckSnprintfLongLongIntModifier.cmake
@@ -0,0 +1,31 @@
+set(CMAKE_REQUIRED_INCLUDES "stdio.h")
+foreach(pgac_modifier "ll" "q" "I64")
+	unset(LONG_LONG_INT_MODIFIER CACHE)
+	CHECK_C_SOURCE_COMPILES("
+		typedef long long int ac_int64;
+
+		ac_int64 a = 20000001;
+		ac_int64 b = 40000005;
+
+		int does_int64_snprintf_work() {
+			ac_int64 c;
+			char buf[100];
+			if (sizeof(ac_int64) != 8)
+				return 0;	/* doesn't look like the right size */
+			
+			c = a * b;
+			snprintf(buf, 100, \"%${pgac_modifier}d\", c);
+			if (strcmp(buf, \"800000140000005\") != 0)
+				return 0;	/* either multiply or snprintf is busted */
+			return 1;
+		}
+		main() {
+			exit(! does_int64_snprintf_work());
+		}
+	" LONG_LONG_INT_MODIFIER)
+	if(LONG_LONG_INT_MODIFIER)
+		set(LONG_LONG_INT_MODIFIER ${pgac_modifier})
+		break()
+	endif(LONG_LONG_INT_MODIFIER)
+endforeach(pgac_modifier)
+message(STATUS "LONG_LONG_INT_MODIFIER ${LONG_LONG_INT_MODIFIER}")
\ No newline at end of file
diff --git a/cmake/CheckTypeAlignment.cmake b/cmake/CheckTypeAlignment.cmake
new file mode 100644
index 0000000..37cbb58
--- /dev/null
+++ b/cmake/CheckTypeAlignment.cmake
@@ -0,0 +1,29 @@
+macro(CHECK_TYPE_ALIGNMENT TYPE NAME)
+	if(NOT ${NAME})
+		message(STATUS "Check alignment of ${TYPE}")
+		
+		set(INCLUDE_HEADERS "#include <stddef.h>
+			#include <stdio.h>
+			#include <stdlib.h>")
+
+		if(HAVE_STDINT_H)
+			set(INCLUDE_HEADERS "${INCLUDE_HEADERS}\n#include <stdint.h>\n")
+		endif(HAVE_STDINT_H)
+
+		file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c"
+			"${INCLUDE_HEADERS}
+			int main(){
+				char diff;
+				struct foo {char a; ${TYPE} b;};
+				struct foo *p = (struct foo *) malloc(sizeof(struct foo));
+				diff = ((char *)&p->b) - ((char *)&p->a);
+				return diff;}
+		")
+
+		try_run(${NAME} COMPILE_RESULT "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
+			"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c")
+
+		message(STATUS "Check alignment of ${TYPE} - ${${NAME}}")
+
+	endif(NOT ${NAME})
+endmacro(CHECK_TYPE_ALIGNMENT TYPE NAME ALIGNOF_TYPE)
\ No newline at end of file
diff --git a/cmake/FindLDAP.cmake b/cmake/FindLDAP.cmake
new file mode 100644
index 0000000..8a5bc63
--- /dev/null
+++ b/cmake/FindLDAP.cmake
@@ -0,0 +1,41 @@
+# - Try to find the LDAP client libraries
+# Once done this will define
+#
+#  LDAP_FOUND - system has libldap
+#  LDAP_INCLUDE_DIR - the ldap include directory
+#  LDAP_LIBRARIES - libldap + liblber (if found) library
+#  LBER_LIBRARIES - liblber library
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+	# Already in cache, be silent
+	set(Ldap_FIND_QUIETLY TRUE)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(UNIX)
+	FIND_PATH(LDAP_INCLUDE_DIR ldap.h)
+	FIND_LIBRARY(LDAP_LIBRARIES NAMES ldap)
+	FIND_LIBRARY(LBER_LIBRARIES NAMES lber)
+
+else(UNIX)
+	FIND_PATH(LDAP_INCLUDE_DIR winldap.h)
+	FIND_LIBRARY(LDAP_LIBRARIES NAMES wldap32)
+endif(UNIX)
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+	set(LDAP_FOUND TRUE)
+	if(LBER_LIBRARIES)
+		set(LDAP_LIBRARIES ${LDAP_LIBRARIES} ${LBER_LIBRARIES})
+	endif(LBER_LIBRARIES)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(LDAP_FOUND)
+	if(NOT Ldap_FIND_QUIETLY)
+		message(STATUS "Found ldap: ${LDAP_LIBRARIES}")
+	endif(NOT Ldap_FIND_QUIETLY)
+else(LDAP_FOUND)
+	if (Ldap_FIND_REQUIRED)
+		message(FATAL_ERROR "Could NOT find ldap")
+	endif (Ldap_FIND_REQUIRED)
+endif(LDAP_FOUND)
+
+MARK_AS_ADVANCED(LDAP_INCLUDE_DIR LDAP_LIBRARIES LBER_LIBRARIES)
diff --git a/cmake/FindLibSocket.cmake b/cmake/FindLibSocket.cmake
new file mode 100644
index 0000000..148f4ec
--- /dev/null
+++ b/cmake/FindLibSocket.cmake
@@ -0,0 +1,11 @@
+find_library( LIBSOCKET_LIBRARY NAMES libsocket socket )
+mark_as_advanced( LIBSOCKET_LIBRARY )
+
+# handle the QUIETLY and REQUIRED arguments and set LIBSOCKET_FOUND to TRUE if
+# all listed variables are TRUE
+include( FindPackageHandleStandardArgs )
+FIND_PACKAGE_HANDLE_STANDARD_ARGS( LIBSOCKET DEFAULT_MSG LIBSOCKET_LIBRARY )
+
+if( LIBSOCKET_FOUND )
+	set( LIBSOCKET_LIBRARIES ${LIBSOCKET_LIBRARY} )
+endif( LIBSOCKET_FOUND )
diff --git a/cmake/FindLibUUID.cmake b/cmake/FindLibUUID.cmake
new file mode 100644
index 0000000..10626c5
--- /dev/null
+++ b/cmake/FindLibUUID.cmake
@@ -0,0 +1,50 @@
+# - Try to find LIBUUID
+# Find LIBUUID headers, libraries and the answer to all questions.
+#
+#  LIBUUID_FOUND               True if libuuid got found
+#  LIBUUID_INCLUDE_DIRS        Location of libuuid headers
+#  LIBUUID_LIBRARIES           List of libraries to use libuuid
+#
+# Copyright (c) 2008 Bjoern Ricks <bjoern.ricks@googlemail.com>
+#
+#  Redistribution and use is allowed according to the terms of the New
+#  BSD license.
+#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+INCLUDE(FindPkgConfig)
+
+IF(LibUUID_FIND_REQUIRED)
+	SET(_pkgconfig_REQUIRED "REQUIRED")
+ELSE(LibUUID_FIND_REQUIRED)
+	SET(_pkgconfig_REQUIRED "")
+ENDIF (LibUUID_FIND_REQUIRED)
+
+IF(LIBUUID_MIN_VERSION)
+	PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid>=${LIBUUID_MIN_VERSION})
+ELSE(LIBUUID_MIN_VERSION)
+	PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid)
+ENDIF(LIBUUID_MIN_VERSION)
+
+IF(NOT LIBUUID_FOUND)
+	FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
+	FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
+
+	# Report results
+	IF(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+		SET(LIBUUID_FOUND 1)
+		IF(NOT LIBUUID_FIND_QUIETLY)
+			MESSAGE(STATUS "Found libuuid: ${LIBUUID_LIBRARIES}")
+		ENDIF(NOT LIBUUID_FIND_QUIETLY)
+	ELSE(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+		IF(LIBUUID_FIND_REQUIRED)
+			MESSAGE(SEND_ERROR "Could NOT find libuuid")
+		ELSE(LIBUUID_FIND_REQUIRED)
+			IF(NOT LIBUUID_FIND_QUIETLY)
+				MESSAGE(STATUS "Could NOT find libuuid")
+			ENDIF(NOT LIBUUID_FIND_QUIETLY)
+		ENDIF (LIBUUID_FIND_REQUIRED)
+	ENDIF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+ENDIF(NOT LIBUUID_FOUND)
+
+MARK_AS_ADVANCED(LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS)
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
new file mode 100644
index 0000000..6603dbe
--- /dev/null
+++ b/cmake/FindReadline.cmake
@@ -0,0 +1,22 @@
+# from http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/FindReadline.cmake
+# http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/COPYING-CMAKE-SCRIPTS
+# --> BSD licensed
+#
+# GNU Readline library finder
+
+
+if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+	set(READLINE_FOUND TRUE)
+else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+	FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h
+		/usr/include/readline
+	)
+
+	FIND_LIBRARY(READLINE_LIBRARY NAMES readline PATHS
+		/opt/csw/lib/64/
+	)
+	include(FindPackageHandleStandardArgs)
+	FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
+
+	MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
+endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
diff --git a/cmake/FindSELinux.cmake b/cmake/FindSELinux.cmake
new file mode 100644
index 0000000..dd6e3ca
--- /dev/null
+++ b/cmake/FindSELinux.cmake
@@ -0,0 +1,55 @@
+# - Try to find the SELinux library
+# Once done this will define
+#
+#  SELINUX_FOUND - System has selinux
+#  SELINUX_INCLUDE_DIR - The selinux include directory
+#  SELINUX_LIBRARIES - The libraries needed to use selinux
+#  SELINUX_DEFINITIONS - Compiler switches required for using selinux
+
+#=============================================================================
+# Copyright 2010  Michael Leupold <lemma@confuego.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+IF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+	# in cache already
+	SET (SELinux_FIND_QUIETLY TRUE)
+ENDIF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+
+# TODO: This should be restricted to Linux only
+IF (NOT WIN32)
+	# use pkg-config to get the directories
+	FIND_PACKAGE (PkgConfig)
+	PKG_CHECK_MODULES (PC_SELINUX libselinux)
+	SET (SELINUX_DEFINITIONS ${PC_SELINUX_CFLAGS_OTHER})
+
+	FIND_PATH (SELINUX_INCLUDE_DIR selinux/selinux.h
+		HINTS
+		${PC_SELINUX_INCLUDEDIR}
+		${PC_SELINUX_INCLUDE_DIRS}
+	)
+
+	FIND_LIBRARY (SELINUX_LIBRARIES selinux libselinux
+		HINTS
+		${PC_SELINUX_LIBDIR}
+		${PC_SELINUX_LIBRARY_DIRS}
+	)
+
+	INCLUDE (FindPackageHandleStandardArgs)
+
+	# handle the QUIETLY and REQUIRED arguments and set SELINUX_FOUND
+	# to TRUE if all listed variables are TRUE
+	FIND_PACKAGE_HANDLE_STANDARD_ARGS (SELinux DEFAULT_MSG
+		SELINUX_INCLUDE_DIR
+		SELINUX_LIBRARIES
+	)
+
+	MARK_AS_ADVANCED (SELINUX_INCLUDE_DIR SELINUX_LIBRARIES)
+
+ENDIF (NOT WIN32)
diff --git a/cmake/FuncAcceptArgtypes.cmake b/cmake/FuncAcceptArgtypes.cmake
new file mode 100644
index 0000000..e333d69
--- /dev/null
+++ b/cmake/FuncAcceptArgtypes.cmake
@@ -0,0 +1,52 @@
+if(HAVE_SYS_TYPES_H)
+	set(INCLUDE_SYS_TYPES_H "#include <sys/types.h>")
+endif(HAVE_SYS_TYPES_H)
+
+if(HAVE_SYS_SOCKET_H)
+	set(INCLUDE_SYS_SOCKET_H "#include <sys/socket.h>")
+endif(HAVE_SYS_SOCKET_H)
+
+
+message(STATUS "Looking for accept function args")
+set(CMAKE_REQUIRED_QUIET 1)
+foreach(ac_cv_func_accept_return "int" "unsigned int PASCAL" "SOCKET WSAAPI")
+	foreach(ac_cv_func_accept_arg1 "unsigned int" "int" "SOCKET")
+		foreach(ac_cv_func_accept_arg2 "struct sockaddr *" "const struct sockaddr *" "void *")
+			foreach(ac_cv_func_accept_arg3 "int" "size_t" "socklen_t" "unsigned int" "void")
+				unset(AC_FUNC_ACCEPT CACHE)
+				CHECK_C_SOURCE_COMPILES("
+					${INCLUDE_SYS_TYPES_H}
+					${INCLUDE_SYS_SOCKET_H}
+					extern ${ac_cv_func_accept_return} accept (${ac_cv_func_accept_arg1}, ${ac_cv_func_accept_arg2}, ${ac_cv_func_accept_arg3} *);
+					int main(void){return 0;}
+				" AC_FUNC_ACCEPT)
+				if(AC_FUNC_ACCEPT)
+					set(ACCEPT_TYPE_RETURN ${ac_cv_func_accept_return})
+					set(ACCEPT_TYPE_ARG1 ${ac_cv_func_accept_arg1})
+					set(ACCEPT_TYPE_ARG2 ${ac_cv_func_accept_arg2})
+					set(ACCEPT_TYPE_ARG3 ${ac_cv_func_accept_arg3})
+					break()
+				endif(AC_FUNC_ACCEPT)
+			endforeach(ac_cv_func_accept_arg3)
+			if(AC_FUNC_ACCEPT)
+				break()
+			endif(AC_FUNC_ACCEPT)
+		endforeach(ac_cv_func_accept_arg2)
+		if(AC_FUNC_ACCEPT)
+			break()
+		endif(AC_FUNC_ACCEPT)
+	endforeach(ac_cv_func_accept_arg1)
+	if(AC_FUNC_ACCEPT)
+		break()
+	endif(AC_FUNC_ACCEPT)
+endforeach(ac_cv_func_accept_return)
+unset(CMAKE_REQUIRED_QUIET)
+
+if(NOT AC_FUNC_ACCEPT)
+	message(ERROR "could not determine argument types")
+endif(NOT AC_FUNC_ACCEPT)
+if(ACCEPT_TYPE_ARG3 STREQUAL "void")
+	set(ACCEPT_TYPE_ARG3 "int")
+endif()
+
+message(STATUS "Looking for accept function args - found ${ACCEPT_TYPE_RETURN}, ${ACCEPT_TYPE_ARG1}, ${ACCEPT_TYPE_ARG2}, ${ACCEPT_TYPE_ARG3} *")
diff --git a/cmake/GenDef.cmake b/cmake/GenDef.cmake
new file mode 100644
index 0000000..499b0bd
--- /dev/null
+++ b/cmake/GenDef.cmake
@@ -0,0 +1,12 @@
+macro(GEN_DEF NAME)
+	SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def\" ")
+	add_custom_command(
+		TARGET ${NAME}
+		PRE_LINK
+		#COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+		#OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+		COMMAND ${PERL_EXECUTABLE} ${PROJECT_SOURCE_DIR}/src/tools/msvc/gendef.pl ${CMAKE_CURRENT_BINARY_DIR}/$<$<BOOL:${CMAKE_BUILD_TYPE}>:${CMAKE_FILES_DIRECTORY}>${NAME}.dir/${CMAKE_CFG_INTDIR} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def ${CMAKE_VS_PLATFORM_NAME}
+		COMMENT " Gen defs "
+	)
+	set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def)
+endmacro(GEN_DEF NAME)
diff --git a/cmake/MakeNLS.cmake b/cmake/MakeNLS.cmake
new file mode 100644
index 0000000..c6db90d
--- /dev/null
+++ b/cmake/MakeNLS.cmake
@@ -0,0 +1,21 @@
+macro(MAKE_MO BIN_NAME LANGUAGES)
+	set(gmo_files "")
+	foreach(lang ${LANGUAGES})
+		if (NOT ";${NLS_LANGUAGES};" MATCHES ";${lang};")
+			continue()
+		endif()
+		set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo)
+		add_custom_command(OUTPUT ${_gmoFile}
+			COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} po/${lang}.po
+			WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+			DEPENDS po/${lang}.po
+		)
+		install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo DESTINATION share/locale/${lang}/LC_MESSAGES/ RENAME ${BIN_NAME}-${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.mo)
+		if(NOT TARGET pofiles)
+			add_custom_target(pofiles)
+		endif()
+		add_custom_target(${BIN_NAME}-mofile-${lang} ALL DEPENDS ${_gmoFile})
+		add_dependencies(pofiles ${BIN_NAME}-mofile-${lang})
+		set(gmo_files "${gmo_files};${_gmoFile}")
+	endforeach()
+endmacro()
diff --git a/cmake/RegressCheck.cmake b/cmake/RegressCheck.cmake
new file mode 100644
index 0000000..1770597
--- /dev/null
+++ b/cmake/RegressCheck.cmake
@@ -0,0 +1,168 @@
+set(tmp_check_folder ${CMAKE_BINARY_DIR}/src/test/regress/tmp_install)
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+	set(env_cmd
+		${CMAKE_COMMAND} -E env
+		"DYLD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+	)
+	set(tmp_env_cmd
+		${CMAKE_COMMAND} -E env
+		"DYLD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+	)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+	set(env_cmd
+		${CMAKE_COMMAND} -E env
+		"LIBPATH=$ENV{DESTDIR}${LIBDIR}:$LIBPATH"
+	)
+	set(tmp_env_cmd
+		${CMAKE_COMMAND} -E env
+		"LIBPATH=${tmp_check_folder}${LIBDIR}:$LIBPATH"
+	)
+else()
+	if (CMAKE_VERSION VERSION_GREATER "3.2.0")
+		set(env_cmd
+			${CMAKE_COMMAND} -E env
+			"LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH"
+		)
+		set(tmp_env_cmd
+			${CMAKE_COMMAND} -E env
+			"LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH"
+		)
+	else()
+		set(env_cmd
+			export "LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH" &&
+		)
+		set(tmp_env_cmd
+			export "LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH" &&
+		)
+	endif()
+endif()
+
+if(MSVC OR MSYS OR MINGW OR CMAKE_GENERATOR STREQUAL Xcode)
+	#Need rewrite
+	set(pre_pg_regress_check
+		${PGBINDIR}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_isolation_regress_check
+		${PGBINDIR}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+else(MSVC)
+	set(pre_pg_regress_check
+		${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_isolation_regress_check
+		${CMAKE_BINARY_DIR}/src/test/isolation/${CMAKE_INSTALL_CONFIG_NAME}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+endif()
+
+set(pg_regress_check
+	${env_cmd}
+	${pre_pg_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check
+	${env_cmd}
+	${pre_pg_isolation_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_isolation_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+if(MAX_CONNECTIONS)
+	set(MAXCONNOPT "${MAXCONNOPT} --max-connections=${MAX_CONNECTIONS}")
+endif()
+
+if(TEMP_CONFIG)
+	set(TEMP_CONF "${TEMP_CONF} --temp-config=${TEMP_CONFIG}")
+endif()
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	set(check_make_command "ninja")
+else()
+	set(check_make_command "make")
+endif()
+
+macro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	add_custom_target(${TARGET_NAME}_installcheck_tmp
+		COMMAND ${pg_regress_check_tmp} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+	
+	add_custom_target(${TARGET_NAME}_installcheck
+		COMMAND ${pg_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	if(CMAKE_GENERATOR STREQUAL "Ninja")
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${TARGET_NAME}_installcheck_tmp
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	else()
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+			COMMAND ${check_make_command} ${TARGET_NAME}_installcheck_tmp DESTDIR=${tmp_check_folder}
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	endif()
+	
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck "tests/install")
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	add_custom_target(${TARGET_NAME}_isolation_installcheck_tmp
+		COMMAND ${pg_isolation_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	add_custom_target(${TARGET_NAME}_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} ${TARGET_NAME}_isolation_installcheck_tmp DESTDIR=${tmp_check_folder}
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_isolation_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_installcheck_tmp PARENT_SCOPE)
+	set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_installcheck PARENT_SCOPE)
+	REGRESS_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
diff --git a/cmake/ReplacePython.cmake b/cmake/ReplacePython.cmake
new file mode 100644
index 0000000..f768307
--- /dev/null
+++ b/cmake/ReplacePython.cmake
@@ -0,0 +1,79 @@
+macro(replace_python2 input_file output_file)
+	file(READ ${input_file} tmp_string)
+	string(REGEX REPLACE
+		"except \([a-zA-Z\\.]*\), *\([a-zA-Z]*\):"
+		"except \\1 as \\2:"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"<type 'exceptions\\.\([a-zA-Z]*\)'>" "<class '\\1'>"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"<type 'long'>" "<class 'int'>"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([0-9][0-9]*\)L" "\\1"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([ [{]\)u\"" "\\1\""
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([ [{]\)u'" "\\1'"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"def next" "def __next__"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"LANGUAGE plpythonu" "LANGUAGE plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"LANGUAGE plpython2u" "LANGUAGE plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION \([^ ]*_\)+plpythonu" "EXTENSION \\1plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION plpythonu" "EXTENSION plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION \([^ ]*_\)+plpython2u" "EXTENSION \\1plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION plpython2u" "EXTENSION plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"installing required extension \"plpython2u\""
+		"installing required extension \"plpython3u\""
+		tmp_string
+		"${tmp_string}")
+	file(WRITE ${output_file} "${tmp_string}")
+endmacro()
+
+macro(replace_python_files r_regress_files)
+	file(MAKE_DIRECTORY sql/python3 expected/python3 results/python3)
+	set(adition_clean "")
+	set(regress_files3 "")
+	foreach(rfile ${r_regress_files})
+		replace_python2("sql/${rfile}.sql" "sql/python3/${rfile}.sql")
+		if(rfile STREQUAL "plpython_types")
+			replace_python2("expected/plpython_types_3.out" "expected/python3/${rfile}.out")
+		else()
+			replace_python2("expected/${rfile}.out" "expected/python3/${rfile}.out")
+		endif()
+		set(adition_clean "${adition_clean};sql/python3/${rfile}.sql;expected/python3/${rfile}.out;")
+		set(regress_files3 "${regress_files3};python3/${rfile}")
+	endforeach(rfile)
+	SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${adition_clean}")
+endmacro()
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt
new file mode 100644
index 0000000..7d25bf0
--- /dev/null
+++ b/contrib/CMakeLists.txt
@@ -0,0 +1,111 @@
+set(contrib_libs postgres)
+
+#TODO: need test under mingw or cygwin
+if(WIN32)
+	set(contrib_libs
+		port
+		pgcommon
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(contrib_libs
+		port
+		postgres
+		pgcommon_srv
+	)
+endif()
+
+set(contrib_check_targets "")
+set(contrib_installcheck_targets "")
+
+add_subdirectory(adminpack)
+add_subdirectory(auth_delay)
+add_subdirectory(auto_explain)
+add_subdirectory(btree_gin)
+add_subdirectory(btree_gist)
+add_subdirectory(bloom)
+add_subdirectory(chkpass)
+add_subdirectory(citext)
+add_subdirectory(cube)
+add_subdirectory(dblink)
+add_subdirectory(dict_int)
+add_subdirectory(dict_xsyn)
+add_subdirectory(earthdistance)
+add_subdirectory(file_fdw)
+add_subdirectory(fuzzystrmatch)
+add_subdirectory(hstore)
+if(PERLLIBS_FOUND)
+	add_subdirectory(hstore_plperl)
+endif()
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(hstore_plpython)
+endif()
+add_subdirectory(intarray)
+add_subdirectory(isn)
+add_subdirectory(lo)
+add_subdirectory(ltree)
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(ltree_plpython)
+endif()
+add_subdirectory(oid2name)
+add_subdirectory(pageinspect)
+add_subdirectory(passwordcheck)
+add_subdirectory(pg_buffercache)
+add_subdirectory(pg_freespacemap)
+add_subdirectory(pg_prewarm)
+add_subdirectory(pg_standby)
+add_subdirectory(pg_stat_statements)
+add_subdirectory(pg_trgm)
+add_subdirectory(pg_visibility)
+add_subdirectory(pgcrypto)
+add_subdirectory(pgrowlocks)
+add_subdirectory(pgstattuple)
+add_subdirectory(postgres_fdw)
+add_subdirectory(seg)
+if(SELINUX_LIBRARIES)
+	add_subdirectory(sepgsql)
+endif()
+add_subdirectory(spi)
+if(OPENSSL_FOUND)
+	add_subdirectory(sslinfo)
+endif()
+add_subdirectory(tablefunc)
+add_subdirectory(tcn)
+add_subdirectory(tsearch2)
+add_subdirectory(tsm_system_rows)
+add_subdirectory(tsm_system_time)
+add_subdirectory(unaccent)
+if(WITH_UUID)
+	add_subdirectory(uuid-ossp)
+endif()
+add_subdirectory(vacuumlo)
+if(LIBXML2_FOUND)
+	add_subdirectory(xml2)
+endif()
+
+add_custom_target(contrib_check
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+	COMMAND make install DESTDIR=${tmp_check_folder}
+	COMMAND make ${contrib_check_targets} DESTDIR=${tmp_check_folder}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+#Make chain for run tests in strict order
+#TODO: we can't run tests separately now
+set(first_element "")
+list(GET contrib_installcheck_targets 0 first_element)
+add_custom_target(contrib_installcheck
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+	DEPENDS tablespace-setup ${first_element}
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+set(last_element OFF)
+foreach(loop_var IN ITEMS ${contrib_installcheck_targets})
+	if(last_element)
+		add_dependencies(${last_element} ${loop_var})
+	endif()
+	set(last_element ${loop_var})
+endforeach()
diff --git a/contrib/adminpack/CMakeLists.txt b/contrib/adminpack/CMakeLists.txt
new file mode 100644
index 0000000..c1f5251
--- /dev/null
+++ b/contrib/adminpack/CMakeLists.txt
@@ -0,0 +1,27 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name adminpack)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
diff --git a/contrib/auth_delay/CMakeLists.txt b/contrib/auth_delay/CMakeLists.txt
new file mode 100644
index 0000000..b890114
--- /dev/null
+++ b/contrib/auth_delay/CMakeLists.txt
@@ -0,0 +1,27 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+	if(OPENSSL_FOUND)
+		include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	endif()
+endif()
+
+set(extension_name auth_delay)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/auto_explain/CMakeLists.txt b/contrib/auto_explain/CMakeLists.txt
new file mode 100644
index 0000000..11ca366
--- /dev/null
+++ b/contrib/auto_explain/CMakeLists.txt
@@ -0,0 +1,18 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name auto_explain)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
diff --git a/contrib/bloom/CMakeLists.txt b/contrib/bloom/CMakeLists.txt
new file mode 100644
index 0000000..634b3f9
--- /dev/null
+++ b/contrib/bloom/CMakeLists.txt
@@ -0,0 +1,35 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name bloom)
+
+add_library(${extension_name} MODULE
+	blcost.c
+	blinsert.c
+	blscan.c
+	blutils.c
+	blvacuum.c
+	blvalidate.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "bloom")
diff --git a/contrib/btree_gin/CMakeLists.txt b/contrib/btree_gin/CMakeLists.txt
new file mode 100644
index 0000000..de598d9
--- /dev/null
+++ b/contrib/btree_gin/CMakeLists.txt
@@ -0,0 +1,47 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name btree_gin)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regres_files
+	install_btree_gin
+	int2
+	int4
+	int8
+	float4
+	float8
+	money
+	oid
+	timestamp
+	timestamptz
+	time
+	timetz
+	date
+	interval
+	macaddr
+	inet
+	cidr
+	text
+	varchar
+	char
+	bytea
+	bit
+	varbit
+	numeric
+)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regres_files}")
diff --git a/contrib/btree_gist/CMakeLists.txt b/contrib/btree_gist/CMakeLists.txt
new file mode 100644
index 0000000..803cb0e
--- /dev/null
+++ b/contrib/btree_gist/CMakeLists.txt
@@ -0,0 +1,75 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name btree_gist)
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	btree_utils_num.c
+	btree_utils_var.c
+	btree_int2.c
+	btree_int4.c
+	btree_int8.c
+	btree_float4.c
+	btree_float8.c
+	btree_cash.c
+	btree_oid.c
+	btree_ts.c
+	btree_time.c
+	btree_date.c
+	btree_interval.c
+	btree_macaddr.c
+	btree_inet.c
+	btree_text.c
+	btree_bytea.c
+	btree_bit.c
+	btree_numeric.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+set(regres_files
+	init
+	int2
+	int4
+	int8
+	float4
+	float8
+	cash
+	oid
+	timestamp
+	timestamptz
+	time
+	timetz
+	date
+	interval
+	macaddr
+	inet
+	cidr
+	text
+	varchar
+	char
+	bytea
+	bit
+	varbit
+	numeric
+	not_equal
+)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regres_files}")
diff --git a/contrib/chkpass/CMakeLists.txt b/contrib/chkpass/CMakeLists.txt
new file mode 100644
index 0000000..6151b0e
--- /dev/null
+++ b/contrib/chkpass/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name chkpass)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/citext/CMakeLists.txt b/contrib/citext/CMakeLists.txt
new file mode 100644
index 0000000..3a0eb0e
--- /dev/null
+++ b/contrib/citext/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name citext)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "citext")
diff --git a/contrib/cube/CMakeLists.txt b/contrib/cube/CMakeLists.txt
new file mode 100644
index 0000000..9fafdea
--- /dev/null
+++ b/contrib/cube/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name cube)
+
+bison_target(CUBE_PARSER cubeparse.y ${CMAKE_CURRENT_SOURCE_DIR}/cubeparse.c)
+flex_target(CUBE_SCANNER cubescan.l  ${CMAKE_CURRENT_SOURCE_DIR}/cubescan.c)
+add_flex_bison_dependency(CUBE_SCANNER CUBE_PARSER)
+set_source_files_properties(${BISON_CUBE_PARSER_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${FLEX_CUBE_SCANNER_OUTPUTS})
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	${BISON_CUBE_PARSER_OUTPUTS}
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "cube")
diff --git a/contrib/dblink/CMakeLists.txt b/contrib/dblink/CMakeLists.txt
new file mode 100644
index 0000000..05507c4
--- /dev/null
+++ b/contrib/dblink/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name dblink)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files paths dblink)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/dict_int/CMakeLists.txt b/contrib/dict_int/CMakeLists.txt
new file mode 100644
index 0000000..5034d47
--- /dev/null
+++ b/contrib/dict_int/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name dict_int)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files dict_int)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/dict_xsyn/CMakeLists.txt b/contrib/dict_xsyn/CMakeLists.txt
new file mode 100644
index 0000000..f8335b6
--- /dev/null
+++ b/contrib/dict_xsyn/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name dict_xsyn)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	xsyn_sample.rules
+	DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regress_files dict_xsyn)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/earthdistance/CMakeLists.txt b/contrib/earthdistance/CMakeLists.txt
new file mode 100644
index 0000000..b4b4381
--- /dev/null
+++ b/contrib/earthdistance/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name earthdistance)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files earthdistance)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/file_fdw/CMakeLists.txt b/contrib/file_fdw/CMakeLists.txt
new file mode 100644
index 0000000..93c354a
--- /dev/null
+++ b/contrib/file_fdw/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name file_fdw)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files file_fdw)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/fuzzystrmatch/CMakeLists.txt b/contrib/fuzzystrmatch/CMakeLists.txt
new file mode 100644
index 0000000..6e21763
--- /dev/null
+++ b/contrib/fuzzystrmatch/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name fuzzystrmatch)
+
+add_library(${extension_name} MODULE ${extension_name}.c dmetaphone.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/hstore/CMakeLists.txt b/contrib/hstore/CMakeLists.txt
new file mode 100644
index 0000000..096e193
--- /dev/null
+++ b/contrib/hstore/CMakeLists.txt
@@ -0,0 +1,38 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name hstore)
+
+add_library(${extension_name} MODULE
+	hstore_io.c
+	hstore_op.c
+	hstore_gist.c
+	hstore_gin.c
+	hstore_compat.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	set_target_properties(${extension_name} PROPERTIES LINK_FLAGS -Wl,--out-implib=libmin${extension_name}.dll.a)
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/hstore_plperl/CMakeLists.txt b/contrib/hstore_plperl/CMakeLists.txt
new file mode 100644
index 0000000..ea738ed
--- /dev/null
+++ b/contrib/hstore_plperl/CMakeLists.txt
@@ -0,0 +1,38 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plperl"
+	"${PROJECT_SOURCE_DIR}/contrib/hstore"
+	${PERL_INCLUDE_PATH}
+)
+
+if(MINGW)
+	link_directories("${PROJECT_BINARY_DIR}/contrib/hstore")
+endif()
+set(extension_name hstore_plperl)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${PERL_LIBRARY} ${PERL_LDFLAGS})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	target_link_libraries(${extension_name} minhstore)
+	target_compile_definitions(${extension_name} PRIVATE -DPLPERL_HAVE_UID_GID)
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore_plperl)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/hstore_plpython/CMakeLists.txt b/contrib/hstore_plpython/CMakeLists.txt
new file mode 100644
index 0000000..fa67001
--- /dev/null
+++ b/contrib/hstore_plpython/CMakeLists.txt
@@ -0,0 +1,57 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plpython"
+	"${PROJECT_SOURCE_DIR}/contrib/hstore"
+	${PYTHON_INCLUDE_DIRS}
+)
+
+if(MINGW)
+	link_directories(
+		"${PROJECT_BINARY_DIR}/contrib/hstore"
+		"${PROJECT_BINARY_DIR}/src/pl/plpython"
+	)
+endif()
+
+set(extension_name hstore_plpython)
+
+add_library(${extension_name}${PYTHON_VERSION_MAJOR} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} ${contrib_libs} ${PYTHON_LIBRARIES})
+set_target_properties(${extension_name}${PYTHON_VERSION_MAJOR} PROPERTIES PREFIX "")
+add_dependencies(${extension_name}${PYTHON_VERSION_MAJOR} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} minhstore minplpython${PYTHON_VERSION_MAJOR})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name}${PYTHON_VERSION_MAJOR} contrib)
+endif()
+install(TARGETS ${extension_name}${PYTHON_VERSION_MAJOR}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	${extension_name}2u.control
+	${extension_name}2u--1.0.sql
+	${extension_name}3u.control
+	${extension_name}3u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore_plpython)
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${regress_files}")
+	set(regress_options
+		"--load-extension=hstore"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files3}")
+else()
+	set(regress_options
+		"--load-extension=hstore"
+		"--load-extension=plpythonu"
+		"--load-extension=hstore_plpythonu"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files}")
+endif()
diff --git a/contrib/intarray/CMakeLists.txt b/contrib/intarray/CMakeLists.txt
new file mode 100644
index 0000000..e5bee80
--- /dev/null
+++ b/contrib/intarray/CMakeLists.txt
@@ -0,0 +1,36 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name intarray)
+set(extension_lib_name _int)
+
+add_library(${extension_lib_name} MODULE
+	_int_bool.c
+	_int_gist.c
+	_int_op.c
+	_int_tool.c
+	_intbig_gist.c
+	_int_gin.c
+	_int_selfuncs.c
+)
+target_link_libraries(${extension_lib_name} ${contrib_libs})
+set_target_properties(${extension_lib_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_lib_name} postgres)
+if (MSVC)
+	gen_def(${extension_lib_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_lib_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ${extension_lib_name})
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/isn/CMakeLists.txt b/contrib/isn/CMakeLists.txt
new file mode 100644
index 0000000..9e19366
--- /dev/null
+++ b/contrib/isn/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name isn)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files isn)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/lo/CMakeLists.txt b/contrib/lo/CMakeLists.txt
new file mode 100644
index 0000000..0c7aab0
--- /dev/null
+++ b/contrib/lo/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name lo)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/ltree/CMakeLists.txt b/contrib/ltree/CMakeLists.txt
new file mode 100644
index 0000000..e097839
--- /dev/null
+++ b/contrib/ltree/CMakeLists.txt
@@ -0,0 +1,37 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name ltree)
+add_definitions(-DLOWER_NODE)
+
+add_library(${extension_name} MODULE
+	ltree_io.c
+	ltree_op.c
+	lquery_op.c
+	_ltree_op.c
+	crc32.c
+	ltxtquery_io.c
+	ltxtquery_op.c
+	ltree_gist.c
+	_ltree_gist.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ltree)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/ltree_plpython/CMakeLists.txt b/contrib/ltree_plpython/CMakeLists.txt
new file mode 100644
index 0000000..dd960aa
--- /dev/null
+++ b/contrib/ltree_plpython/CMakeLists.txt
@@ -0,0 +1,49 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plpython"
+	"${PROJECT_SOURCE_DIR}/contrib/ltree"
+	${PYTHON_INCLUDE_DIRS}
+)
+
+set(extension_name ltree_plpython)
+
+add_library(${extension_name}${PYTHON_VERSION_MAJOR} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} ${contrib_libs} ${PYTHON_LIBRARIES})
+set_target_properties(${extension_name}${PYTHON_VERSION_MAJOR} PROPERTIES PREFIX "")
+add_dependencies(${extension_name}${PYTHON_VERSION_MAJOR} postgres ltree)
+if (MSVC)
+	gen_def(${extension_name}${PYTHON_VERSION_MAJOR})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name}${PYTHON_VERSION_MAJOR} contrib)
+endif()
+install(TARGETS ${extension_name}${PYTHON_VERSION_MAJOR}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	${extension_name}2u.control
+	${extension_name}2u--1.0.sql
+	${extension_name}3u.control
+	${extension_name}3u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ltree_plpython)
+
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${regress_files}")
+	set(regress_options
+		"--load-extension=ltree"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files3}")
+else()
+	set(regress_options
+		"--load-extension=hstore"
+		"--load-extension=plpythonu"
+		"--load-extension=ltree"
+		"--load-extension=ltree_plpythonu"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files}")
+endif()
diff --git a/contrib/oid2name/CMakeLists.txt b/contrib/oid2name/CMakeLists.txt
new file mode 100644
index 0000000..3f1cefd
--- /dev/null
+++ b/contrib/oid2name/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name oid2name)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+
+if(MSVC OR MINGW)
+	target_link_libraries(${extension_name} pgcommon pq)
+endif()
+
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pageinspect/CMakeLists.txt b/contrib/pageinspect/CMakeLists.txt
new file mode 100644
index 0000000..3997184
--- /dev/null
+++ b/contrib/pageinspect/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pageinspect)
+
+add_library(${extension_name} MODULE
+	rawpage.c
+	heapfuncs.c
+	btreefuncs.c
+	fsmfuncs.c
+	brinfuncs.c
+	ginfuncs.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.5.sql
+	${extension_name}--1.4--1.5.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/passwordcheck/CMakeLists.txt b/contrib/passwordcheck/CMakeLists.txt
new file mode 100644
index 0000000..468e4e8
--- /dev/null
+++ b/contrib/passwordcheck/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name passwordcheck)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pg_buffercache/CMakeLists.txt b/contrib/pg_buffercache/CMakeLists.txt
new file mode 100644
index 0000000..4a99728
--- /dev/null
+++ b/contrib/pg_buffercache/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_buffercache)
+
+add_library(${extension_name} MODULE ${extension_name}_pages.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_freespacemap/CMakeLists.txt b/contrib/pg_freespacemap/CMakeLists.txt
new file mode 100644
index 0000000..0045ddc
--- /dev/null
+++ b/contrib/pg_freespacemap/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_freespacemap)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_prewarm/CMakeLists.txt b/contrib/pg_prewarm/CMakeLists.txt
new file mode 100644
index 0000000..8018abd
--- /dev/null
+++ b/contrib/pg_prewarm/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_prewarm)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_standby/CMakeLists.txt b/contrib/pg_standby/CMakeLists.txt
new file mode 100644
index 0000000..67305e9
--- /dev/null
+++ b/contrib/pg_standby/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_standby)
+
+add_executable(${extension_name} ${extension_name}.c)
+target_link_libraries(${extension_name} port pgcommon pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pg_stat_statements/CMakeLists.txt b/contrib/pg_stat_statements/CMakeLists.txt
new file mode 100644
index 0000000..ec6891f
--- /dev/null
+++ b/contrib/pg_stat_statements/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_stat_statements)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_trgm/CMakeLists.txt b/contrib/pg_trgm/CMakeLists.txt
new file mode 100644
index 0000000..d3bf9b0
--- /dev/null
+++ b/contrib/pg_trgm/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_trgm)
+
+add_library(${extension_name} MODULE
+	trgm_op.c
+	trgm_gist.c
+	trgm_gin.c
+	trgm_regexp.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.3.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files pg_trgm pg_word_trgm)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/pg_visibility/CMakeLists.txt b/contrib/pg_visibility/CMakeLists.txt
new file mode 100644
index 0000000..bc8db81
--- /dev/null
+++ b/contrib/pg_visibility/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_visibility)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pgcrypto/CMakeLists.txt b/contrib/pgcrypto/CMakeLists.txt
new file mode 100644
index 0000000..b4bfabd
--- /dev/null
+++ b/contrib/pgcrypto/CMakeLists.txt
@@ -0,0 +1,133 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+)
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+set(extension_name pgcrypto)
+
+set(pgcrypto_src
+	pgcrypto.c
+	px.c
+	px-hmac.c
+	px-crypt.c
+	crypt-gensalt.c
+	crypt-blowfish.c
+	crypt-des.c
+	crypt-md5.c
+	mbuf.c
+	pgp.c
+	pgp-armor.c
+	pgp-cfb.c
+	pgp-compress.c
+	pgp-decrypt.c
+	pgp-encrypt.c
+	pgp-info.c
+	pgp-mpi.c
+	pgp-pubdec.c
+	pgp-pubenc.c
+	pgp-pubkey.c
+	pgp-s2k.c
+	pgp-pgsql.c
+)
+
+set(regress_files
+	init
+	md5
+	sha1
+	hmac-md5
+	hmac-sha1
+	blowfish
+	rijndael
+	crypt-des
+	crypt-md5
+	crypt-blowfish
+	crypt-xdes
+	pgp-armor
+	pgp-decrypt
+	pgp-encrypt
+	pgp-pubkey-decrypt
+	pgp-pubkey-encrypt
+	pgp-info
+)
+
+if(OPENSSL_FOUND)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	set(pgcrypto_src ${pgcrypto_src} openssl.c pgp-mpi-openssl.c)
+	set(regress_files ${regress_files}
+		sha2
+		des
+		3des
+		cast5
+	)
+else()
+	add_executable(gen-rtab rijndael.c)
+	target_compile_definitions(gen-rtab PRIVATE -DPRINT_TABS)
+
+	add_custom_command(
+		DEPENDS gen-rtab
+		OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/rijndael.tbl
+		COMMAND gen-rtab > rijndael.tbl
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	set(pgcrypto_src ${pgcrypto_src}
+		md5.c
+		sha1.c
+		sha2.c
+		internal.c
+		internal-sha2.c
+		blf.c
+		rijndael.tbl
+		rijndael.c
+		fortuna.c
+		random.c
+		pgp-mpi-internal.c
+		imath.c
+	)
+	set(regress_files ${regress_files} sha2)
+endif()
+
+if(ZLIB_FOUND)
+	set(regress_files ${regress_files} pgp-compression)
+endif()
+
+add_library(${extension_name} MODULE ${pgcrypto_src})
+target_link_libraries(${extension_name}
+	${contrib_libs}
+)
+if(OPENSSL_FOUND)
+	target_link_libraries(${extension_name} ${OPENSSL_LIBRARIES})
+endif()
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+if(ZLIB_FOUND)
+	target_link_libraries(${extension_name} ${ZLIB_LIBRARIES})
+endif()
+if(WIN32)
+	target_link_libraries(${extension_name} ws2_32)
+endif()
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.3.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/pgrowlocks/CMakeLists.txt b/contrib/pgrowlocks/CMakeLists.txt
new file mode 100644
index 0000000..ab294ce
--- /dev/null
+++ b/contrib/pgrowlocks/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pgrowlocks)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pgstattuple/CMakeLists.txt b/contrib/pgstattuple/CMakeLists.txt
new file mode 100644
index 0000000..5f0cac4
--- /dev/null
+++ b/contrib/pgstattuple/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pgstattuple)
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	pgstatindex.c
+	pgstatapprox.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files pgstattuple)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/postgres_fdw/CMakeLists.txt b/contrib/postgres_fdw/CMakeLists.txt
new file mode 100644
index 0000000..eb243ff
--- /dev/null
+++ b/contrib/postgres_fdw/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name postgres_fdw)
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	option.c
+	deparse.c
+	connection.c
+	shippable.c
+)
+target_link_libraries(${extension_name} ${contrib_libs} pq)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files postgres_fdw)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/seg/CMakeLists.txt b/contrib/seg/CMakeLists.txt
new file mode 100644
index 0000000..d464851
--- /dev/null
+++ b/contrib/seg/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name seg)
+
+bison_target(CUBE_PARSER segparse.y ${CMAKE_CURRENT_SOURCE_DIR}/segparse.c)
+flex_target(CUBE_SCANNER segscan.l  ${CMAKE_CURRENT_SOURCE_DIR}/segscan.c)
+add_flex_bison_dependency(CUBE_SCANNER CUBE_PARSER)
+set_source_files_properties(${BISON_CUBE_PARSER_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${FLEX_CUBE_SCANNER_OUTPUTS})
+
+add_library(${extension_name} MODULE
+	${extension_name}.c
+	${BISON_CUBE_PARSER_OUTPUTS}
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files seg)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/sepgsql/CMakeLists.txt b/contrib/sepgsql/CMakeLists.txt
new file mode 100644
index 0000000..c44c78c
--- /dev/null
+++ b/contrib/sepgsql/CMakeLists.txt
@@ -0,0 +1,45 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name sepgsql)
+
+set(sepgsql_sql_output
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql.in
+	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	COMMAND sed 's,MODULE_PATHNAME,$$libdir/${extension_name},g' sepgsql.sql.in > ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_library(${extension_name} MODULE
+	hooks.c
+	selinux.c
+	uavc.c
+	label.c
+	dml.c
+	database.c
+	schema.c
+	relation.c
+	proc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+)
+target_link_libraries(${extension_name} ${contrib_libs} ${SELINUX_LIBRARIES})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	DESTINATION ${PGSHAREDIR}/contrib)
+
+#set(regress_files seg)
+#CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/spi/CMakeLists.txt b/contrib/spi/CMakeLists.txt
new file mode 100644
index 0000000..49bc5d7
--- /dev/null
+++ b/contrib/spi/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+
+set(modules_list 
+	autoinc
+	insert_username
+	moddatetime
+	refint
+	timetravel
+)
+
+foreach(loop_var IN ITEMS ${modules_list})
+	add_library(${loop_var} MODULE ${loop_var}.c)
+	target_compile_definitions(${loop_var} PRIVATE -DREFINT_VERBOSE)
+	target_link_libraries(${loop_var} ${contrib_libs})
+	set_target_properties(${loop_var} PROPERTIES PREFIX "")
+	add_dependencies(${loop_var} postgres)
+	if(MSVC)
+		gen_def(${loop_var})
+	endif()
+	if(NOT PGXS)
+		CMAKE_SET_TARGET_FOLDER(${loop_var} contrib/spi)
+	endif()
+	install(TARGETS ${loop_var}
+			RUNTIME DESTINATION ${PGBINDIR}
+			LIBRARY DESTINATION ${LIBDIR})
+	install(FILES ${loop_var}.control ${loop_var}--1.0.sql ${loop_var}--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+endforeach(loop_var)
diff --git a/contrib/sslinfo/CMakeLists.txt b/contrib/sslinfo/CMakeLists.txt
new file mode 100644
index 0000000..60d0a77
--- /dev/null
+++ b/contrib/sslinfo/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	${OPENSSL_INCLUDE_DIR}
+)
+
+set(extension_name sslinfo)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${OPENSSL_LIBRARIES})
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/tablefunc/CMakeLists.txt b/contrib/tablefunc/CMakeLists.txt
new file mode 100644
index 0000000..1c1550d
--- /dev/null
+++ b/contrib/tablefunc/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tablefunc)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tablefunc)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tcn/CMakeLists.txt b/contrib/tcn/CMakeLists.txt
new file mode 100644
index 0000000..87273a8
--- /dev/null
+++ b/contrib/tcn/CMakeLists.txt
@@ -0,0 +1,21 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tcn)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/tsearch2/CMakeLists.txt b/contrib/tsearch2/CMakeLists.txt
new file mode 100644
index 0000000..09e792c
--- /dev/null
+++ b/contrib/tsearch2/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsearch2)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsearch2)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tsm_system_rows/CMakeLists.txt b/contrib/tsm_system_rows/CMakeLists.txt
new file mode 100644
index 0000000..874b018
--- /dev/null
+++ b/contrib/tsm_system_rows/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsm_system_rows)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsm_system_rows)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tsm_system_time/CMakeLists.txt b/contrib/tsm_system_time/CMakeLists.txt
new file mode 100644
index 0000000..c723e1a
--- /dev/null
+++ b/contrib/tsm_system_time/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsm_system_time)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsm_system_time)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/unaccent/CMakeLists.txt b/contrib/unaccent/CMakeLists.txt
new file mode 100644
index 0000000..be6fa70
--- /dev/null
+++ b/contrib/unaccent/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name unaccent)
+
+add_library(${extension_name} MODULE ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	${extension_name}.rules
+	DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regress_files unaccent)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/uuid-ossp/CMakeLists.txt b/contrib/uuid-ossp/CMakeLists.txt
new file mode 100644
index 0000000..4886f0f
--- /dev/null
+++ b/contrib/uuid-ossp/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+include_directories(${LIBUUID_INCLUDE_DIRS})
+include_directories("${PROJECT_SOURCE_DIR}/contrib/pgcrypto")
+
+set(extension_name uuid-ossp)
+
+add_library(${extension_name} MODULE ${extension_name}.c ${UUID_EXTRA_OBJS})
+target_link_libraries(${extension_name} ${contrib_libs} ${LIBUUID_LIBRARIES})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files uuid_ossp)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/vacuumlo/CMakeLists.txt b/contrib/vacuumlo/CMakeLists.txt
new file mode 100644
index 0000000..e7b0481
--- /dev/null
+++ b/contrib/vacuumlo/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name vacuumlo)
+
+add_executable(${extension_name} ${extension_name}.c)
+target_link_libraries(${extension_name} port pgcommon pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/xml2/CMakeLists.txt b/contrib/xml2/CMakeLists.txt
new file mode 100644
index 0000000..4880422
--- /dev/null
+++ b/contrib/xml2/CMakeLists.txt
@@ -0,0 +1,40 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	${LIBXML2_INCLUDE_DIR}
+)
+
+if(LIBXSLT_FOUND)
+	include_directories(BEFORE ${LIBXSLT_INCLUDE_DIR})
+endif()
+
+set(extension_name xml2)
+set(extension_lib_name pgxml)
+
+add_library(${extension_lib_name} MODULE xpath.c xslt_proc.c)
+target_link_libraries(${extension_lib_name}
+	${contrib_libs}
+	${LIBXML2_LIBRARIES}
+)
+if(LIBXSLT_FOUND)
+	target_link_libraries(${extension_lib_name} ${LIBXSLT_LIBRARIES})
+endif()
+set_target_properties(${extension_lib_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_lib_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_lib_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files xml2)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..fc4f7bd
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,85 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(gen_errorcodes_depend
+	${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt
+	${PROJECT_SOURCE_DIR}/src/backend/utils/generate-errcodes.pl
+)
+set(gen_errorcodes_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/errcodes.h
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_errorcodes_depend}
+	OUTPUT ${gen_errorcodes_output}
+	COMMAND ${PERL_EXECUTABLE} generate-errcodes.pl errcodes.txt > ${gen_errorcodes_output}
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/backend/utils
+)
+
+add_custom_target(gen_errorcodes DEPENDS ${gen_errorcodes_output})
+
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${gen_errorcodes_output})
+
+set(PARSER_SCAN_FLEX_FLAGS, "-Cfe -p -p")
+bison_target(PARSER_GRAM
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.y
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+)
+flex_target(PARSER_SCAN
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.l
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+	${PARSER_SCAN_FLEX_FLAGS}
+)
+
+set_source_files_properties(${BISON_PARSER_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_PARSER_SCAN_OUTPUTS})
+
+add_custom_command(
+	MAIN_DEPENDENCY ${BISON_PARSER_GRAM_OUTPUTS}
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+	COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/src/backend/parser/gram.h ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+)
+
+add_custom_target(generate_parser_gram_h DEPENDS ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h)
+
+add_subdirectory(include)
+add_subdirectory(port)
+add_subdirectory(common)
+add_subdirectory(fe_utils)
+add_subdirectory(interfaces/libpq)
+add_subdirectory(interfaces/ecpg/pgtypeslib)
+add_subdirectory(interfaces/ecpg/ecpglib)
+add_subdirectory(interfaces/ecpg/compatlib)
+add_subdirectory(interfaces/ecpg/include)
+
+add_subdirectory(backend)
+add_subdirectory(timezone)
+add_subdirectory(test/regress)
+add_subdirectory(test/isolation)
+
+add_subdirectory(pl/plpgsql/src)
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(pl/plpython)
+endif()
+if(PERLLIBS_FOUND)
+	add_subdirectory(pl/plperl)
+endif()
+if(TCL_FOUND)
+	add_subdirectory(pl/tcl)
+endif()
+
+add_subdirectory(bin/initdb)
+add_subdirectory(bin/pg_archivecleanup)
+add_subdirectory(bin/pg_basebackup)
+add_subdirectory(bin/pg_config)
+add_subdirectory(bin/pg_controldata)
+add_subdirectory(bin/pg_ctl)
+add_subdirectory(bin/pg_dump)
+add_subdirectory(bin/pg_resetxlog)
+add_subdirectory(bin/pg_rewind)
+add_subdirectory(bin/pg_test_fsync)
+add_subdirectory(bin/pg_test_timing)
+add_subdirectory(bin/pg_upgrade)
+add_subdirectory(bin/pg_xlogdump)
+add_subdirectory(bin/pgbench)
+add_subdirectory(bin/psql)
+add_subdirectory(bin/scripts)
diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt
new file mode 100644
index 0000000..9633c6c
--- /dev/null
+++ b/src/backend/CMakeLists.txt
@@ -0,0 +1,1103 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+set(postgres_include_catalog "${PROJECT_SOURCE_DIR}/src/include/catalog")
+
+set(gen_fmgrtab_depend
+	utils/Gen_fmgrtab.pl
+	${CMAKE_CURRENT_SOURCE_DIR}/catalog/Catalog.pm
+	${postgres_include_catalog}/pg_proc.h
+)
+set(gen_fmgrtab_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/fmgroids.h
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/fmgrtab.c
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_fmgrtab_depend}
+	OUTPUT ${gen_fmgrtab_output}
+	COMMAND ${PERL_EXECUTABLE} -I${CMAKE_CURRENT_SOURCE_DIR}/catalog Gen_fmgrtab.pl ${postgres_include_catalog}/pg_proc.h
+	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/utils/fmgroids.h ${PROJECT_SOURCE_DIR}/src/include/utils/fmgroids.h
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
+)
+
+set(gen_probe_depend
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/Gen_dummy_probes.sed
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/probes.d
+)
+
+set(gen_probe_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/probes.h
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_probe_depend}
+	OUTPUT ${gen_probe_output}
+	COMMAND sed -f Gen_dummy_probes.sed probes.d >  ${gen_probe_output}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
+)
+
+flex_target(GUC_SCANNER utils/misc/guc-file.l  ${CMAKE_CURRENT_SOURCE_DIR}/utils/misc/guc-file.c)
+set_source_files_properties(utils/misc/guc.c PROPERTIES OBJECT_DEPENDS ${FLEX_GUC_SCANNER_OUTPUTS})
+
+if(WIN32 OR MINGW)
+	set(dynloader_SRCS port/dynloader/win32.c)
+	set(dynloader_H port/dynloader/win32.h)
+elseif(CYGWIN)
+	set(dynloader_SRCS port/dynloader/cygwin.c)
+	set(dynloader_H port/dynloader/cygwin.h)
+elseif(APPLE)
+	set(dynloader_SRCS port/dynloader/darwin.c)
+	set(dynloader_H port/dynloader/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(dynloader_SRCS port/dynloader/linux.c)
+	set(dynloader_H port/dynloader/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+	set(dynloader_SRCS port/dynloader/hpux.c)
+	set(dynloader_H port/dynloader/hpux.h)
+#TODO: FreeBSD, OpenBSD, NetBSD is equal loader
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+	set(dynloader_SRCS port/dynloader/freebsd.c)
+	set(dynloader_H port/dynloader/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+	set(dynloader_SRCS port/dynloader/openbsd.c)
+	set(dynloader_H port/dynloader/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+	set(dynloader_SRCS port/dynloader/netbsd.c)
+	set(dynloader_H port/dynloader/netbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(dynloader_SRCS port/dynloader/solaris.c)
+	set(dynloader_H port/dynloader/solaris.h)
+else(WIN32 OR MINGW)
+	message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+add_custom_command(
+	MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${dynloader_H}"
+	OUTPUT "${PROJECT_SOURCE_DIR}/src/include/dynloader.h"
+	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${dynloader_H} ${PROJECT_SOURCE_DIR}/src/include/dynloader.h
+)
+
+#Need for bin/pg_xlogdump
+set(access_rmgrdesc_SRC
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/brindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/clogdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/committsdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/dbasedesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/gindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/gistdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/hashdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/heapdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/mxactdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/nbtdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/relmapdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/replorigindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/seqdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/smgrdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/spgdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/standbydesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/tblspcdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/xactdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/xlogdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/genericdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/logicalmsgdesc.c
+)
+
+set(rmgrdesc_SRC
+	${access_rmgrdesc_SRC}
+	PARENT_SCOPE
+)
+
+set(access_SRCS
+	${gen_fmgrtab_output}
+	${gen_probe_output}
+	${PROJECT_SOURCE_DIR}/src/include/dynloader.h
+	${access_rmgrdesc_SRC}
+
+	access/brin/brin.c
+	access/brin/brin_pageops.c
+	access/brin/brin_revmap.c
+	access/brin/brin_tuple.c
+	access/brin/brin_xlog.c
+	access/brin/brin_minmax.c
+	access/brin/brin_inclusion.c
+	access/brin/brin_validate.c
+
+	access/common/heaptuple.c
+	access/common/indextuple.c
+	access/common/printtup.c
+	access/common/reloptions.c
+	access/common/scankey.c
+	access/common/tupconvert.c
+	access/common/tupdesc.c
+
+	access/gin/ginutil.c
+	access/gin/gininsert.c
+	access/gin/ginxlog.c
+	access/gin/ginentrypage.c
+	access/gin/gindatapage.c
+	access/gin/ginbtree.c
+	access/gin/ginscan.c
+	access/gin/ginget.c
+	access/gin/ginvacuum.c
+	access/gin/ginarrayproc.c
+	access/gin/ginbulk.c
+	access/gin/ginfast.c
+	access/gin/ginpostinglist.c
+	access/gin/ginlogic.c
+	access/gin/ginvalidate.c
+
+	access/gist/gist.c
+	access/gist/gistutil.c
+	access/gist/gistxlog.c
+	access/gist/gistvacuum.c
+	access/gist/gistget.c
+	access/gist/gistscan.c
+	access/gist/gistproc.c
+	access/gist/gistsplit.c
+	access/gist/gistbuild.c
+	access/gist/gistbuildbuffers.c
+	access/gist/gistvalidate.c
+
+	access/hash/hash.c
+	access/hash/hashfunc.c
+	access/hash/hashinsert.c
+	access/hash/hashovfl.c
+	access/hash/hashpage.c
+	access/hash/hashscan.c
+	access/hash/hashsearch.c
+	access/hash/hashsort.c
+	access/hash/hashutil.c
+	access/hash/hashvalidate.c
+
+	access/heap/heapam.c
+	access/heap/hio.c
+	access/heap/pruneheap.c
+	access/heap/rewriteheap.c
+	access/heap/syncscan.c
+	access/heap/tuptoaster.c
+	access/heap/visibilitymap.c
+
+	access/index/genam.c
+	access/index/indexam.c
+	access/index/amapi.c
+	access/index/amvalidate.c
+
+	access/nbtree/nbtcompare.c
+	access/nbtree/nbtinsert.c
+	access/nbtree/nbtpage.c
+	access/nbtree/nbtree.c
+	access/nbtree/nbtsearch.c
+	access/nbtree/nbtutils.c
+	access/nbtree/nbtsort.c
+	access/nbtree/nbtxlog.c
+	access/nbtree/nbtvalidate.c
+
+	access/spgist/spgutils.c
+	access/spgist/spginsert.c
+	access/spgist/spgscan.c
+	access/spgist/spgvacuum.c
+	access/spgist/spgdoinsert.c
+	access/spgist/spgxlog.c
+	access/spgist/spgtextproc.c
+	access/spgist/spgquadtreeproc.c
+	access/spgist/spgkdtreeproc.c
+	access/spgist/spgvalidate.c
+
+	access/tablesample/bernoulli.c
+	access/tablesample/system.c
+	access/tablesample/tablesample.c
+
+	access/transam/clog.c
+	access/transam/commit_ts.c
+	access/transam/multixact.c
+	access/transam/generic_xlog.c
+	access/transam/parallel.c
+	access/transam/rmgr.c
+	access/transam/slru.c
+	access/transam/subtrans.c
+	access/transam/timeline.c
+	access/transam/transam.c
+	access/transam/twophase.c
+	access/transam/twophase_rmgr.c
+	access/transam/varsup.c
+	access/transam/xact.c
+	access/transam/xlog.c
+	access/transam/xlogarchive.c
+	access/transam/xlogfuncs.c
+	access/transam/xloginsert.c
+	access/transam/xlogreader.c
+	access/transam/xlogutils.c
+)
+
+bison_target(BOOTSTRAP_PARSER bootstrap/bootparse.y ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/bootparse.c)
+flex_target(BOOTSTRAP_SCANNER bootstrap/bootscanner.l  ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/bootscanner.c)
+add_flex_bison_dependency(BOOTSTRAP_SCANNER BOOTSTRAP_PARSER)
+
+set_source_files_properties(bootstrap/bootparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_BOOTSTRAP_SCANNER_OUTPUTS})
+
+set(bootstrap_SRCS
+	bootstrap/bootstrap.c
+	${BISON_BOOTSTRAP_PARSER_OUTPUTS}
+)
+
+set_source_files_properties(
+	${BISON_BOOTSTRAP_PARSER_OUTPUTS}
+	PROPERTIES GENERATED TRUE
+)
+
+set(POSTGRES_BKI_SRCS
+	${postgres_include_catalog}/pg_proc.h
+	${postgres_include_catalog}/pg_type.h
+	${postgres_include_catalog}/pg_attribute.h
+	${postgres_include_catalog}/pg_class.h
+	${postgres_include_catalog}/pg_attrdef.h
+	${postgres_include_catalog}/pg_constraint.h
+	${postgres_include_catalog}/pg_inherits.h
+	${postgres_include_catalog}/pg_index.h
+	${postgres_include_catalog}/pg_operator.h
+	${postgres_include_catalog}/pg_opfamily.h
+	${postgres_include_catalog}/pg_opclass.h
+	${postgres_include_catalog}/pg_am.h
+	${postgres_include_catalog}/pg_amop.h
+	${postgres_include_catalog}/pg_amproc.h
+	${postgres_include_catalog}/pg_language.h
+	${postgres_include_catalog}/pg_largeobject_metadata.h
+	${postgres_include_catalog}/pg_largeobject.h
+	${postgres_include_catalog}/pg_aggregate.h
+	${postgres_include_catalog}/pg_statistic.h
+	${postgres_include_catalog}/pg_rewrite.h
+	${postgres_include_catalog}/pg_trigger.h
+	${postgres_include_catalog}/pg_event_trigger.h
+	${postgres_include_catalog}/pg_description.h
+	${postgres_include_catalog}/pg_cast.h
+	${postgres_include_catalog}/pg_enum.h
+	${postgres_include_catalog}/pg_namespace.h
+	${postgres_include_catalog}/pg_conversion.h
+	${postgres_include_catalog}/pg_depend.h
+	${postgres_include_catalog}/pg_database.h
+	${postgres_include_catalog}/pg_db_role_setting.h
+	${postgres_include_catalog}/pg_tablespace.h
+	${postgres_include_catalog}/pg_pltemplate.h
+	${postgres_include_catalog}/pg_authid.h
+	${postgres_include_catalog}/pg_auth_members.h
+	${postgres_include_catalog}/pg_shdepend.h
+	${postgres_include_catalog}/pg_shdescription.h
+	${postgres_include_catalog}/pg_ts_config.h
+	${postgres_include_catalog}/pg_ts_config_map.h
+	${postgres_include_catalog}/pg_ts_dict.h
+	${postgres_include_catalog}/pg_ts_parser.h
+	${postgres_include_catalog}/pg_ts_template.h
+	${postgres_include_catalog}/pg_extension.h
+	${postgres_include_catalog}/pg_foreign_data_wrapper.h
+	${postgres_include_catalog}/pg_foreign_server.h
+	${postgres_include_catalog}/pg_user_mapping.h
+	${postgres_include_catalog}/pg_foreign_table.h
+	${postgres_include_catalog}/pg_policy.h
+	${postgres_include_catalog}/pg_replication_origin.h
+	${postgres_include_catalog}/pg_default_acl.h
+	${postgres_include_catalog}/pg_init_privs.h
+	${postgres_include_catalog}/pg_seclabel.h
+	${postgres_include_catalog}/pg_shseclabel.h
+	${postgres_include_catalog}/pg_collation.h
+	${postgres_include_catalog}/pg_range.h
+	${postgres_include_catalog}/pg_transform.h
+	${postgres_include_catalog}/toasting.h
+	${postgres_include_catalog}/indexing.h
+)
+
+set(catalog_SRCS
+	catalog/catalog.c
+	catalog/dependency.c
+	catalog/heap.c
+	catalog/index.c
+	catalog/indexing.c
+	catalog/namespace.c
+	catalog/aclchk.c
+	catalog/objectaccess.c
+	catalog/objectaddress.c
+	catalog/pg_aggregate.c
+	catalog/pg_collation.c
+	catalog/pg_constraint.c
+	catalog/pg_conversion.c
+	catalog/pg_depend.c
+	catalog/pg_enum.c
+	catalog/pg_inherits.c
+	catalog/pg_largeobject.c
+	catalog/pg_namespace.c
+	catalog/pg_operator.c
+	catalog/pg_proc.c
+	catalog/pg_range.c
+	catalog/pg_db_role_setting.c
+	catalog/pg_shdepend.c
+	catalog/pg_type.c
+	catalog/storage.c
+	catalog/toasting.c
+)
+
+set(catalog_include
+	"-I${PROJECT_SOURCE_DIR}/src/backend/catalog"
+	"-I${PROJECT_SOURCE_DIR}/src/include/catalog"
+)
+
+add_custom_command(
+	DEPENDS ${POSTGRES_BKI_SRCS}
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h
+	COMMAND ${PERL_EXECUTABLE} genbki.pl ${catalog_include} --set-version=${POSTGRES_MAJOR_VERSION} ${POSTGRES_BKI_SRCS}
+	COMMAND ${CMAKE_COMMAND} -E copy schemapg.h ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/catalog
+)
+
+set_source_files_properties(utils/cache/relcache.c
+	PROPERTIES OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h)
+
+set(commands_SRCS
+	commands/aggregatecmds.c
+	commands/alter.c
+	commands/analyze.c
+	commands/async.c
+	commands/amcmds.c
+	commands/cluster.c
+	commands/comment.c
+	commands/collationcmds.c
+	commands/constraint.c
+	commands/conversioncmds.c
+	commands/copy.c
+	commands/createas.c
+	commands/dbcommands.c
+	commands/define.c
+	commands/discard.c
+	commands/dropcmds.c
+	commands/event_trigger.c
+	commands/explain.c
+	commands/extension.c
+	commands/foreigncmds.c
+	commands/functioncmds.c
+	commands/indexcmds.c
+	commands/lockcmds.c
+	commands/matview.c
+	commands/operatorcmds.c
+	commands/opclasscmds.c
+	commands/policy.c
+	commands/portalcmds.c
+	commands/prepare.c
+	commands/proclang.c
+	commands/schemacmds.c
+	commands/seclabel.c
+	commands/sequence.c
+	commands/tablecmds.c
+	commands/tablespace.c
+	commands/trigger.c
+	commands/tsearchcmds.c
+	commands/typecmds.c
+	commands/user.c
+	commands/vacuum.c
+	commands/vacuumlazy.c
+	commands/variable.c
+	commands/view.c
+)
+
+set(executor_SRCS
+	executor/execAmi.c
+	executor/execCurrent.c
+	executor/execGrouping.c
+	executor/execIndexing.c
+	executor/execJunk.c
+	executor/execMain.c
+	executor/execProcnode.c
+	executor/execParallel.c
+	executor/execQual.c
+	executor/execScan.c
+	executor/execTuples.c
+	executor/execUtils.c
+	executor/functions.c
+	executor/instrument.c
+	executor/tqueue.c
+	executor/nodeAppend.c
+	executor/nodeAgg.c
+	executor/nodeBitmapAnd.c
+	executor/nodeBitmapOr.c
+	executor/nodeBitmapHeapscan.c
+	executor/nodeBitmapIndexscan.c
+	executor/nodeCustom.c
+	executor/nodeHash.c
+	executor/nodeHashjoin.c
+	executor/nodeIndexscan.c
+	executor/nodeIndexonlyscan.c
+	executor/nodeLimit.c
+	executor/nodeLockRows.c
+	executor/nodeMaterial.c
+	executor/nodeMergeAppend.c
+	executor/nodeMergejoin.c
+	executor/nodeModifyTable.c
+	executor/nodeNestloop.c
+	executor/nodeFunctionscan.c
+	executor/nodeRecursiveunion.c
+	executor/nodeResult.c
+	executor/nodeSamplescan.c
+	executor/nodeSeqscan.c
+	executor/nodeSetOp.c
+	executor/nodeSort.c
+	executor/nodeUnique.c
+	executor/nodeValuesscan.c
+	executor/nodeCtescan.c
+	executor/nodeWorktablescan.c
+	executor/nodeGroup.c
+	executor/nodeGather.c
+	executor/nodeSubplan.c
+	executor/nodeSubqueryscan.c
+	executor/nodeTidscan.c
+	executor/nodeForeignscan.c
+	executor/nodeWindowAgg.c
+	executor/tstoreReceiver.c
+	executor/spi.c
+)
+
+set(lib_SRCS
+	lib/binaryheap.c
+	lib/bipartite_match.c
+	lib/hyperloglog.c
+	lib/ilist.c
+	lib/pairingheap.c
+	lib/rbtree.c
+	lib/stringinfo.c
+)
+
+if(OPENSSL_FOUND)
+	set(libpq_ssl_SRCS libpq/be-secure-openssl.c)
+endif(OPENSSL_FOUND)
+
+set(libpq_SRCS
+	libpq/be-fsstubs.c
+	libpq/be-secure.c
+	libpq/auth.c
+	libpq/crypt.c
+	libpq/hba.c
+	libpq/pqcomm.c
+	libpq/pqformat.c
+	libpq/pqmq.c
+	libpq/pqsignal.c
+	libpq/ifaddr.c
+	${libpq_ssl_SRCS}
+)
+
+set(utils_SRCS
+	utils/error/assert.c
+	utils/error/elog.c
+	utils/cache/attoptcache.c
+	utils/cache/catcache.c
+	utils/cache/evtcache.c
+	utils/cache/inval.c
+	utils/cache/plancache.c
+	utils/cache/relcache.c
+	utils/cache/relmapper.c
+	utils/cache/relfilenodemap.c
+	utils/cache/spccache.c
+	utils/cache/syscache.c
+	utils/cache/lsyscache.c
+	utils/cache/typcache.c
+	utils/cache/ts_cache.c
+	utils/mmgr/aset.c
+	utils/mmgr/mcxt.c
+	utils/mmgr/portalmem.c
+	utils/adt/acl.c
+	utils/adt/arrayfuncs.c
+	utils/adt/array_expanded.c
+	utils/adt/array_selfuncs.c
+	utils/adt/array_typanalyze.c
+	utils/adt/array_userfuncs.c
+	utils/adt/arrayutils.c
+	utils/adt/ascii.c
+	utils/adt/bool.c
+	utils/adt/cash.c
+	utils/adt/char.c
+	utils/adt/date.c
+	utils/adt/datetime.c
+	utils/adt/datum.c
+	utils/adt/dbsize.c
+	utils/adt/domains.c
+	utils/adt/encode.c
+	utils/adt/enum.c
+	utils/adt/expandeddatum.c
+	utils/adt/float.c
+	utils/adt/format_type.c
+	utils/adt/formatting.c
+	utils/adt/genfile.c
+	utils/adt/geo_ops.c
+	utils/adt/geo_selfuncs.c
+	utils/adt/geo_spgist.c
+	utils/adt/inet_cidr_ntop.c
+	utils/adt/inet_net_pton.c
+	utils/adt/int.c
+	utils/adt/int8.c
+	utils/adt/json.c
+	utils/adt/jsonb.c
+	utils/adt/jsonb_gin.c
+	utils/adt/jsonb_op.c
+	utils/adt/jsonb_util.c
+	utils/adt/jsonfuncs.c
+	utils/adt/like.c
+	#utils/adt/like_match.c
+	utils/adt/lockfuncs.c
+	utils/adt/mac.c
+	utils/adt/misc.c
+	utils/adt/nabstime.c
+	utils/adt/name.c
+	utils/adt/network.c
+	utils/adt/network_gist.c
+	utils/adt/network_selfuncs.c
+	utils/adt/numeric.c
+	utils/adt/numutils.c
+	utils/adt/oid.c
+	utils/adt/oracle_compat.c
+	utils/adt/orderedsetaggs.c
+	utils/adt/pg_locale.c
+	utils/adt/pg_lsn.c
+	utils/adt/pg_upgrade_support.c
+	utils/adt/pgstatfuncs.c
+	utils/adt/pseudotypes.c
+	utils/adt/quote.c
+	utils/adt/rangetypes.c
+	utils/adt/rangetypes_gist.c
+	utils/adt/rangetypes_selfuncs.c
+	utils/adt/rangetypes_spgist.c
+	utils/adt/rangetypes_typanalyze.c
+	utils/adt/regexp.c
+	utils/adt/regproc.c
+	utils/adt/ri_triggers.c
+	utils/adt/rowtypes.c
+	utils/adt/ruleutils.c
+	utils/adt/selfuncs.c
+	utils/adt/tid.c
+	utils/adt/timestamp.c
+	utils/adt/trigfuncs.c
+	utils/adt/tsginidx.c
+	utils/adt/tsgistidx.c
+	utils/adt/tsquery.c
+	utils/adt/tsquery_cleanup.c
+	utils/adt/tsquery_gist.c
+	utils/adt/tsquery_op.c
+	utils/adt/tsquery_rewrite.c
+	utils/adt/tsquery_util.c
+	utils/adt/tsrank.c
+	utils/adt/tsvector.c
+	utils/adt/tsvector_op.c
+	utils/adt/tsvector_parser.c
+	utils/adt/txid.c
+	utils/adt/uuid.c
+	utils/adt/varbit.c
+	utils/adt/varchar.c
+	utils/adt/varlena.c
+	utils/adt/amutils.c
+	utils/adt/version.c
+	utils/adt/windowfuncs.c
+	utils/adt/xid.c
+	utils/adt/xml.c
+	utils/adt/network_spgist.c
+	utils/fmgr/dfmgr.c
+	utils/fmgr/fmgr.c
+	utils/fmgr/funcapi.c
+	utils/hash/dynahash.c
+	utils/hash/hashfn.c
+	utils/hash/pg_crc.c
+	utils/init/globals.c
+	utils/init/miscinit.c
+	utils/init/postinit.c
+	utils/resowner/resowner.c
+	utils/sort/logtape.c
+	utils/sort/sortsupport.c
+	utils/sort/tuplesort.c
+	utils/sort/tuplestore.c
+	utils/time/combocid.c
+	utils/time/tqual.c
+	utils/time/snapmgr.c
+	utils/misc/guc.c
+	utils/misc/help_config.c
+	utils/misc/pg_rusage.c
+	utils/misc/pg_controldata.c
+	utils/misc/pg_config.c
+	utils/misc/ps_status.c
+	utils/misc/rls.c
+	utils/misc/sampling.c
+	utils/misc/superuser.c
+	utils/misc/timeout.c
+	utils/misc/tzparser.c
+	utils/mb/encnames.c
+	utils/mb/conv.c
+	utils/mb/mbutils.c
+	utils/mb/wchar.c
+	utils/mb/wstrcmp.c
+	utils/mb/wstrncmp.c
+)
+
+set(nodes_SRCS
+	nodes/nodeFuncs.c
+	nodes/nodes.c
+	nodes/list.c
+	nodes/bitmapset.c
+	nodes/tidbitmap.c
+	nodes/copyfuncs.c
+	nodes/equalfuncs.c
+	nodes/makefuncs.c
+	nodes/outfuncs.c
+	nodes/readfuncs.c
+	nodes/print.c
+	nodes/read.c
+	nodes/params.c
+	nodes/value.c
+	nodes/extensible.c
+)
+
+set(optimizer_SRCS
+	optimizer/geqo/geqo_copy.c
+	optimizer/geqo/geqo_eval.c
+	optimizer/geqo/geqo_main.c
+	optimizer/geqo/geqo_misc.c
+	optimizer/geqo/geqo_mutation.c
+	optimizer/geqo/geqo_pool.c
+	optimizer/geqo/geqo_random.c
+	optimizer/geqo/geqo_recombination.c
+	optimizer/geqo/geqo_selection.c
+	optimizer/geqo/geqo_erx.c
+	optimizer/geqo/geqo_pmx.c
+	optimizer/geqo/geqo_cx.c
+	optimizer/geqo/geqo_px.c
+	optimizer/geqo/geqo_ox1.c
+	optimizer/geqo/geqo_ox2.c
+	optimizer/path/allpaths.c
+	optimizer/path/clausesel.c
+	optimizer/path/costsize.c
+	optimizer/path/equivclass.c
+	optimizer/path/indxpath.c
+	optimizer/path/joinpath.c
+	optimizer/path/joinrels.c
+	optimizer/path/pathkeys.c
+	optimizer/path/tidpath.c
+	optimizer/plan/analyzejoins.c
+	optimizer/plan/createplan.c
+	optimizer/plan/initsplan.c
+	optimizer/plan/planagg.c
+	optimizer/plan/planmain.c
+	optimizer/plan/planner.c
+	optimizer/plan/setrefs.c
+	optimizer/plan/subselect.c
+	optimizer/prep/prepjointree.c
+	optimizer/prep/prepqual.c
+	optimizer/prep/prepsecurity.c
+	optimizer/prep/preptlist.c
+	optimizer/prep/prepunion.c
+	optimizer/util/clauses.c
+	optimizer/util/joininfo.c
+	optimizer/util/orclauses.c
+	optimizer/util/pathnode.c
+	optimizer/util/placeholder.c
+	optimizer/util/plancat.c
+	optimizer/util/predtest.c
+	optimizer/util/relnode.c
+	optimizer/util/restrictinfo.c
+	optimizer/util/tlist.c
+	optimizer/util/var.c
+)
+
+set(rewrite_SRCS
+	rewrite/rewriteRemove.c
+	rewrite/rewriteDefine.c
+	rewrite/rewriteHandler.c
+	rewrite/rewriteManip.c
+	rewrite/rewriteSupport.c
+	rewrite/rowsecurity.c
+)
+
+set(parser_SRCS
+	parser/analyze.c
+	#parser/gram.c
+	parser/parser.c
+	parser/parse_agg.c
+	parser/parse_clause.c
+	parser/parse_coerce.c
+	parser/parse_collate.c
+	parser/parse_cte.c
+	parser/parse_expr.c
+	parser/parse_func.c
+	parser/parse_node.c
+	parser/parse_oper.c
+	parser/parse_param.c
+	parser/parse_relation.c
+	parser/parse_target.c
+	parser/parse_type.c
+	parser/parse_utilcmd.c
+	parser/scansup.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+)
+
+set_source_files_properties(
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+	PROPERTIES GENERATED TRUE
+)
+
+set(tcop_SRCS
+	tcop/dest.c
+	tcop/fastpath.c
+	tcop/postgres.c
+	tcop/pquery.c
+	tcop/utility.c
+)
+
+set(tsearch_SRCS
+	tsearch/ts_locale.c
+	tsearch/ts_parse.c
+	tsearch/wparser.c
+	tsearch/wparser_def.c
+	tsearch/dict.c
+	tsearch/dict_simple.c
+	tsearch/dict_synonym.c
+	tsearch/dict_thesaurus.c
+	tsearch/dict_ispell.c
+	tsearch/regis.c
+	tsearch/spell.c
+	tsearch/to_tsany.c
+	tsearch/ts_selfuncs.c
+	tsearch/ts_typanalyze.c
+	tsearch/ts_utils.c
+)
+
+install(FILES
+			tsearch/dicts/ispell_sample.dict
+			tsearch/dicts/ispell_sample.affix
+			tsearch/dicts/hunspell_sample.affix
+			tsearch/dicts/hunspell_sample_long.affix
+			tsearch/dicts/hunspell_sample_long.dict
+			tsearch/dicts/hunspell_sample_num.affix
+			tsearch/dicts/hunspell_sample_num.dict
+			tsearch/dicts/synonym_sample.syn
+			tsearch/dicts/thesaurus_sample.ths
+		DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regex_SRCS
+	regex/regcomp.c
+	regex/regerror.c
+	regex/regexec.c
+	regex/regfree.c
+	regex/regprefix.c
+	regex/regexport.c
+)
+
+set(postmaster_SRCS
+	postmaster/autovacuum.c
+	postmaster/bgworker.c
+	postmaster/bgwriter.c
+	postmaster/checkpointer.c
+	postmaster/fork_process.c
+	postmaster/pgarch.c
+	postmaster/pgstat.c
+	postmaster/postmaster.c
+	postmaster/startup.c
+	postmaster/syslogger.c
+	postmaster/walwriter.c
+)
+
+if(WIN32 OR CYGWIN OR MINGW)
+	set(backend_port_win32_SRC
+		port/win32/timer.c
+		port/win32/socket.c
+		port/win32/signal.c
+		# I hope it is not necessary for modern MinGW
+		#port/win32/mingwcompat.c
+		port/win32/crashdump.c
+	)
+	if(NAVE_MINIDUMP_TYPE)
+		set(backend_port_win32_SRC
+			${backend_port_win32_SRC}
+			port/win32/crashdump.c
+		)
+	endif(NAVE_MINIDUMP_TYPE)
+endif()
+
+set(gen_lwlocknames_depend
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/generate-lwlocknames.pl
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.txt
+)
+
+set(gen_lwlocknames_output
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.c
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.h
+	${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+)
+
+
+add_custom_command(
+	OUTPUT ${gen_lwlocknames_output}
+	MAIN_DEPENDENCY ${gen_lwlocknames_depend}
+	COMMAND ${PERL_EXECUTABLE} generate-lwlocknames.pl lwlocknames.txt
+	COMMAND ${CMAKE_COMMAND} -E copy lwlocknames.h ${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr
+)
+
+set(backend_port_SRCS
+	port/atomics.c
+	port/tas/${TAS}
+	${backend_port_win32_SRC}
+	${backend_port_darwin_SRC}
+	${dynloader_SRCS}
+	${SEMA_IMPLEMENTATION}
+	${SHMEM_IMPLEMENTATION}
+)
+
+
+set(storage_SRCS
+	${gen_lwlocknames_output}
+	storage/buffer/buf_table.c
+	storage/buffer/buf_init.c
+	storage/buffer/bufmgr.c
+	storage/buffer/freelist.c
+	storage/buffer/localbuf.c
+	storage/file/fd.c
+	storage/file/buffile.c
+	storage/file/copydir.c
+	storage/file/reinit.c
+	storage/freespace/freespace.c
+	storage/freespace/fsmpage.c
+	storage/freespace/indexfsm.c
+	storage/ipc/dsm_impl.c
+	storage/ipc/dsm.c
+	storage/ipc/ipc.c
+	storage/ipc/ipci.c
+	storage/ipc/pmsignal.c
+	storage/ipc/procarray.c
+	storage/ipc/procsignal.c
+	storage/ipc/shmem.c
+	storage/ipc/shmqueue.c
+	storage/ipc/shm_mq.c
+	storage/ipc/shm_toc.c
+	storage/ipc/sinval.c
+	storage/ipc/sinvaladt.c
+	storage/ipc/standby.c
+	storage/ipc/latch.c
+	storage/large_object/inv_api.c
+	storage/lmgr/lmgr.c # Need some for check s_lock
+	storage/lmgr/lock.c
+	storage/lmgr/proc.c
+	storage/lmgr/deadlock.c
+	storage/lmgr/lwlock.c
+	storage/lmgr/spin.c
+	storage/lmgr/s_lock.c
+	storage/lmgr/predicate.c
+	storage/page/bufpage.c
+	storage/page/checksum.c
+	storage/page/itemptr.c
+	storage/smgr/md.c
+	storage/smgr/smgr.c
+	storage/smgr/smgrtype.c
+)
+
+if(NOT MSVC)
+	set_source_files_properties(storage/page/checksum.c
+		PROPERTIES COMPILE_FLAGS ${CFLAGS_VECTOR})
+endif()
+bison_target(REPL_GRAM
+	replication/repl_gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/repl_gram.c
+)
+flex_target(REPL_SCAN
+	replication/repl_scanner.l
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/repl_scanner.c
+)
+set_source_files_properties(${BISON_REPL_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_REPL_SCAN_OUTPUTS})
+
+bison_target(SYNC_GRAM
+	replication/syncrep_gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/syncrep_gram.c
+)
+flex_target(SYNC_SCAN
+	replication/syncrep_scanner.l
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/syncrep_scanner.c
+)
+set_source_files_properties(${BISON_SYNC_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_SYNC_SCAN_OUTPUTS})
+
+
+set(replication_SRCS
+	replication/walsender.c
+	replication/walreceiverfuncs.c
+	replication/walreceiver.c
+	replication/basebackup.c
+	replication/slot.c
+	replication/slotfuncs.c
+	replication/syncrep.c
+	replication/logical/decode.c
+	replication/logical/logical.c
+	replication/logical/logicalfuncs.c
+	replication/logical/reorderbuffer.c
+	replication/logical/origin.c
+	replication/logical/snapbuild.c
+	replication/logical/message.c
+	${BISON_REPL_GRAM_OUTPUTS}
+	${BISON_SYNC_GRAM_OUTPUTS}
+)
+
+set(timezone_SRCS
+	${PROJECT_SOURCE_DIR}/src/timezone/localtime.c
+	${PROJECT_SOURCE_DIR}/src/timezone/strftime.c
+	${PROJECT_SOURCE_DIR}/src/timezone/pgtz.c
+)
+
+add_custom_command(
+	OUTPUT "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c"
+	#MAIN_DEPENDENCY gen_qsort_tuple.pl
+	COMMAND ${PERL_EXECUTABLE} "gen_qsort_tuple.pl" > "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils/sort
+)
+
+set_source_files_properties(utils/sort/tuplesort.c
+	PROPERTIES OBJECT_DEPENDS "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c")
+
+set(postgres_SRCS
+	${storage_SRCS}
+	${access_SRCS}
+	${bootstrap_SRCS}
+	${commands_SRCS}
+	${catalog_SRCS}
+	${executor_SRCS}
+	foreign/foreign.c
+	${utils_SRCS}
+	${lib_SRCS}
+	${libpq_SRCS}
+	${nodes_SRCS}
+	${optimizer_SRCS}
+	${rewrite_SRCS}
+	${parser_SRCS}
+	${tcop_SRCS}
+	${tsearch_SRCS}
+	${regex_SRCS}
+	${postmaster_SRCS}
+	${backend_port_SRCS}
+	${replication_SRCS}
+	${timezone_SRCS}
+	main/main.c
+)
+
+if(OPENSSL_FOUND)
+	include_directories(BEFORE	${OPENSSL_INCLUDE_DIR})
+endif()
+if(LIBXML2_FOUND)
+	include_directories(BEFORE	${LIBXML2_INCLUDE_DIR})
+endif()
+#include_directories(BEFORE
+#	${OPENSSL_INCLUDE_DIR}
+#	${LIBXML2_INCLUDE_DIR}
+#)
+
+if(MSVC)
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:${WIN32_STACK_RLIMIT}")
+endif()
+
+if(MINGW OR CYGWIN)
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,${WIN32_STACK_RLIMIT} -Wl,--export-all-symbols")
+endif()
+
+add_executable(postgres
+	${postgres_SRCS}
+)
+
+target_link_libraries(postgres
+	pgcommon_srv
+	port_srv
+	pq
+	${READLINE_LIBRARY}
+	${CMAKE_THREAD_LIBS_INIT}
+	${DL_LIBRARIES}
+	${LIB_M}
+	${GSS_LIBS}
+)
+
+if(OPENSSL_FOUND)
+	target_link_libraries(postgres ${OPENSSL_LIBRARIES})
+endif()
+
+if(LIBXML2_FOUND)
+	target_link_libraries(postgres ${LIBXML2_LIBRARIES})
+endif()
+
+if(USE_PAM)
+	target_link_libraries(postgres ${PAM_LIB})
+endif()
+
+if(LDAP_FOUND)
+	target_link_libraries(postgres ${LBER_LIBRARIES})
+endif()
+
+add_dependencies(postgres gen_errorcodes generate_parser_gram_h)
+
+if(UNIX AND NOT APPLE)
+	target_link_libraries(postgres rt)
+endif()
+
+
+target_compile_definitions(postgres PRIVATE -DPG_KRB_SRVTAB="${PG_KRB_SRVTAB}")
+
+if(WIN32)
+	target_compile_definitions(postgres PRIVATE -DBUILDING_DLL -DEXEC_BACKEND)
+endif()
+
+if(MINGW)
+	set_target_properties(postgres PROPERTIES LINK_FLAGS -Wl,--out-implib=libpostgres.dll.a)
+endif()
+
+set_target_properties(postgres PROPERTIES ENABLE_EXPORTS 1)
+set_target_properties(postgres PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
+#Realy need?
+add_custom_target(duplicate_oids
+	COMMAND ${PERL_EXECUTABLE} ./duplicate_oids
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/include/catalog
+)
+
+add_library(pqwalreceiver MODULE
+	replication/libpqwalreceiver/libpqwalreceiver.c
+	${backend_port_win32_SRC}
+	${backend_port_darwin_SRC}
+)
+
+if(MSVC)
+	gen_def(pqwalreceiver)
+	gen_def(postgres)
+endif()
+
+if(WIN32)
+	target_link_libraries(pqwalreceiver postgres)
+endif()
+
+#Strange logic
+if(MINGW)
+	target_compile_definitions(pqwalreceiver PRIVATE -DBUILDING_DLL)
+endif()
+
+target_link_libraries(pqwalreceiver pq)
+
+install(TARGETS postgres pqwalreceiver
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(FILES
+	catalog/postgres.bki
+	catalog/postgres.description
+	catalog/postgres.shdescription
+	catalog/information_schema.sql
+	catalog/sql_features.txt
+	catalog/system_views.sql
+	libpq/pg_hba.conf.sample
+	libpq/pg_ident.conf.sample
+	utils/misc/postgresql.conf.sample
+DESTINATION ${PGSHAREDIR})
+
+add_subdirectory(utils/mb/conversion_procs)
+add_subdirectory(snowball)
+
+if(ENABLE_NLS)
+	MAKE_MO(postgres "de;es;fr;id;it;ja;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/backend/snowball/CMakeLists.txt b/src/backend/snowball/CMakeLists.txt
new file mode 100644
index 0000000..1299271
--- /dev/null
+++ b/src/backend/snowball/CMakeLists.txt
@@ -0,0 +1,126 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/snowball"
+	"${PROJECT_SOURCE_DIR}/src/include/snowball/libstemmer"
+)
+
+set(snow_languages
+	"danish\;danish"
+	"dutch\;dutch"
+	"english\;english"
+	"finnish\;finnish"
+	"french\;french"
+	"german\;german"
+	"hungarian\;hungarian"
+	"italian\;italian"
+	"norwegian\;norwegian"
+	"portuguese\;portuguese"
+	"romanian\;romanian"
+	"russian\;english"
+	"spanish\;spanish"
+	"swedish\;swedish"
+	"turkish\;turkish"
+)
+
+#Create snowball_create.sql
+file(STRINGS snowball.sql.in snowball_sql_tmpl NEWLINE_CONSUME)
+file(STRINGS snowball_func.sql.in snowball_func_sql_tmpl NEWLINE_CONSUME)
+
+file(WRITE "snowball_create.sql" ${snowball_func_sql_tmpl})
+
+foreach(pair_language ${snow_languages})
+	LIST(GET pair_language 0 lang)
+	LIST(GET pair_language 1 ascii_lang)
+	if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/stopwords/${lang}.stop")
+		set(stopwords ", StopWords=${lang}")
+	else()
+		set(stopwords "")
+	endif()
+	string(REPLACE "_LANGNAME_"
+		"${lang}" out_string
+		"${snowball_sql_tmpl}")
+	string(REPLACE "_DICTNAME_"
+		"${lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_CFGNAME_"
+		"${lang}" out_string
+		"${out_string}")
+	string(REPLACE "_ASCDICTNAME_"
+		"${ascii_lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_NONASCDICTNAME_"
+		"${lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_STOPWORDS_"
+		"${stopwords}" out_string
+		"${out_string}")
+	file(APPEND "snowball_create.sql" ${out_string})
+endforeach()
+
+
+set(snowball_SRCS
+	dict_snowball.c
+	libstemmer/api.c
+	libstemmer/utilities.c
+	libstemmer/stem_ISO_8859_1_danish.c
+	libstemmer/stem_ISO_8859_1_dutch.c
+	libstemmer/stem_ISO_8859_1_english.c
+	libstemmer/stem_ISO_8859_1_finnish.c
+	libstemmer/stem_ISO_8859_1_french.c
+	libstemmer/stem_ISO_8859_1_german.c
+	libstemmer/stem_ISO_8859_1_hungarian.c
+	libstemmer/stem_ISO_8859_1_italian.c
+	libstemmer/stem_ISO_8859_1_norwegian.c
+	libstemmer/stem_ISO_8859_1_porter.c
+	libstemmer/stem_ISO_8859_1_portuguese.c
+	libstemmer/stem_ISO_8859_1_spanish.c
+	libstemmer/stem_ISO_8859_1_swedish.c
+	libstemmer/stem_ISO_8859_2_romanian.c
+	libstemmer/stem_KOI8_R_russian.c
+	libstemmer/stem_UTF_8_danish.c
+	libstemmer/stem_UTF_8_dutch.c
+	libstemmer/stem_UTF_8_english.c
+	libstemmer/stem_UTF_8_finnish.c
+	libstemmer/stem_UTF_8_french.c
+	libstemmer/stem_UTF_8_german.c
+	libstemmer/stem_UTF_8_hungarian.c
+	libstemmer/stem_UTF_8_italian.c
+	libstemmer/stem_UTF_8_norwegian.c
+	libstemmer/stem_UTF_8_porter.c
+	libstemmer/stem_UTF_8_portuguese.c
+	libstemmer/stem_UTF_8_romanian.c
+	libstemmer/stem_UTF_8_russian.c
+	libstemmer/stem_UTF_8_spanish.c
+	libstemmer/stem_UTF_8_swedish.c
+	libstemmer/stem_UTF_8_turkish.c
+)
+
+add_library(dict_snowball MODULE ${snowball_SRCS})
+target_link_libraries(dict_snowball postgres)
+if (MSVC)
+	gen_def(dict_snowball)
+	target_link_libraries(dict_snowball pgcommon port)
+endif()
+set_target_properties(dict_snowball PROPERTIES PREFIX "")
+install(TARGETS dict_snowball
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(FILES snowball_create.sql
+		DESTINATION ${PGSHAREDIR})
+
+install(FILES
+		stopwords/danish.stop
+		stopwords/dutch.stop
+		stopwords/english.stop
+		stopwords/finnish.stop
+		stopwords/french.stop
+		stopwords/german.stop
+		stopwords/hungarian.stop
+		stopwords/italian.stop
+		stopwords/norwegian.stop
+		stopwords/portuguese.stop
+		stopwords/russian.stop
+		stopwords/spanish.stop
+		stopwords/swedish.stop
+		stopwords/turkish.stop
+		DESTINATION ${PGSHAREDIR}/tsearch_data)
diff --git a/src/backend/utils/mb/conversion_procs/CMakeLists.txt b/src/backend/utils/mb/conversion_procs/CMakeLists.txt
new file mode 100644
index 0000000..008f58e
--- /dev/null
+++ b/src/backend/utils/mb/conversion_procs/CMakeLists.txt
@@ -0,0 +1,201 @@
+set(procs_list
+	ascii_and_mic
+	cyrillic_and_mic
+	euc_cn_and_mic
+	euc_jp_and_sjis
+	euc_kr_and_mic
+	euc_tw_and_big5
+	latin2_and_win1250
+	latin_and_mic
+	utf8_and_ascii
+	utf8_and_big5
+	utf8_and_cyrillic
+	utf8_and_euc_cn
+	utf8_and_euc_jp
+	utf8_and_euc_kr
+	utf8_and_euc_tw
+	utf8_and_gb18030
+	utf8_and_gbk
+	utf8_and_iso8859
+	utf8_and_iso8859_1
+	utf8_and_johab
+	utf8_and_sjis
+	utf8_and_win
+	utf8_and_uhc
+	utf8_and_euc2004
+	utf8_and_sjis2004
+	euc2004_sjis2004
+)
+
+# conversion_name source_encoding destination_encoding function object
+set(conversions_list
+	"ascii_to_mic\;SQL_ASCII\;MULE_INTERNAL\;ascii_to_mic\;ascii_and_mic"
+	"mic_to_ascii\;MULE_INTERNAL\;SQL_ASCII\;mic_to_ascii\;ascii_and_mic"
+	"koi8_r_to_mic\;KOI8R\;MULE_INTERNAL\;koi8r_to_mic\;cyrillic_and_mic"
+	"mic_to_koi8_r\;MULE_INTERNAL\;KOI8R\;mic_to_koi8r\;cyrillic_and_mic"
+	"iso_8859_5_to_mic\;ISO-8859-5\;MULE_INTERNAL\;iso_to_mic\;cyrillic_and_mic"
+	"mic_to_iso_8859_5\;MULE_INTERNAL\;ISO-8859-5\;mic_to_iso\;cyrillic_and_mic"
+	"windows_1251_to_mic\;WIN1251\;MULE_INTERNAL\;win1251_to_mic\;cyrillic_and_mic"
+	"mic_to_windows_1251\;MULE_INTERNAL\;WIN1251\;mic_to_win1251\;cyrillic_and_mic"
+	"windows_866_to_mic\;WIN866\;MULE_INTERNAL\;win866_to_mic\;cyrillic_and_mic"
+	"mic_to_windows_866\;MULE_INTERNAL\;WIN866\;mic_to_win866\;cyrillic_and_mic"
+	"koi8_r_to_windows_1251\;KOI8R\;WIN1251\;koi8r_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_koi8_r\;WIN1251\;KOI8R\;win1251_to_koi8r\;cyrillic_and_mic"
+	"koi8_r_to_windows_866\;KOI8R\;WIN866\;koi8r_to_win866\;cyrillic_and_mic"
+	"windows_866_to_koi8_r\;WIN866\;KOI8R\;win866_to_koi8r\;cyrillic_and_mic"
+	"windows_866_to_windows_1251\;WIN866\;WIN1251\;win866_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_windows_866\;WIN1251\;WIN866\;win1251_to_win866\;cyrillic_and_mic"
+	"iso_8859_5_to_koi8_r\;ISO-8859-5\;KOI8R\;iso_to_koi8r\;cyrillic_and_mic"
+	"koi8_r_to_iso_8859_5\;KOI8R\;ISO-8859-5\;koi8r_to_iso\;cyrillic_and_mic"
+	"iso_8859_5_to_windows_1251\;ISO-8859-5\;WIN1251\;iso_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_iso_8859_5\;WIN1251\;ISO-8859-5\;win1251_to_iso\;cyrillic_and_mic"
+	"iso_8859_5_to_windows_866\;ISO-8859-5\;WIN866\;iso_to_win866\;cyrillic_and_mic"
+	"windows_866_to_iso_8859_5\;WIN866\;ISO-8859-5\;win866_to_iso\;cyrillic_and_mic"
+	"euc_cn_to_mic\;EUC_CN\;MULE_INTERNAL\;euc_cn_to_mic\;euc_cn_and_mic"
+	"mic_to_euc_cn\;MULE_INTERNAL\;EUC_CN\;mic_to_euc_cn\;euc_cn_and_mic"
+	"euc_jp_to_sjis\;EUC_JP\;SJIS\;euc_jp_to_sjis\;euc_jp_and_sjis"
+	"sjis_to_euc_jp\;SJIS\;EUC_JP\;sjis_to_euc_jp\;euc_jp_and_sjis"
+	"euc_jp_to_mic\;EUC_JP\;MULE_INTERNAL\;euc_jp_to_mic\;euc_jp_and_sjis"
+	"sjis_to_mic\;SJIS\;MULE_INTERNAL\;sjis_to_mic\;euc_jp_and_sjis"
+	"mic_to_euc_jp\;MULE_INTERNAL\;EUC_JP\;mic_to_euc_jp\;euc_jp_and_sjis"
+	"mic_to_sjis\;MULE_INTERNAL\;SJIS\;mic_to_sjis\;euc_jp_and_sjis"
+	"euc_kr_to_mic\;EUC_KR\;MULE_INTERNAL\;euc_kr_to_mic\;euc_kr_and_mic"
+	"mic_to_euc_kr\;MULE_INTERNAL\;EUC_KR\;mic_to_euc_kr\;euc_kr_and_mic"
+	"euc_tw_to_big5\;EUC_TW\;BIG5\;euc_tw_to_big5\;euc_tw_and_big5"
+	"big5_to_euc_tw\;BIG5\;EUC_TW\;big5_to_euc_tw\;euc_tw_and_big5"
+	"euc_tw_to_mic\;EUC_TW\;MULE_INTERNAL\;euc_tw_to_mic\;euc_tw_and_big5"
+	"big5_to_mic\;BIG5\;MULE_INTERNAL\;big5_to_mic\;euc_tw_and_big5"
+	"mic_to_euc_tw\;MULE_INTERNAL\;EUC_TW\;mic_to_euc_tw\;euc_tw_and_big5"
+	"mic_to_big5\;MULE_INTERNAL\;BIG5\;mic_to_big5\;euc_tw_and_big5"
+	"iso_8859_2_to_mic\;LATIN2\;MULE_INTERNAL\;latin2_to_mic\;latin2_and_win1250"
+	"mic_to_iso_8859_2\;MULE_INTERNAL\;LATIN2\;mic_to_latin2\;latin2_and_win1250"
+	"windows_1250_to_mic\;WIN1250\;MULE_INTERNAL\;win1250_to_mic\;latin2_and_win1250"
+	"mic_to_windows_1250\;MULE_INTERNAL\;WIN1250\;mic_to_win1250\;latin2_and_win1250"
+	"iso_8859_2_to_windows_1250\;LATIN2\;WIN1250\;latin2_to_win1250\;latin2_and_win1250"
+	"windows_1250_to_iso_8859_2\;WIN1250\;LATIN2\;win1250_to_latin2\;latin2_and_win1250"
+	"iso_8859_1_to_mic\;LATIN1\;MULE_INTERNAL\;latin1_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_1\;MULE_INTERNAL\;LATIN1\;mic_to_latin1\;latin_and_mic"
+	"iso_8859_3_to_mic\;LATIN3\;MULE_INTERNAL\;latin3_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_3\;MULE_INTERNAL\;LATIN3\;mic_to_latin3\;latin_and_mic"
+	"iso_8859_4_to_mic\;LATIN4\;MULE_INTERNAL\;latin4_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_4\;MULE_INTERNAL\;LATIN4\;mic_to_latin4\;latin_and_mic"
+	"ascii_to_utf8\;SQL_ASCII\;UTF8\;ascii_to_utf8\;utf8_and_ascii"
+	"utf8_to_ascii\;UTF8\;SQL_ASCII\;utf8_to_ascii\;utf8_and_ascii"
+	"big5_to_utf8\;BIG5\;UTF8\;big5_to_utf8\;utf8_and_big5"
+	"utf8_to_big5\;UTF8\;BIG5\;utf8_to_big5\;utf8_and_big5"
+	"utf8_to_koi8_r\;UTF8\;KOI8R\;utf8_to_koi8r\;utf8_and_cyrillic"
+	"koi8_r_to_utf8\;KOI8R\;UTF8\;koi8r_to_utf8\;utf8_and_cyrillic"
+	"utf8_to_koi8_u\;UTF8\;KOI8U\;utf8_to_koi8u\;utf8_and_cyrillic"
+	"koi8_u_to_utf8\;KOI8U\;UTF8\;koi8u_to_utf8\;utf8_and_cyrillic"
+	"utf8_to_windows_866\;UTF8\;WIN866\;utf8_to_win\;utf8_and_win"
+	"windows_866_to_utf8\;WIN866\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_874\;UTF8\;WIN874\;utf8_to_win\;utf8_and_win"
+	"windows_874_to_utf8\;WIN874\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1250\;UTF8\;WIN1250\;utf8_to_win\;utf8_and_win"
+	"windows_1250_to_utf8\;WIN1250\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1251\;UTF8\;WIN1251\;utf8_to_win\;utf8_and_win"
+	"windows_1251_to_utf8\;WIN1251\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1252\;UTF8\;WIN1252\;utf8_to_win\;utf8_and_win"
+	"windows_1252_to_utf8\;WIN1252\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1253\;UTF8\;WIN1253\;utf8_to_win\;utf8_and_win"
+	"windows_1253_to_utf8\;WIN1253\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1254\;UTF8\;WIN1254\;utf8_to_win\;utf8_and_win"
+	"windows_1254_to_utf8\;WIN1254\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1255\;UTF8\;WIN1255\;utf8_to_win\;utf8_and_win"
+	"windows_1255_to_utf8\;WIN1255\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1256\;UTF8\;WIN1256\;utf8_to_win\;utf8_and_win"
+	"windows_1256_to_utf8\;WIN1256\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1257\;UTF8\;WIN1257\;utf8_to_win\;utf8_and_win"
+	"windows_1257_to_utf8\;WIN1257\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1258\;UTF8\;WIN1258\;utf8_to_win\;utf8_and_win"
+	"windows_1258_to_utf8\;WIN1258\;UTF8\;win_to_utf8\;utf8_and_win"
+	"euc_cn_to_utf8\;EUC_CN\;UTF8\;euc_cn_to_utf8\;utf8_and_euc_cn"
+	"utf8_to_euc_cn\;UTF8\;EUC_CN\;utf8_to_euc_cn\;utf8_and_euc_cn"
+	"euc_jp_to_utf8\;EUC_JP\;UTF8\;euc_jp_to_utf8\;utf8_and_euc_jp"
+	"utf8_to_euc_jp\;UTF8\;EUC_JP\;utf8_to_euc_jp\;utf8_and_euc_jp"
+	"euc_kr_to_utf8\;EUC_KR\;UTF8\;euc_kr_to_utf8\;utf8_and_euc_kr"
+	"utf8_to_euc_kr\;UTF8\;EUC_KR\;utf8_to_euc_kr\;utf8_and_euc_kr"
+	"euc_tw_to_utf8\;EUC_TW\;UTF8\;euc_tw_to_utf8\;utf8_and_euc_tw"
+	"utf8_to_euc_tw\;UTF8\;EUC_TW\;utf8_to_euc_tw\;utf8_and_euc_tw"
+	"gb18030_to_utf8\;GB18030\;UTF8\;gb18030_to_utf8\;utf8_and_gb18030"
+	"utf8_to_gb18030\;UTF8\;GB18030\;utf8_to_gb18030\;utf8_and_gb18030"
+	"gbk_to_utf8\;GBK\;UTF8\;gbk_to_utf8\;utf8_and_gbk"
+	"utf8_to_gbk\;UTF8\;GBK\;utf8_to_gbk\;utf8_and_gbk"
+	"utf8_to_iso_8859_2\;UTF8\;LATIN2\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_2_to_utf8\;LATIN2\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_3\;UTF8\;LATIN3\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_3_to_utf8\;LATIN3\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_4\;UTF8\;LATIN4\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_4_to_utf8\;LATIN4\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_9\;UTF8\;LATIN5\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_9_to_utf8\;LATIN5\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_10\;UTF8\;LATIN6\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_10_to_utf8\;LATIN6\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_13\;UTF8\;LATIN7\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_13_to_utf8\;LATIN7\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_14\;UTF8\;LATIN8\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_14_to_utf8\;LATIN8\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_15\;UTF8\;LATIN9\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_15_to_utf8\;LATIN9\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_16\;UTF8\;LATIN10\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_16_to_utf8\;LATIN10\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_5\;UTF8\;ISO-8859-5\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_5_to_utf8\;ISO-8859-5\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_6\;UTF8\;ISO-8859-6\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_6_to_utf8\;ISO-8859-6\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_7\;UTF8\;ISO-8859-7\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_7_to_utf8\;ISO-8859-7\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_8\;UTF8\;ISO-8859-8\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_8_to_utf8\;ISO-8859-8\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"iso_8859_1_to_utf8\;LATIN1\;UTF8\;iso8859_1_to_utf8\;utf8_and_iso8859_1"
+	"utf8_to_iso_8859_1\;UTF8\;LATIN1\;utf8_to_iso8859_1\;utf8_and_iso8859_1"
+	"johab_to_utf8\;JOHAB\;UTF8\;johab_to_utf8\;utf8_and_johab"
+	"utf8_to_johab\;UTF8\;JOHAB\;utf8_to_johab\;utf8_and_johab"
+	"sjis_to_utf8\;SJIS\;UTF8\;sjis_to_utf8\;utf8_and_sjis"
+	"utf8_to_sjis\;UTF8\;SJIS\;utf8_to_sjis\;utf8_and_sjis"
+	"uhc_to_utf8\;UHC\;UTF8\;uhc_to_utf8\;utf8_and_uhc"
+	"utf8_to_uhc\;UTF8\;UHC\;utf8_to_uhc\;utf8_and_uhc"
+	"euc_jis_2004_to_utf8\;EUC_JIS_2004\;UTF8\;euc_jis_2004_to_utf8\;utf8_and_euc2004"
+	"utf8_to_euc_jis_2004\;UTF8\;EUC_JIS_2004\;utf8_to_euc_jis_2004\;utf8_and_euc2004"
+	"shift_jis_2004_to_utf8\;SHIFT_JIS_2004\;UTF8\;shift_jis_2004_to_utf8\;utf8_and_sjis2004"
+	"utf8_to_shift_jis_2004\;UTF8\;SHIFT_JIS_2004\;utf8_to_shift_jis_2004\;utf8_and_sjis2004"
+	"euc_jis_2004_to_shift_jis_2004\;EUC_JIS_2004\;SHIFT_JIS_2004\;euc_jis_2004_to_shift_jis_2004\;euc2004_sjis2004"
+	"shift_jis_2004_to_euc_jis_2004\;SHIFT_JIS_2004\;EUC_JIS_2004\;shift_jis_2004_to_euc_jis_2004\;euc2004_sjis2004"
+)
+
+file(WRITE "conversion_create.sql" "")
+foreach(pair_conversion ${conversions_list})
+	LIST(GET pair_conversion 0 con_name)
+	LIST(GET pair_conversion 1 se)
+	LIST(GET pair_conversion 2 de)
+	LIST(GET pair_conversion 3 func)
+	LIST(GET pair_conversion 4 obj)
+	
+	file(APPEND "conversion_create.sql" "-- ${se} --> ${de}\n")
+	file(APPEND "conversion_create.sql" "CREATE OR REPLACE FUNCTION ${func} (INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) RETURNS VOID AS '$libdir/${obj}', '${func}' LANGUAGE C STRICT;\n")
+	file(APPEND "conversion_create.sql" "COMMENT ON FUNCTION ${func}(INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) IS 'internal conversion function for ${se} to ${de}';\n")
+	file(APPEND "conversion_create.sql" "DROP CONVERSION pg_catalog.${con_name};\n")
+	file(APPEND "conversion_create.sql" "CREATE DEFAULT CONVERSION pg_catalog.${con_name} FOR '${se}' TO '${de}' FROM ${func};\n")
+	file(APPEND "conversion_create.sql" "COMMENT ON CONVERSION pg_catalog.${con_name} IS 'conversion for ${se} to ${de}';\n")
+endforeach()
+
+foreach(loop_var IN ITEMS ${procs_list})
+	if(loop_var STREQUAL "euc_tw_and_big5")
+		add_library(${loop_var} MODULE ${loop_var}/${loop_var}.c ${loop_var}/big5.c)
+	else()
+		add_library(${loop_var} MODULE ${loop_var}/${loop_var}.c)
+	endif()
+	set_target_properties(${loop_var} PROPERTIES PREFIX "")
+	add_dependencies(${loop_var} gen_errorcodes)
+	target_link_libraries(${loop_var} postgres)
+	if(MSVC)
+		gen_def(${loop_var})
+	endif()
+	CMAKE_SET_TARGET_FOLDER(${loop_var} conversion_procs)
+	install(TARGETS ${loop_var}
+			RUNTIME DESTINATION ${PGBINDIR}
+			LIBRARY DESTINATION ${LIBDIR})
+endforeach(loop_var)
+
+install(FILES conversion_create.sql
+		DESTINATION ${PGSHAREDIR})
diff --git a/src/bin/initdb/CMakeLists.txt b/src/bin/initdb/CMakeLists.txt
new file mode 100644
index 0000000..52c3272
--- /dev/null
+++ b/src/bin/initdb/CMakeLists.txt
@@ -0,0 +1,35 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/timezone"
+)
+
+add_executable(initdb
+	initdb.c
+	findtimezone.c
+	"${PROJECT_SOURCE_DIR}/src/timezone/localtime.c"
+	"${PROJECT_SOURCE_DIR}/src/backend/utils/mb/encnames.c"
+)
+
+target_link_libraries(initdb
+	pgfeutils
+	pgcommon
+	port
+	pq
+	${GSS_LIBS}
+)
+
+if(UNIX AND NOT APPLE)
+	target_link_libraries(initdb rt)
+endif()
+
+target_compile_definitions(initdb PRIVATE -DFRONTEND)
+CMAKE_SET_TARGET_FOLDER(initdb bin)
+
+install(TARGETS initdb
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(initdb "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_archivecleanup/CMakeLists.txt b/src/bin/pg_archivecleanup/CMakeLists.txt
new file mode 100644
index 0000000..7c79ac3
--- /dev/null
+++ b/src/bin/pg_archivecleanup/CMakeLists.txt
@@ -0,0 +1,20 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_archivecleanup pg_archivecleanup.c)
+
+target_link_libraries(pg_archivecleanup
+	port
+#	pq
+	pgcommon
+	${M_LIB}
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_archivecleanup bin)
+
+install(TARGETS pg_archivecleanup
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/pg_basebackup/CMakeLists.txt b/src/bin/pg_basebackup/CMakeLists.txt
new file mode 100644
index 0000000..a985e08
--- /dev/null
+++ b/src/bin/pg_basebackup/CMakeLists.txt
@@ -0,0 +1,51 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	${ZLIB_INCLUDE_DIRS}
+)
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+
+add_library(common_basebackup STATIC
+	receivelog.c
+	streamutil.c
+)
+
+target_link_libraries(common_basebackup
+	port
+	pq
+)
+
+set(basebackup_list 
+	pg_basebackup
+	pg_receivexlog
+	pg_recvlogical
+)
+
+foreach(loop_var IN ITEMS ${basebackup_list})
+	add_executable(${loop_var} ${loop_var}.c)
+
+	target_link_libraries(${loop_var}
+		pgfeutils
+		port
+		pq
+		pgcommon
+		${M_LIB}
+		common_basebackup
+	)
+	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
+	if(ZLIB_FOUND)
+		target_link_libraries(${loop_var} ${ZLIB_LIBRARIES})
+	endif()
+endforeach()
+
+install(TARGETS ${basebackup_list}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_basebackup "de;es;fr;it;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/bin/pg_config/CMakeLists.txt b/src/bin/pg_config/CMakeLists.txt
new file mode 100644
index 0000000..c9cb6e4
--- /dev/null
+++ b/src/bin/pg_config/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_config
+	pg_config.c
+)
+
+target_link_libraries(pg_config
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_config bin)
+
+install(TARGETS pg_config
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_config "cs;de;es;fr;it;ja;ko;nb;pl;pt_BR;ro;ru;sv;ta;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/bin/pg_controldata/CMakeLists.txt b/src/bin/pg_controldata/CMakeLists.txt
new file mode 100644
index 0000000..70a673c
--- /dev/null
+++ b/src/bin/pg_controldata/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_controldata
+	pg_controldata.c
+)
+
+target_link_libraries(pg_controldata
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_controldata bin)
+
+install(TARGETS pg_controldata
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_controldata "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_ctl/CMakeLists.txt b/src/bin/pg_ctl/CMakeLists.txt
new file mode 100644
index 0000000..8636d38
--- /dev/null
+++ b/src/bin/pg_ctl/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_ctl
+	pg_ctl.c
+)
+
+target_link_libraries(pg_ctl
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_ctl bin)
+
+install(TARGETS pg_ctl
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_ctl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_dump/CMakeLists.txt b/src/bin/pg_dump/CMakeLists.txt
new file mode 100644
index 0000000..e0da845
--- /dev/null
+++ b/src/bin/pg_dump/CMakeLists.txt
@@ -0,0 +1,88 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	${ZLIB_INCLUDE_DIRS}
+)
+
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+add_library(libdump STATIC
+	pg_backup_archiver.c
+	pg_backup_db.c
+	pg_backup_custom.c
+	pg_backup_null.c
+	pg_backup_tar.c
+	pg_backup_directory.c
+	pg_backup_utils.c
+	parallel.c
+	compress_io.c
+	dumputils.c
+)
+
+add_executable(pg_dump
+	pg_dump.c
+	common.c
+	pg_dump_sort.c
+)
+
+target_link_libraries(pg_dump
+	libdump
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_dump bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_dump ${ZLIB_LIBRARIES})
+endif()
+
+add_executable(pg_restore
+	pg_restore.c
+)
+
+target_link_libraries(pg_restore
+	libdump
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_restore bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_restore ${ZLIB_LIBRARIES})
+endif()
+
+add_executable(pg_dumpall
+	pg_dumpall.c
+	dumputils.c
+)
+
+target_link_libraries(pg_dumpall
+	libdump
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_dumpall bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_dumpall ${ZLIB_LIBRARIES})
+endif()
+
+install(TARGETS pg_dump pg_restore pg_dumpall
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_dump "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/bin/pg_resetxlog/CMakeLists.txt b/src/bin/pg_resetxlog/CMakeLists.txt
new file mode 100644
index 0000000..e0d34ea
--- /dev/null
+++ b/src/bin/pg_resetxlog/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_resetxlog
+	pg_resetxlog.c
+)
+
+target_link_libraries(pg_resetxlog
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_resetxlog bin)
+
+install(TARGETS pg_resetxlog
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_resetxlog "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_rewind/CMakeLists.txt b/src/bin/pg_rewind/CMakeLists.txt
new file mode 100644
index 0000000..a81091f
--- /dev/null
+++ b/src/bin/pg_rewind/CMakeLists.txt
@@ -0,0 +1,37 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_rewind
+	pg_rewind.c
+	parsexlog.c
+	datapagemap.c
+	timeline.c
+	fetch.c
+	file_ops.c
+	copy_fetch.c
+	libpq_fetch.c
+	filemap.c
+	logging.c
+	${PROJECT_SOURCE_DIR}/src/backend/access/transam/xlogreader.c
+)
+
+target_link_libraries(pg_rewind
+	pgcommon
+	port
+	pq
+)
+
+target_compile_definitions(pg_rewind PRIVATE -DFRONTEND)
+
+CMAKE_SET_TARGET_FOLDER(pg_rewind bin)
+
+install(TARGETS pg_rewind
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_rewind "de;es;fr;it;ko;pl;ru;zh_CN")
+endif()
diff --git a/src/bin/pg_test_fsync/CMakeLists.txt b/src/bin/pg_test_fsync/CMakeLists.txt
new file mode 100644
index 0000000..4509380
--- /dev/null
+++ b/src/bin/pg_test_fsync/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_test_fsync
+	pg_test_fsync.c
+	
+)
+
+target_link_libraries(pg_test_fsync
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_test_fsync bin)
+
+install(TARGETS pg_test_fsync
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
diff --git a/src/bin/pg_test_timing/CMakeLists.txt b/src/bin/pg_test_timing/CMakeLists.txt
new file mode 100644
index 0000000..dce9232
--- /dev/null
+++ b/src/bin/pg_test_timing/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_test_timing
+	pg_test_timing.c
+	
+)
+
+target_link_libraries(pg_test_timing
+	pgcommon
+	port
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_test_timing bin)
+
+install(TARGETS pg_test_timing
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+
diff --git a/src/bin/pg_upgrade/CMakeLists.txt b/src/bin/pg_upgrade/CMakeLists.txt
new file mode 100644
index 0000000..cd9a902
--- /dev/null
+++ b/src/bin/pg_upgrade/CMakeLists.txt
@@ -0,0 +1,39 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_upgrade
+	check.c
+	controldata.c
+	dump.c
+	exec.c
+	file.c
+	function.c
+	info.c
+	option.c
+	parallel.c
+	pg_upgrade.c
+	relfilenode.c
+	server.c
+	tablespace.c
+	util.c
+	version.c 
+)
+
+target_link_libraries(pg_upgrade
+	pgfeutils
+	pgcommon
+	port
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_upgrade bin)
+
+install(TARGETS pg_upgrade
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+
+
diff --git a/src/bin/pg_xlogdump/CMakeLists.txt b/src/bin/pg_xlogdump/CMakeLists.txt
new file mode 100644
index 0000000..f8b45a1
--- /dev/null
+++ b/src/bin/pg_xlogdump/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_xlogdump
+	${PROJECT_SOURCE_DIR}/src/backend/access/transam/xlogreader.c
+	pg_xlogdump.c
+	compat.c
+	rmgrdesc.c
+	${rmgrdesc_SRC}
+)
+
+target_link_libraries(pg_xlogdump
+	pgcommon
+	port
+	pq
+)
+
+target_compile_definitions(pg_xlogdump PRIVATE -DFRONTEND)
+
+CMAKE_SET_TARGET_FOLDER(pg_xlogdump bin)
+
+install(TARGETS pg_xlogdump
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/pgbench/CMakeLists.txt b/src/bin/pgbench/CMakeLists.txt
new file mode 100644
index 0000000..b10af2c
--- /dev/null
+++ b/src/bin/pgbench/CMakeLists.txt
@@ -0,0 +1,32 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+bison_target(PGBENCH_PARSER exprparse.y ${PROJECT_SOURCE_DIR}/src/bin/pgbench/exprparse.c)
+flex_target(PGBENCH_SCANNER exprscan.l  ${PROJECT_SOURCE_DIR}/src/bin/pgbench/exprscan.c)
+add_flex_bison_dependency(PGBENCH_SCANNER PGBENCH_PARSER)
+
+set_source_files_properties(exprparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_PGBENCH_SCANNER_OUTPUTS})
+
+add_executable(pgbench
+	pgbench.c
+	${BISON_PGBENCH_PARSER_OUTPUTS}
+)
+
+target_link_libraries(pgbench
+	pgfeutils
+	port
+	pq
+	pgcommon
+	${M_LIB}
+)
+
+add_dependencies(pgbench postgres)
+
+CMAKE_SET_TARGET_FOLDER(pgbench bin)
+
+install(TARGETS pgbench
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/psql/CMakeLists.txt b/src/bin/psql/CMakeLists.txt
new file mode 100644
index 0000000..ceccf23
--- /dev/null
+++ b/src/bin/psql/CMakeLists.txt
@@ -0,0 +1,72 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY create_help.pl
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/psql/sql_help.c ${PROJECT_SOURCE_DIR}/src/bin/psql/sql_help.h
+	COMMAND ${PERL_EXECUTABLE} create_help.pl ../../../doc/src/sgml/ref sql_help
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/psql
+)
+
+flex_target(SCANSLASH_SCAN
+	psqlscanslash.l
+	${CMAKE_CURRENT_SOURCE_DIR}/psqlscanslash.c
+)
+
+set(psql_SRCS
+	command.c
+	common.c
+	help.c
+	help.h
+	input.c
+	stringutils.c
+	mainloop.c
+	copy.c
+	copy.h
+	startup.c
+	prompt.c
+	variables.c
+	large_obj.c
+	describe.c
+	tab-complete.c
+	../pg_dump/dumputils.c
+	sql_help.c
+	crosstabview.c
+	${FLEX_SCANSLASH_SCAN_OUTPUTS}
+)
+
+add_executable(psql
+	${psql_SRCS}
+)
+
+target_link_libraries(psql
+	pgfeutils
+	pgcommon
+	port
+	pq
+	${READLINE_LIBRARY}
+	${CMAKE_THREAD_LIBS_INIT}
+)
+
+if(OPENSSL_FOUND)
+	target_link_libraries(psql ${OPENSSL_LIBRARIES})
+endif()
+if(NOT MSVC)
+	target_link_libraries(psql m)
+endif()
+
+add_dependencies(psql postgres)
+
+CMAKE_SET_TARGET_FOLDER(psql bin)
+
+install(TARGETS psql
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pslq "cs;de;es;fr;it;ja;pl;pt_BR;ru;zh_CN;zh_TW")
+endif()
+
diff --git a/src/bin/scripts/CMakeLists.txt b/src/bin/scripts/CMakeLists.txt
new file mode 100644
index 0000000..c06548a
--- /dev/null
+++ b/src/bin/scripts/CMakeLists.txt
@@ -0,0 +1,89 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/bin/psql"
+)
+
+add_library(common_dump STATIC
+	common.c
+	${PROJECT_SOURCE_DIR}/src/bin/pg_dump/dumputils.c
+)
+
+add_library(common_print STATIC
+	common.c
+)
+
+set(common_libs
+	pgfeutils
+	pgcommon
+	port
+	pq
+	${LIB_M}
+)
+
+add_executable(createlang
+	createlang.c
+)
+
+target_link_libraries(createlang
+	common_print
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(createlang bin)
+
+add_executable(droplang
+	droplang.c
+)
+
+target_link_libraries(droplang
+	common_print
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(droplang bin)
+
+add_executable(pg_isready
+	pg_isready.c
+	common.c
+)
+
+target_link_libraries(pg_isready
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_isready bin)
+
+set(dump_modules_list 
+	createdb
+	createuser
+	dropdb
+	dropuser
+	clusterdb
+	vacuumdb
+	reindexdb
+)
+
+foreach(loop_var IN ITEMS ${dump_modules_list})
+	add_executable(${loop_var}
+		${loop_var}.c
+		${dump_parser_src}
+	)
+
+	target_link_libraries(${loop_var}
+		common_dump
+		${common_libs}
+	)
+
+	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
+endforeach()
+
+
+install(TARGETS ${dump_modules_list} createlang droplang pg_isready
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pgscripts "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
new file mode 100644
index 0000000..7a24165
--- /dev/null
+++ b/src/common/CMakeLists.txt
@@ -0,0 +1,48 @@
+set(pgcommon_srv_SRCS
+	exec.c
+	pg_lzcompress.c
+	pgfnames.c
+	psprintf.c
+	relpath.c
+	rmtree.c
+	string.c
+	username.c
+	wait_error.c
+	controldata_utils.c
+	config_info.c
+	keywords.c
+	md5.c
+	ip.c
+)
+
+set(pgcommon_SRCS
+	${pgcommon_srv_SRCS}
+	fe_memutils.c
+	restricted_token.c
+	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+)
+
+add_library(pgcommon_srv STATIC ${pgcommon_srv_SRCS})
+add_library(pgcommon STATIC ${pgcommon_SRCS})
+
+set_source_files_properties(
+	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+	PROPERTIES GENERATED TRUE
+)
+
+add_dependencies(pgcommon_srv generate_parser_gram_h)
+add_dependencies(pgcommon_srv gen_errorcodes)
+add_dependencies(pgcommon gen_errorcodes)
+
+target_compile_definitions(pgcommon PRIVATE -DFRONTEND)
+
+target_compile_definitions(pgcommon PRIVATE -DVAL_CPPFLAGS="${CMAKE_CXX_FLAGS}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_CFLAGS="${CMAKE_C_FLAGS} ${COMPILE_DEFINITIONS}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_CC="${CMAKE_C_COMPILER}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_LDFLAGS="${CMAKE_SHARED_LINKER_FLAGS}")
+
+# because port used in shared libraries
+set_property(TARGET pgcommon PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+
+install(TARGETS pgcommon
+		ARCHIVE DESTINATION ${LIBDIR})
diff --git a/src/fe_utils/CMakeLists.txt b/src/fe_utils/CMakeLists.txt
new file mode 100644
index 0000000..6bf3fd3
--- /dev/null
+++ b/src/fe_utils/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/bin/psql"
+)
+
+set(psqlscan_flags, "-Cfe -p -p")
+
+flex_target(psqlscan
+	psqlscan.l
+	"${CMAKE_CURRENT_SOURCE_DIR}/psqlscan.c"
+	${psqlscan_flags}
+)
+
+add_library(pgfeutils STATIC
+	mbprint.c
+	print.c
+	psqlscan.c
+	simple_list.c
+	string_utils.c
+	${FLEX_psqlscan_OUTPUTS}
+)
diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt
new file mode 100644
index 0000000..c084822
--- /dev/null
+++ b/src/include/CMakeLists.txt
@@ -0,0 +1,78 @@
+set(INCLUDEDIR_INTERNAL ${PKGINCLUDEDIR}/internal)
+
+# These headers are needed by the public headers of the interfaces.
+install(FILES
+	postgres_ext.h
+	pg_config.h
+	pg_config_ext.h
+	pg_config_os.h
+	pg_config_manual.h
+	DESTINATION ${INCLUDEDIR})
+install(FILES
+	libpq/libpq-fs.h
+	DESTINATION ${INCLUDEDIR}/libpq)
+
+# These headers are needed by the not-so-public headers of the interfaces.
+install(FILES
+	c.h
+	port.h
+	postgres_fe.h
+	DESTINATION ${INCLUDEDIR_INTERNAL})
+install(FILES
+	libpq/pqcomm.h
+	DESTINATION ${INCLUDEDIR_INTERNAL}/libpq)
+
+# These headers are needed for server-side development
+set(SUBDIRS
+	access
+	bootstrap
+	catalog
+	commands
+	common
+	datatype
+	executor
+	foreign
+	lib
+	libpq
+	mb
+	nodes
+	optimizer
+	parser
+	postmaster
+	regex
+	replication
+	rewrite
+	storage
+	tcop
+	snowball
+	tsearch
+	utils
+	port
+	portability
+)
+
+install(FILES
+	c.h
+	dynloader.h
+	fmgr.h
+	funcapi.h
+	getaddrinfo.h
+	getopt_long.h
+	miscadmin.h
+	pg_config_ext.h
+	pg_config.h
+	pg_config_manual.h
+	pg_config_os.h
+	pg_getopt.h
+	pgstat.h
+	pgtar.h
+	pgtime.h
+	pg_trace.h
+	port.h
+	postgres_ext.h
+	postgres_fe.h
+	postgres.h
+	rusagestub.h
+	windowapi.h
+	DESTINATION ${INCLUDEDIRSERVER})
+install(DIRECTORY ${SUBDIRS} DESTINATION ${INCLUDEDIRSERVER})
diff --git a/src/include/pg_config_cmake.in b/src/include/pg_config_cmake.in
new file mode 100644
index 0000000..48685ae
--- /dev/null
+++ b/src/include/pg_config_cmake.in
@@ -0,0 +1,930 @@
+#ifndef AUTO_CONFIG_H
+#define AUTO_CONFIG_H
+
+/* Define to the type of arg 1 of 'accept' */
+#define ACCEPT_TYPE_ARG1 @ACCEPT_TYPE_ARG1@
+
+/* Define to the type of arg 2 of 'accept' */
+#define ACCEPT_TYPE_ARG2 @ACCEPT_TYPE_ARG2@
+
+/* Define to the type of arg 3 of 'accept' */
+#define ACCEPT_TYPE_ARG3 @ACCEPT_TYPE_ARG3@
+
+/* Define to the return type of 'accept' */
+#define ACCEPT_TYPE_RETURN @ACCEPT_TYPE_RETURN@
+
+/* The normal alignment of `double', in bytes. */
+#define ALIGNOF_DOUBLE @ALIGNOF_DOUBLE@
+
+/* The normal alignment of `int', in bytes. */
+#define ALIGNOF_INT @ALIGNOF_INT@
+
+/* The normal alignment of `long', in bytes. */
+#define ALIGNOF_LONG @ALIGNOF_LONG@
+
+/* The normal alignment of `long long int', in bytes. */
+#define ALIGNOF_LONG_LONG_INT @ALIGNOF_LONG_LONG_INT@
+
+/* The normal alignment of `short', in bytes. */
+#define ALIGNOF_SHORT @ALIGNOF_SHORT@
+
+/* Size of a disk block --- this also limits the size of a tuple. You can set
+   it bigger if you need bigger tuples (although TOAST should reduce the need
+   to have large tuples, since fields can be spread across multiple tuples).
+   BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is
+   currently 2^15 (32768). This is determined by the 15-bit widths of the
+   lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h).
+   Changing BLCKSZ requires an initdb. */
+#define BLCKSZ @BLCKSZ@
+
+/* Define to the default TCP port number on which the server listens and to
+   which clients will try to connect. This can be overridden at run-time, but
+   it's convenient if your clients have the right default compiled in.
+   (-DPGPORT=PORTNUM) */
+#define DEF_PGPORT @PGPORT@
+
+/* Define to the default TCP port number as a string constant. */
+#define DEF_PGPORT_STR "@PGPORT@"
+
+/* Define to build with GSSAPI support. */
+#cmakedefine ENABLE_GSS
+
+#cmakedefine ENABLE_NLS
+
+#cmakedefine ENABLE_THREAD_SAFETY 1
+
+/* Define to nothing if C supports flexible array members, and to 1 if it does
+   not. That way, with a declaration like `struct s { int n; double
+   d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99
+   compilers. When computing the size of such an object, don't use 'sizeof
+   (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)'
+   instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with
+   MSVC and with C++ compilers. */
+#define FLEXIBLE_ARRAY_MEMBER @FLEXIBLE_ARRAY_MEMBER@
+
+/* float4 values are passed by value if 'true', by reference if 'false' */
+#define FLOAT4PASSBYVAL @FLOAT4PASSBYVAL@
+
+/* float8, int8, and related values are passed by value if 'true', by
+   reference if 'false' */
+#define FLOAT8PASSBYVAL @FLOAT8PASSBYVAL@
+
+#cmakedefine GETTIMEOFDAY_1ARG
+
+#ifdef GETTIMEOFDAY_1ARG
+#	define gettimeofday(a,b) gettimeofday(a)
+#endif
+
+/* Define if you have the `append_history' function. */
+#cmakedefine HAVE_APPEND_HISTORY
+
+/* Define if you want to use atomics if available. */
+#cmakedefine HAVE_ATOMICS
+
+/* Define to 1 if you have the <atomic.h> header file. */
+#cmakedefine HAVE_ATOMIC_H 1
+
+/* Define if you have the `cbrt' function. */
+#cmakedefine HAVE_CBRT 1
+
+/* Define to 1 if you have the `class' function. */
+#cmakedefine HAVE_CLASS 1
+
+/* Define to 1 if you have the <crtdefs.h> header file. */
+#cmakedefine HAVE_CRTDEFS_H 1
+
+/* Define if you have the `crypt' function. */
+#cmakedefine HAVE_CRYPT
+
+/* Define if you have the <crypt.h> header file. */
+#cmakedefine HAVE_CRYPT_H
+
+/* Define to 1 if you have the declaration of `fdatasync' */
+#cmakedefine HAVE_DECL_FDATASYNC 1
+
+/* Define to 1 if you have the declaration of `F_FULLFSYNC' */
+#cmakedefine HAVE_DECL_F_FULLFSYNC 1
+
+/* Define to 1 if you have the declaration of `posix_fadvise' */
+#cmakedefine HAVE_DECL_POSIX_FADVISE 1
+
+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_SNPRINTF @HAVE_DECL_SNPRINTF@
+
+/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRLCAT @HAVE_DECL_STRLCAT@
+
+/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRLCPY @HAVE_DECL_STRLCPY@
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+   don't. */
+#cmakedefine HAVE_DECL_SYS_SIGLIST 1
+
+/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_VSNPRINTF @HAVE_DECL_VSNPRINTF@
+
+/* Define to 1 if you have the <dld.h> header file. */
+#cmakedefine HAVE_DLD_H
+
+/* Define to 1 if you have the `dlopen' function. */
+#cmakedefine HAVE_DLOPEN 1
+
+/* Define to 1 if you have the <editline/history.h> header file. */
+#cmakedefine HAVE_EDITLINE_HISTORY_H
+
+/* Define to 1 if you have the <editline/readline.h> header file. */
+#cmakedefine HAVE_EDITLINE_READLINE_H
+
+/* Define to 1 if you have the `fdatasync' function. */
+#cmakedefine HAVE_FDATASYNC 1
+
+/* Define to 1 if you have the `fls' function. */
+#cmakedefine HAVE_FLS
+
+/* Define to 1 if you have the `fpclass' function. */
+#cmakedefine HAVE_FPCLASS 1
+
+/* Define to 1 if you have the `fp_class' function. */
+#cmakedefine HAVE_FP_CLASS 1
+
+/* Define to 1 if you have the `fp_class_d' function. */
+#cmakedefine HAVE_FP_CLASS_D 1
+
+/* Define to 1 if you have the <fp_class.h> header file. */
+#cmakedefine HAVE_FP_CLASS_H 1
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#cmakedefine HAVE_FSEEKO 1
+
+/* Define to 1 if your compiler understands __func__. */
+#cmakedefine HAVE_FUNCNAME__FUNC
+
+/* Define to 1 if your compiler understands __FUNCTION__. */
+#cmakedefine HAVE_FUNCNAME__FUNCTION
+
+/* Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int). */
+#cmakedefine HAVE_GCC__ATOMIC_INT32_CAS 1
+
+/* Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).
+   */
+#cmakedefine HAVE_GCC__ATOMIC_INT64_CAS 1
+
+/* Define to 1 if you have __sync_lock_test_and_set(char *) and friends. */
+#cmakedefine HAVE_GCC__SYNC_CHAR_TAS 1
+
+/* Define to 1 if you have __sync_compare_and_swap(int *, int, int). */
+#cmakedefine HAVE_GCC__SYNC_INT32_CAS 1
+
+/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */
+#cmakedefine HAVE_GCC__SYNC_INT32_TAS 1
+
+/* Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64). */
+#cmakedefine HAVE_GCC__SYNC_INT64_CAS 1
+
+/* Define to 1 if you have the `getaddrinfo' function. */
+#cmakedefine HAVE_GETADDRINFO 1
+
+/* Define to 1 if you have the `gethostbyname_r' function. */
+#cmakedefine HAVE_GETHOSTBYNAME_R 1
+
+/* Define to 1 if you have the `getifaddrs' function. */
+#cmakedefine HAVE_GETIFADDRS 1
+
+/* Define to 1 if you have the `getopt' function. */
+#cmakedefine HAVE_GETOPT 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#cmakedefine HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
+#cmakedefine HAVE_GETOPT_LONG 1
+
+/* Define to 1 if you have the `getpeereid' function. */
+#cmakedefine HAVE_GETPEEREID 1
+
+/* Define to 1 if you have the `getpeerucred' function. */
+#cmakedefine HAVE_GETPEERUCRED 1
+
+/* Define to 1 if you have the `getpwuid_r' function. */
+#cmakedefine HAVE_GETPWUID_R 1
+
+/* Define to 1 if you have the `getrlimit' function. */
+#cmakedefine HAVE_GETRLIMIT 1
+
+/* Define to 1 if you have the `getrusage' function. */
+#cmakedefine HAVE_GETRUSAGE 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#cmakedefine HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+#cmakedefine HAVE_GSSAPI_GSSAPI_H 1
+
+/* Define to 1 if you have the <gssapi.h> header file. */
+#cmakedefine HAVE_GSSAPI_H 1
+
+/* Define to 1 if you have the <history.h> header file. */
+#cmakedefine HAVE_HISTORY_H 1
+
+/* Define to 1 if you have the `history_truncate_file' function. */
+#cmakedefine HAVE_HISTORY_TRUNCATE_FILE 1
+
+/* Define to 1 if you have the <ieeefp.h> header file. */
+#cmakedefine HAVE_IEEEFP_H @HAVE_IEEEFP_H@
+
+/* Define to 1 if you have the <ifaddrs.h> header file. */
+#cmakedefine HAVE_IFADDRS_H 1
+
+/* Define to 1 if you have the `inet_aton' function. */
+#cmakedefine HAVE_INET_ATON 1
+
+/* Define to 1 if the system has the type `int64'. */
+#cmakedefine HAVE_INT64 1
+
+/* Define to 1 if the system has the type `int8'. */
+#cmakedefine HAVE_INT8 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `intptr_t'. */
+/*#cmakedefine HAVE_INTPTR_T 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <inttypes.h> header file. */
+/*#cmakedefine HAVE_INTTYPES_H 1*/
+
+/* Define to 1 if you have the global variable 'int opterr'. */
+#cmakedefine HAVE_INT_OPTERR 1
+
+/* Define to 1 if you have the global variable 'int optreset'. */
+#cmakedefine HAVE_INT_OPTRESET 1
+
+/* Define to 1 if you have the global variable 'int timezone'. */
+#cmakedefine HAVE_INT_TIMEZONE 1
+
+/* Define to 1 if you have support for IPv6. */
+#cmakedefine HAVE_IPV6 1
+
+/* Define to 1 if you have isinf(). */
+#cmakedefine HAVE_ISINF 1
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#cmakedefine HAVE_LANGINFO_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <ldap.h> header file. */
+/*#cmakedefine HAVE_LDAP_H 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `crypto' library (-lcrypto). */
+/*#cmakedefine HAVE_LIBCRYPTO 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `ldap' library (-lldap). */
+/*#cmakedefine HAVE_LIBLDAP 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `ldap_r' library (-lldap_r). */
+/*#cmakedefine HAVE_LIBLDAP_R 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `m' library (-lm). */
+/*#cmakedefine HAVE_LIBM*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `pam' library (-lpam). */
+/*#cmakedefine HAVE_LIBPAM 1*/
+
+/* Define if you have a function readline library */
+#cmakedefine HAVE_LIBREADLINE 1
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `selinux' library (-lselinux). */
+/*#cmakedefine HAVE_LIBSELINUX 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `ssl' library (-lssl). */
+/*#cmakedefine HAVE_LIBSSL 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `wldap32' library (-lwldap32). */
+/*#cmakedefine HAVE_LIBWLDAP32 1*/
+
+/* Define to 1 if you have the `xml2' library (-lxml2). */
+#cmakedefine HAVE_LIBXML2 1
+
+/* Define to 1 if you have the `xslt' library (-lxslt). */
+#cmakedefine HAVE_LIBXSLT 1
+
+/* Define to 1 if you have the `z' library (-lz). */
+#cmakedefine HAVE_LIBZ 1
+
+/* Define to 1 if constants of type 'long long int' should have the suffix LL.
+   */
+#cmakedefine HAVE_LL_CONSTANTS 1
+
+/* Define to 1 if the system has the type `locale_t'. */
+#cmakedefine HAVE_LOCALE_T
+
+/* Define to 1 if `long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_INT_64 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if `long long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_LONG_INT_64 1
+
+/* Define to 1 if you have the <mbarrier.h> header file. */
+#cmakedefine HAVE_MBARRIER_H 1
+
+/* Define to 1 if you have the `mbstowcs_l' function. */
+#cmakedefine HAVE_MBSTOWCS_L 1
+
+/* Define to 1 if you have the `memmove' function. */
+#cmakedefine HAVE_MEMMOVE 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <memory.h> header file. */
+/*#cmakedefine HAVE_MEMORY_H 1*/
+
+/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
+#cmakedefine HAVE_MINIDUMP_TYPE 1
+
+/* Define to 1 if you have the `mkdtemp' function. */
+#cmakedefine HAVE_MKDTEMP 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <netinet/in.h> header file. */
+/*#cmakedefine HAVE_NETINET_IN_H 1*/
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#cmakedefine HAVE_NETINET_TCP_H 1
+
+/* Define to 1 if you have the <net/if.h> header file. */
+#cmakedefine HAVE_NET_IF_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <ossp/uuid.h> header file. */
+/*#cmakedefine HAVE_OSSP_UUID_H 1*/
+
+/* Define to 1 if you have the <pam/pam_appl.h> header file. */
+#cmakedefine HAVE_PAM_PAM_APPL_H 1
+
+/* Define to 1 if you have the `poll' function. */
+#cmakedefine HAVE_POLL 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+#cmakedefine HAVE_POLL_H 1
+
+/* Define to 1 if you have the `posix_fadvise' function. */
+#cmakedefine HAVE_POSIX_FADVISE 1
+
+/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */
+#cmakedefine HAVE_PPC_LWARX_MUTEX_HINT 1
+
+/* Define to 1 if you have the `pstat' function. */
+#cmakedefine HAVE_PSTAT 1
+
+/* Define to 1 if the PS_STRINGS thing exists. */
+#cmakedefine HAVE_PS_STRINGS 1
+
+/* TODO BUT DO NOT NEED:Define if you have POSIX threads libraries and header files. */
+/*#cmakedefine HAVE_PTHREAD 1*/
+
+/* Define to 1 if you have the `pthread_is_threaded_np' function. */
+#cmakedefine HAVE_PTHREAD_IS_THREADED_NP 1
+
+/* TODO BUT DO NOT NEED:Have PTHREAD_PRIO_INHERIT. */
+/*#cmakedefine HAVE_PTHREAD_PRIO_INHERIT 1*/
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#cmakedefine HAVE_PWD_H 1
+
+/* Define to 1 if you have the `random' function. */
+#cmakedefine HAVE_RANDOM 1
+
+/* Define to 1 if you have the <readline.h> header file. */
+#cmakedefine HAVE_READLINE_H 1
+
+/* Define to 1 if you have the <readline/history.h> header file. */
+#cmakedefine HAVE_READLINE_HISTORY_H 1
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#cmakedefine HAVE_READLINE_READLINE_H 1
+
+/* Define to 1 if you have the `readlink' function. */
+#cmakedefine HAVE_READLINK 1
+
+/* Define to 1 if you have the `rint' function. */
+#cmakedefine HAVE_RINT 1
+
+/* Define to 1 if you have the global variable
+   'rl_completion_append_character'. */
+#cmakedefine HAVE_RL_COMPLETION_APPEND_CHARACTER 1
+
+/* Define to 1 if you have the `rl_completion_matches' function. */
+#cmakedefine HAVE_RL_COMPLETION_MATCHES 1
+
+/* Define to 1 if you have the `rl_filename_completion_function' function. */
+#cmakedefine HAVE_RL_FILENAME_COMPLETION_FUNCTION 1
+
+/* Define to 1 if you have the `rl_reset_screen_size' function. */
+#cmakedefine HAVE_RL_RESET_SCREEN_SIZE 1
+
+/* Define to 1 if you have the <security/pam_appl.h> header file. */
+#cmakedefine HAVE_SECURITY_PAM_APPL_H 1
+
+/* Define to 1 if you have the `setproctitle' function. */
+#cmakedefine HAVE_SETPROCTITLE 1
+
+/* Define to 1 if you have the `setsid' function. */
+#cmakedefine HAVE_SETSID 1
+
+/* Define to 1 if you have the `shm_open' function. */
+#cmakedefine HAVE_SHM_OPEN 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `snprintf' function. */
+/*#cmakedefine HAVE_SNPRINTF 1*/
+
+/* Define to 1 if you have spinlocks. */
+#cmakedefine HAVE_SPINLOCKS 1
+
+/* Define to 1 if you have the `srandom' function. */
+#cmakedefine HAVE_SRANDOM 1
+
+/* Define to 1 if you have the `SSL_get_current_compression' function. */
+#cmakedefine HAVE_SSL_GET_CURRENT_COMPRESSION 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <stdlib.h> header file. */
+/*#cmakedefine HAVE_STDLIB_H 1*/
+
+/* Define to 1 if you have the `strerror' function. */
+#cmakedefine HAVE_STRERROR 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `strlcat' function. */
+/*#cmakedefine HAVE_STRLCAT 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `strlcpy' function. */
+/*#cmakedefine HAVE_STRLCPY 1*/
+
+/* Define to 1 if you have the `strtoll' function. */
+#cmakedefine HAVE_STRTOLL 1
+
+/* Define to 1 if you have the `strtoq' function. */
+#cmakedefine HAVE_STRTOQ 1
+
+/* Define to 1 if you have the `strtoull' function. */
+#cmakedefine HAVE_STRTOULL 1
+
+/* Define to 1 if you have the `strtouq' function. */
+#cmakedefine HAVE_STRTOUQ 1
+
+/* Define to 1 if the system has the type `struct addrinfo'. */
+#cmakedefine HAVE_STRUCT_ADDRINFO 1
+
+/* Define to 1 if the system has the type `struct cmsgcred'. */
+#cmakedefine HAVE_STRUCT_CMSGCRED 1
+
+/* Define to 1 if the system has the type `struct option'. */
+#cmakedefine HAVE_STRUCT_OPTION 1
+
+/* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
+
+/* Define to 1 if the system has the type `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE 1
+
+/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
+
+/* Define to 1 if `ss_len' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
+
+/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY 1
+
+/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#cmakedefine HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define to 1 if you have the `symlink' function. */
+#cmakedefine HAVE_SYMLINK 1
+
+/* Define to 1 if you have the `sync_file_range' function. */
+#cmakedefine HAVE_SYNC_FILE_RANGE 1
+
+/* Define to 1 if you have the syslog interface. */
+#cmakedefine HAVE_SYSLOG 1
+
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#cmakedefine HAVE_SYS_EPOLL_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/ipc.h> header file. */
+#cmakedefine HAVE_SYS_IPC_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#cmakedefine HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/pstat.h> header file. */
+#cmakedefine HAVE_SYS_PSTAT_H 1
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#cmakedefine HAVE_SYS_RESOURCE_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#cmakedefine HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/sem.h> header file. */
+#cmakedefine HAVE_SYS_SEM_H 1
+
+/* Define to 1 if you have the <sys/shm.h> header file. */
+#cmakedefine HAVE_SYS_SHM_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#cmakedefine HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+#cmakedefine HAVE_SYS_SOCKIO_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/tas.h> header file. */
+#cmakedefine HAVE_SYS_TAS_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#cmakedefine HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/ucred.h> header file. */
+#cmakedefine HAVE_SYS_UCRED_H 1
+
+/* Define to 1 if you have the <sys/un.h> header file. */
+#cmakedefine HAVE_SYS_UN_H 1
+
+/* Define to 1 if you have the <termios.h> header file. */
+#cmakedefine HAVE_TERMIOS_H 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#cmakedefine HAVE_TM_ZONE 1
+
+/* Define to 1 if you have the `towlower' function. */
+#cmakedefine HAVE_TOWLOWER 1
+
+/* Define to 1 if you have the external array `tzname'. */
+#cmakedefine HAVE_TZNAME 1
+
+/* Define to 1 if you have the <ucred.h> header file. */
+#cmakedefine HAVE_UCRED_H 1
+
+/* Define to 1 if the system has the type `uint64'. */
+#cmakedefine HAVE_UINT64 1
+
+/* Define to 1 if the system has the type `uint8'. */
+#cmakedefine HAVE_UINT8 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `uintptr_t'. */
+/*#cmakedefine HAVE_UINTPTR_T 1*/
+
+/* Define to 1 if the system has the type `union semun'. */
+#cmakedefine HAVE_UNION_SEMUN 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/* Define to 1 if you have unix sockets. */
+#cmakedefine HAVE_UNIX_SOCKETS 1
+
+/* Define to 1 if you have the `unsetenv' function. */
+#cmakedefine HAVE_UNSETENV 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `unsigned long long int'. */
+/*#cmakedefine HAVE_UNSIGNED_LONG_LONG_INT 1*/
+
+/* Define to 1 if you have the `utime' function. */
+#cmakedefine HAVE_UTIME 1
+
+/* Define to 1 if you have the `utimes' function. */
+#cmakedefine HAVE_UTIMES 1
+
+/* Define to 1 if you have the <utime.h> header file. */
+#cmakedefine HAVE_UTIME_H 1
+
+/* Define to 1 if you have BSD UUID support. */
+#cmakedefine HAVE_UUID_BSD 1
+
+/* Define to 1 if you have E2FS UUID support. */
+#cmakedefine HAVE_UUID_E2FS 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <uuid.h> header file. */
+/*#cmakedefine HAVE_UUID_H 1*/
+
+/* Define to 1 if you have OSSP UUID support. */
+#cmakedefine HAVE_UUID_OSSP 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <uuid/uuid.h> header file. */
+/*#cmakedefine HAVE_UUID_UUID_H 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `vsnprintf' function. */
+/*#cmakedefine HAVE_VSNPRINTF 1*/
+
+/* Define to 1 if you have the <wchar.h> header file. */
+#cmakedefine HAVE_WCHAR_H 1
+
+/* Define to 1 if you have the `wcstombs' function. */
+#cmakedefine HAVE_WCSTOMBS 1
+
+/* Define to 1 if you have the `wcstombs_l' function. */
+#cmakedefine HAVE_WCSTOMBS_L 1
+
+/* Define to 1 if you have the <wctype.h> header file. */
+#cmakedefine HAVE_WCTYPE_H 1
+
+/* Define to 1 if you have the <winldap.h> header file. */
+#cmakedefine HAVE_WINLDAP_H 1
+
+/* Define to 1 if your compiler understands __builtin_bswap32. */
+#cmakedefine HAVE__BUILTIN_BSWAP32 1
+
+/* Define to 1 if your compiler understands __builtin_bswap64. */
+#cmakedefine HAVE__BUILTIN_BSWAP64 1
+
+/* Define to 1 if your compiler understands __builtin_constant_p. */
+#cmakedefine HAVE__BUILTIN_CONSTANT_P 1
+
+/* Define to 1 if your compiler understands __builtin_types_compatible_p. */
+#cmakedefine HAVE__BUILTIN_TYPES_COMPATIBLE_P 1
+
+/* Define to 1 if your compiler understands __builtin_unreachable. */
+#cmakedefine HAVE__BUILTIN_UNREACHABLE 1
+
+/* Define to 1 if you have __cpuid. */
+#cmakedefine HAVE__CPUID 1
+
+/* Define to 1 if you have __cpuid. */
+#cmakedefine HAVE__GET_CPUID 1
+
+/* Define to 1 if your compiler understands _Static_assert. */
+#cmakedefine HAVE__STATIC_ASSERT 1
+
+/* Define to 1 if your compiler understands __VA_ARGS__ in macros. */
+#cmakedefine HAVE__VA_ARGS 1
+
+/* Define to the appropriate snprintf length modifier for 64-bit ints. */
+#define INT64_MODIFIER "@LONG_LONG_INT_MODIFIER@"
+
+/* Define to 1 if `locale_t' requires <xlocale.h>. */
+#cmakedefine LOCALE_T_IN_XLOCALE 1
+
+/* Define as the maximum alignment requirement of any C data type. */
+#define MAXIMUM_ALIGNOF @MAXIMUM_ALIGNOF@
+
+/* Define bytes to use libc memset(). */
+#define MEMSET_LOOP_LIMIT @MEMSET_LOOP_LIMIT@
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
+
+/* TODO BUT DO NOT NEED:Define to the full name of this package. */
+/*#define PACKAGE_NAME "@PACKAGE_NAME@"*/
+
+/* TODO:Define to the full name and version of this package. */
+/*#define PACKAGE_STRING "@PACKAGE_STRING@"*/
+
+/* TODO BUT DO NOT NEED:Define to the one symbol short name of this package. */
+/*#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"*/
+
+/* TODO BUT DO NOT NEED:Define to the home page for this package. */
+/*#define PACKAGE_URL "@PACKAGE_URL@"*/
+
+/* TODO BUT DO NOT NEED:Define to the version of this package. */
+/*#define PACKAGE_VERSION "@PACKAGE_VERSION@"*/
+
+/* Define to the name of a signed 128-bit integer type. */
+#define PG_INT128_TYPE @PG_INT128_TYPE@
+
+/* Define to the name of a signed 64-bit integer type. */
+#define PG_INT64_TYPE @PG_INT64_TYPE@
+
+/* Define to the name of the default PostgreSQL service principal in Kerberos
+   (GSSAPI). */
+#define PG_KRB_SRVNAM "@PG_KRB_SRVNAM@"
+
+/* PostgreSQL major version as a string */
+#define PG_MAJORVERSION "@POSTGRES_MAJOR_VERSION@"
+
+/* Define to gnu_printf if compiler supports it, else printf. */
+#define PG_PRINTF_ATTRIBUTE @PG_PRINTF_ATTRIBUTE@
+
+/* PostgreSQL version as a string */
+#define PG_VERSION "@PG_VERSION@"
+
+/* PostgreSQL version as a number */
+#define PG_VERSION_NUM @PG_VERSION_NUM@
+
+/* A string containing the version number, platform, and C compiler */
+#define PG_VERSION_STR "PostgreSQL @PG_VERSION@ on @CMAKE_SYSTEM_NAME@, compiled by @CMAKE_C_COMPILER_ID@, @VOID_POINTER_SIZE_BIT@-bit"
+
+/* Define to 1 to allow profiling output to be saved separately for each
+   process. */
+#cmakedefine PROFILE_PID_DIR 1
+
+/* TODO BUT DO NOT NEED:Define to necessary symbol if this constant uses a non-standard name on
+   your system. */
+/*#cmakedefine PTHREAD_CREATE_JOINABLE*/
+
+/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus,
+   the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger
+   than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be
+   less than your OS' limit on file size. This is often 2 GB or 4GB in a
+   32-bit operating system, unless you have large file support enabled. By
+   default, we make the limit 1 GB to avoid any possible integer-overflow
+   problems within the OS. A limit smaller than necessary only means we divide
+   a large relation into more chunks than necessary, so it seems best to err
+   in the direction of a small limit. A power-of-2 value is recommended to
+   save a few cycles in md.c, but is not absolutely required. Changing
+   RELSEG_SIZE requires an initdb. */
+#define RELSEG_SIZE @RELSEG_SIZE@
+
+/* The size of `long', as computed by sizeof. */
+#define SIZEOF_LONG @SIZEOF_LONG@
+
+/* TODO BUT DO NOT NEED:The size of `off_t', as computed by sizeof. */
+/*#define SIZEOF_OFF_T @SIZEOF_OFF_T@*/
+
+/* The size of `size_t', as computed by sizeof. */
+#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@
+
+/* The size of `void *', as computed by sizeof. */
+#define SIZEOF_VOID_P @CMAKE_SIZEOF_VOID_P@
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the ANSI C header files. */
+/*#cmakedefine STDC_HEADERS 1*/
+
+/* Define to 1 if strerror_r() returns a int. */
+#cmakedefine STRERROR_R_INT 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if your <sys/time.h> declares `struct tm'. */
+/*#cmakedefine TM_IN_SYS_TIME 1*/
+
+/* Define to 1 to build with assertion checks. (--enable-cassert) */
+#cmakedefine USE_ASSERT_CHECKING 1
+
+/* Define to 1 to build with Bonjour support. (--with-bonjour) */
+#cmakedefine USE_BONJOUR 1
+
+/* Define to 1 to build with BSD Authentication support. (--with-bsd-auth) */
+#cmakedefine USE_BSD_AUTH 1
+
+/* Define to 1 if you want float4 values to be passed by value. */
+#cmakedefine USE_FLOAT4_BYVAL 1
+
+/* Define to 1 if you want float8, int8, etc values to be passed by value. */
+#cmakedefine USE_FLOAT8_BYVAL 1
+
+/* Define to 1 if you want 64-bit integer timestamp and interval support. */
+#cmakedefine USE_INTEGER_DATETIMES 1
+
+/* Define to 1 to build with LDAP support. (--with-ldap) */
+#cmakedefine USE_LDAP 1
+
+/* Define to 1 to build with XML support. (-DWITH_LIBXML) */
+#cmakedefine USE_LIBXML 1
+
+/* Define to 1 to use XSLT support when building contrib/xml2. */
+#cmakedefine USE_LIBXSLT 1
+
+/* Define to select named POSIX semaphores. */
+#cmakedefine USE_NAMED_POSIX_SEMAPHORES 1
+
+/* Define to build with OpenSSL support. (--with-openssl) */
+#cmakedefine USE_OPENSSL 1
+
+/* Define to 1 to build with PAM support. (--with-pam) */
+#cmakedefine USE_PAM 1
+
+/* Use replacement snprintf() functions. */
+#cmakedefine USE_REPL_SNPRINTF 1
+
+/* Define to 1 to use Intel SSE 4.2 CRC instructions with a runtime check. */
+#cmakedefine USE_SLICING_BY_8_CRC32C 1
+
+/* Define to 1 use Intel SSE 4.2 CRC instructions. */
+#cmakedefine USE_SSE42_CRC32C 1
+
+/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */
+#cmakedefine USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1
+
+/* Define to build with systemd support. (--with-systemd) */
+#cmakedefine USE_SYSTEMD
+
+/* Define to select SysV-style semaphores. */
+#cmakedefine USE_SYSV_SEMAPHORES
+
+/* Define to select SysV-style shared memory. */
+#cmakedefine USE_SYSV_SHARED_MEMORY
+
+/* Define to select unnamed POSIX semaphores. */
+#cmakedefine USE_UNNAMED_POSIX_SEMAPHORES
+
+/* Define to select Win32-style semaphores. */
+#cmakedefine USE_WIN32_SEMAPHORES
+
+/* TODO BUT DO NOT NEED:Define to select Win32-style shared memory. */
+/*#cmakedefine USE_WIN32_SHARED_MEMORY*/
+
+/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
+#cmakedefine WCSTOMBS_L_IN_XLOCALE 1
+
+/* NOT NEED:Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+/*#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+#  undef WORDS_BIGENDIAN
+# endif
+#endif*/
+
+/* Size of a WAL file block. This need have no particular relation to BLCKSZ.
+   XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O,
+   XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O
+   buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb.
+   */
+#define XLOG_BLCKSZ @XLOG_BLCKSZ@
+
+/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2
+   and larger than XLOG_BLCKSZ (preferably, a great deal larger than
+   XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */
+#define XLOG_SEG_SIZE @XLOG_SEG_SIZE@
+
+/* TODO BUT DO NOT NEED:Number of bits in a file offset, on hosts where this is settable. */
+/*#undef _FILE_OFFSET_BITS*/
+
+/* TODO BUT DO NOT NEED:Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/*#undef _LARGEFILE_SOURCE*/
+
+/* TODO BUT DO NOT NEED:Define for large files, on AIX-style hosts. */
+/*#undef _LARGE_FILES*/
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#undef inline
+#endif
+
+/* Define to the type of a signed integer type wide enough to hold a pointer,
+   if such a type exists, and if the system does not define it. */
+/*#undef intptr_t*/
+
+/* Define to empty if the C compiler does not understand signed types. */
+/*#undef signed*/
+
+/* Define to the type of an unsigned integer type wide enough to hold a
+   pointer, if such a type exists, and if the system does not define it. */
+/*#undef uintptr_t*/
+
+#cmakedefine HAVE_INT128
+
+#ifdef WIN32
+#undef PG_INT128_TYPE
+#endif
+
+#define LONG_LONG_INT_MODIFIER @LONG_LONG_INT_MODIFIER@
+
+#define POSTGRES_MAJOR_VERSION @POSTGRES_MAJOR_VERSION@
+
+#define POSTGRES_MINOR_VERSION @POSTGRES_MINOR_VERSION@
+
+#define POSTGRES_PATCH_VERSION @POSTGRES_PATCH_VERSION@
+
+#ifdef __APPLE__
+#	if __BIG_ENDIAN
+#		define WORDS_BIGENDIAN 1
+#	endif
+#else
+#cmakedefine WORDS_BIGENDIAN 1
+#endif
+
+#define DLSUFFIX "@CMAKE_SHARED_MODULE_SUFFIX@"
+
+#cmakedefine HAVE_MKSTEMP 1
+
+#cmakedefine HAVE_NBTOOL_CONFIG_H 1
+
+/*#include "@pgos_include_SRCS@"*/
+
+#endif  // AUTO_CONFIG_H
diff --git a/src/include/pg_config_ext_cmake.in b/src/include/pg_config_ext_cmake.in
new file mode 100644
index 0000000..a73f04b
--- /dev/null
+++ b/src/include/pg_config_ext_cmake.in
@@ -0,0 +1 @@
+#define PG_INT64_TYPE @PG_INT64_TYPE@
\ No newline at end of file
diff --git a/src/include/pg_config_paths_cmake.in b/src/include/pg_config_paths_cmake.in
new file mode 100644
index 0000000..f1b3c08
--- /dev/null
+++ b/src/include/pg_config_paths_cmake.in
@@ -0,0 +1,12 @@
+#define PGBINDIR "@PGBINDIR@"
+#define PGSHAREDIR "@PGSHAREDIR@"
+#define SYSCONFDIR "@SYSCONFDIR@" 
+#define INCLUDEDIR "@INCLUDEDIR@"
+#define PKGINCLUDEDIR "@PKGINCLUDEDIR@"
+#define INCLUDEDIRSERVER "@INCLUDEDIRSERVER@"
+#define LIBDIR "@LIBDIR@"
+#define PKGLIBDIR "@PKGLIBDIR@"
+#define LOCALEDIR "@LOCALEDIR@"
+#define DOCDIR "@DOCDIR@"
+#define HTMLDIR "@HTMLDIR@"
+#define MANDIR "@MANDIR@"
\ No newline at end of file
diff --git a/src/interfaces/ecpg/compatlib/CMakeLists.txt b/src/interfaces/ecpg/compatlib/CMakeLists.txt
new file mode 100644
index 0000000..3214951
--- /dev/null
+++ b/src/interfaces/ecpg/compatlib/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+set(ecpg_compat_SRC
+	informix.c
+)
+if(USE_REPL_SNPRINTF)
+	set(ecpg_compat_SRC
+		${ecpg_compat_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+add_library(ecpg_compat SHARED ${ecpg_compat_SRC})
+if (MSVC)
+	gen_def(ecpg_compat)
+endif()
+target_link_libraries(ecpg_compat ${LIB_M} pgtypes pq ecpg)
+target_compile_definitions(ecpg_compat PRIVATE -DFRONTEND)
+set_target_properties(ecpg_compat PROPERTIES VERSION "3.8")
+
+install(TARGETS ecpg_compat
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/interfaces/ecpg/ecpglib/CMakeLists.txt b/src/interfaces/ecpg/ecpglib/CMakeLists.txt
new file mode 100644
index 0000000..158ec62
--- /dev/null
+++ b/src/interfaces/ecpg/ecpglib/CMakeLists.txt
@@ -0,0 +1,76 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+set(ecpg_SRC
+	execute.c
+	typename.c
+	descriptor.c
+	sqlda.c
+	data.c
+	error.c
+	prepare.c
+	memory.c
+	connect.c
+	misc.c
+	${PROJECT_SOURCE_DIR}/src/port/path.c
+	${PROJECT_SOURCE_DIR}/src/port/pgstrcasecmp.c
+)
+
+if(USE_REPL_SNPRINTF)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/rint.c
+	)
+endif()
+
+if(NOT HAVE_DECL_STRLCPY)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/strlcpy.c
+	)
+endif()
+
+if(NOT HAVE_ISINF)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/isinf.c
+	)
+endif()
+
+if(WIN32)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/win32setlocale.c
+	)
+else()
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/thread.c
+	)
+endif()
+
+add_library(ecpg SHARED ${ecpg_SRC})
+if (MSVC)
+	gen_def(ecpg)
+endif()
+target_link_libraries(ecpg ${LIB_M} pgtypes pq)
+target_compile_definitions(ecpg PRIVATE -DFRONTEND)
+set_target_properties(ecpg PROPERTIES VERSION "6.8")
+
+install(TARGETS ecpg
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(ecpg "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;tr;zh_CN")
+endif()
diff --git a/src/interfaces/ecpg/include/CMakeLists.txt b/src/interfaces/ecpg/include/CMakeLists.txt
new file mode 100644
index 0000000..63c42e8
--- /dev/null
+++ b/src/interfaces/ecpg/include/CMakeLists.txt
@@ -0,0 +1,25 @@
+set(INCLUDEDIR_INTERNAL ${PKGINCLUDEDIR}/internal)
+
+install(FILES
+	ecpgerrno.h
+	ecpglib.h
+	ecpgtype.h
+	sqlca.h
+	sql3types.h
+	ecpg_informix.h
+	pgtypes_error.h
+	pgtypes_numeric.h
+	pgtypes_timestamp.h
+	pgtypes_date.h
+	pgtypes_interval.h
+	sqlda.h
+	sqlda-compat.h
+	sqlda-native.h
+	ecpg_config.h
+	DESTINATION ${INCLUDEDIR})
+
+install(FILES
+	datetime.h
+	decimal.h
+	sqltypes.h
+	DESTINATION ${PKGINCLUDEDIR}/informix/esql)
diff --git a/src/interfaces/ecpg/include/ecpg_config_cmake.in b/src/interfaces/ecpg/include/ecpg_config_cmake.in
new file mode 100644
index 0000000..1f3fcb8
--- /dev/null
+++ b/src/interfaces/ecpg/include/ecpg_config_cmake.in
@@ -0,0 +1,19 @@
+/* Define to 1 if the system has the type `int64'. */
+#cmakedefine HAVE_INT64 1
+
+/* Define to 1 if `long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_INT_64 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if `long long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_LONG_INT_64 1
+
+/* Define to 1 if you want 64-bit integer timestamp and interval support.
+   (--enable-integer-datetimes) */
+#cmakedefine USE_INTEGER_DATETIMES 1
+
+/* Define to 1 to build client libraries as thread-safe code.
+ *    (--enable-thread-safety) */
+#cmakedefine ENABLE_THREAD_SAFETY 1
diff --git a/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt b/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt
new file mode 100644
index 0000000..a36ddca
--- /dev/null
+++ b/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt
@@ -0,0 +1,41 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+)
+set(pgtypes_SRC
+	numeric.c
+	datetime.c
+	common.c
+	dt_common.c
+	timestamp.c
+	interval.c
+	${PROJECT_SOURCE_DIR}/src/port/pgstrcasecmp.c
+)
+if(USE_REPL_SNPRINTF)
+	set(pgtypes_SRC
+		${pgtypes_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(pgtypes_SRC
+		${pgtypes_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/rint.c
+	)
+endif()
+
+add_library(pgtypes SHARED ${pgtypes_SRC})
+if (MSVC)
+	gen_def(pgtypes)
+endif()
+
+target_link_libraries(pgtypes ${LIB_M})
+target_compile_definitions(pgtypes PRIVATE -DFRONTEND)
+set_target_properties(pgtypes PROPERTIES VERSION "3.7")
+
+
+install(TARGETS pgtypes
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/interfaces/libpq/CMakeLists.txt b/src/interfaces/libpq/CMakeLists.txt
new file mode 100644
index 0000000..8afcc6c
--- /dev/null
+++ b/src/interfaces/libpq/CMakeLists.txt
@@ -0,0 +1,108 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+)
+
+if(USE_OPENSSL)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	set(pq_ssl_SRCS fe-secure-openssl.c)
+endif(USE_OPENSSL)
+
+set(pq_SRCS
+	fe-auth.c
+	fe-connect.c
+	fe-exec.c
+	fe-misc.c
+	fe-print.c
+	fe-lobj.c
+	fe-protocol2.c
+	fe-protocol3.c
+	pqexpbuffer.c
+	fe-secure.c
+	libpq-events.c
+
+	${PORT_DIR}/chklocale.c
+	${PORT_DIR}/inet_net_ntop.c
+	${PORT_DIR}/noblock.c
+	${PORT_DIR}/pgstrcasecmp.c
+	${PORT_DIR}/pqsignal.c
+	${PORT_DIR}/thread.c
+
+	${PROJECT_SOURCE_DIR}/src/common/ip.c
+	${PROJECT_SOURCE_DIR}/src/common/md5.c
+	${MB_UTILS_BACKEND_DIR}/encnames.c
+	${MB_UTILS_BACKEND_DIR}/wchar.c
+
+	${fallback_SRCS}
+	${pq_ssl_SRCS}
+)
+
+if(USE_REPL_SNPRINTF)
+	set(pq_SRCS ${pq_SRCS} ${PORT_DIR}/snprintf.c)
+endif()
+
+set(RES_FILES "")
+if(WIN32)
+	set(pq_SRCS ${pq_SRCS}
+		win32.c
+		${PORT_DIR}/win32error.c
+		${PORT_DIR}/win32setlocale.c
+		${PORT_DIR}/pgsleep.c
+		${PORT_DIR}/open.c
+		${PORT_DIR}/system.c
+		${PORT_DIR}/inet_aton.c
+		${PORT_DIR}/thread.c
+		${PORT_DIR}/getaddrinfo.c
+	)
+	if (Threads_FOUND)
+		set(pq_SRCS ${pq_SRCS} pthread-win32.c)
+	endif()
+	set(RES_FILES "libpq.rc")
+	set(CMAKE_RC_COMPILER_INIT windres)
+	ENABLE_LANGUAGE(RC)
+	SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
+endif()
+
+add_library(pq SHARED ${pq_SRCS} ${RES_FILES})
+target_link_libraries(pq
+	${CMAKE_THREAD_LIBS_INIT}
+	${LIBSOCKET_LIBRARIES}
+	${GSS_LIBS}
+)
+if(USE_OPENSSL)
+	target_link_libraries(pq ${OPENSSL_LIBRARIES})
+endif()
+if (MSVC)
+	gen_def(pq)
+endif()
+if(CRYPT_LIB)
+	target_link_libraries(pq ${CRYPT_LIB})
+endif()
+if(WIN32)
+	target_link_libraries(pq
+		#port
+		Secur32
+		ws2_32
+	)
+endif()
+
+if(LDAP_FOUND)
+	target_link_libraries(pq ${LDAP_LIBRARIES})
+endif()
+
+if(USE_OPENSSL)
+	target_include_directories(pq PUBLIC ${OPENSSL_INCLUDE_DIR})
+endif()
+
+
+target_compile_definitions(pq PRIVATE -DFRONTEND -DUNSAFE_STAT_OK)
+install(TARGETS pq
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(libpq "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;tr;zh_CN;zh_TW")
+endif()
+
+#TODO 
+#set_target_properties(pq PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.list")
diff --git a/src/pl/plperl/CMakeLists.txt b/src/pl/plperl/CMakeLists.txt
new file mode 100644
index 0000000..ba73e7c
--- /dev/null
+++ b/src/pl/plperl/CMakeLists.txt
@@ -0,0 +1,100 @@
+if(WIN32)
+	add_definitions(-DPLPERL_HAVE_UID_GID)
+endif()
+
+execute_process(
+	COMMAND ${PERL_EXECUTABLE} -e "use List::Util qw(first); print first { -r \"$_/ExtUtils/xsubpp\" } @INC"
+	OUTPUT_VARIABLE XSUBPPDIR
+)
+execute_process(
+	COMMAND ${PERL_EXECUTABLE} -V:usemultiplicity
+	OUTPUT_VARIABLE PERL_MULTIPLICITY
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/SPI.c"
+	MAIN_DEPENDENCY SPI.xs plperl_helpers.h
+	COMMAND ${PERL_EXECUTABLE} ${XSUBPPDIR}/ExtUtils/xsubpp -typemap ${PERL_PRIVLIB}/ExtUtils/typemap SPI.xs > "${CMAKE_CURRENT_SOURCE_DIR}/SPI.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/Util.c"
+	MAIN_DEPENDENCY Util.xs plperl_helpers.h
+	COMMAND ${PERL_EXECUTABLE} ${XSUBPPDIR}/ExtUtils/xsubpp -typemap ${PERL_PRIVLIB}/ExtUtils/typemap Util.xs > "${CMAKE_CURRENT_SOURCE_DIR}/Util.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	MAIN_DEPENDENCY plc_perlboot.pl plc_trusted.pl
+	COMMAND ${PERL_EXECUTABLE} text2macro.pl "--strip='^(\\#.*|\\s*)$$'" plc_perlboot.pl plc_trusted.pl > "${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	MAIN_DEPENDENCY plperl_opmask.pl
+	COMMAND ${PERL_EXECUTABLE} plperl_opmask.pl "${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plname "plperl")
+
+set(plperl_SRCS
+	"${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	"${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	plperl.c
+	SPI.c
+	Util.c
+)
+
+include_directories(${PERL_INCLUDE_PATH})
+add_library(${plname} MODULE ${plperl_SRCS})
+target_link_libraries(${plname} postgres ${PERL_LIBRARY} ${PERL_LDFLAGS})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} port)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+		plperl.control
+		plperl--1.0.sql
+		plperl--unpackaged--1.0.sql
+		plperlu.control
+		plperlu--1.0.sql
+		plperlu--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	plperl.h
+	ppport.h
+	DESTINATION ${INCLUDEDIRSERVER})
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB} --load-extension=plperl --load-extension=plperlu)
+set(plregres_files
+	plperl
+	plperl_lc
+	plperl_trigger
+	plperl_shared
+	plperl_elog
+	plperl_util
+	plperl_init
+	plperlu
+	plperl_array
+)
+
+if(PERL_MULTIPLICITY STREQUAL "usemultiplicity='define'")
+	set(plregres_files ${plregres_files} plperl_plperlu)
+endif()
+
+REGRESS_CHECK(plperl "${REGRESS_OPTS}" "${plregres_files}")
+
+if(ENABLE_NLS)
+	MAKE_MO(plperl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;sv;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/pl/plpgsql/src/CMakeLists.txt b/src/pl/plpgsql/src/CMakeLists.txt
new file mode 100644
index 0000000..29efb6a
--- /dev/null
+++ b/src/pl/plpgsql/src/CMakeLists.txt
@@ -0,0 +1,37 @@
+BISON_TARGET(PLPGSQL_PARSER pl_gram.y ${CMAKE_CURRENT_SOURCE_DIR}/pl_gram.c COMPILE_FLAGS "-d")
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/plerrcodes.h"
+	MAIN_DEPENDENCY generate-plerrcodes.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-plerrcodes.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/plerrcodes.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plpgsql_SRCS
+	pl_handler.c
+	pl_comp.c
+	plerrcodes.h
+	pl_exec.c
+	pl_funcs.c
+	pl_scanner.c
+	${BISON_PLPGSQL_PARSER_OUTPUT_SOURCE}
+)
+
+add_library(plpgsql MODULE ${plpgsql_SRCS})
+target_link_libraries(plpgsql postgres)
+if (MSVC)
+	gen_def(plpgsql)
+	target_link_libraries(plpgsql port pgcommon)
+endif()
+set_target_properties(plpgsql PROPERTIES PREFIX "")
+add_dependencies(plpgsql postgres)
+
+install(TARGETS plpgsql
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+
+if(ENABLE_NLS)
+	MAKE_MO(plpgsql "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;zh_CN;zh_TW")
+endif()
diff --git a/src/pl/plpython/CMakeLists.txt b/src/pl/plpython/CMakeLists.txt
new file mode 100644
index 0000000..e443e81
--- /dev/null
+++ b/src/pl/plpython/CMakeLists.txt
@@ -0,0 +1,92 @@
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	MAIN_DEPENDENCY generate-spiexceptions.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-spiexceptions.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plname "plpython${PYTHON_VERSION_MAJOR}")
+
+set(plpython_SRCS
+	"${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	plpy_cursorobject.c
+	plpy_elog.c
+	plpy_exec.c
+	plpy_main.c
+	plpy_planobject.c
+	plpy_plpymodule.c
+	plpy_procedure.c
+	plpy_resultobject.c
+	plpy_spi.c
+	plpy_subxactobject.c
+	plpy_typeio.c
+	plpy_util.c
+)
+
+include_directories(${PYTHON_INCLUDE_DIRS})
+add_library(${plname} MODULE ${plpython_SRCS})
+target_link_libraries(${plname} postgres ${PYTHON_LIBRARIES})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} port)
+endif()
+if(MINGW)
+	set_target_properties(${plname} PROPERTIES LINK_FLAGS -Wl,--out-implib=libmin${plname}.dll.a)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	plpython2u.control
+	plpython2u--1.0.sql
+	plpython2u--unpackaged--1.0.sql
+	plpython3u.control
+	plpython3u--1.0.sql
+	plpython3u--unpackaged--1.0.sql
+	plpythonu.control
+	plpythonu--1.0.sql
+	plpythonu--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB})
+if (PYTHON_VERSION_MAJOR EQUAL 2)
+	set(REGRESS_OPTS ${REGRESS_OPTS} --load-extension=plpythonu)
+endif()
+
+set(plregres_files
+	plpython_schema
+	plpython_populate
+	plpython_test
+	plpython_do
+	plpython_global
+	plpython_import
+	plpython_spi
+	plpython_newline
+	plpython_void
+	plpython_params
+	plpython_setof
+	plpython_record
+	plpython_trigger
+	plpython_types
+	plpython_error
+	plpython_unicode
+	plpython_quote
+	plpython_composite
+	plpython_subtransaction
+	plpython_drop
+)
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${plregres_files}")
+	REGRESS_CHECK(plpython "${REGRESS_OPTS}" "${regress_files3}")
+else()
+	REGRESS_CHECK(plpython "${REGRESS_OPTS}" "${plregres_files}")
+endif()
+
+if(ENABLE_NLS)
+	MAKE_MO(plpython "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/pl/tcl/CMakeLists.txt b/src/pl/tcl/CMakeLists.txt
new file mode 100644
index 0000000..b75d44f
--- /dev/null
+++ b/src/pl/tcl/CMakeLists.txt
@@ -0,0 +1,49 @@
+set(plname "pltcl")
+
+include_directories(${TCL_INCLUDE_PATH})
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h"
+	MAIN_DEPENDENCY generate-pltclerrcodes.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-pltclerrcodes.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(gen_pltclerrcodes DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h")
+
+add_library(${plname} MODULE
+	pltcl.c
+)
+
+target_link_libraries(${plname} postgres ${TCL_LIBRARY})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} port)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres gen_pltclerrcodes)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+		${plname}.control
+		${plname}--1.0.sql
+		${plname}--unpackaged--1.0.sql
+		${plname}u.control
+		${plname}u--1.0.sql
+		${plname}u--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB} --load-extension=pltcl)
+set(plregres_files
+	pltcl_setup
+	pltcl_queries
+	pltcl_unicode
+)
+REGRESS_CHECK(pltcl "${REGRESS_OPTS}" "${plregres_files}")
+
+if(ENABLE_NLS)
+	MAKE_MO(pltcl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/port/CMakeLists.txt b/src/port/CMakeLists.txt
new file mode 100644
index 0000000..eae5a31
--- /dev/null
+++ b/src/port/CMakeLists.txt
@@ -0,0 +1,164 @@
+if(USE_SSE42_CRC32C)
+	SET(PG_CRC32C_OBJS pg_crc32c_sse42.c)
+elseif(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK)
+	SET(PG_CRC32C_OBJS
+		pg_crc32c_sse42.c
+		pg_crc32c_sb8.c
+		pg_crc32c_choose.c
+	)
+elseif(USE_SLICING_BY_8_CRC32C)
+	SET(PG_CRC32C_OBJS pg_crc32c_sb8.c)
+endif()
+
+set_source_files_properties(pg_crc32c_sse42.c PROPERTIES COMPILE_FLAGS "${CFLAGS_SSE42}")
+
+set(port_SRCS
+	chklocale.c
+	erand48.c
+	inet_net_ntop.c
+	noblock.c
+	path.c
+	pgcheckdir.c
+	pgmkdirp.c
+	pgsleep.c
+	pgstrcasecmp.c
+	pqsignal.c
+	qsort.c
+	qsort_arg.c
+	quotes.c
+	sprompt.c
+	tar.c
+	thread.c
+	${fallback_SRCS}
+	${PG_CRC32C_OBJS}
+)
+
+if(NOT HAVE_FLS)
+	set(port_SRCS
+		${port_SRCS}
+		fls.c
+	)
+endif(NOT HAVE_FLS)
+
+if(NOT HAVE_ISINF)
+	set(port_SRCS
+		${port_SRCS}
+		isinf.c
+	)
+endif()
+
+if(NOT HAVE_MKDTEMP)
+	set(port_SRCS
+		${port_SRCS}
+		mkdtemp.c
+	)
+endif()
+
+if(NOT HAVE_GETOPT)
+	set(port_SRCS
+		${port_SRCS}
+		getopt.c
+	)
+endif()
+
+if(NOT (HAVE_STRUCT_OPTION AND HAVE_GETOPT_LONG))
+	set(port_SRCS
+		${port_SRCS}
+		getopt_long.c
+	)
+endif()
+
+if(NOT HAVE_GETTIMEOFDAY)
+	set(port_SRCS
+		${port_SRCS}
+		gettimeofday.c
+	)
+endif()
+
+if(NOT HAVE_INET_ATON)
+	set(port_SRCS
+		${port_SRCS}
+		inet_aton.c
+	)
+endif()
+
+if(NOT HAVE_RANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		random.c
+	)
+endif()
+
+if(NOT HAVE_SRANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		srandom.c
+	)
+endif()
+
+if(USE_REPL_SNPRINTF)
+	set(port_SRCS
+		${port_SRCS}
+		snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(port_SRCS
+		${port_SRCS}
+		rint.c
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(port_SRCS
+		${port_SRCS}
+		dirmod.c
+		kill.c
+		open.c
+		getrusage.c
+		system.c
+		win32security.c
+		win32env.c
+		win32error.c
+		win32setlocale.c
+	)
+endif()
+
+if(MSVC)
+	set(port_SRCS
+		${port_SRCS}
+		dirent.c
+	)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	# Solaris' getopt() doesn't do what we want for long options, so always use
+	# our version on that platform.
+	set(port_SRCS
+		${port_SRCS}
+		getopt.c
+	)
+endif()
+
+if(NOT HAVE_CRYPT)
+	set(port_SRCS
+		${port_SRCS}
+		crypt.c
+	)
+endif()
+
+add_library(port_srv STATIC ${port_SRCS})
+add_library(port STATIC ${port_SRCS})
+
+add_dependencies(port_srv gen_errorcodes)
+add_dependencies(port gen_errorcodes)
+
+# because port used in shared libraries
+set_property(TARGET port PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+
+
+target_compile_definitions(port PRIVATE -DFRONTEND)
+set_source_files_properties(thread.c PROPERTIES COMPILE_FLAGS ${PTHREAD_CFLAGS})
+install(TARGETS port
+		ARCHIVE DESTINATION ${LIBDIR})
diff --git a/src/test/isolation/CMakeLists.txt b/src/test/isolation/CMakeLists.txt
new file mode 100644
index 0000000..2b13ee4
--- /dev/null
+++ b/src/test/isolation/CMakeLists.txt
@@ -0,0 +1,64 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/test/regress"
+)
+
+add_executable(pg_isolation_regress
+	${PROJECT_SOURCE_DIR}/src/test/regress/pg_regress.c
+	isolation_main.c
+)
+
+target_link_libraries(pg_isolation_regress
+	pq
+	pgcommon
+	port
+)
+
+target_compile_definitions(pg_isolation_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}"
+)
+
+bison_target(SPEC_PARSER specparse.y ${CMAKE_CURRENT_SOURCE_DIR}/specparse.c)
+flex_target(SPEC_SCANNER specscanner.l  ${CMAKE_CURRENT_SOURCE_DIR}/specscanner.c)
+add_flex_bison_dependency(SPEC_SCANNER SPEC_PARSER)
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/specparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_SPEC_SCANNER_OUTPUTS})
+
+add_executable(isolationtester
+	isolationtester.c
+	${BISON_SPEC_PARSER_OUTPUTS}
+)
+
+target_link_libraries(isolationtester
+	pgcommon
+	port
+	pq
+)
+
+add_custom_target(isolation_check
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+	COMMAND make install DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+	COMMAND make isolation_installcheck_tmp DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+add_custom_target(isolation_installcheck
+	COMMAND ${pg_isolation_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/isolation_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(isolation_installcheck_tmp
+	COMMAND ${pg_isolation_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/isolation_schedule --dlpath=${CMAKE_CURRENT_BINARY_DIR}/tmp_install${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+install(TARGETS isolationtester
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(TARGETS pg_isolation_regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/test/regress/CMakeLists.txt b/src/test/regress/CMakeLists.txt
new file mode 100644
index 0000000..fdc1fc2
--- /dev/null
+++ b/src/test/regress/CMakeLists.txt
@@ -0,0 +1,81 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/port"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_regress
+	pg_regress.c
+	pg_regress_main.c
+)
+
+target_link_libraries(pg_regress
+	pq
+	pgcommon
+	port
+)
+
+target_compile_definitions(pg_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}")
+
+
+add_library(regress MODULE regress.c)
+#target_link_libraries(regress
+#	pq
+#)
+if (MSVC)
+	gen_def(regress)
+endif()
+
+if(MSVC OR MINGW)
+	target_link_libraries(regress postgres port pgcommon)
+endif()
+
+set_target_properties(regress PROPERTIES PREFIX "")
+add_dependencies(regress postgres)
+
+add_custom_target(tablespace-setup
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ./testtablespace
+	COMMAND ${CMAKE_COMMAND} -E make_directory ./testtablespace
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install ${check_make_command} install
+		COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/ ${check_make_command} installcheck_tmp
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} install DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} installcheck_tmp DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+
+add_custom_target(installcheck
+	COMMAND ${pg_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/parallel_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(installcheck_tmp
+	COMMAND ${pg_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/parallel_schedule --dlpath=${CMAKE_CURRENT_BINARY_DIR}/tmp_install${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+install(TARGETS pg_regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(TARGETS regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/timezone/CMakeLists.txt b/src/timezone/CMakeLists.txt
new file mode 100644
index 0000000..4f60ce9
--- /dev/null
+++ b/src/timezone/CMakeLists.txt
@@ -0,0 +1,76 @@
+#TODO compile timezones
+
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+
+
+set(tzdata 
+	${CMAKE_CURRENT_SOURCE_DIR}/data/africa
+	${CMAKE_CURRENT_SOURCE_DIR}/data/antarctica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/asia
+	${CMAKE_CURRENT_SOURCE_DIR}/data/australasia
+	${CMAKE_CURRENT_SOURCE_DIR}/data/europe
+	${CMAKE_CURRENT_SOURCE_DIR}/data/northamerica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/southamerica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/pacificnew
+	${CMAKE_CURRENT_SOURCE_DIR}/data/etcetera
+	${CMAKE_CURRENT_SOURCE_DIR}/data/factory
+	${CMAKE_CURRENT_SOURCE_DIR}/data/backward
+	${CMAKE_CURRENT_SOURCE_DIR}/data/systemv
+)
+
+add_executable(zic
+	zic.c
+)
+target_link_libraries(zic
+	port
+)
+
+if(MSVC)
+	foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
+		string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
+		set_target_properties(zic PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+		set_target_properties(zic PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+		set_target_properties(zic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+	endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
+endif(MSVC)
+
+
+install(FILES 
+	tznames/Africa.txt
+	tznames/America.txt
+	tznames/Antarctica.txt
+	tznames/Asia.txt
+	tznames/Atlantic.txt
+	tznames/Australia.txt
+	tznames/Etc.txt
+	tznames/Europe.txt
+	tznames/Indian.txt
+	tznames/Pacific.txt
+	tznames/Default
+	tznames/Australia
+	tznames/India
+DESTINATION ${PGSHAREDIR}/timezonesets)
+
+function(JOIN VALUES GLUE OUTPUT)
+  string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
+  string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
+  set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
+endfunction()
+
+if(MINGW)
+	string(SUBSTRING ${PGSHAREDIR} 2 -1 PGSHAREDIR_ZIC)
+else()
+	set(PGSHAREDIR_ZIC ${PGSHAREDIR})
+endif()
+
+JOIN("${tzdata}" " " tzdata_string)
+install(
+	CODE "message('${CMAKE_CURRENT_BINARY_DIR}/zic${CMAKE_EXECUTABLE_SUFFIX} \$ENV{DESTDIR}${PGSHAREDIR_ZIC}/timezone -p US/Eastern ${tzdata_string}')"
+	CODE "execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/zic${CMAKE_EXECUTABLE_SUFFIX} -d \"\$ENV{DESTDIR}${PGSHAREDIR_ZIC}/timezone\" -p \"US/Eastern\" ${tzdata_string})"
+)
+
#116Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Mark Kirkwood (#115)
Re: WIP: About CMake v2

Mark Kirkwood wrote:

Actually, it was not that tricky to separate out the cmake only
changes, and test this on unmodified sources. It appears to work
fine for me - passes 'make check' (needs the v1_1 incremental
patch applied of course). The Patch is attached. I wonder if the
original had some changes for building under latest
Windows...(I'm using Ubuntu 16.10, with cmake 3.5).

Thanks for all your works! Can you make push request here:
https://github.com/stalkerg/postgres_cmake

I have rebased (merge) to master and make other important fix.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#117Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Mark Kirkwood (#114)
Re: WIP: About CMake v2

Mark Kirkwood wrote:

Yeah, there seems to be a lot of these. Looking through them
almost all concern the addition of piece of code to wrap putenv.
e.g:

I made this small wrapper special for MSVC 2015 without Service Packs
because postgres macross were in conflict with MS internal functions.
After some time and some updates for MSVC Michael Paquier could not
reproduce my problem but I keep this patch to avoid problems in the
future.
I can check old behavior again and revert all changes if needed and
ofcourse I have plans to make separate patch for this changes.

Thanks!
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#118Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#105)
Re: WIP: About CMake v2

On Tue, Nov 8, 2016 at 9:12 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Wed, Nov 9, 2016 at 7:54 AM, Craig Ringer
<craig.ringer@2ndquadrant.com> wrote:

On 9 Nov. 2016 06:37, "Yury Zhuravlev" <u.zhuravlev@postgrespro.ru> wrote:

This approach I see only in Postgres project and not fully understood.
Can you explain me more what reasons led to this approach?

It's predictable. The default has the same result for everyone. I quite like
it myself.

+1. Let's tell to the system what we want him to do and not let him
guess what we'd like to be done or it will get harder to test and
develop code for all kind of code paths with #ifdef's. That's one step
away from Skynet.

Exaggerate much?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#119Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Yury Zhuravlev (#117)
Re: WIP: About CMake v2

I see there are some patches for the putenv issue with Visual studio
2013 in progress on this list - it is probably best to work with the
author to see if 2015 has any new issues and keep all changes for that
*out* of the cmake patches.

regards

Mark

On 16/11/16 21:22, Yury Zhuravlev wrote:

I made this small wrapper special for MSVC 2015 without Service Packs
because postgres macross were in conflict with MS internal functions.
After some time and some updates for MSVC Michael Paquier could not
reproduce my problem but I keep this patch to avoid problems in the
future. I can check old behavior again and revert all changes if
needed and ofcourse I have plans to make separate patch for this changes.
Thanks!

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#120Michael Paquier
michael.paquier@gmail.com
In reply to: Mark Kirkwood (#119)
Re: WIP: About CMake v2

On Wed, Nov 16, 2016 at 2:14 PM, Mark Kirkwood
<mark.kirkwood@catalyst.net.nz> wrote:

I see there are some patches for the putenv issue with Visual studio 2013 in
progress on this list - it is probably best to work with the author to see
if 2015 has any new issues and keep all changes for that *out* of the cmake
patches.

I don't recall all the details here, but no wrappers should be needed,
particularly on Windows where we already do that:
src/include/port/win32.h:#define putenv(x) pgwin32_putenv(x)
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#121Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#120)
Re: WIP: About CMake v2

Michael Paquier wrote:

src/include/port/win32.h:#define putenv(x) pgwin32_putenv(x)

and my MSVC2015 drop down here because pgwin32_putenv has wrong signature.
I hope it is not true now.

--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#122Yuriy Zhuravlev
stalkerg@gmail.com
In reply to: Peter Eisentraut (#102)
5 attachment(s)
Re: WIP: About CMake v2

Hello hackers.

----

I think you notice what I changed email, it is happened because I quit from
PgPro.

Good news is that I have time to work on CMake. Bad news I have to find a
new job. ;)

----

What is new in that patchset:

1.

I separated changes to several patches. Main patch include only new
CMake files without postgres files changes.
2.

I cleaned all the unnecessary postgres changes.
3.

I update cmake with latest master, add STRONG_RANDOM option and etc.
4.

Add small document about CMake and Postgres. (README.cmake bad idea for
name but I think now it’s ok)
5.

I have stopped use gendef.pl for MSVC build.
6.

Fix for AIX 7.1

About patches:

cmake_v2_1_main_files.patch

Only CMake files. CMakeFiles.txt is main files with rules. *.cmake is
special modules with macros and functions. *.in is template for generate
headers. (like autoconf)

cmake_v2_2_c_define.patch

Small chages in c.h . At first it is “#pragma fenv_access (off)” it is
necessary if we use /fp:strict for MSVC compiler. Without this pragma we
can’t calc floats for const variables in compiller time (2 * M_PI for
example). Strict mode important if we want to be close with ieee754 float
format on MSVC (1.0 / 0.0 = inf for example). Detail info here:
https://msdn.microsoft.com/en-us/library/e7s85ffb.aspx

Second change is because I find and set HAVE_INT128 directly from CMake.
PG_INT128_TYPE used only for autoconfig scripts.

cmake_v2_3_rijndael.patch

First I added special wraparound because here CMake have circular
dependency (cmake very smart here). Second I removed rijndael.tbl because
it generated during build process every time.

cmake_v2_4_uuid.patch

Another small patch. Right place for uuid.h I find by CMake and not
necessary this ifdef hell.

cmake_v2_5_readme.patch

Small exercise to CMake world for all who want to try.

Questions for discussion:

In generated project by CMake we always have only one enter point. Also
INSTALL macross support only including to “all” targets. It follows that it
is impossible build contrib modules separately only with “all” target. Here
write about this behavior:
https://cmake.org/cmake/help/v3.7/prop_tgt/EXCLUDE_FROM_ALL.html

Interesting note:

Many folks here love only command line but many novices developers from
modern generation love GUI. Also using command line on Windows it's really
big pain. With CMake you can work with Postgres under MSVC more
comfortable. For example my screenshots of regress tests result runing from
MSVC: https://twitter.com/stalkerg/status/814423972263657472

Fin:

I hope this patchset one step closer to merge. In future I see a lot of
work but I suppose it is right and important direction. I'm ready for this
long journey.

Big thanks Peter Eisentraut for advices and the right vector of
development.

Also big thanks Mark Kirkwood for help and discussion.

Happy New Year, everyone!

Attachments:

cmake_v2_1_main_files.patchtext/x-patch; charset=US-ASCII; name=cmake_v2_1_main_files.patchDownload
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000000..f6c3858580
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,1412 @@
+cmake_minimum_required(VERSION 2.8.4)
+
+project(Postgres C)
+
+include(CheckTypeSize)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckIncludeFiles)
+include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
+include(TestBigEndian)
+include(CheckStructHasMember)
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+	message(STATUS "${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}")
+	message(FATAL_ERROR "You must use another folder for build PostgreSQL")
+endif()
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+set(POSTGRES_MAJOR_VERSION 10)
+set(POSTGRES_MINOR_VERSION 0)
+set(POSTGRES_PATCH_VERSION 0)
+set(POSTGRES_VERSION
+  ${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.${POSTGRES_PATCH_VERSION})
+
+set(PG_VERSION "10devel")
+set(PG_VERSION_NUM 100000)
+set(PACKAGE_BUGREPORT "pgsql-bugs@postgresql.org")
+
+ # Offer the user the choice of overriding the installation directories
+set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
+set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
+set(INSTALL_INCLUDE_DIR include CACHE PATH
+  "Installation directory for header files")
+
+if(NOT PGBINDIR)
+	set(PGBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
+endif(NOT PGBINDIR)
+
+if(NOT PGSHAREDIR)
+	set(PGSHAREDIR "${CMAKE_INSTALL_PREFIX}/share/postgresql")
+endif(NOT PGSHAREDIR)
+
+if(NOT SYSCONFDIR)
+	set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
+endif(NOT SYSCONFDIR)
+
+if(NOT INCLUDEDIR)
+	set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT INCLUDEDIR)
+
+if(NOT PKGINCLUDEDIR)
+	set(PKGINCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT PKGINCLUDEDIR)
+
+if(NOT INCLUDEDIRSERVER)
+	set(INCLUDEDIRSERVER "${CMAKE_INSTALL_PREFIX}/include/server")
+endif(NOT INCLUDEDIRSERVER)
+
+if(MSVC)
+	if(NOT LIBDIR)
+		set(LIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+	endif(NOT LIBDIR)
+
+	if(NOT PKGLIBDIR)
+		set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+	endif(NOT PKGLIBDIR)
+else()
+	if(NOT LIBDIR)
+		set(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+	endif(NOT LIBDIR)
+
+	if(NOT PKGLIBDIR)
+		set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+	endif(NOT PKGLIBDIR)
+endif()
+
+if(NOT LOCALEDIR)
+	set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
+endif(NOT LOCALEDIR)
+
+if(NOT DOCDIR)
+	set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT DOCDIR)
+
+if(NOT HTMLDIR)
+	set(HTMLDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT HTMLDIR)
+
+if(NOT MANDIR)
+	set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
+endif(NOT MANDIR)
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+	set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+endif()
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|OpenBSD")
+	set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-x,-soname,")
+endif()
+
+set(PLUGIN_TYPE MODULE)
+
+if(MSVC)
+	# Try hide warnings
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS ")
+	option(USE_FP_STRICT "use strict mode for float and double in MSVC" ON)
+	if (USE_FP_STRICT)
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:strict")
+	endif()
+	# We can't use MODULE because CMake get export symbols only for SHARED.
+	set(PLUGIN_TYPE SHARED)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND "${CMAKE_C_FLAGS}" MATCHES "aix64")
+	SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> <LINK_FLAGS> -X64 cr <TARGET> <OBJECTS>")
+	SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> -X64 r <TARGET> <OBJECTS>")
+endif()
+
+test_big_endian(WORDS_BIGENDIAN)
+set(FIND_LIBRARY_USE_LIB64_PATHS ON)
+
+find_package(Perl REQUIRED)
+option(WITH_PERL "libperl is optional" OFF)
+if(WITH_PERL)
+	find_package(PerlLibs)
+endif()
+if(PERLLIBS_FOUND)
+	EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts OUTPUT_VARIABLE PERL_CFLAGS)
+	EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts OUTPUT_VARIABLE PERL_LDFLAGS)
+	STRING(REGEX REPLACE "[\r\n]" " " PERL_CFLAGS ${PERL_CFLAGS})
+	STRING(REGEX REPLACE " +$" "" PERL_CFLAGS ${PERL_CFLAGS})
+	STRING(STRIP "${PERL_CFLAGS}" PERL_CFLAGS)
+	STRING(REGEX REPLACE "[\r\n]" " " PERL_LDFLAGS ${PERL_LDFLAGS})
+	STRING(REGEX REPLACE " +$" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+	STRING(REGEX REPLACE "-lperl" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+	if(MINGW AND NOT MSYS)
+		STRING(REGEX REPLACE "\\\\" "/" PERL_LDFLAGS ${PERL_LDFLAGS})
+	endif()
+	STRING(STRIP "${PERL_LDFLAGS}" PERL_LDFLAGS)
+endif()
+
+option(WITH_TAP "try enable TAP tests" OFF)
+# It's really pain to use the TAP tests without env cmake command
+if (CMAKE_VERSION VERSION_GREATER "3.2.0")
+	find_program(PROVE prove)
+endif()
+if(NOT WITH_TAP)
+	set(PROVE "")
+endif()
+
+find_package(BISON REQUIRED)
+find_package(FLEX REQUIRED)
+find_package(Threads)
+
+option(WITH_OPENSSL "OPENSSL is optional" OFF)
+if(WITH_OPENSSL)
+	find_package(OpenSSL)
+endif()
+find_package(ZLIB)
+
+option(WITH_PYTHON "Python is optional" OFF)
+if(WITH_PYTHON)
+	find_package(PythonInterp)
+	find_package(PythonLibs)
+endif()
+find_package(SELinux)
+
+option(WITH_LIBXML "LIBXML is optional" OFF)
+if(WITH_LIBXML)
+	find_package(LibXml2)
+	find_package(LibXslt)
+endif()
+
+option(WITH_TCL "TCL is optional" OFF)
+if(WITH_TCL)
+	find_package(TCL)
+endif()
+find_package(LibSocket)
+
+option(USE_PAM "build with PAM support" OFF)
+if(USE_PAM)
+	find_library(PAM_LIB pam)
+	if(NOT PAM_LIB)
+		message(ERROR "library 'pam' is required for PAM")
+	endif()
+endif()
+
+option(USE_LDAP "build with LDAP support" OFF)
+if(USE_LDAP)
+	find_package(LDAP REQUIRED)
+endif()
+
+if(WIN32 OR MINGW)
+	set(NEED_REPL_SNPRINTF ON)
+else()
+	set(NEED_REPL_SNPRINTF OFF)
+endif()
+
+option(ENABLE_NLS "Define if you want National Language Support" OFF)
+if(ENABLE_NLS)
+	include(MakeNLS)
+	find_package(Gettext REQUIRED)
+	find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
+	if(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+		message(FATAL_ERROR "xgettext not found")
+	endif(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+	if(NOT NLS_LANGUAGES)
+		set(NLS_LANGUAGES "ko;cs;pt_BR;zh_CN;ru;fr;de;es;it;tr;ja;pl;zh_TW")
+	endif()
+
+	if(NOT NEED_REPL_SNPRINTF)
+		check_c_source_runs("
+			#include <stdio.h>
+			#include <string.h>
+
+			int main()
+			{
+			  char buf[100];
+
+			  /* can it swap arguments? */
+			  snprintf(buf, 100, \"%2\$d %1\$d\", 3, 4);
+			  if (strcmp(buf, \"4 3\") != 0)
+				return 1;
+			  return 0;
+			}
+		" SNPRINTF_ARG_CONTROL)
+		if(NOT SNPRINTF_ARG_CONTROL)
+			set(NEED_REPL_SNPRINTF ON)
+		endif()
+	endif()
+endif()
+
+option(ENABLE_GSS "Define to build with GSSAPI support." OFF)
+if(ENABLE_GSS)
+	check_include_files(gssapi/gssapi.h HAVE_GSSAPI_GSSAPI_H)
+	check_include_files(gssapi.h HAVE_GSSAPI_H)
+	set(PG_KRB_SRVTAB "FILE:${SYSCONFDIR}/krb5.keytab")
+	if(WIN32)
+		SET(GSS_LIBS "-lgssapi32")
+	else()
+		set(CMAKE_REQUIRED_LIBRARIES_OLD ${CMAKE_REQUIRED_LIBRARIES})
+		set(CMAKE_REQUIRED_LIBRARIES "-lgssapi_krb5")
+		check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+		if(NOT HAVE_GSS_INIT)
+			set(CMAKE_REQUIRED_LIBRARIES "-lgss")
+			check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+			if(NOT HAVE_GSS_INIT)
+				set(CMAKE_REQUIRED_LIBRARIES "-lgssapi -lkrb5 -lcrypto")
+				check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+			endif(NOT HAVE_GSS_INIT)
+		endif(NOT HAVE_GSS_INIT)
+		if(HAVE_GSS_INIT)
+			set(GSS_LIBS ${CMAKE_REQUIRED_LIBRARIES})
+		else()
+			message(FATAL_ERROR "Not found gss_init_sec_context function for GSSAPI")
+		endif()
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_OLD})
+	endif()
+else()
+	set(GSS_LIBS "")
+endif()
+
+option(USE_SYSTEMD "Define to build with systemd support" OFF)
+option(USE_BSD_AUTH "Define to build with BSD Authentication support" OFF)
+option(USE_ASSERT_CHECKING "Define to build with assertion checks." OFF)
+option(USE_BONJOUR "Define to build with Bonjour support." OFF)
+if(USE_BONJOUR)
+	check_include_files(dns_sd.h HAVE_DNS_SD_H)
+	if(NOT HAVE_DNS_SD_H)
+		message(FATAL_ERROR "header file <dns_sd.h> is required for Bonjour")
+	endif()
+endif()
+
+option(STRONG_RANDOM "Strong random number source" ON)
+option(STRONG_RANDOM_SOURCE "which random number source to use - openssl, win32, dev" OFF)
+if(STRONG_RANDOM)
+	if(NOT STRONG_RANDOM_SOURCE)
+		if(WITH_OPENSSL)
+			set(STRONG_RANDOM_SOURCE "openssl")
+		elseif(WIN32)
+			set(STRONG_RANDOM_SOURCE "win32")
+		elseif(EXISTS "/dev/urandom")
+			set(STRONG_RANDOM_SOURCE "dev")
+		endif()
+	endif()
+	if(STRONG_RANDOM_SOURCE STREQUAL "openssl")
+		set(USE_OPENSSL_RANDOM 1)
+	elseif(STRONG_RANDOM_SOURCE STREQUAL "win32")
+		set(USE_WIN32_RANDOM 1)
+	elseif(STRONG_RANDOM_SOURCE STREQUAL "dev")
+		set(USE_DEV_URANDOM 1)
+	else()
+		message(ERROR "no source of strong random numbers was found
+PostgreSQL can use OpenSSL or /dev/urandom as a source of random numbers,
+for authentication protocols. You can use -DSTRONG_RANDOM=OFF to use of a built-in
+pseudo random number generator, but that may be insecure.")
+	endif()
+
+	set(HAVE_STRONG_RANDOM 1)
+else()
+	message(WARNING "Not using a strong random number source may be insecure.")
+endif()
+
+if(NOT MSVC)
+	find_library(DL_LIBRARIES NAMES dl)
+	find_library(M_LIB m)
+	if(NOT M_LIB)
+		set(M_LIB "")
+	endif()
+endif()
+
+if(NOT DL_LIBRARIES)
+	set(DL_LIBRARIES "")
+endif()
+
+if(LIBXML2_FOUND)
+	set(HAVE_LIBXML2 1)
+	set(USE_LIBXML 1)
+endif()
+
+if(LIBXSLT_FOUND)
+	set(HAVE_LIBXSLT 1)
+	set(USE_LIBXSLT 1)
+endif()
+
+if(ZLIB_FOUND)
+	set(HAVE_LIBZ 1)
+endif()
+
+if(NOT CMAKE_C_FLAGS)
+	set(CMAKE_C_FLAGS "-O2")
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCC)
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.3 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.3)
+		# Disable strict-aliasing rules; needed for gcc 3.3+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+	endif()
+
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.4 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.4)
+		# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+	endif()
+
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+		# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexcess-precision=standard")
+	endif()
+
+	# Optimization flags for specific files that benefit from vectorization
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+	if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+		set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+	endif()
+
+	option(PROFILE_PID_DIR "Enable to allow profiling output to be saved separately for each process." OFF)
+endif()
+
+if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+	# Disable strict-aliasing rules; needed for gcc 3.3+
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+	# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+
+	# Optimization flags for specific files that benefit from vectorization
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+	set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+endif()
+
+if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
+	# Intel's compiler has a bug/misoptimization in checking for
+	# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mp1")
+	# Make sure strict aliasing is off (though this is said to be the default)
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+endif()
+
+check_symbol_exists(strlcpy "stdio.h;string.h" HAVE_DECL_STRLCPY)
+if(NOT HAVE_DECL_STRLCPY)
+	set(HAVE_DECL_STRLCPY 0)
+endif()
+check_symbol_exists(strlcat "stdio.h;string.h" HAVE_DECL_STRLCAT)
+if(NOT HAVE_DECL_STRLCAT)
+	set(HAVE_DECL_STRLCAT 0)
+endif()
+check_symbol_exists(snprintf "stdio.h;string.h" HAVE_DECL_SNPRINTF)
+if(NOT HAVE_DECL_SNPRINTF)
+	set(HAVE_DECL_SNPRINTF 0)
+endif()
+check_symbol_exists(vsnprintf "stdio.h;string.h" HAVE_DECL_VSNPRINTF)
+if(NOT HAVE_DECL_VSNPRINTF)
+	set(HAVE_DECL_VSNPRINTF 0)
+endif()
+check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV)
+check_symbol_exists(srandom "stdlib.h" HAVE_SRANDOM)
+
+# Test math functions
+check_symbol_exists(rint "math.h" HAVE_RINT)
+
+if(WIN32 AND NOT MINGW)
+	set(LIB_M "")
+else()
+	set(LIB_M m)
+endif()
+set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${LIB_M}")
+check_c_source_runs("
+	#include <math.h>
+	int main(void){
+#ifdef _MSC_VER
+		return isinf(INFINITY) ? 0 : 1;
+#else
+		return isinf(1.0/0.0) ? 0 : 1;
+#endif
+	}
+" HAVE_ISINF)
+
+# Check common include files
+
+check_include_files(ieeefp.h HAVE_IEEEFP_H)
+if(NOT HAVE_IEEEFP_H)
+	set(HAVE_IEEEFP_H 0)
+else()
+	set(HAVE_IEEEFP_H 1)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ieeefp.h")
+endif()
+
+check_include_files(fp_class.h HAVE_FP_CLASS_H)
+if (HAVE_FP_CLASS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fp_class.h")
+endif()
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};float.h;math.h")
+
+check_include_files(sys/un.h HAVE_SYS_UN_H)
+check_include_files(ucred.h HAVE_UCRED_H)
+check_include_files(sys/ucred.h HAVE_SYS_UCRED_H)
+check_include_files(sys/types.h HAVE_SYS_TYPES_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H)
+check_include_files(stdint.h HAVE_STDINT_H)
+
+check_include_files(sys/select.h HAVE_SYS_SELECT_H)
+check_include_files(sys/poll.h HAVE_SYS_POLL_H)
+check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
+check_include_files(sys/pstat.h HAVE_SYS_PSTAT_H)
+check_include_files(sys/tas.h HAVE_SYS_TAS_H)
+check_include_files(dld.h HAVE_DLD_H)
+check_include_files(langinfo.h HAVE_LANGINFO_H)
+check_include_files(poll.h HAVE_POLL_H)
+
+check_include_files(wchar.h HAVE_WCHAR_H)
+check_include_files(wctype.h HAVE_WCTYPE_H)
+check_include_files(winldap.h HAVE_WINLDAP_H)
+check_include_files(pwd.h HAVE_PWD_H)
+check_include_files(crtdefs.h HAVE_CRTDEFS_H)
+
+check_include_files(nbtool_config.h HAVE_NBTOOL_CONFIG_H)
+
+check_include_files(mbarrier.h HAVE_MBARRIER_H)
+check_include_files(atomic.h HAVE_ATOMIC_H)
+
+check_include_files(netinet/tcp.h HAVE_NETINET_TCP_H)
+check_include_files(net/if.h HAVE_NET_IF_H)
+
+check_include_files(pam/pam_appl.h HAVE_PAM_PAM_APPL_H)
+check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
+if(USE_PAM AND NOT (HAVE_PAM_PAM_APPL_H OR HAVE_SECURITY_PAM_APPL_H))
+	message(FATAL_ERROR "header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.")
+endif()
+
+check_include_files(syslog.h HAVE_SYSLOG)
+check_include_files(termios.h HAVE_TERMIOS_H)
+
+check_include_files("sys/ipc.h" HAVE_SYS_IPC_H)
+check_include_files("sys/sem.h" HAVE_SYS_SEM_H)
+check_include_files("sys/shm.h" HAVE_SYS_SHM_H)
+check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+
+check_include_files(ifaddrs.h HAVE_IFADDRS_H)
+check_include_files(crypt.h HAVE_CRYPT_H)
+check_include_files(unistd.h HAVE_UNISTD_H)
+
+check_include_files("locale.h" HAVE_LOCALE_H)
+check_include_files("xlocale.h" HAVE_XLOCALE_H)
+
+check_include_files(bsd_auth.h HAVE_BSD_AUTH_H)
+check_include_files(strings.h HAVE_STRINGS_H)
+check_include_files(string.h HAVE_STRING_H)
+check_include_files(getopt.h HAVE_GETOPT_H)
+check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
+check_include_files(sys/time.h HAVE_SYS_TIME_H)
+check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
+check_include_files(utime.h HAVE_UTIME_H)
+
+# Check functions
+
+check_function_exists(fpclass HAVE_FPCLASS) # Need for isinf implementation
+check_function_exists(fp_class HAVE_FP_CLASS)
+check_function_exists(fp_class_d HAVE_FP_CLASS_D)
+check_function_exists(class HAVE_CLASS)
+
+check_function_exists(getpeereid HAVE_GETPEEREID)
+check_function_exists(getpeerucred HAVE_GETPEERUCRED)
+check_function_exists(memmove HAVE_MEMMOVE)
+if(MSVC)
+	check_function_exists(_mbstowcs_l HAVE_MBSTOWCS_L)
+else()
+	check_function_exists(mbstowcs_l HAVE_MBSTOWCS_L)
+endif()
+
+check_function_exists(towlower HAVE_TOWLOWER)
+check_function_exists(wcstombs HAVE_WCSTOMBS)
+
+check_function_exists(mkdtemp HAVE_MKDTEMP)
+check_function_exists(mkstemp HAVE_MKSTEMP)
+check_function_exists(poll HAVE_POLL)
+
+check_function_exists(getrlimit HAVE_GETRLIMIT)
+check_function_exists(readlink HAVE_READLINK)
+check_function_exists(cbrt HAVE_CBRT)
+check_function_exists(pthread_is_threaded_np HAVE_PTHREAD_IS_THREADED_NP)
+check_function_exists(random HAVE_RANDOM)
+check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
+
+#So strange
+check_function_exists(pstat HAVE_PSTAT)
+
+if(HAVE_IFADDRS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ifaddrs.h")
+endif()
+check_function_exists(getifaddrs HAVE_GETIFADDRS)
+
+if(MSVC)
+	set(HAVE_MINIDUMP_TYPE 1)
+endif()
+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fcntl.h")
+	check_function_exists(posix_fadvise HAVE_DECL_POSIX_FADVISE)
+	if(HAVE_DECL_POSIX_FADVISE)
+		set(HAVE_POSIX_FADVISE 1)
+	endif()
+endif()
+
+find_library(CRYPT_LIB crypt)
+if(CRYPT_LIB)
+	set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${CRYPT_LIB}")
+endif()
+
+if(HAVE_CRYPT_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};crypt.h")
+endif()
+check_function_exists(crypt HAVE_CRYPT)
+
+if(HAVE_UNISTD_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};unistd.h")
+endif()
+check_function_exists(fdatasync HAVE_DECL_FDATASYNC)
+check_function_exists(sys_siglist HAVE_DECL_FDATASYNC)
+check_function_exists(setproctitle HAVE_SETPROCTITLE)
+check_function_exists(setsid HAVE_SETSID)
+if(HAVE_UNISTD_H)
+	check_symbol_exists(sys_siglist "signal.h;unistd.h" HAVE_DECL_SYS_SIGLIST)
+	check_symbol_exists(opterr "unistd.h" HAVE_INT_OPTERR)
+	check_symbol_exists(optreset "unistd.h" HAVE_INT_OPTRESET)
+else()
+	check_symbol_exists(sys_siglist "signal.h" HAVE_DECL_SYS_SIGLIST)
+endif()
+
+set(CMAKE_MACOSX_RPATH 1)
+#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+if(MSVC)
+	check_function_exists(_fseeki64 HAVE_FSEEKO)
+else()
+	check_function_exists(fseeko HAVE_FSEEKO)
+endif()
+
+if(NOT MSVC)
+	check_include_files(dlfcn.h HAVE_DLFCN_H)
+	if(HAVE_DLFCN_H)
+		set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};dlfcn.h")
+	endif()
+	set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARIES})
+	check_function_exists(dlopen HAVE_DLOPEN)
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES "")
+
+if(HAVE_STRINGS_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};strings.h")
+endif()
+if(HAVE_STRING_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};string.h")
+endif()
+check_function_exists(fls HAVE_FLS)
+
+if(HAVE_GETOPT_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};getopt.h")
+endif()
+
+check_function_exists(strtoll HAVE_STRTOLL)
+check_function_exists(strtoq HAVE_STRTOQ)
+check_function_exists(strtoull HAVE_STRTOULL)
+check_function_exists(strtouq HAVE_STRTOUQ)
+
+check_type_size("struct option" HAVE_STRUCT_OPTION)
+check_function_exists(getopt HAVE_GETOPT)
+check_function_exists(getopt_long HAVE_GETOPT_LONG)
+check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
+check_function_exists(getpwuid_r HAVE_GETPWUID_R)
+check_function_exists(strerror_r HAVE_STRERROR_R)
+check_function_exists(strerror HAVE_STRERROR)
+#I am not sure about this code.
+check_c_source_runs("
+#include <string.h>
+int main(void){
+#ifndef _AIX
+int strerror_r(int, char *, size_t);
+#else
+/* Older AIX has 'int' for the third argument so we don't test the args. */
+int strerror_r();
+#endif
+return 0;
+}
+" STRERROR_R_INT)
+
+check_c_source_runs("
+int main(void){
+int a = 0; int *p = &a; int r;
+ __asm__ __volatile__ (\" lwarx %0,0,%1,1\n\" : \"=&r\"(r) : \"r\"(p));
+return 0;
+}
+" HAVE_PPC_LWARX_MUTEX_HINT)
+
+check_c_source_runs("
+#include <machine/vmparam.h>
+#include <sys/exec.h>
+int main(void){
+PS_STRINGS->ps_nargvstr = 1;
+PS_STRINGS->ps_argvstr = \"foo\";
+return 0;
+}
+" HAVE_PS_STRINGS)
+
+if(HAVE_SYS_MMAN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/mman.h")
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -lrt")
+endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+check_function_exists(shm_open HAVE_SHM_OPEN)
+
+
+if(HAVE_SYS_TIME_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/time.h")
+endif()
+if(HAVE_SYS_RESOURCE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/resource.h")
+endif()
+check_function_exists(getrusage HAVE_GETRUSAGE)
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+
+if(HAVE_UTIME_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};utime.h")
+endif()
+check_function_exists(utime HAVE_UTIME)
+check_function_exists(utimes HAVE_UTIMES)
+
+set(OLD_INCLUDES "${CMAKE_EXTRA_INCLUDE_FILES}")
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/in.h;arpa/inet.h")
+check_function_exists(inet_aton HAVE_INET_ATON)
+set(CMAKE_EXTRA_INCLUDE_FILES "${OLD_INCLUDES}")
+
+if(OPENSSL_FOUND)
+	set(USE_OPENSSL 1)
+	set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}")
+	set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
+	check_function_exists(SSL_get_current_compression HAVE_SSL_GET_CURRENT_COMPRESSION)
+endif(OPENSSL_FOUND)
+
+if(USE_SYSTEMD)
+	check_include_files(systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
+	if(NOT HAVE_SYSTEMD_SD_DAEMON_H)
+		message(FATAL_ERROR "header file <systemd/sd-daemon.h> is required for systemd support")
+	endif()
+endif()
+
+
+if(USE_BSD_AUTH AND NOT HAVE_BSD_AUTH_H)
+	message(FATAL_ERROR "header file <bsd_auth.h> is required for BSD Authentication support")
+endif()
+
+# Check ReadLine includes
+option(WITH_READLINE "do not use GNU Readline nor BSD Libedit for editing" ON)
+if(WITH_READLINE AND NOT MSVC)
+	find_package(Readline)
+	if(READLINE_FOUND)
+		#Sometimes for redline need curses
+		message(STATUS "Found Readline: ${READLINE_LIBRARY}")
+		find_package(Curses)
+		if(NOT CURSES_FOUND)
+			set(CURSES_NEED_NCURSES TRUE)
+		endif()
+		find_package(Curses)
+		check_include_files("stdio.h;readline.h" HAVE_READLINE_H)
+		check_include_files("stdio.h;history.h" HAVE_HISTORY_H)
+		check_include_files("stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H)
+		check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H)
+		check_include_files("stdio.h;editline/history.h" HAVE_EDITLINE_HISTORY_H)
+		check_include_files("stdio.h;editline/readline.h" HAVE_EDITLINE_READLINE_H)
+
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${READLINE_LIBRARY})
+		if(CURSES_FOUND)
+			set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CURSES_LIBRARIES})
+			set(READLINE_LIBRARY ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
+		endif()
+		check_function_exists(rl_completion_append_character HAVE_RL_COMPLETION_APPEND_CHARACTER)
+		check_function_exists(rl_completion_matches HAVE_RL_COMPLETION_MATCHES)
+		check_function_exists(rl_filename_completion_function HAVE_RL_FILENAME_COMPLETION_FUNCTION)
+		check_function_exists(rl_reset_screen_size HAVE_RL_RESET_SCREEN_SIZE)
+		check_function_exists(append_history HAVE_APPEND_HISTORY)
+		check_function_exists(history_truncate_file HAVE_HISTORY_TRUNCATE_FILE)
+	endif(READLINE_FOUND)
+endif()
+
+if(READLINE_FOUND)
+	set(HAVE_LIBREADLINE TRUE)
+else()
+	set(READLINE_LIBRARY "")
+	set(HAVE_LIBREADLINE FALSE)
+endif()
+
+# Check if _GNU_SOURCE is available.
+check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
+check_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_DECL_F_FULLFSYNC)
+
+include(ReplacePython)
+include(CheckCpuID)
+include(CheckSSE42)
+
+if(MSVC)
+	if(HAVE__GET_CPUID OR HAVE__CPUID)
+		set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+	endif()
+else()
+	if(HAVE_SSE42 AND HAVE_SSE42_INTRINSICS)
+		set(USE_SSE42_CRC32C 1)
+	elseif(HAVE_SSE42_INTRINSICS AND (HAVE__GET_CPUID OR HAVE__CPUID))
+		set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+	else()
+		set(USE_SLICING_BY_8_CRC32C 1)
+	endif()
+endif()
+
+include(FuncAcceptArgtypes)
+include(CheckTypeAlignment)
+check_type_alignment(double ALIGNOF_DOUBLE)
+check_type_alignment(int ALIGNOF_INT)
+check_type_alignment(long ALIGNOF_LONG)
+check_type_alignment("long long int" ALIGNOF_LONG_LONG_INT)
+check_type_alignment(short ALIGNOF_SHORT)
+
+check_type_size(int64 HAVE_INT64)
+check_type_size(uint64 HAVE_UINT64)
+check_type_size(int8 HAVE_INT8)
+check_type_size(uint8 HAVE_UINT8)
+check_type_size("void *" VOID_POINTER_SIZE)
+math(EXPR VOID_POINTER_SIZE_BIT "${VOID_POINTER_SIZE}*8")
+check_type_size("long int" LONG_INT_SIZE)
+check_type_size("long long int" HAVE_LONG_LONG_INT)
+check_type_size("long" SIZEOF_LONG)
+check_type_size("size_t" SIZEOF_SIZE_T)
+check_type_size(__int128 PG_INT128_TYPE)
+if(PG_INT128_TYPE AND NOT WIN32)
+	set(HAVE_INT128 1)
+	set(PG_INT128_TYPE __int128)
+endif()
+
+
+if(HAVE_LOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};locale.h")
+endif()
+check_type_size("locale_t" HAVE_LOCALE_T)
+if(NOT HAVE_LOCALE_T AND HAVE_XLOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+	check_type_size("locale_t" HAVE_LOCALE_T)
+	if(HAVE_LOCALE_T)
+		set(LOCALE_T_IN_XLOCALE 1)
+	else()
+		set(LOCALE_T_IN_XLOCALE 0)
+	endif()
+else()
+	set(LOCALE_T_IN_XLOCALE 0)
+endif()
+
+check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+#check_function_exists(wcstombs_l HAVE_WCSTOMBS_L)
+if(NOT HAVE_WCSTOMBS_L AND HAVE_XLOCALE_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+	check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+	if(HAVE_WCSTOMBS_L)
+		set(WCSTOMBS_L_IN_XLOCALE 1)
+	else()
+		set(WCSTOMBS_L_IN_XLOCALE 0)
+	endif()
+else()
+	set(WCSTOMBS_L_IN_XLOCALE 0)
+endif()
+
+if(LONG_INT_SIZE EQUAL 8)
+	set(PG_INT64_TYPE "long int")
+	set(HAVE_LONG_INT_64 ${LONG_INT_SIZE})
+else(LONG_INT_SIZE EQUAL 8)
+	if(HAVE_LONG_LONG_INT EQUAL 8)
+		set(PG_INT64_TYPE "long long int")
+		set(HAVE_LONG_LONG_INT_64 1)
+	else()
+		message(FATAL_ERROR "Cannot find a working 64-bit integer type.")
+	endif()
+endif(LONG_INT_SIZE EQUAL 8)
+
+message(STATUS "PG_INT64_TYPE: ${PG_INT64_TYPE} HAVE_LONG_INT_64: ${HAVE_LONG_INT_64}")
+# Compute maximum alignment of any basic type.
+# We assume long's alignment is at least as strong as char, short, or int;
+# but we must check long long (if it exists) and double.
+
+if(NOT MAXIMUM_ALIGNOF)
+	set(MAX_ALIGNOF ${ALIGNOF_LONG})
+	if(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+		set(MAX_ALIGNOF ${ALIGNOF_DOUBLE})
+	endif(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+	if(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+		set(MAX_ALIGNOF ${HAVE_LONG_LONG_INT_64})
+	endif(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+	if(MAX_ALIGNOF)
+		set(MAXIMUM_ALIGNOF ${MAX_ALIGNOF})
+	endif(MAX_ALIGNOF)
+endif(NOT MAXIMUM_ALIGNOF)
+message(STATUS "MAXIMUM_ALIGNOF ${MAXIMUM_ALIGNOF}")
+
+if(HAVE_LONG_LONG_INT_64)
+	if(NOT NEED_REPL_SNPRINTF)
+		include(CheckSnprintfLongLongIntModifier)
+		if(NOT LONG_LONG_INT_MODIFIER)
+			set(LONG_LONG_INT_MODIFIER "ll")
+			set(NEED_REPL_SNPRINTF ON)
+		endif(NOT LONG_LONG_INT_MODIFIER)
+	else(NOT NEED_REPL_SNPRINTF)
+		set(LONG_LONG_INT_MODIFIER "ll")
+	endif(NOT NEED_REPL_SNPRINTF)
+else(HAVE_LONG_LONG_INT_64)
+	set(LONG_LONG_INT_MODIFIER "l")
+endif(HAVE_LONG_LONG_INT_64)
+
+if(HAVE_LONG_LONG_INT_64)
+	message(STATUS "HAVE_LONG_LONG_INT_64 ${HAVE_LONG_LONG_INT_64}")
+endif()
+if(HAVE_LONG_LONG_INT_64)
+	include(CheckLLConstants)
+endif()
+
+#TODO: some strange here
+option(USE_FLOAT4_BYVAL "float4 values are passed by value" ON)
+if(USE_FLOAT4_BYVAL)
+	set(FLOAT4PASSBYVAL 1)
+else(USE_FLOAT4_BYVAL)
+	set(FLOAT4PASSBYVAL 0)
+endif(USE_FLOAT4_BYVAL)
+
+if(VOID_POINTER_SIZE EQUAL 8)
+	option(USE_FLOAT8_BYVAL "float8 values are passed by value" ON)
+else()
+	option(USE_FLOAT8_BYVAL "float8 values are passed by value" OFF)
+endif()
+if(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+	message(FATAL_ERROR "USE_FLOAT8_BYVAL is not supported on 32-bit platforms.")
+elseif(USE_FLOAT8_BYVAL AND VOID_POINTER_SIZE EQUAL 8)
+	set(FLOAT8PASSBYVAL 1)
+	set(USE_FLOAT8_BYVAL 1)
+else()
+	set(FLOAT8PASSBYVAL 0)
+	set(USE_FLOAT8_BYVAL 0)
+endif(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+
+if (_GNU_SOURCE)
+	add_definitions(-D_GNU_SOURCE)
+endif()
+if(Threads_FOUND)
+	set(ENABLE_THREAD_SAFETY 1)
+	set(THREADS_PREFER_PTHREAD_FLAG ON)
+	set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS")
+	if(THREADS_HAVE_PTHREAD_ARG)
+		set(PTHREAD_CFLAGS "${PTHREAD_CFLAGS} -pthread")
+	endif()
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PTHREAD_CFLAGS}")
+endif()
+
+set(PORT_DIR "${PROJECT_SOURCE_DIR}/src/port")
+set(PQ_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/libpq")
+set(MB_UTILS_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/utils/mb")
+
+
+set(fallback_SRCS "")
+
+if(NOT HAVE_DECL_STRLCPY)
+  set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcpy.c")
+endif(NOT HAVE_DECL_STRLCPY)
+
+if(NOT HAVE_DECL_STRLCAT)
+	set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcat.c")
+endif(NOT HAVE_DECL_STRLCAT)
+
+if(NOT HAVE_GETPEEREID)
+	set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/getpeereid.c")
+endif(NOT HAVE_GETPEEREID)
+
+set(TABLE_BLOCKSIZE 8 CACHE STRING "set table block size in kB")
+
+if(TABLE_BLOCKSIZE EQUAL 1)
+	set(BLCKSZ 1024)
+elseif(TABLE_BLOCKSIZE EQUAL 2)
+	set(BLCKSZ 2048)
+elseif(TABLE_BLOCKSIZE EQUAL 4)
+	set(BLCKSZ 4096)
+elseif(TABLE_BLOCKSIZE EQUAL 8)
+	set(BLCKSZ 8192)
+elseif(TABLE_BLOCKSIZE EQUAL 16)
+	set(BLCKSZ 16384)
+elseif(TABLE_BLOCKSIZE EQUAL 32)
+	set(BLCKSZ 32768)
+else(TABLE_BLOCKSIZE EQUAL 1)
+	message(FATAL_ERROR "Invalid block size. Allowed values are 1,2,4,8,16,32.")
+endif(TABLE_BLOCKSIZE EQUAL 1)
+
+message(STATUS "BLCKSZ - ${BLCKSZ}")
+
+set(SEGSIZE 1 CACHE STRING "set table segment size in GB")
+math(EXPR RELSEG_SIZE "(1024 / ${TABLE_BLOCKSIZE}) * ${SEGSIZE} * 1024")
+
+set(WAL_BLOCKSIZE 8 CACHE STRING "set WAL block size in kB")
+
+if(WAL_BLOCKSIZE EQUAL 1)
+	set(XLOG_BLCKSZ 1024)
+elseif(WAL_BLOCKSIZE EQUAL 2)
+	set(XLOG_BLCKSZ 2048)
+elseif(WAL_BLOCKSIZE EQUAL 4)
+	set(XLOG_BLCKSZ 4096)
+elseif(WAL_BLOCKSIZE EQUAL 8)
+	set(XLOG_BLCKSZ 8192)
+elseif(WAL_BLOCKSIZE EQUAL 16)
+	set(XLOG_BLCKSZ 16384)
+elseif(WAL_BLOCKSIZE EQUAL 32)
+	set(XLOG_BLCKSZ 32768)
+elseif(WAL_BLOCKSIZE EQUAL 64)
+	set(XLOG_BLCKSZ 65536)
+else(WAL_BLOCKSIZE EQUAL 1)
+	message(FATAL_ERROR "Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64.")
+endif(WAL_BLOCKSIZE EQUAL 1)
+
+message(STATUS "XLOG_BLCKSZ - ${XLOG_BLCKSZ}")
+
+set(WAL_SEGSIZE 16 CACHE STRING "set WAL segment size in MB")
+
+if (";1;2;4;8;16;32;64;" MATCHES ";${WAL_SEGSIZE};")
+	math(EXPR XLOG_SEG_SIZE "${WAL_SEGSIZE} * 1024 * 1024")
+else()
+	message(FATAL_ERROR "${WAL_SEGSIZE} Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.")
+endif()
+
+message(STATUS "XLOG_SEG_SIZE - ${XLOG_SEG_SIZE}")
+
+option(HAVE_ATOMICS "Define to ON if you want to use atomics if available." ON)
+
+if(HAVE_ATOMICS)
+	check_c_source_compiles("
+		int main(void){
+			char lock = 0;
+			__sync_lock_test_and_set(&lock, 1);
+			__sync_lock_release(&lock);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_CHAR_TAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int lock = 0;
+			__sync_lock_test_and_set(&lock, 1);
+			__sync_lock_release(&lock);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT32_TAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int val = 0;
+			__sync_val_compare_and_swap(&val, 0, 37);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT32_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			${PG_INT64_TYPE} lock = 0;
+			__sync_val_compare_and_swap(&lock, 0, (${PG_INT64_TYPE}) 37);
+			return 0;
+		}
+	" HAVE_GCC__SYNC_INT64_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			int val = 0;
+			int expect = 0;
+			__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+			return 0;
+		}
+	" HAVE_GCC__ATOMIC_INT32_CAS)
+
+	check_c_source_compiles("
+		int main(void){
+			${PG_INT64_TYPE} val = 0;
+			${PG_INT64_TYPE} expect = 0;
+			__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+			return 0;
+		}
+	" HAVE_GCC__ATOMIC_INT64_CAS)
+endif(HAVE_ATOMICS)
+
+check_c_source_runs("
+	int main(void){
+		static unsigned long int x = __builtin_bswap32(0xaabbccdd);
+		return 0;
+	}
+" HAVE__BUILTIN_BSWAP32)
+
+check_c_source_runs("
+	int main(void){
+		static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);
+		return 0;
+	}
+" HAVE__BUILTIN_BSWAP64)
+
+check_c_source_runs("
+	int main(void){
+		static int x; static int y[__builtin_constant_p(x) ? x : 1];
+		return 0;
+	}
+" HAVE__BUILTIN_CONSTANT_P)
+
+check_c_source_runs("
+	int main(void){
+		int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)];
+		return 0;
+	}
+" HAVE__BUILTIN_TYPES_COMPATIBLE_P)
+
+check_c_source_runs("
+	int main(void){
+		__builtin_unreachable();
+		return 0;
+	}
+" HAVE__BUILTIN_UNREACHABLE)
+
+check_c_source_runs("
+	int main(void){
+		{ _Static_assert(1, \"foo\"); }
+		return 0;
+	}
+" HAVE__STATIC_ASSERT)
+
+if(NOT PGPORT)
+	set(PGPORT 5432)
+endif(NOT PGPORT)
+
+include(CheckFlexibleArray)
+
+check_c_source_compiles("
+	#include <sys/time.h>
+	int main(void){
+		struct timeval *tp;
+		struct timezone *tzp;
+		gettimeofday(tp,tzp);
+		return 0;
+	}
+" GETTIMEOFDAY_2ARG)
+
+if(NOT GETTIMEOFDAY_2ARG)
+	set(GETTIMEOFDAY_1ARG 1)
+endif(NOT GETTIMEOFDAY_2ARG)
+
+check_c_source_compiles("
+	#include <time.h>
+	int main(void){
+		int res;
+	#ifndef __CYGWIN__
+		res = timezone / 60;
+	#else
+		res = _timezone / 60;
+	#endif
+		return 0;
+	}
+" HAVE_INT_TIMEZONE)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		printf(\"%s\", __func__);
+		return 0;
+	}
+" HAVE_FUNCNAME__FUNC)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		printf(\"%s\", __FUNCTION__);
+		return 0;
+	}
+" HAVE_FUNCNAME__FUNCTION)
+
+check_c_source_compiles("
+	#include <stdio.h>
+	int main(void){
+		#define debug(...) fprintf(stderr, __VA_ARGS__)
+		debug(\"%s\", \"blarg\");
+		return 0;
+	}
+" HAVE__VA_ARGS)
+
+check_struct_has_member("struct tm" tm_zone "sys/types.h;time.h" HAVE_TM_ZONE LANGUAGE C)
+check_struct_has_member("struct tm" tm_gmtoff "sys/types.h;time.h" HAVE_STRUCT_TM_TM_ZONE LANGUAGE C)
+set(CMAKE_EXTRA_INCLUDE_FILES "time.h")
+check_type_size("*tzname" HAVE_TZNAME)
+
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+	set(CMAKE_REQUIRED_FLAGS "-Werror")
+endif()
+check_c_source_compiles("
+	extern int pgac_write(int ignore, const char *fmt,...) __attribute__((format(gnu_printf, 2, 3)));
+	int main(void){return 0;}
+" PG_PRINTF_ATTRIBUTE)
+
+if(PG_PRINTF_ATTRIBUTE)
+	set(PG_PRINTF_ATTRIBUTE gnu_printf)
+else(PG_PRINTF_ATTRIBUTE)
+	set(PG_PRINTF_ATTRIBUTE printf)
+endif(PG_PRINTF_ATTRIBUTE)
+
+if(NOT MEMSET_LOOP_LIMIT)
+	set(MEMSET_LOOP_LIMIT 1024)
+endif(NOT MEMSET_LOOP_LIMIT)
+
+
+if(WIN32 OR MINGW)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;winsock2.h;ws2tcpip.h")
+else()
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/socket.h;netdb.h")
+endif()
+
+check_type_size("struct addrinfo" HAVE_STRUCT_ADDRINFO)
+check_type_size("struct cmsgcred" HAVE_STRUCT_CMSGCRED)
+if(HAVE_STRUCT_ADDRINFO)
+	CHECK_STRUCT_HAS_MEMBER("struct addrinfo" sa_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_SA_LEN LANGUAGE C)
+	if(NOT (WIN32 OR MINGW))
+		set(HAVE_GETADDRINFO 1)
+	endif()
+endif(HAVE_STRUCT_ADDRINFO)
+
+check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
+if(HAVE_STRUCT_SOCKADDR_STORAGE)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN LANGUAGE C)
+	CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN LANGUAGE C)
+endif(HAVE_STRUCT_SOCKADDR_STORAGE)
+
+# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
+if(HAVE_SYS_UN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/un.h")
+else(HAVE_SYS_UN_H)
+	set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
+endif(HAVE_SYS_UN_H)
+check_type_size("struct sockaddr_un" HAVE_UNIX_SOCKETS)
+
+if(WIN32)
+	set(HAVE_IPV6 1)
+else()
+	set(CMAKE_EXTRA_INCLUDE_FILES "netinet/in.h")
+	check_type_size("struct sockaddr_in6" HAVE_IPV6)
+endif()
+
+set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/ipc.h;sys/sem.h")
+check_type_size("union semun" HAVE_UNION_SEMUN)
+
+check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
+
+check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
+
+if(WIN32 OR MINGW)
+	set(USE_WIN32_SEMAPHORES 1)
+	set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_sema.c")
+else(WIN32 OR MINGW)
+	if(USE_NAMED_POSIX_SEMAPHORES)
+		set(USE_NAMED_POSIX_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+	elseif(USE_UNNAMED_POSIX_SEMAPHORES)
+		set(USE_UNNAMED_POSIX_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+	else(USE_NAMED_POSIX_SEMAPHORES)
+		set(USE_SYSV_SEMAPHORES 1)
+		set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_sema.c")
+	endif(USE_NAMED_POSIX_SEMAPHORES)
+endif(WIN32 OR MINGW)
+
+#Realy bad name for win32
+set(USE_SYSV_SHARED_MEMORY 1)
+if(WIN32 OR MINGW)
+	set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_shmem.c")
+else(WIN32 OR MINGW)
+	set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_shmem.c")
+endif(WIN32 OR MINGW)
+
+option(HAVE_SPINLOCKS "Define to ON if you have spinlocks." ON)
+
+
+option(USE_INTEGER_DATETIMES "Define to ON if you want 64-bit integer timestamp and interval support." ON)
+
+if(WIN32)
+	option(HAVE_SYMLINK "Define to ON if you have the `symlink' function." ON)
+else(WIN32)
+	set(HAVE_SYMLINK 1)
+endif(WIN32)
+
+option(PG_KRB_SRVNAM "Define to the name of the default PostgreSQL service principal in Kerberos (GSSAPI)." "postgres")
+
+#TODO: Need test this
+if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+	if(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+		set(TAS sunstudio_sparc.s)
+	else(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+		set(TAS sunstudio_x86.s)
+	endif(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+elseif(CMAKE_C_COMPILER_ID STREQUAL "HP-UX")
+	set(TAS hpux_hppa.s)
+else(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+	set(TAS dummy.s)
+endif(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+
+if(WIN32 OR MINGW)
+	set(CMAKE_EXTRA_INCLUDE_FILES
+		${CMAKE_EXTRA_INCLUDE_FILES}
+		windows.h
+		string.h
+		dbghelp.h
+	)
+	set(CMAKE_REQUIRED_DEFINITIONS "WIN32_LEAN_AND_MEAN")
+	check_type_size(MINIDUMP_TYPE NAVE_MINIDUMP_TYPE)
+endif(WIN32 OR MINGW)
+
+set(WIN32_STACK_RLIMIT 4194304)
+if(WIN32)
+	add_definitions(-DWIN32_STACK_RLIMIT=${WIN32_STACK_RLIMIT})
+endif()
+
+if(NEED_REPL_SNPRINTF)
+	option(USE_REPL_SNPRINTF "Use replacement snprintf() functions." ON)
+endif()
+
+include(GenDef)
+#Not work correctly for postgres see bug: 
+#https://gitlab.kitware.com/cmake/cmake/issues/16161
+#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+
+include(RegressCheck)
+
+# Need add sco and unixware?
+if(WIN32 OR MINGW)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/win32.h)
+elseif(APPLE)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/hpux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/newtbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/solaris.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/aix.h)
+elseif(CYGWIN)
+	set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/cygwin.h)
+else(WIN32 OR MINGW)
+	message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+# Try make fake host tuple for regress and isolation tests
+if(MINGW AND VOID_POINTER_SIZE EQUAL 8)
+	set(HOST_TUPLE "x86_64-w64-mingw32")
+elseif(MINGW AND VOID_POINTER_SIZE EQUAL 4)
+	set(HOST_TUPLE "i686-pc-mingw32")
+elseif(CYGWIN)
+	set(HOST_TUPLE "i686-pc-cygwin")
+elseif(MSVC AND VOID_POINTER_SIZE EQUAL 4)
+	set(HOST_TUPLE "i686-pc-win32vc")
+else()
+	set(HOST_TUPLE ${CMAKE_HOST_SYSTEM})
+endif()
+
+set(WITH_UUID "OFF" CACHE STRING "type of uuid lib [bsd, e2fs, ossp]")
+if(WITH_UUID)
+	find_package(LibUUID)
+
+	if(WITH_UUID STREQUAL "bsd")
+		set(HAVE_UUID_BSD 1)
+		set(UUID_EXTRA_OBJS
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+		)
+	elseif(WITH_UUID STREQUAL "e2fs")
+		set(HAVE_UUID_E2FS 1)
+		set(UUID_EXTRA_OBJS
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+			${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+		)
+	elseif(WITH_UUID STREQUAL "ossp")
+		set(HAVE_UUID_OSSP 1)
+		set(UUID_EXTRA_OBJS "")
+	else()
+		message(WARNING "Not correct type of uuid lib:${WITH_UUID}")
+	endif()
+endif()
+
+#file(REMOVE ${PROJECT_SOURCE_DIR}/src/include/pg_config_os.h)
+file(GENERATE OUTPUT ${PROJECT_SOURCE_DIR}/src/include/pg_config_os.h
+	INPUT ${pgos_include_SRCS})
+
+if(MINGW OR MSVC)
+	include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32")
+endif()
+
+if(MSVC)
+	include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32_msvc")
+endif()
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_ext_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_ext.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/include/pg_config_paths_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/port/pg_config_paths.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config_cmake.in"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config.h"
+)
+
+configure_file(
+	"${PROJECT_SOURCE_DIR}/PGXS.cmake.in"
+	"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake"
+	@ONLY
+)
+
+install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake
+		DESTINATION ${LIBDIR}/cmake)
+
+
+option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
+mark_as_advanced(CMAKE_USE_FOLDERS)
+
+macro(CMAKE_SET_TARGET_FOLDER tgt folder)
+	if(CMAKE_USE_FOLDERS)
+		set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+		if(MSVC AND TARGET ${tgt})
+			set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
+		endif()
+	else()
+		set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+	endif()
+endmacro()
+
+# Add sub-directories
+add_subdirectory(src)
+add_subdirectory(contrib)
+
+message(STATUS "------------------")
+message(STATUS "    Conclusion")
+message(STATUS "Host tuple: ${HOST_TUPLE}")
+message(STATUS "OpenSSL: ${OPENSSL_FOUND} version: ${OPENSSL_VERSION} libs: ${OPENSSL_LIBRARIES}")
+message(STATUS "Python: ${PYTHONINTERP_FOUND}")
+message(STATUS "PythonLibs: ${PYTHONLIBS_FOUND}")
+message(STATUS "PerlLibs: ${PERLLIBS_FOUND}")
+message(STATUS "LibXML2: ${LIBXML2_FOUND}")
+message(STATUS "LibXslt: ${LIBXSLT_FOUND}")
+message(STATUS "TCL: ${TCL_FOUND}")
+message(STATUS "PAM: ${PAM_LIB}")
+message(STATUS "PROVE (TAP tests): ${PROVE}")
+message(STATUS "Strong random source: ${STRONG_RANDOM_SOURCE}")
+message(STATUS "------------------")
diff --git a/PGXS.cmake.in b/PGXS.cmake.in
new file mode 100644
index 0000000000..01a1100cce
--- /dev/null
+++ b/PGXS.cmake.in
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 2.8)
+
+set(POSTGRES_MAJOR_VERSION "@POSTGRES_MAJOR_VERSION@")
+set(POSTGRES_MINOR_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_PATCH_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_VERSION "@POSTGRES_VERSION@")
+set(PG_VERSION "9.6devel")
+set(PG_VERSION_NUM 90600)
+
+set(PGBINDIR "@PGBINDIR@")
+set(PGSHAREDIR "@PGSHAREDIR@")
+set(SYSCONFDIR "@SYSCONFDIR@")
+set(INCLUDEDIR "@INCLUDEDIR@")
+set(PKGINCLUDEDIR "@PKGINCLUDEDIR@")
+set(INCLUDEDIRSERVER "@INCLUDEDIRSERVER@")
+set(LIBDIR "@LIBDIR@")
+set(PKGLIBDIR "@PKGLIBDIR@")
+set(LOCALEDIR "@LOCALEDIR@")
+set(DOCDIR "@DOCDIR@")
+set(HTMLDIR "@HTMLDIR@")
+set(MANDIR "@MANDIR@")
+
+
+set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+set(CMAKE_MACOSX_RPATH 1)
+
+set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
+set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "@CMAKE_SHARED_LIBRARY_SONAME_C_FLAG@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+
+include_directories(${INCLUDEDIRSERVER})
+link_directories(${LIBDIR})
+
+if(WIN32)
+	set(contrib_libs
+		port
+		pgcommon
+	)
+endif()
+
+if(MSVC)
+	set(contrib_libs
+		${contrib_libs}
+		postgres
+	)
+endif()
diff --git a/cmake/CheckCpuID.cmake b/cmake/CheckCpuID.cmake
new file mode 100644
index 0000000000..3346302361
--- /dev/null
+++ b/cmake/CheckCpuID.cmake
@@ -0,0 +1,17 @@
+CHECK_C_SOURCE_COMPILES("
+	#include <cpuid.h>
+	int main() {
+		unsigned int exx[4] = {0, 0, 0, 0};
+		__get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]);
+		return 0;
+	}
+" HAVE__GET_CPUID)
+
+CHECK_C_SOURCE_COMPILES("
+	#include <intrin.h>
+	int main() {
+		unsigned int exx[4] = {0, 0, 0, 0};
+		__cpuid(exx[0], 1);
+		return 0;
+	}
+" HAVE__CPUID)
diff --git a/cmake/CheckFlexibleArray.cmake b/cmake/CheckFlexibleArray.cmake
new file mode 100644
index 0000000000..ce57aa4f65
--- /dev/null
+++ b/cmake/CheckFlexibleArray.cmake
@@ -0,0 +1,37 @@
+set(C99_C_FLAG_CANDIDATES
+   " "
+   "-std=c99"
+   "-std=gnu99"
+   "-c99"
+   "-AC99"
+   "-xc99=all"
+   "-qlanglvl=extc99"
+)
+
+message(STATUS "Check flexible array support")
+if(NOT MSVC)
+	foreach(FLAG ${C99_C_FLAG_CANDIDATES})
+		set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+		unset(FLEXIBLE_ARRAY_MEMBER CACHE)
+		CHECK_C_SOURCE_COMPILES("
+			int main(void){
+				int x = 10;
+				int y[x];
+				return 0;
+			}
+		" FLEXIBLE_ARRAY_MEMBER)
+		if(FLEXIBLE_ARRAY_MEMBER)
+			set(C99_C_FLAGS_INTERNAL "${FLAG}")
+			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
+			break()
+		endif(FLEXIBLE_ARRAY_MEMBER)
+	endforeach(FLAG ${C99_C_FLAG_CANDIDATES})
+endif()
+
+if(FLEXIBLE_ARRAY_MEMBER)
+	message(STATUS "Check flexible array support - yes with ${C99_C_FLAGS_INTERNAL}")
+	set(FLEXIBLE_ARRAY_MEMBER "")
+else(FLEXIBLE_ARRAY_MEMBER)
+	message(STATUS "Check flexible array support - no")
+	set(FLEXIBLE_ARRAY_MEMBER 1)
+endif(FLEXIBLE_ARRAY_MEMBER)
\ No newline at end of file
diff --git a/cmake/CheckLLConstants.cmake b/cmake/CheckLLConstants.cmake
new file mode 100644
index 0000000000..68bf65fd02
--- /dev/null
+++ b/cmake/CheckLLConstants.cmake
@@ -0,0 +1,9 @@
+CHECK_C_SOURCE_COMPILES("
+	main() {
+		#define INT64CONST(x)  x##LL
+		long long int foo = INT64CONST(0x1234567890123456);
+		return 0;
+	}
+" HAVE_LL_CONSTANTS)
+
+message(STATUS "HAVE_LL_CONSTANTS ${HAVE_LL_CONSTANTS}")
\ No newline at end of file
diff --git a/cmake/CheckSSE42.cmake b/cmake/CheckSSE42.cmake
new file mode 100644
index 0000000000..3fee3b4641
--- /dev/null
+++ b/cmake/CheckSSE42.cmake
@@ -0,0 +1,30 @@
+foreach(FLAG ";-msse4.2")
+	unset(HAVE_SSE42_INTRINSICS CACHE)
+	set(CMAKE_REQUIRED_FLAGS ${FLAG})
+	check_c_source_runs("
+		#include <nmmintrin.h>
+		int main(void) {
+			unsigned int crc = 0;
+			crc = _mm_crc32_u8(crc, 0);
+			crc = _mm_crc32_u32(crc, 0);
+			/* return computed value, to prevent the above being optimized away */
+			return !(crc == 0);
+		}
+	" HAVE_SSE42_INTRINSICS)
+	if (HAVE_SSE42_INTRINSICS)
+		set(CFLAGS_SSE42 ${FLAG})
+		break()
+	endif()
+endforeach()
+
+message(STATUS "SSE4.2 flags: ${CFLAGS_SSE42}")
+set(CMAKE_REQUIRED_FLAGS ${CFLAGS_SSE42})
+check_c_source_compiles("
+	#ifndef __SSE4_2__
+	#error __SSE4_2__ not defined
+	#endif
+	int main(void){
+		return 0;
+	}
+" HAVE_SSE42)
+set(CMAKE_REQUIRED_FLAGS "")
diff --git a/cmake/CheckSnprintfLongLongIntModifier.cmake b/cmake/CheckSnprintfLongLongIntModifier.cmake
new file mode 100644
index 0000000000..f07623890a
--- /dev/null
+++ b/cmake/CheckSnprintfLongLongIntModifier.cmake
@@ -0,0 +1,31 @@
+set(CMAKE_REQUIRED_INCLUDES "stdio.h")
+foreach(pgac_modifier "ll" "q" "I64")
+	unset(LONG_LONG_INT_MODIFIER CACHE)
+	CHECK_C_SOURCE_COMPILES("
+		typedef long long int ac_int64;
+
+		ac_int64 a = 20000001;
+		ac_int64 b = 40000005;
+
+		int does_int64_snprintf_work() {
+			ac_int64 c;
+			char buf[100];
+			if (sizeof(ac_int64) != 8)
+				return 0;	/* doesn't look like the right size */
+			
+			c = a * b;
+			snprintf(buf, 100, \"%${pgac_modifier}d\", c);
+			if (strcmp(buf, \"800000140000005\") != 0)
+				return 0;	/* either multiply or snprintf is busted */
+			return 1;
+		}
+		main() {
+			exit(! does_int64_snprintf_work());
+		}
+	" LONG_LONG_INT_MODIFIER)
+	if(LONG_LONG_INT_MODIFIER)
+		set(LONG_LONG_INT_MODIFIER ${pgac_modifier})
+		break()
+	endif(LONG_LONG_INT_MODIFIER)
+endforeach(pgac_modifier)
+message(STATUS "LONG_LONG_INT_MODIFIER ${LONG_LONG_INT_MODIFIER}")
\ No newline at end of file
diff --git a/cmake/CheckTypeAlignment.cmake b/cmake/CheckTypeAlignment.cmake
new file mode 100644
index 0000000000..37cbb580d3
--- /dev/null
+++ b/cmake/CheckTypeAlignment.cmake
@@ -0,0 +1,29 @@
+macro(CHECK_TYPE_ALIGNMENT TYPE NAME)
+	if(NOT ${NAME})
+		message(STATUS "Check alignment of ${TYPE}")
+		
+		set(INCLUDE_HEADERS "#include <stddef.h>
+			#include <stdio.h>
+			#include <stdlib.h>")
+
+		if(HAVE_STDINT_H)
+			set(INCLUDE_HEADERS "${INCLUDE_HEADERS}\n#include <stdint.h>\n")
+		endif(HAVE_STDINT_H)
+
+		file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c"
+			"${INCLUDE_HEADERS}
+			int main(){
+				char diff;
+				struct foo {char a; ${TYPE} b;};
+				struct foo *p = (struct foo *) malloc(sizeof(struct foo));
+				diff = ((char *)&p->b) - ((char *)&p->a);
+				return diff;}
+		")
+
+		try_run(${NAME} COMPILE_RESULT "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
+			"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c")
+
+		message(STATUS "Check alignment of ${TYPE} - ${${NAME}}")
+
+	endif(NOT ${NAME})
+endmacro(CHECK_TYPE_ALIGNMENT TYPE NAME ALIGNOF_TYPE)
\ No newline at end of file
diff --git a/cmake/FindLDAP.cmake b/cmake/FindLDAP.cmake
new file mode 100644
index 0000000000..8a5bc6315f
--- /dev/null
+++ b/cmake/FindLDAP.cmake
@@ -0,0 +1,41 @@
+# - Try to find the LDAP client libraries
+# Once done this will define
+#
+#  LDAP_FOUND - system has libldap
+#  LDAP_INCLUDE_DIR - the ldap include directory
+#  LDAP_LIBRARIES - libldap + liblber (if found) library
+#  LBER_LIBRARIES - liblber library
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+	# Already in cache, be silent
+	set(Ldap_FIND_QUIETLY TRUE)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(UNIX)
+	FIND_PATH(LDAP_INCLUDE_DIR ldap.h)
+	FIND_LIBRARY(LDAP_LIBRARIES NAMES ldap)
+	FIND_LIBRARY(LBER_LIBRARIES NAMES lber)
+
+else(UNIX)
+	FIND_PATH(LDAP_INCLUDE_DIR winldap.h)
+	FIND_LIBRARY(LDAP_LIBRARIES NAMES wldap32)
+endif(UNIX)
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+	set(LDAP_FOUND TRUE)
+	if(LBER_LIBRARIES)
+		set(LDAP_LIBRARIES ${LDAP_LIBRARIES} ${LBER_LIBRARIES})
+	endif(LBER_LIBRARIES)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(LDAP_FOUND)
+	if(NOT Ldap_FIND_QUIETLY)
+		message(STATUS "Found ldap: ${LDAP_LIBRARIES}")
+	endif(NOT Ldap_FIND_QUIETLY)
+else(LDAP_FOUND)
+	if (Ldap_FIND_REQUIRED)
+		message(FATAL_ERROR "Could NOT find ldap")
+	endif (Ldap_FIND_REQUIRED)
+endif(LDAP_FOUND)
+
+MARK_AS_ADVANCED(LDAP_INCLUDE_DIR LDAP_LIBRARIES LBER_LIBRARIES)
diff --git a/cmake/FindLibSocket.cmake b/cmake/FindLibSocket.cmake
new file mode 100644
index 0000000000..148f4ec296
--- /dev/null
+++ b/cmake/FindLibSocket.cmake
@@ -0,0 +1,11 @@
+find_library( LIBSOCKET_LIBRARY NAMES libsocket socket )
+mark_as_advanced( LIBSOCKET_LIBRARY )
+
+# handle the QUIETLY and REQUIRED arguments and set LIBSOCKET_FOUND to TRUE if
+# all listed variables are TRUE
+include( FindPackageHandleStandardArgs )
+FIND_PACKAGE_HANDLE_STANDARD_ARGS( LIBSOCKET DEFAULT_MSG LIBSOCKET_LIBRARY )
+
+if( LIBSOCKET_FOUND )
+	set( LIBSOCKET_LIBRARIES ${LIBSOCKET_LIBRARY} )
+endif( LIBSOCKET_FOUND )
diff --git a/cmake/FindLibUUID.cmake b/cmake/FindLibUUID.cmake
new file mode 100644
index 0000000000..10626c54b2
--- /dev/null
+++ b/cmake/FindLibUUID.cmake
@@ -0,0 +1,50 @@
+# - Try to find LIBUUID
+# Find LIBUUID headers, libraries and the answer to all questions.
+#
+#  LIBUUID_FOUND               True if libuuid got found
+#  LIBUUID_INCLUDE_DIRS        Location of libuuid headers
+#  LIBUUID_LIBRARIES           List of libraries to use libuuid
+#
+# Copyright (c) 2008 Bjoern Ricks <bjoern.ricks@googlemail.com>
+#
+#  Redistribution and use is allowed according to the terms of the New
+#  BSD license.
+#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+INCLUDE(FindPkgConfig)
+
+IF(LibUUID_FIND_REQUIRED)
+	SET(_pkgconfig_REQUIRED "REQUIRED")
+ELSE(LibUUID_FIND_REQUIRED)
+	SET(_pkgconfig_REQUIRED "")
+ENDIF (LibUUID_FIND_REQUIRED)
+
+IF(LIBUUID_MIN_VERSION)
+	PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid>=${LIBUUID_MIN_VERSION})
+ELSE(LIBUUID_MIN_VERSION)
+	PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid)
+ENDIF(LIBUUID_MIN_VERSION)
+
+IF(NOT LIBUUID_FOUND)
+	FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
+	FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
+
+	# Report results
+	IF(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+		SET(LIBUUID_FOUND 1)
+		IF(NOT LIBUUID_FIND_QUIETLY)
+			MESSAGE(STATUS "Found libuuid: ${LIBUUID_LIBRARIES}")
+		ENDIF(NOT LIBUUID_FIND_QUIETLY)
+	ELSE(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+		IF(LIBUUID_FIND_REQUIRED)
+			MESSAGE(SEND_ERROR "Could NOT find libuuid")
+		ELSE(LIBUUID_FIND_REQUIRED)
+			IF(NOT LIBUUID_FIND_QUIETLY)
+				MESSAGE(STATUS "Could NOT find libuuid")
+			ENDIF(NOT LIBUUID_FIND_QUIETLY)
+		ENDIF (LIBUUID_FIND_REQUIRED)
+	ENDIF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+ENDIF(NOT LIBUUID_FOUND)
+
+MARK_AS_ADVANCED(LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS)
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
new file mode 100644
index 0000000000..6603dbeb97
--- /dev/null
+++ b/cmake/FindReadline.cmake
@@ -0,0 +1,22 @@
+# from http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/FindReadline.cmake
+# http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/COPYING-CMAKE-SCRIPTS
+# --> BSD licensed
+#
+# GNU Readline library finder
+
+
+if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+	set(READLINE_FOUND TRUE)
+else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+	FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h
+		/usr/include/readline
+	)
+
+	FIND_LIBRARY(READLINE_LIBRARY NAMES readline PATHS
+		/opt/csw/lib/64/
+	)
+	include(FindPackageHandleStandardArgs)
+	FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
+
+	MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
+endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
diff --git a/cmake/FindSELinux.cmake b/cmake/FindSELinux.cmake
new file mode 100644
index 0000000000..dd6e3ca425
--- /dev/null
+++ b/cmake/FindSELinux.cmake
@@ -0,0 +1,55 @@
+# - Try to find the SELinux library
+# Once done this will define
+#
+#  SELINUX_FOUND - System has selinux
+#  SELINUX_INCLUDE_DIR - The selinux include directory
+#  SELINUX_LIBRARIES - The libraries needed to use selinux
+#  SELINUX_DEFINITIONS - Compiler switches required for using selinux
+
+#=============================================================================
+# Copyright 2010  Michael Leupold <lemma@confuego.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+IF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+	# in cache already
+	SET (SELinux_FIND_QUIETLY TRUE)
+ENDIF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+
+# TODO: This should be restricted to Linux only
+IF (NOT WIN32)
+	# use pkg-config to get the directories
+	FIND_PACKAGE (PkgConfig)
+	PKG_CHECK_MODULES (PC_SELINUX libselinux)
+	SET (SELINUX_DEFINITIONS ${PC_SELINUX_CFLAGS_OTHER})
+
+	FIND_PATH (SELINUX_INCLUDE_DIR selinux/selinux.h
+		HINTS
+		${PC_SELINUX_INCLUDEDIR}
+		${PC_SELINUX_INCLUDE_DIRS}
+	)
+
+	FIND_LIBRARY (SELINUX_LIBRARIES selinux libselinux
+		HINTS
+		${PC_SELINUX_LIBDIR}
+		${PC_SELINUX_LIBRARY_DIRS}
+	)
+
+	INCLUDE (FindPackageHandleStandardArgs)
+
+	# handle the QUIETLY and REQUIRED arguments and set SELINUX_FOUND
+	# to TRUE if all listed variables are TRUE
+	FIND_PACKAGE_HANDLE_STANDARD_ARGS (SELinux DEFAULT_MSG
+		SELINUX_INCLUDE_DIR
+		SELINUX_LIBRARIES
+	)
+
+	MARK_AS_ADVANCED (SELINUX_INCLUDE_DIR SELINUX_LIBRARIES)
+
+ENDIF (NOT WIN32)
diff --git a/cmake/FuncAcceptArgtypes.cmake b/cmake/FuncAcceptArgtypes.cmake
new file mode 100644
index 0000000000..e333d69aea
--- /dev/null
+++ b/cmake/FuncAcceptArgtypes.cmake
@@ -0,0 +1,52 @@
+if(HAVE_SYS_TYPES_H)
+	set(INCLUDE_SYS_TYPES_H "#include <sys/types.h>")
+endif(HAVE_SYS_TYPES_H)
+
+if(HAVE_SYS_SOCKET_H)
+	set(INCLUDE_SYS_SOCKET_H "#include <sys/socket.h>")
+endif(HAVE_SYS_SOCKET_H)
+
+
+message(STATUS "Looking for accept function args")
+set(CMAKE_REQUIRED_QUIET 1)
+foreach(ac_cv_func_accept_return "int" "unsigned int PASCAL" "SOCKET WSAAPI")
+	foreach(ac_cv_func_accept_arg1 "unsigned int" "int" "SOCKET")
+		foreach(ac_cv_func_accept_arg2 "struct sockaddr *" "const struct sockaddr *" "void *")
+			foreach(ac_cv_func_accept_arg3 "int" "size_t" "socklen_t" "unsigned int" "void")
+				unset(AC_FUNC_ACCEPT CACHE)
+				CHECK_C_SOURCE_COMPILES("
+					${INCLUDE_SYS_TYPES_H}
+					${INCLUDE_SYS_SOCKET_H}
+					extern ${ac_cv_func_accept_return} accept (${ac_cv_func_accept_arg1}, ${ac_cv_func_accept_arg2}, ${ac_cv_func_accept_arg3} *);
+					int main(void){return 0;}
+				" AC_FUNC_ACCEPT)
+				if(AC_FUNC_ACCEPT)
+					set(ACCEPT_TYPE_RETURN ${ac_cv_func_accept_return})
+					set(ACCEPT_TYPE_ARG1 ${ac_cv_func_accept_arg1})
+					set(ACCEPT_TYPE_ARG2 ${ac_cv_func_accept_arg2})
+					set(ACCEPT_TYPE_ARG3 ${ac_cv_func_accept_arg3})
+					break()
+				endif(AC_FUNC_ACCEPT)
+			endforeach(ac_cv_func_accept_arg3)
+			if(AC_FUNC_ACCEPT)
+				break()
+			endif(AC_FUNC_ACCEPT)
+		endforeach(ac_cv_func_accept_arg2)
+		if(AC_FUNC_ACCEPT)
+			break()
+		endif(AC_FUNC_ACCEPT)
+	endforeach(ac_cv_func_accept_arg1)
+	if(AC_FUNC_ACCEPT)
+		break()
+	endif(AC_FUNC_ACCEPT)
+endforeach(ac_cv_func_accept_return)
+unset(CMAKE_REQUIRED_QUIET)
+
+if(NOT AC_FUNC_ACCEPT)
+	message(ERROR "could not determine argument types")
+endif(NOT AC_FUNC_ACCEPT)
+if(ACCEPT_TYPE_ARG3 STREQUAL "void")
+	set(ACCEPT_TYPE_ARG3 "int")
+endif()
+
+message(STATUS "Looking for accept function args - found ${ACCEPT_TYPE_RETURN}, ${ACCEPT_TYPE_ARG1}, ${ACCEPT_TYPE_ARG2}, ${ACCEPT_TYPE_ARG3} *")
diff --git a/cmake/GenDef.cmake b/cmake/GenDef.cmake
new file mode 100644
index 0000000000..0d89bd0784
--- /dev/null
+++ b/cmake/GenDef.cmake
@@ -0,0 +1,32 @@
+if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+	find_program(NM_EXECUTABLE nm)
+endif()
+
+macro(GEN_DEF NAME)
+	if(MSVC)
+		set_target_properties(${NAME} PROPERTIES ENABLE_EXPORTS 1)
+		set_target_properties(${NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
+		#SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def\" ")
+		#add_custom_command(
+		#	TARGET ${NAME}
+		#	PRE_LINK
+		#	#COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+		#	#OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+		#	COMMAND ${PERL_EXECUTABLE} ${PROJECT_SOURCE_DIR}/src/tools/msvc/gendef.pl ${CMAKE_CURRENT_BINARY_DIR}/$<$<BOOL:${CMAKE_BUILD_TYPE}>:${CMAKE_FILES_DIRECTORY}>${NAME}.dir/${CMAKE_CFG_INTDIR} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def ${CMAKE_VS_PLATFORM_NAME}
+		#	COMMENT " Gen defs "
+		#)
+		#set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def)
+	elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND CMAKE_C_COMPILER_ID MATCHES "xlc")
+		# TODO for xls
+		SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINK_FLAGS "-Wl,-bE:${CMAKE_CURRENT_BINARY_DIR}/${NAME}.exp")
+		if("${CMAKE_C_FLAGS}" MATCHES "aix64")
+			set(FLAG_64 "-X64")
+		endif()
+		add_custom_command(
+			TARGET ${NAME}
+			PRE_LINK
+			COMMAND ${NM_EXECUTABLE} ${FLAG_64} -BCg ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${NAME}.dir/*.o | egrep ' [TDB] ' | sed -e 's/.* //' | egrep -v '\\$$' | sed -e 's/^[.]//' | sort | uniq > ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.exp
+			COMMENT " Gen exports "
+		)
+	endif()
+endmacro(GEN_DEF NAME)
diff --git a/cmake/MakeNLS.cmake b/cmake/MakeNLS.cmake
new file mode 100644
index 0000000000..c6db90d85f
--- /dev/null
+++ b/cmake/MakeNLS.cmake
@@ -0,0 +1,21 @@
+macro(MAKE_MO BIN_NAME LANGUAGES)
+	set(gmo_files "")
+	foreach(lang ${LANGUAGES})
+		if (NOT ";${NLS_LANGUAGES};" MATCHES ";${lang};")
+			continue()
+		endif()
+		set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo)
+		add_custom_command(OUTPUT ${_gmoFile}
+			COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} po/${lang}.po
+			WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+			DEPENDS po/${lang}.po
+		)
+		install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo DESTINATION share/locale/${lang}/LC_MESSAGES/ RENAME ${BIN_NAME}-${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.mo)
+		if(NOT TARGET pofiles)
+			add_custom_target(pofiles)
+		endif()
+		add_custom_target(${BIN_NAME}-mofile-${lang} ALL DEPENDS ${_gmoFile})
+		add_dependencies(pofiles ${BIN_NAME}-mofile-${lang})
+		set(gmo_files "${gmo_files};${_gmoFile}")
+	endforeach()
+endmacro()
diff --git a/cmake/RegressCheck.cmake b/cmake/RegressCheck.cmake
new file mode 100644
index 0000000000..0c16d2176d
--- /dev/null
+++ b/cmake/RegressCheck.cmake
@@ -0,0 +1,284 @@
+set(tmp_check_folder ${CMAKE_BINARY_DIR}/src/test/regress/tmp_install)
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+	set(env_cmd
+		${CMAKE_COMMAND} -E env
+		"DYLD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+		"PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH"
+	)
+	set(tmp_env_cmd
+		${CMAKE_COMMAND} -E env
+		"DYLD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+		"PATH=${tmp_check_folder}${PGBINDIR}:$$PATH"
+	)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+	set(env_cmd
+		${CMAKE_COMMAND} -E env
+		"LIBPATH=$ENV{DESTDIR}${LIBDIR}:$LIBPATH"
+		"PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH"
+	)
+	set(tmp_env_cmd
+		${CMAKE_COMMAND} -E env
+		"LIBPATH=${tmp_check_folder}${LIBDIR}:$LIBPATH"
+		"PATH=${tmp_check_folder}${PGBINDIR}:$$PATH"
+	)
+elseif(MSVC)
+	# We really need add PATH but only for ecpg
+	set(env_cmd "")
+else()
+	if (CMAKE_VERSION VERSION_GREATER "3.2.0")
+		set(env_cmd
+			${CMAKE_COMMAND} -E env
+			"LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH"
+			"PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH"
+		)
+		set(tmp_env_cmd
+			${CMAKE_COMMAND} -E env
+			"LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH"
+			"PATH=${tmp_check_folder}${PGBINDIR}:$$PATH"
+		)
+	else()
+		set(env_cmd
+			export "LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH"
+				   "PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH" &&
+		)
+		set(tmp_env_cmd
+			export "LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH"
+				   "PATH=${tmp_check_folder}${PGBINDIR}:$$PATH" &&
+		)
+	endif()
+endif()
+
+if(MSVC OR MSYS OR MINGW OR CMAKE_GENERATOR STREQUAL Xcode)
+	#Need rewrite
+	set(pre_pg_regress_check
+		${PGBINDIR}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_isolation_regress_check
+		${PGBINDIR}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+else()
+	set(pre_pg_regress_check
+		${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_isolation_regress_check
+		${CMAKE_BINARY_DIR}/src/test/isolation/${CMAKE_INSTALL_CONFIG_NAME}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+	set(pre_pg_ecpg_regress_check
+		${CMAKE_BINARY_DIR}/src/interfaces/ecpg/test/${CMAKE_INSTALL_CONFIG_NAME}/pg_ecpg_regress${CMAKE_EXECUTABLE_SUFFIX}
+		--inputdir="${CMAKE_BINARY_DIR}/src/interfaces/ecpg/test"
+		--temp-instance="tmp_check"
+		--encoding=UTF8
+		--no-locale
+	)
+endif()
+
+set(pg_regress_check
+	${env_cmd}
+	${pre_pg_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check
+	${env_cmd}
+	${pre_pg_isolation_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_isolation_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+set(pg_ecpg_regress_check
+	${env_cmd}
+	${pre_pg_ecpg_regress_check}
+	--bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_ecpg_regress_check_tmp
+	${tmp_env_cmd}
+	${pre_pg_ecpg_regress_check}
+	--bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+if(MAX_CONNECTIONS)
+	set(MAXCONNOPT "${MAXCONNOPT} --max-connections=${MAX_CONNECTIONS}")
+endif()
+
+if(TEMP_CONFIG)
+	set(TEMP_CONF "${TEMP_CONF} --temp-config=${TEMP_CONFIG}")
+endif()
+
+
+set(TAP_FLAGS "-I;${CMAKE_SOURCE_DIR}/src/test/perl/;--verbose")
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	set(check_make_command "ninja")
+else()
+	set(check_make_command ${CMAKE_MAKE_PROGRAM})
+endif()
+
+macro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	add_custom_target(${TARGET_NAME}_installcheck_tmp
+		COMMAND ${pg_regress_check_tmp} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+	
+	add_custom_target(${TARGET_NAME}_installcheck
+		COMMAND ${pg_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	if(CMAKE_GENERATOR STREQUAL "Ninja")
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${TARGET_NAME}_installcheck_tmp
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	else()
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+			COMMAND ${check_make_command} ${TARGET_NAME}_installcheck_tmp DESTDIR=${tmp_check_folder}
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	endif()
+	
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck "tests/install")
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	add_custom_target(${TARGET_NAME}_isolation_installcheck_tmp
+		COMMAND ${pg_isolation_regress_check_tmp} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS pg_isolation_regress
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	add_custom_target(${TARGET_NAME}_isolation_installcheck
+		COMMAND ${pg_isolation_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath==$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+		DEPENDS pg_isolation_regress
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	add_custom_target(${TARGET_NAME}_isolation_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} ${TARGET_NAME}_isolation_installcheck_tmp DESTDIR=${tmp_check_folder}
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_isolation_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+	set(TAP_TMP_CMD
+		${CMAKE_COMMAND} -E env
+		TESTDIR="${CMAKE_CURRENT_SOURCE_DIR}" PGPORT="65432" PG_REGRESS="${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}"
+		${PROVE}
+	)
+	set(TAP_CMD
+		${CMAKE_COMMAND} -E env
+		PATH="$ENV{DESTDIR}${BINDIR}:$$PATH" TESTDIR="${CMAKE_CURRENT_SOURCE_DIR}" PGPORT="65432" PG_REGRESS="${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}"
+		${PROVE}
+	)
+	add_custom_target(${TARGET_NAME}_installcheck_tmp
+		COMMAND ${tmp_env_cmd} ${TAP_TMP_CMD} ${OPTS} ${REGRESS_FILES}
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	add_custom_target(${TARGET_NAME}_installcheck
+		COMMAND ${env_cmd} ${TAP_CMD} ${OPTS} ${REGRESS_FILES}
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	if(CMAKE_GENERATOR STREQUAL "Ninja")
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+			COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${TARGET_NAME}_installcheck_tmp
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	else()
+		add_custom_target(${TARGET_NAME}_check
+			COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+			COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+			COMMAND ${check_make_command} ${TARGET_NAME}_installcheck_tmp DESTDIR=${tmp_check_folder}
+			DEPENDS tablespace-setup
+			WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+		)
+	endif()
+
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck_tmp tests/tmp)
+	CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+
+# Contrib macros
+macro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_installcheck_tmp PARENT_SCOPE)
+	set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_installcheck PARENT_SCOPE)
+	REGRESS_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(CONTRIB_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_isolation_installcheck_tmp PARENT_SCOPE)
+	set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_isolation_installcheck PARENT_SCOPE)
+	ISOLATION_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(CONTRIB_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+	set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_tap_installcheck_tmp PARENT_SCOPE)
+	set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_tap_installcheck PARENT_SCOPE)
+	TAP_CHECK("${TARGET_NAME}_tap" "${OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+
+
+# Modules macros
+macro(MODULES_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	set(modules_check_targets ${modules_check_targets} ${TARGET_NAME}_installcheck_tmp PARENT_SCOPE)
+	set(modules_installcheck_targets ${modules_installcheck_targets} ${TARGET_NAME}_installcheck PARENT_SCOPE)
+	REGRESS_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(MODULES_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(MODULES_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+	set(modules_check_targets ${modules_check_targets} ${TARGET_NAME}_isolation_installcheck_tmp PARENT_SCOPE)
+	set(modules_installcheck_targets ${modules_installcheck_targets} ${TARGET_NAME}_isolation_installcheck PARENT_SCOPE)
+	ISOLATION_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(MODULES_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(MODULES_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+	set(modules_check_targets ${modules_check_targets} ${TARGET_NAME}_tap_installcheck_tmp PARENT_SCOPE)
+	set(modules_installcheck_targets ${modules_installcheck_targets} ${TARGET_NAME}_tap_installcheck PARENT_SCOPE)
+	TAP_CHECK("${TARGET_NAME}_tap" "${OPTS}" "${REGRESS_FILES}")
+endmacro(MODULES_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
diff --git a/cmake/ReplacePython.cmake b/cmake/ReplacePython.cmake
new file mode 100644
index 0000000000..f7683072f1
--- /dev/null
+++ b/cmake/ReplacePython.cmake
@@ -0,0 +1,79 @@
+macro(replace_python2 input_file output_file)
+	file(READ ${input_file} tmp_string)
+	string(REGEX REPLACE
+		"except \([a-zA-Z\\.]*\), *\([a-zA-Z]*\):"
+		"except \\1 as \\2:"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"<type 'exceptions\\.\([a-zA-Z]*\)'>" "<class '\\1'>"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"<type 'long'>" "<class 'int'>"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([0-9][0-9]*\)L" "\\1"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([ [{]\)u\"" "\\1\""
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"\([ [{]\)u'" "\\1'"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"def next" "def __next__"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"LANGUAGE plpythonu" "LANGUAGE plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"LANGUAGE plpython2u" "LANGUAGE plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION \([^ ]*_\)+plpythonu" "EXTENSION \\1plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION plpythonu" "EXTENSION plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION \([^ ]*_\)+plpython2u" "EXTENSION \\1plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"EXTENSION plpython2u" "EXTENSION plpython3u"
+		tmp_string
+		"${tmp_string}")
+	string(REGEX REPLACE
+		"installing required extension \"plpython2u\""
+		"installing required extension \"plpython3u\""
+		tmp_string
+		"${tmp_string}")
+	file(WRITE ${output_file} "${tmp_string}")
+endmacro()
+
+macro(replace_python_files r_regress_files)
+	file(MAKE_DIRECTORY sql/python3 expected/python3 results/python3)
+	set(adition_clean "")
+	set(regress_files3 "")
+	foreach(rfile ${r_regress_files})
+		replace_python2("sql/${rfile}.sql" "sql/python3/${rfile}.sql")
+		if(rfile STREQUAL "plpython_types")
+			replace_python2("expected/plpython_types_3.out" "expected/python3/${rfile}.out")
+		else()
+			replace_python2("expected/${rfile}.out" "expected/python3/${rfile}.out")
+		endif()
+		set(adition_clean "${adition_clean};sql/python3/${rfile}.sql;expected/python3/${rfile}.out;")
+		set(regress_files3 "${regress_files3};python3/${rfile}")
+	endforeach(rfile)
+	SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${adition_clean}")
+endmacro()
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt
new file mode 100644
index 0000000000..73594ea8f0
--- /dev/null
+++ b/contrib/CMakeLists.txt
@@ -0,0 +1,123 @@
+set(contrib_libs postgres)
+
+#TODO: need test under mingw or cygwin
+if(WIN32)
+	set(contrib_libs
+		pgport
+		pgcommon
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(contrib_libs
+		pgport
+		postgres
+		pgcommon_srv
+	)
+endif()
+
+set(contrib_check_targets "")
+set(contrib_installcheck_targets "")
+
+# Tests
+add_subdirectory(adminpack)
+add_subdirectory(auth_delay)
+add_subdirectory(auto_explain)
+add_subdirectory(btree_gin)
+add_subdirectory(btree_gist)
+add_subdirectory(bloom)
+add_subdirectory(chkpass)
+add_subdirectory(citext)
+add_subdirectory(cube)
+add_subdirectory(dblink)
+add_subdirectory(dict_int)
+add_subdirectory(dict_xsyn)
+add_subdirectory(earthdistance)
+add_subdirectory(file_fdw)
+add_subdirectory(fuzzystrmatch)
+add_subdirectory(hstore)
+if(PERLLIBS_FOUND)
+	add_subdirectory(hstore_plperl)
+endif()
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(hstore_plpython)
+endif()
+add_subdirectory(intarray)
+add_subdirectory(isn)
+add_subdirectory(lo)
+add_subdirectory(ltree)
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(ltree_plpython)
+endif()
+add_subdirectory(oid2name)
+add_subdirectory(pageinspect)
+add_subdirectory(passwordcheck)
+add_subdirectory(pg_buffercache)
+add_subdirectory(pg_freespacemap)
+add_subdirectory(pg_prewarm)
+add_subdirectory(pg_standby)
+add_subdirectory(pg_stat_statements)
+add_subdirectory(pg_trgm)
+add_subdirectory(pg_visibility)
+add_subdirectory(pgcrypto)
+add_subdirectory(pgrowlocks)
+add_subdirectory(pgstattuple)
+add_subdirectory(postgres_fdw)
+add_subdirectory(seg)
+if(SELINUX_LIBRARIES)
+	add_subdirectory(sepgsql)
+endif()
+add_subdirectory(spi)
+if(OPENSSL_FOUND)
+	add_subdirectory(sslinfo)
+endif()
+add_subdirectory(tablefunc)
+add_subdirectory(tcn)
+add_subdirectory(tsearch2)
+add_subdirectory(tsm_system_rows)
+add_subdirectory(tsm_system_time)
+add_subdirectory(unaccent)
+if(WITH_UUID)
+	add_subdirectory(uuid-ossp)
+endif()
+add_subdirectory(vacuumlo)
+if(LIBXML2_FOUND)
+	add_subdirectory(xml2)
+endif()
+
+add_subdirectory(test_decoding)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(contrib_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+		COMMAND DESTDIR=${tmp_check_folder} -j1 ${check_make_command} ${contrib_check_targets}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(contrib_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} ${contrib_check_targets} DESTDIR=${tmp_check_folder}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+# Make chain for run tests in strict order
+# TODO: we can't run tests separately now
+set(first_element "")
+list(GET contrib_installcheck_targets 0 first_element)
+add_custom_target(contrib_installcheck
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+	DEPENDS tablespace-setup ${first_element}
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+set(last_element OFF)
+foreach(loop_var IN ITEMS ${contrib_installcheck_targets})
+	if(last_element)
+		add_dependencies(${last_element} ${loop_var})
+	endif()
+	set(last_element ${loop_var})
+endforeach()
diff --git a/contrib/adminpack/CMakeLists.txt b/contrib/adminpack/CMakeLists.txt
new file mode 100644
index 0000000000..c0cdd5e237
--- /dev/null
+++ b/contrib/adminpack/CMakeLists.txt
@@ -0,0 +1,27 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name adminpack)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
diff --git a/contrib/auth_delay/CMakeLists.txt b/contrib/auth_delay/CMakeLists.txt
new file mode 100644
index 0000000000..89db8151c7
--- /dev/null
+++ b/contrib/auth_delay/CMakeLists.txt
@@ -0,0 +1,27 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+	if(OPENSSL_FOUND)
+		include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	endif()
+endif()
+
+set(extension_name auth_delay)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/auto_explain/CMakeLists.txt b/contrib/auto_explain/CMakeLists.txt
new file mode 100644
index 0000000000..6ac45e9c26
--- /dev/null
+++ b/contrib/auto_explain/CMakeLists.txt
@@ -0,0 +1,18 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name auto_explain)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
diff --git a/contrib/bloom/CMakeLists.txt b/contrib/bloom/CMakeLists.txt
new file mode 100644
index 0000000000..793ce3f79c
--- /dev/null
+++ b/contrib/bloom/CMakeLists.txt
@@ -0,0 +1,38 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name bloom)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	blcost.c
+	blinsert.c
+	blscan.c
+	blutils.c
+	blvacuum.c
+	blvalidate.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "bloom")
+if(PROVE)
+	CONTRIB_TAP_CHECK(${extension_name} "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/contrib/btree_gin/CMakeLists.txt b/contrib/btree_gin/CMakeLists.txt
new file mode 100644
index 0000000000..3a214d48b4
--- /dev/null
+++ b/contrib/btree_gin/CMakeLists.txt
@@ -0,0 +1,47 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name btree_gin)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regres_files
+	install_btree_gin
+	int2
+	int4
+	int8
+	float4
+	float8
+	money
+	oid
+	timestamp
+	timestamptz
+	time
+	timetz
+	date
+	interval
+	macaddr
+	inet
+	cidr
+	text
+	varchar
+	char
+	bytea
+	bit
+	varbit
+	numeric
+)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regres_files}")
diff --git a/contrib/btree_gist/CMakeLists.txt b/contrib/btree_gist/CMakeLists.txt
new file mode 100644
index 0000000000..843cf2c0b5
--- /dev/null
+++ b/contrib/btree_gist/CMakeLists.txt
@@ -0,0 +1,75 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name btree_gist)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	${extension_name}.c
+	btree_utils_num.c
+	btree_utils_var.c
+	btree_int2.c
+	btree_int4.c
+	btree_int8.c
+	btree_float4.c
+	btree_float8.c
+	btree_cash.c
+	btree_oid.c
+	btree_ts.c
+	btree_time.c
+	btree_date.c
+	btree_interval.c
+	btree_macaddr.c
+	btree_inet.c
+	btree_text.c
+	btree_bytea.c
+	btree_bit.c
+	btree_numeric.c
+	btree_uuid.c
+)
+target_link_libraries(${extension_name} ${contrib_libs} ${LIB_M})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+gen_def(${extension_name})
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+set(regres_files
+	init
+	int2
+	int4
+	int8
+	float4
+	float8
+	cash
+	oid
+	timestamp
+	timestamptz
+	time
+	timetz
+	date
+	interval
+	macaddr
+	inet
+	cidr
+	text
+	varchar
+	char
+	bytea
+	bit
+	varbit
+	numeric
+	not_equal
+)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regres_files}")
diff --git a/contrib/chkpass/CMakeLists.txt b/contrib/chkpass/CMakeLists.txt
new file mode 100644
index 0000000000..1265b65d2a
--- /dev/null
+++ b/contrib/chkpass/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name chkpass)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/citext/CMakeLists.txt b/contrib/citext/CMakeLists.txt
new file mode 100644
index 0000000000..4d33eb6a72
--- /dev/null
+++ b/contrib/citext/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name citext)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "citext")
diff --git a/contrib/cube/CMakeLists.txt b/contrib/cube/CMakeLists.txt
new file mode 100644
index 0000000000..b5d1a2b03a
--- /dev/null
+++ b/contrib/cube/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name cube)
+
+bison_target(CUBE_PARSER cubeparse.y ${CMAKE_CURRENT_SOURCE_DIR}/cubeparse.c)
+flex_target(CUBE_SCANNER cubescan.l  ${CMAKE_CURRENT_SOURCE_DIR}/cubescan.c)
+add_flex_bison_dependency(CUBE_SCANNER CUBE_PARSER)
+set_source_files_properties(${BISON_CUBE_PARSER_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${FLEX_CUBE_SCANNER_OUTPUTS})
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	${extension_name}.c
+	${BISON_CUBE_PARSER_OUTPUTS}
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "cube")
diff --git a/contrib/dblink/CMakeLists.txt b/contrib/dblink/CMakeLists.txt
new file mode 100644
index 0000000000..7e6184c7ed
--- /dev/null
+++ b/contrib/dblink/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name dblink)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files paths dblink)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/dict_int/CMakeLists.txt b/contrib/dict_int/CMakeLists.txt
new file mode 100644
index 0000000000..c9fac9d5bf
--- /dev/null
+++ b/contrib/dict_int/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name dict_int)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files dict_int)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/dict_xsyn/CMakeLists.txt b/contrib/dict_xsyn/CMakeLists.txt
new file mode 100644
index 0000000000..a2e26908d9
--- /dev/null
+++ b/contrib/dict_xsyn/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name dict_xsyn)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	xsyn_sample.rules
+	DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regress_files dict_xsyn)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/earthdistance/CMakeLists.txt b/contrib/earthdistance/CMakeLists.txt
new file mode 100644
index 0000000000..c46b122039
--- /dev/null
+++ b/contrib/earthdistance/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name earthdistance)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+	set_target_properties(${extension_name} PROPERTIES C_FLAGS " /fp:precise")
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files earthdistance)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/file_fdw/CMakeLists.txt b/contrib/file_fdw/CMakeLists.txt
new file mode 100644
index 0000000000..8eec7a569a
--- /dev/null
+++ b/contrib/file_fdw/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name file_fdw)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files file_fdw)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/fuzzystrmatch/CMakeLists.txt b/contrib/fuzzystrmatch/CMakeLists.txt
new file mode 100644
index 0000000000..107941c202
--- /dev/null
+++ b/contrib/fuzzystrmatch/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name fuzzystrmatch)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c dmetaphone.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/hstore/CMakeLists.txt b/contrib/hstore/CMakeLists.txt
new file mode 100644
index 0000000000..b75ff4d3ad
--- /dev/null
+++ b/contrib/hstore/CMakeLists.txt
@@ -0,0 +1,38 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name hstore)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	hstore_io.c
+	hstore_op.c
+	hstore_gist.c
+	hstore_gin.c
+	hstore_compat.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	set_target_properties(${extension_name} PROPERTIES LINK_FLAGS -Wl,--out-implib=libmin${extension_name}.dll.a)
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/hstore_plperl/CMakeLists.txt b/contrib/hstore_plperl/CMakeLists.txt
new file mode 100644
index 0000000000..399c1ab021
--- /dev/null
+++ b/contrib/hstore_plperl/CMakeLists.txt
@@ -0,0 +1,38 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plperl"
+	"${PROJECT_SOURCE_DIR}/contrib/hstore"
+	${PERL_INCLUDE_PATH}
+)
+
+if(MINGW)
+	link_directories("${PROJECT_BINARY_DIR}/contrib/hstore")
+endif()
+set(extension_name hstore_plperl)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${PERL_LIBRARY} ${PERL_LDFLAGS})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	target_link_libraries(${extension_name} minhstore)
+	target_compile_definitions(${extension_name} PRIVATE -DPLPERL_HAVE_UID_GID)
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore_plperl)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/hstore_plpython/CMakeLists.txt b/contrib/hstore_plpython/CMakeLists.txt
new file mode 100644
index 0000000000..8e4909829c
--- /dev/null
+++ b/contrib/hstore_plpython/CMakeLists.txt
@@ -0,0 +1,58 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plpython"
+	"${PROJECT_SOURCE_DIR}/contrib/hstore"
+	${PYTHON_INCLUDE_DIRS}
+)
+
+if(MINGW)
+	link_directories(
+		"${PROJECT_BINARY_DIR}/contrib/hstore"
+		"${PROJECT_BINARY_DIR}/src/pl/plpython"
+	)
+endif()
+
+set(extension_name hstore_plpython)
+
+add_library(${extension_name}${PYTHON_VERSION_MAJOR} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} ${contrib_libs} ${PYTHON_LIBRARIES})
+set_target_properties(${extension_name}${PYTHON_VERSION_MAJOR} PROPERTIES PREFIX "")
+target_compile_definitions(${extension_name}${PYTHON_VERSION_MAJOR} PRIVATE -DPLPYTHON_LIBNAME="plpython${PYTHON_VERSION_MAJOR}")
+add_dependencies(${extension_name}${PYTHON_VERSION_MAJOR} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(MINGW)
+	target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} minhstore minplpython${PYTHON_VERSION_MAJOR})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name}${PYTHON_VERSION_MAJOR} contrib)
+endif()
+install(TARGETS ${extension_name}${PYTHON_VERSION_MAJOR}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	${extension_name}2u.control
+	${extension_name}2u--1.0.sql
+	${extension_name}3u.control
+	${extension_name}3u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files hstore_plpython)
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${regress_files}")
+	set(regress_options
+		"--load-extension=hstore"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files3}")
+else()
+	set(regress_options
+		"--load-extension=hstore"
+		"--load-extension=plpythonu"
+		"--load-extension=hstore_plpythonu"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files}")
+endif()
diff --git a/contrib/intarray/CMakeLists.txt b/contrib/intarray/CMakeLists.txt
new file mode 100644
index 0000000000..be696c21c6
--- /dev/null
+++ b/contrib/intarray/CMakeLists.txt
@@ -0,0 +1,36 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name intarray)
+set(extension_lib_name _int)
+
+add_library(${extension_lib_name} ${PLUGIN_TYPE}
+	_int_bool.c
+	_int_gist.c
+	_int_op.c
+	_int_tool.c
+	_intbig_gist.c
+	_int_gin.c
+	_int_selfuncs.c
+)
+target_link_libraries(${extension_lib_name} ${contrib_libs})
+set_target_properties(${extension_lib_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_lib_name} postgres)
+if (MSVC)
+	gen_def(${extension_lib_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_lib_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ${extension_lib_name})
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/isn/CMakeLists.txt b/contrib/isn/CMakeLists.txt
new file mode 100644
index 0000000000..6180d4e955
--- /dev/null
+++ b/contrib/isn/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name isn)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files isn)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/lo/CMakeLists.txt b/contrib/lo/CMakeLists.txt
new file mode 100644
index 0000000000..9f63d58ed5
--- /dev/null
+++ b/contrib/lo/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name lo)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/ltree/CMakeLists.txt b/contrib/ltree/CMakeLists.txt
new file mode 100644
index 0000000000..66f02565e4
--- /dev/null
+++ b/contrib/ltree/CMakeLists.txt
@@ -0,0 +1,37 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name ltree)
+add_definitions(-DLOWER_NODE)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	ltree_io.c
+	ltree_op.c
+	lquery_op.c
+	_ltree_op.c
+	crc32.c
+	ltxtquery_io.c
+	ltxtquery_op.c
+	ltree_gist.c
+	_ltree_gist.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ltree)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/ltree_plpython/CMakeLists.txt b/contrib/ltree_plpython/CMakeLists.txt
new file mode 100644
index 0000000000..a27c6c1bbd
--- /dev/null
+++ b/contrib/ltree_plpython/CMakeLists.txt
@@ -0,0 +1,50 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/pl/plpython"
+	"${PROJECT_SOURCE_DIR}/contrib/ltree"
+	${PYTHON_INCLUDE_DIRS}
+)
+
+set(extension_name ltree_plpython)
+
+add_library(${extension_name}${PYTHON_VERSION_MAJOR} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name}${PYTHON_VERSION_MAJOR} ${contrib_libs} ${PYTHON_LIBRARIES})
+set_target_properties(${extension_name}${PYTHON_VERSION_MAJOR} PROPERTIES PREFIX "")
+add_dependencies(${extension_name}${PYTHON_VERSION_MAJOR} postgres ltree)
+target_compile_definitions(${extension_name}${PYTHON_VERSION_MAJOR} PRIVATE -DPLPYTHON_LIBNAME="plpython${PYTHON_VERSION_MAJOR}")
+if (MSVC)
+	gen_def(${extension_name}${PYTHON_VERSION_MAJOR})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name}${PYTHON_VERSION_MAJOR} contrib)
+endif()
+install(TARGETS ${extension_name}${PYTHON_VERSION_MAJOR}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}u.control
+	${extension_name}u--1.0.sql
+	${extension_name}2u.control
+	${extension_name}2u--1.0.sql
+	${extension_name}3u.control
+	${extension_name}3u--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files ltree_plpython)
+
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${regress_files}")
+	set(regress_options
+		"--load-extension=ltree"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files3}")
+else()
+	set(regress_options
+		"--load-extension=hstore"
+		"--load-extension=plpythonu"
+		"--load-extension=ltree"
+		"--load-extension=ltree_plpythonu"
+	)
+	CONTRIB_REGRESS_CHECK(${extension_name} "${regress_options}" "${regress_files}")
+endif()
diff --git a/contrib/oid2name/CMakeLists.txt b/contrib/oid2name/CMakeLists.txt
new file mode 100644
index 0000000000..f644a49cb6
--- /dev/null
+++ b/contrib/oid2name/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name oid2name)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+
+if(MSVC OR MINGW)
+	target_link_libraries(${extension_name} pgcommon pq)
+endif()
+
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pageinspect/CMakeLists.txt b/contrib/pageinspect/CMakeLists.txt
new file mode 100644
index 0000000000..d6ce1c5217
--- /dev/null
+++ b/contrib/pageinspect/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pageinspect)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	rawpage.c
+	heapfuncs.c
+	btreefuncs.c
+	fsmfuncs.c
+	brinfuncs.c
+	ginfuncs.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.5.sql
+	${extension_name}--1.4--1.5.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/passwordcheck/CMakeLists.txt b/contrib/passwordcheck/CMakeLists.txt
new file mode 100644
index 0000000000..1503cf0baf
--- /dev/null
+++ b/contrib/passwordcheck/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name passwordcheck)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pg_buffercache/CMakeLists.txt b/contrib/pg_buffercache/CMakeLists.txt
new file mode 100644
index 0000000000..8b59418d01
--- /dev/null
+++ b/contrib/pg_buffercache/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_buffercache)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}_pages.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_freespacemap/CMakeLists.txt b/contrib/pg_freespacemap/CMakeLists.txt
new file mode 100644
index 0000000000..1020343783
--- /dev/null
+++ b/contrib/pg_freespacemap/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_freespacemap)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_prewarm/CMakeLists.txt b/contrib/pg_prewarm/CMakeLists.txt
new file mode 100644
index 0000000000..d5fc677f5a
--- /dev/null
+++ b/contrib/pg_prewarm/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_prewarm)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_standby/CMakeLists.txt b/contrib/pg_standby/CMakeLists.txt
new file mode 100644
index 0000000000..f2a406b8c7
--- /dev/null
+++ b/contrib/pg_standby/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_standby)
+
+add_executable(${extension_name} ${extension_name}.c)
+target_link_libraries(${extension_name} pgport pgcommon pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/pg_stat_statements/CMakeLists.txt b/contrib/pg_stat_statements/CMakeLists.txt
new file mode 100644
index 0000000000..b8fa0278eb
--- /dev/null
+++ b/contrib/pg_stat_statements/CMakeLists.txt
@@ -0,0 +1,26 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_stat_statements)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pg_trgm/CMakeLists.txt b/contrib/pg_trgm/CMakeLists.txt
new file mode 100644
index 0000000000..ad8c93c618
--- /dev/null
+++ b/contrib/pg_trgm/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_trgm)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	trgm_op.c
+	trgm_gist.c
+	trgm_gin.c
+	trgm_regexp.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.3.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files pg_trgm pg_word_trgm)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/pg_visibility/CMakeLists.txt b/contrib/pg_visibility/CMakeLists.txt
new file mode 100644
index 0000000000..653e0c4973
--- /dev/null
+++ b/contrib/pg_visibility/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pg_visibility)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pgcrypto/CMakeLists.txt b/contrib/pgcrypto/CMakeLists.txt
new file mode 100644
index 0000000000..a614d475c5
--- /dev/null
+++ b/contrib/pgcrypto/CMakeLists.txt
@@ -0,0 +1,132 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+)
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+set(extension_name pgcrypto)
+
+set(pgcrypto_src
+	pgcrypto.c
+	px.c
+	px-hmac.c
+	px-crypt.c
+	crypt-gensalt.c
+	crypt-blowfish.c
+	crypt-des.c
+	crypt-md5.c
+	mbuf.c
+	pgp.c
+	pgp-armor.c
+	pgp-cfb.c
+	pgp-compress.c
+	pgp-decrypt.c
+	pgp-encrypt.c
+	pgp-info.c
+	pgp-mpi.c
+	pgp-pubdec.c
+	pgp-pubenc.c
+	pgp-pubkey.c
+	pgp-s2k.c
+	pgp-pgsql.c
+)
+
+set(regress_files
+	init
+	md5
+	sha1
+	hmac-md5
+	hmac-sha1
+	blowfish
+	rijndael
+	crypt-des
+	crypt-md5
+	crypt-blowfish
+	crypt-xdes
+	pgp-armor
+	pgp-decrypt
+	pgp-encrypt
+	pgp-pubkey-decrypt
+	pgp-pubkey-encrypt
+	pgp-info
+)
+
+if(OPENSSL_FOUND)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	set(pgcrypto_src ${pgcrypto_src} openssl.c pgp-mpi-openssl.c)
+	set(regress_files ${regress_files}
+		sha2
+		des
+		3des
+		cast5
+	)
+else()
+	add_executable(gen-rtab rijndael.c)
+	target_link_libraries(gen-rtab pgport)
+	target_compile_definitions(gen-rtab PRIVATE -DPRINT_TABS)
+
+	add_custom_command(
+		DEPENDS gen-rtab
+		OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/rijndael.tbl
+		COMMAND gen-rtab > rijndael.tbl
+		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	)
+
+	set(pgcrypto_src ${pgcrypto_src}
+		md5.c
+		sha1.c
+		sha2.c
+		internal.c
+		internal-sha2.c
+		blf.c
+		rijndael.tbl
+		rijndael.c
+		pgp-mpi-internal.c
+		imath.c
+	)
+	set(regress_files ${regress_files} sha2)
+endif()
+
+if(ZLIB_FOUND)
+	set(regress_files ${regress_files} pgp-compression)
+endif()
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${pgcrypto_src})
+target_link_libraries(${extension_name}
+	${contrib_libs}
+)
+if(OPENSSL_FOUND)
+	target_link_libraries(${extension_name} ${OPENSSL_LIBRARIES})
+endif()
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+if(ZLIB_FOUND)
+	target_link_libraries(${extension_name} ${ZLIB_LIBRARIES})
+endif()
+if(WIN32)
+	target_link_libraries(${extension_name} ws2_32)
+endif()
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.3.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/pgrowlocks/CMakeLists.txt b/contrib/pgrowlocks/CMakeLists.txt
new file mode 100644
index 0000000000..d7c9a16edb
--- /dev/null
+++ b/contrib/pgrowlocks/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pgrowlocks)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/pgstattuple/CMakeLists.txt b/contrib/pgstattuple/CMakeLists.txt
new file mode 100644
index 0000000000..217f6f8243
--- /dev/null
+++ b/contrib/pgstattuple/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name pgstattuple)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	${extension_name}.c
+	pgstatindex.c
+	pgstatapprox.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.4.sql
+	${extension_name}--1.4--1.5.sql
+	${extension_name}--1.3--1.4.sql
+	${extension_name}--1.2--1.3.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files pgstattuple)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/postgres_fdw/CMakeLists.txt b/contrib/postgres_fdw/CMakeLists.txt
new file mode 100644
index 0000000000..fd7ef3ec18
--- /dev/null
+++ b/contrib/postgres_fdw/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name postgres_fdw)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	${extension_name}.c
+	option.c
+	deparse.c
+	connection.c
+	shippable.c
+)
+target_link_libraries(${extension_name} ${contrib_libs} pq)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files postgres_fdw)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/seg/CMakeLists.txt b/contrib/seg/CMakeLists.txt
new file mode 100644
index 0000000000..c07a1e6718
--- /dev/null
+++ b/contrib/seg/CMakeLists.txt
@@ -0,0 +1,34 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name seg)
+
+bison_target(CUBE_PARSER segparse.y ${CMAKE_CURRENT_SOURCE_DIR}/segparse.c)
+flex_target(CUBE_SCANNER segscan.l  ${CMAKE_CURRENT_SOURCE_DIR}/segscan.c)
+add_flex_bison_dependency(CUBE_SCANNER CUBE_PARSER)
+set_source_files_properties(${BISON_CUBE_PARSER_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${FLEX_CUBE_SCANNER_OUTPUTS})
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	${extension_name}.c
+	${BISON_CUBE_PARSER_OUTPUTS}
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files seg)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/sepgsql/CMakeLists.txt b/contrib/sepgsql/CMakeLists.txt
new file mode 100644
index 0000000000..4b16b30c14
--- /dev/null
+++ b/contrib/sepgsql/CMakeLists.txt
@@ -0,0 +1,45 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name sepgsql)
+
+set(sepgsql_sql_output
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql.in
+	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	COMMAND sed 's,MODULE_PATHNAME,$$libdir/${extension_name},g' sepgsql.sql.in > ${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	hooks.c
+	selinux.c
+	uavc.c
+	label.c
+	dml.c
+	database.c
+	schema.c
+	relation.c
+	proc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+)
+target_link_libraries(${extension_name} ${contrib_libs} ${SELINUX_LIBRARIES})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${CMAKE_CURRENT_SOURCE_DIR}/sepgsql.sql
+	DESTINATION ${PGSHAREDIR}/contrib)
+
+#set(regress_files seg)
+#CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/spi/CMakeLists.txt b/contrib/spi/CMakeLists.txt
new file mode 100644
index 0000000000..1e95e7c4aa
--- /dev/null
+++ b/contrib/spi/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+
+set(modules_list 
+	autoinc
+	insert_username
+	moddatetime
+	refint
+	timetravel
+)
+
+foreach(loop_var IN ITEMS ${modules_list})
+	add_library(${loop_var} ${PLUGIN_TYPE} ${loop_var}.c)
+	target_compile_definitions(${loop_var} PRIVATE -DREFINT_VERBOSE)
+	target_link_libraries(${loop_var} ${contrib_libs})
+	set_target_properties(${loop_var} PROPERTIES PREFIX "")
+	add_dependencies(${loop_var} postgres)
+	if(MSVC)
+		gen_def(${loop_var})
+	endif()
+	if(NOT PGXS)
+		CMAKE_SET_TARGET_FOLDER(${loop_var} contrib/spi)
+	endif()
+	install(TARGETS ${loop_var}
+			RUNTIME DESTINATION ${PGBINDIR}
+			LIBRARY DESTINATION ${LIBDIR})
+	install(FILES ${loop_var}.control ${loop_var}--1.0.sql ${loop_var}--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+endforeach(loop_var)
diff --git a/contrib/sslinfo/CMakeLists.txt b/contrib/sslinfo/CMakeLists.txt
new file mode 100644
index 0000000000..4fe9796f8f
--- /dev/null
+++ b/contrib/sslinfo/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	${OPENSSL_INCLUDE_DIR}
+)
+
+set(extension_name sslinfo)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${OPENSSL_LIBRARIES})
+if(CRYPT_LIB)
+	target_link_libraries(${extension_name} ${CRYPT_LIB})
+endif()
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.2.sql
+	${extension_name}--1.1--1.2.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/tablefunc/CMakeLists.txt b/contrib/tablefunc/CMakeLists.txt
new file mode 100644
index 0000000000..a324993315
--- /dev/null
+++ b/contrib/tablefunc/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tablefunc)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tablefunc)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tcn/CMakeLists.txt b/contrib/tcn/CMakeLists.txt
new file mode 100644
index 0000000000..6c0f7b05df
--- /dev/null
+++ b/contrib/tcn/CMakeLists.txt
@@ -0,0 +1,21 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tcn)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/test_decoding/CMakeLists.txt b/contrib/test_decoding/CMakeLists.txt
new file mode 100644
index 0000000000..03bb01fa13
--- /dev/null
+++ b/contrib/test_decoding/CMakeLists.txt
@@ -0,0 +1,61 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_decoding)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	test_decoding.c
+)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+set(regerss_checks
+	ddl
+	xact
+	rewrite
+	toast
+	permissions
+	decoding_in_xact
+	decoding_into_rel
+	binary
+	prepared
+	replorigin
+	time
+	messages
+)
+
+set(regress_options
+	--temp-config ${CMAKE_SOURCE_DIR}/contrib/test_decoding/logical.conf
+)
+
+set(isolation_checks
+	mxact
+	delayed_startup
+	ondisk_startup
+	concurrent_ddl_dml
+)
+
+# Don't add tests to installcheck
+REGRESS_CHECK(${extension_name} "${regress_options}" "${regerss_checks}")
+ISOLATION_CHECK(${extension_name} "${regress_options}" "${isolation_checks}")
+set(contrib_check_targets
+	${contrib_check_targets}
+	${extension_name}_installcheck_tmp
+	${extension_name}_isolation_installcheck_tmp
+PARENT_SCOPE)
diff --git a/contrib/tsearch2/CMakeLists.txt b/contrib/tsearch2/CMakeLists.txt
new file mode 100644
index 0000000000..81d9d9d2ff
--- /dev/null
+++ b/contrib/tsearch2/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsearch2)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsearch2)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tsm_system_rows/CMakeLists.txt b/contrib/tsm_system_rows/CMakeLists.txt
new file mode 100644
index 0000000000..5dad7075e8
--- /dev/null
+++ b/contrib/tsm_system_rows/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsm_system_rows)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsm_system_rows)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/tsm_system_time/CMakeLists.txt b/contrib/tsm_system_time/CMakeLists.txt
new file mode 100644
index 0000000000..825847ab78
--- /dev/null
+++ b/contrib/tsm_system_time/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name tsm_system_time)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs} ${LIB_M})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files tsm_system_time)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/unaccent/CMakeLists.txt b/contrib/unaccent/CMakeLists.txt
new file mode 100644
index 0000000000..7f325672d6
--- /dev/null
+++ b/contrib/unaccent/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(extension_name unaccent)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
+target_link_libraries(${extension_name} ${contrib_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	${extension_name}.rules
+	DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regress_files unaccent)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/uuid-ossp/CMakeLists.txt b/contrib/uuid-ossp/CMakeLists.txt
new file mode 100644
index 0000000000..4f38f75723
--- /dev/null
+++ b/contrib/uuid-ossp/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+include_directories(${LIBUUID_INCLUDE_DIRS})
+include_directories("${PROJECT_SOURCE_DIR}/contrib/pgcrypto")
+
+set(extension_name uuid-ossp)
+
+add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c ${UUID_EXTRA_OBJS})
+target_link_libraries(${extension_name} ${contrib_libs} ${LIBUUID_LIBRARIES})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files uuid_ossp)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/contrib/vacuumlo/CMakeLists.txt b/contrib/vacuumlo/CMakeLists.txt
new file mode 100644
index 0000000000..5070bd84a0
--- /dev/null
+++ b/contrib/vacuumlo/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(extension_name vacuumlo)
+
+add_executable(${extension_name} ${extension_name}.c)
+target_link_libraries(${extension_name} pgport pgcommon pq)
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_name} postgres)
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/contrib/xml2/CMakeLists.txt b/contrib/xml2/CMakeLists.txt
new file mode 100644
index 0000000000..14d86aeb6c
--- /dev/null
+++ b/contrib/xml2/CMakeLists.txt
@@ -0,0 +1,40 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include"
+	${LIBXML2_INCLUDE_DIR}
+)
+
+if(LIBXSLT_FOUND)
+	include_directories(BEFORE ${LIBXSLT_INCLUDE_DIR})
+endif()
+
+set(extension_name xml2)
+set(extension_lib_name pgxml)
+
+add_library(${extension_lib_name} ${PLUGIN_TYPE} xpath.c xslt_proc.c)
+target_link_libraries(${extension_lib_name}
+	${contrib_libs}
+	${LIBXML2_LIBRARIES}
+)
+if(LIBXSLT_FOUND)
+	target_link_libraries(${extension_lib_name} ${LIBXSLT_LIBRARIES})
+endif()
+set_target_properties(${extension_lib_name} PROPERTIES PREFIX "")
+add_dependencies(${extension_lib_name} postgres)
+if(MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
+endif()
+install(TARGETS ${extension_lib_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.1.sql
+	${extension_name}--1.0--1.1.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(regress_files xml2)
+CONTRIB_REGRESS_CHECK(${extension_name} "" "${regress_files}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000000..4b950d4ae1
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,91 @@
+include_directories("${PROJECT_SOURCE_DIR}/src/include")
+
+set(gen_errorcodes_depend
+	${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt
+	${PROJECT_SOURCE_DIR}/src/backend/utils/generate-errcodes.pl
+)
+set(gen_errorcodes_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/errcodes.h
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_errorcodes_depend}
+	DEPENDS ${gen_errorcodes_depend}
+	OUTPUT ${gen_errorcodes_output}
+	COMMAND ${PERL_EXECUTABLE} generate-errcodes.pl errcodes.txt > ${gen_errorcodes_output}
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/backend/utils
+)
+
+add_custom_target(gen_errorcodes DEPENDS ${gen_errorcodes_output})
+
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${gen_errorcodes_output})
+
+set(PARSER_SCAN_FLEX_FLAGS, "-Cfe -p -p")
+bison_target(PARSER_GRAM
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.y
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+)
+flex_target(PARSER_SCAN
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.l
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+	${PARSER_SCAN_FLEX_FLAGS}
+)
+
+set_source_files_properties(${BISON_PARSER_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_PARSER_SCAN_OUTPUTS})
+
+add_custom_command(
+	MAIN_DEPENDENCY ${BISON_PARSER_GRAM_OUTPUTS}
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+	COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/src/backend/parser/gram.h ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+)
+
+add_custom_target(generate_parser_gram_h DEPENDS ${PROJECT_SOURCE_DIR}/src/include/parser/gram.h)
+
+add_subdirectory(include)
+add_subdirectory(port)
+add_subdirectory(common)
+add_subdirectory(fe_utils)
+add_subdirectory(interfaces/libpq)
+add_subdirectory(interfaces/ecpg/pgtypeslib)
+add_subdirectory(interfaces/ecpg/ecpglib)
+add_subdirectory(interfaces/ecpg/compatlib)
+add_subdirectory(interfaces/ecpg/include)
+add_subdirectory(interfaces/ecpg/preproc)
+add_subdirectory(interfaces/ecpg/test)
+
+add_subdirectory(backend)
+add_subdirectory(timezone)
+add_subdirectory(test/regress)
+add_subdirectory(test/isolation)
+add_subdirectory(test/modules)
+add_subdirectory(test/recovery)
+add_subdirectory(test/ssl)
+
+add_subdirectory(pl/plpgsql/src)
+if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+	add_subdirectory(pl/plpython)
+endif()
+if(PERLLIBS_FOUND)
+	add_subdirectory(pl/plperl)
+endif()
+if(TCL_FOUND)
+	add_subdirectory(pl/tcl)
+endif()
+
+add_subdirectory(bin/initdb)
+add_subdirectory(bin/pg_archivecleanup)
+add_subdirectory(bin/pg_basebackup)
+add_subdirectory(bin/pg_config)
+add_subdirectory(bin/pg_controldata)
+add_subdirectory(bin/pg_ctl)
+add_subdirectory(bin/pg_dump)
+add_subdirectory(bin/pg_resetxlog)
+add_subdirectory(bin/pg_rewind)
+add_subdirectory(bin/pg_test_fsync)
+add_subdirectory(bin/pg_test_timing)
+add_subdirectory(bin/pg_upgrade)
+add_subdirectory(bin/pg_xlogdump)
+add_subdirectory(bin/pgbench)
+add_subdirectory(bin/psql)
+add_subdirectory(bin/scripts)
diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt
new file mode 100644
index 0000000000..4790e07818
--- /dev/null
+++ b/src/backend/CMakeLists.txt
@@ -0,0 +1,1113 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+set(postgres_include_catalog "${PROJECT_SOURCE_DIR}/src/include/catalog")
+
+set(gen_fmgrtab_depend
+	utils/Gen_fmgrtab.pl
+	${CMAKE_CURRENT_SOURCE_DIR}/catalog/Catalog.pm
+	${postgres_include_catalog}/pg_proc.h
+)
+set(gen_fmgrtab_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/fmgroids.h
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/fmgrtab.c
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_fmgrtab_depend}
+	OUTPUT ${gen_fmgrtab_output}
+	COMMAND ${PERL_EXECUTABLE} -I${CMAKE_CURRENT_SOURCE_DIR}/catalog Gen_fmgrtab.pl ${postgres_include_catalog}/pg_proc.h
+	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/utils/fmgroids.h ${PROJECT_SOURCE_DIR}/src/include/utils/fmgroids.h
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
+)
+
+set(gen_probe_depend
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/Gen_dummy_probes.sed
+	${CMAKE_CURRENT_SOURCE_DIR}/utils/probes.d
+)
+
+set(gen_probe_output
+	${PROJECT_SOURCE_DIR}/src/include/utils/probes.h
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY ${gen_probe_depend}
+	OUTPUT ${gen_probe_output}
+	COMMAND sed -f Gen_dummy_probes.sed probes.d >  ${gen_probe_output}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
+)
+
+flex_target(GUC_SCANNER utils/misc/guc-file.l  ${CMAKE_CURRENT_SOURCE_DIR}/utils/misc/guc-file.c)
+set_source_files_properties(utils/misc/guc.c PROPERTIES OBJECT_DEPENDS ${FLEX_GUC_SCANNER_OUTPUTS})
+
+if(WIN32 OR MINGW)
+	set(dynloader_SRCS port/dynloader/win32.c)
+	set(dynloader_H port/dynloader/win32.h)
+elseif(CYGWIN)
+	set(dynloader_SRCS port/dynloader/cygwin.c)
+	set(dynloader_H port/dynloader/cygwin.h)
+elseif(APPLE)
+	set(dynloader_SRCS port/dynloader/darwin.c)
+	set(dynloader_H port/dynloader/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(dynloader_SRCS port/dynloader/linux.c)
+	set(dynloader_H port/dynloader/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+	set(dynloader_SRCS port/dynloader/hpux.c)
+	set(dynloader_H port/dynloader/hpux.h)
+#TODO: FreeBSD, OpenBSD, NetBSD is equal loader
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+	set(dynloader_SRCS port/dynloader/freebsd.c)
+	set(dynloader_H port/dynloader/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+	set(dynloader_SRCS port/dynloader/openbsd.c)
+	set(dynloader_H port/dynloader/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+	set(dynloader_SRCS port/dynloader/netbsd.c)
+	set(dynloader_H port/dynloader/netbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	set(dynloader_SRCS port/dynloader/solaris.c)
+	set(dynloader_H port/dynloader/solaris.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+	set(dynloader_SRCS port/dynloader/aix.c)
+	set(dynloader_H port/dynloader/aix.h)
+else(WIN32 OR MINGW)
+	message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+add_custom_command(
+	MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${dynloader_H}"
+	OUTPUT "${PROJECT_SOURCE_DIR}/src/include/dynloader.h"
+	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${dynloader_H} ${PROJECT_SOURCE_DIR}/src/include/dynloader.h
+)
+
+#Need for bin/pg_xlogdump
+set(access_rmgrdesc_SRC
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/brindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/clogdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/committsdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/dbasedesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/gindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/gistdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/hashdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/heapdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/mxactdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/nbtdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/relmapdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/replorigindesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/seqdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/smgrdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/spgdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/standbydesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/tblspcdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/xactdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/xlogdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/genericdesc.c
+	${CMAKE_CURRENT_SOURCE_DIR}/access/rmgrdesc/logicalmsgdesc.c
+)
+
+set(rmgrdesc_SRC
+	${access_rmgrdesc_SRC}
+	PARENT_SCOPE
+)
+
+set(access_SRCS
+	${gen_fmgrtab_output}
+	${gen_probe_output}
+	${PROJECT_SOURCE_DIR}/src/include/dynloader.h
+	${access_rmgrdesc_SRC}
+
+	access/brin/brin.c
+	access/brin/brin_pageops.c
+	access/brin/brin_revmap.c
+	access/brin/brin_tuple.c
+	access/brin/brin_xlog.c
+	access/brin/brin_minmax.c
+	access/brin/brin_inclusion.c
+	access/brin/brin_validate.c
+
+	access/common/heaptuple.c
+	access/common/indextuple.c
+	access/common/printtup.c
+	access/common/reloptions.c
+	access/common/scankey.c
+	access/common/tupconvert.c
+	access/common/tupdesc.c
+
+	access/gin/ginutil.c
+	access/gin/gininsert.c
+	access/gin/ginxlog.c
+	access/gin/ginentrypage.c
+	access/gin/gindatapage.c
+	access/gin/ginbtree.c
+	access/gin/ginscan.c
+	access/gin/ginget.c
+	access/gin/ginvacuum.c
+	access/gin/ginarrayproc.c
+	access/gin/ginbulk.c
+	access/gin/ginfast.c
+	access/gin/ginpostinglist.c
+	access/gin/ginlogic.c
+	access/gin/ginvalidate.c
+
+	access/gist/gist.c
+	access/gist/gistutil.c
+	access/gist/gistxlog.c
+	access/gist/gistvacuum.c
+	access/gist/gistget.c
+	access/gist/gistscan.c
+	access/gist/gistproc.c
+	access/gist/gistsplit.c
+	access/gist/gistbuild.c
+	access/gist/gistbuildbuffers.c
+	access/gist/gistvalidate.c
+
+	access/hash/hash.c
+	access/hash/hashfunc.c
+	access/hash/hashinsert.c
+	access/hash/hashovfl.c
+	access/hash/hashpage.c
+	access/hash/hashsearch.c
+	access/hash/hashsort.c
+	access/hash/hashutil.c
+	access/hash/hashvalidate.c
+
+	access/heap/heapam.c
+	access/heap/hio.c
+	access/heap/pruneheap.c
+	access/heap/rewriteheap.c
+	access/heap/syncscan.c
+	access/heap/tuptoaster.c
+	access/heap/visibilitymap.c
+
+	access/index/genam.c
+	access/index/indexam.c
+	access/index/amapi.c
+	access/index/amvalidate.c
+
+	access/nbtree/nbtcompare.c
+	access/nbtree/nbtinsert.c
+	access/nbtree/nbtpage.c
+	access/nbtree/nbtree.c
+	access/nbtree/nbtsearch.c
+	access/nbtree/nbtutils.c
+	access/nbtree/nbtsort.c
+	access/nbtree/nbtxlog.c
+	access/nbtree/nbtvalidate.c
+
+	access/spgist/spgutils.c
+	access/spgist/spginsert.c
+	access/spgist/spgscan.c
+	access/spgist/spgvacuum.c
+	access/spgist/spgdoinsert.c
+	access/spgist/spgxlog.c
+	access/spgist/spgtextproc.c
+	access/spgist/spgquadtreeproc.c
+	access/spgist/spgkdtreeproc.c
+	access/spgist/spgvalidate.c
+
+	access/tablesample/bernoulli.c
+	access/tablesample/system.c
+	access/tablesample/tablesample.c
+
+	access/transam/clog.c
+	access/transam/commit_ts.c
+	access/transam/multixact.c
+	access/transam/generic_xlog.c
+	access/transam/parallel.c
+	access/transam/rmgr.c
+	access/transam/slru.c
+	access/transam/subtrans.c
+	access/transam/timeline.c
+	access/transam/transam.c
+	access/transam/twophase.c
+	access/transam/twophase_rmgr.c
+	access/transam/varsup.c
+	access/transam/xact.c
+	access/transam/xlog.c
+	access/transam/xlogarchive.c
+	access/transam/xlogfuncs.c
+	access/transam/xloginsert.c
+	access/transam/xlogreader.c
+	access/transam/xlogutils.c
+)
+
+bison_target(BOOTSTRAP_PARSER bootstrap/bootparse.y ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/bootparse.c)
+flex_target(BOOTSTRAP_SCANNER bootstrap/bootscanner.l  ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/bootscanner.c)
+add_flex_bison_dependency(BOOTSTRAP_SCANNER BOOTSTRAP_PARSER)
+
+set_source_files_properties(bootstrap/bootparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_BOOTSTRAP_SCANNER_OUTPUTS})
+
+set(bootstrap_SRCS
+	bootstrap/bootstrap.c
+	${BISON_BOOTSTRAP_PARSER_OUTPUTS}
+)
+
+set_source_files_properties(
+	${BISON_BOOTSTRAP_PARSER_OUTPUTS}
+	PROPERTIES GENERATED TRUE
+)
+
+set(POSTGRES_BKI_SRCS
+	${postgres_include_catalog}/pg_proc.h
+	${postgres_include_catalog}/pg_type.h
+	${postgres_include_catalog}/pg_attribute.h
+	${postgres_include_catalog}/pg_class.h
+	${postgres_include_catalog}/pg_attrdef.h
+	${postgres_include_catalog}/pg_constraint.h
+	${postgres_include_catalog}/pg_inherits.h
+	${postgres_include_catalog}/pg_index.h
+	${postgres_include_catalog}/pg_operator.h
+	${postgres_include_catalog}/pg_opfamily.h
+	${postgres_include_catalog}/pg_opclass.h
+	${postgres_include_catalog}/pg_am.h
+	${postgres_include_catalog}/pg_amop.h
+	${postgres_include_catalog}/pg_amproc.h
+	${postgres_include_catalog}/pg_language.h
+	${postgres_include_catalog}/pg_largeobject_metadata.h
+	${postgres_include_catalog}/pg_largeobject.h
+	${postgres_include_catalog}/pg_aggregate.h
+	${postgres_include_catalog}/pg_statistic.h
+	${postgres_include_catalog}/pg_rewrite.h
+	${postgres_include_catalog}/pg_trigger.h
+	${postgres_include_catalog}/pg_event_trigger.h
+	${postgres_include_catalog}/pg_description.h
+	${postgres_include_catalog}/pg_cast.h
+	${postgres_include_catalog}/pg_enum.h
+	${postgres_include_catalog}/pg_namespace.h
+	${postgres_include_catalog}/pg_conversion.h
+	${postgres_include_catalog}/pg_depend.h
+	${postgres_include_catalog}/pg_database.h
+	${postgres_include_catalog}/pg_db_role_setting.h
+	${postgres_include_catalog}/pg_tablespace.h
+	${postgres_include_catalog}/pg_pltemplate.h
+	${postgres_include_catalog}/pg_authid.h
+	${postgres_include_catalog}/pg_auth_members.h
+	${postgres_include_catalog}/pg_shdepend.h
+	${postgres_include_catalog}/pg_shdescription.h
+	${postgres_include_catalog}/pg_ts_config.h
+	${postgres_include_catalog}/pg_ts_config_map.h
+	${postgres_include_catalog}/pg_ts_dict.h
+	${postgres_include_catalog}/pg_ts_parser.h
+	${postgres_include_catalog}/pg_ts_template.h
+	${postgres_include_catalog}/pg_extension.h
+	${postgres_include_catalog}/pg_foreign_data_wrapper.h
+	${postgres_include_catalog}/pg_foreign_server.h
+	${postgres_include_catalog}/pg_user_mapping.h
+	${postgres_include_catalog}/pg_foreign_table.h
+	${postgres_include_catalog}/pg_policy.h
+	${postgres_include_catalog}/pg_replication_origin.h
+	${postgres_include_catalog}/pg_default_acl.h
+	${postgres_include_catalog}/pg_init_privs.h
+	${postgres_include_catalog}/pg_seclabel.h
+	${postgres_include_catalog}/pg_shseclabel.h
+	${postgres_include_catalog}/pg_collation.h
+	${postgres_include_catalog}/pg_partitioned_table.h
+	${postgres_include_catalog}/pg_range.h
+	${postgres_include_catalog}/pg_transform.h
+	${postgres_include_catalog}/pg_sequence.h
+	${postgres_include_catalog}/toasting.h
+	${postgres_include_catalog}/indexing.h
+)
+
+set(catalog_SRCS
+	catalog/catalog.c
+	catalog/dependency.c
+	catalog/heap.c
+	catalog/index.c
+	catalog/indexing.c
+	catalog/namespace.c
+	catalog/aclchk.c
+	catalog/objectaccess.c
+	catalog/objectaddress.c
+	catalog/pg_aggregate.c
+	catalog/pg_collation.c
+	catalog/pg_constraint.c
+	catalog/pg_conversion.c
+	catalog/pg_depend.c
+	catalog/pg_enum.c
+	catalog/pg_inherits.c
+	catalog/pg_largeobject.c
+	catalog/pg_namespace.c
+	catalog/pg_operator.c
+	catalog/pg_proc.c
+	catalog/pg_range.c
+	catalog/pg_db_role_setting.c
+	catalog/pg_shdepend.c
+	catalog/pg_type.c
+	catalog/storage.c
+	catalog/toasting.c
+	catalog/partition.c
+)
+
+set(catalog_include
+	"-I${PROJECT_SOURCE_DIR}/src/backend/catalog"
+	"-I${PROJECT_SOURCE_DIR}/src/include/catalog"
+)
+
+add_custom_command(
+	DEPENDS ${POSTGRES_BKI_SRCS}
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h
+	COMMAND ${PERL_EXECUTABLE} -I${CMAKE_CURRENT_SOURCE_DIR}/catalog genbki.pl ${catalog_include} --set-version=${POSTGRES_MAJOR_VERSION} ${POSTGRES_BKI_SRCS}
+	COMMAND ${CMAKE_COMMAND} -E copy schemapg.h ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/catalog
+)
+
+set_source_files_properties(utils/cache/relcache.c
+	PROPERTIES OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/include/catalog/schemapg.h)
+
+set(commands_SRCS
+	commands/aggregatecmds.c
+	commands/alter.c
+	commands/analyze.c
+	commands/async.c
+	commands/amcmds.c
+	commands/cluster.c
+	commands/comment.c
+	commands/collationcmds.c
+	commands/constraint.c
+	commands/conversioncmds.c
+	commands/copy.c
+	commands/createas.c
+	commands/dbcommands.c
+	commands/define.c
+	commands/discard.c
+	commands/dropcmds.c
+	commands/event_trigger.c
+	commands/explain.c
+	commands/extension.c
+	commands/foreigncmds.c
+	commands/functioncmds.c
+	commands/indexcmds.c
+	commands/lockcmds.c
+	commands/matview.c
+	commands/operatorcmds.c
+	commands/opclasscmds.c
+	commands/policy.c
+	commands/portalcmds.c
+	commands/prepare.c
+	commands/proclang.c
+	commands/schemacmds.c
+	commands/seclabel.c
+	commands/sequence.c
+	commands/tablecmds.c
+	commands/tablespace.c
+	commands/trigger.c
+	commands/tsearchcmds.c
+	commands/typecmds.c
+	commands/user.c
+	commands/vacuum.c
+	commands/vacuumlazy.c
+	commands/variable.c
+	commands/view.c
+)
+
+set(executor_SRCS
+	executor/execAmi.c
+	executor/execCurrent.c
+	executor/execGrouping.c
+	executor/execIndexing.c
+	executor/execJunk.c
+	executor/execMain.c
+	executor/execProcnode.c
+	executor/execParallel.c
+	executor/execQual.c
+	executor/execScan.c
+	executor/execTuples.c
+	executor/execUtils.c
+	executor/functions.c
+	executor/instrument.c
+	executor/tqueue.c
+	executor/nodeAppend.c
+	executor/nodeAgg.c
+	executor/nodeBitmapAnd.c
+	executor/nodeBitmapOr.c
+	executor/nodeBitmapHeapscan.c
+	executor/nodeBitmapIndexscan.c
+	executor/nodeCustom.c
+	executor/nodeHash.c
+	executor/nodeHashjoin.c
+	executor/nodeIndexscan.c
+	executor/nodeIndexonlyscan.c
+	executor/nodeLimit.c
+	executor/nodeLockRows.c
+	executor/nodeMaterial.c
+	executor/nodeMergeAppend.c
+	executor/nodeMergejoin.c
+	executor/nodeModifyTable.c
+	executor/nodeNestloop.c
+	executor/nodeFunctionscan.c
+	executor/nodeRecursiveunion.c
+	executor/nodeResult.c
+	executor/nodeSamplescan.c
+	executor/nodeSeqscan.c
+	executor/nodeSetOp.c
+	executor/nodeSort.c
+	executor/nodeUnique.c
+	executor/nodeValuesscan.c
+	executor/nodeCtescan.c
+	executor/nodeWorktablescan.c
+	executor/nodeGroup.c
+	executor/nodeGather.c
+	executor/nodeSubplan.c
+	executor/nodeSubqueryscan.c
+	executor/nodeTidscan.c
+	executor/nodeForeignscan.c
+	executor/nodeWindowAgg.c
+	executor/tstoreReceiver.c
+	executor/spi.c
+)
+
+set(lib_SRCS
+	lib/binaryheap.c
+	lib/bipartite_match.c
+	lib/hyperloglog.c
+	lib/ilist.c
+	lib/pairingheap.c
+	lib/rbtree.c
+	lib/stringinfo.c
+)
+
+if(OPENSSL_FOUND)
+	set(libpq_ssl_SRCS libpq/be-secure-openssl.c)
+endif(OPENSSL_FOUND)
+
+set(libpq_SRCS
+	libpq/be-fsstubs.c
+	libpq/be-secure.c
+	libpq/auth.c
+	libpq/crypt.c
+	libpq/hba.c
+	libpq/pqcomm.c
+	libpq/pqformat.c
+	libpq/pqmq.c
+	libpq/pqsignal.c
+	libpq/ifaddr.c
+	${libpq_ssl_SRCS}
+)
+
+set(utils_SRCS
+	utils/error/assert.c
+	utils/error/elog.c
+	utils/cache/attoptcache.c
+	utils/cache/catcache.c
+	utils/cache/evtcache.c
+	utils/cache/inval.c
+	utils/cache/plancache.c
+	utils/cache/relcache.c
+	utils/cache/relmapper.c
+	utils/cache/relfilenodemap.c
+	utils/cache/spccache.c
+	utils/cache/syscache.c
+	utils/cache/lsyscache.c
+	utils/cache/typcache.c
+	utils/cache/ts_cache.c
+	utils/mmgr/aset.c
+	utils/mmgr/dsa.c
+	utils/mmgr/mcxt.c
+	utils/mmgr/portalmem.c
+	utils/mmgr/freepage.c
+	utils/adt/acl.c
+	utils/adt/arrayfuncs.c
+	utils/adt/array_expanded.c
+	utils/adt/array_selfuncs.c
+	utils/adt/array_typanalyze.c
+	utils/adt/array_userfuncs.c
+	utils/adt/arrayutils.c
+	utils/adt/ascii.c
+	utils/adt/bool.c
+	utils/adt/cash.c
+	utils/adt/char.c
+	utils/adt/date.c
+	utils/adt/datetime.c
+	utils/adt/datum.c
+	utils/adt/dbsize.c
+	utils/adt/domains.c
+	utils/adt/encode.c
+	utils/adt/enum.c
+	utils/adt/expandeddatum.c
+	utils/adt/float.c
+	utils/adt/format_type.c
+	utils/adt/formatting.c
+	utils/adt/genfile.c
+	utils/adt/geo_ops.c
+	utils/adt/geo_selfuncs.c
+	utils/adt/geo_spgist.c
+	utils/adt/inet_cidr_ntop.c
+	utils/adt/inet_net_pton.c
+	utils/adt/int.c
+	utils/adt/int8.c
+	utils/adt/json.c
+	utils/adt/jsonb.c
+	utils/adt/jsonb_gin.c
+	utils/adt/jsonb_op.c
+	utils/adt/jsonb_util.c
+	utils/adt/jsonfuncs.c
+	utils/adt/like.c
+	#utils/adt/like_match.c
+	utils/adt/lockfuncs.c
+	utils/adt/mac.c
+	utils/adt/misc.c
+	utils/adt/nabstime.c
+	utils/adt/name.c
+	utils/adt/network.c
+	utils/adt/network_gist.c
+	utils/adt/network_selfuncs.c
+	utils/adt/numeric.c
+	utils/adt/numutils.c
+	utils/adt/oid.c
+	utils/adt/oracle_compat.c
+	utils/adt/orderedsetaggs.c
+	utils/adt/pg_locale.c
+	utils/adt/pg_lsn.c
+	utils/adt/pg_upgrade_support.c
+	utils/adt/pgstatfuncs.c
+	utils/adt/pseudotypes.c
+	utils/adt/quote.c
+	utils/adt/rangetypes.c
+	utils/adt/rangetypes_gist.c
+	utils/adt/rangetypes_selfuncs.c
+	utils/adt/rangetypes_spgist.c
+	utils/adt/rangetypes_typanalyze.c
+	utils/adt/regexp.c
+	utils/adt/regproc.c
+	utils/adt/ri_triggers.c
+	utils/adt/rowtypes.c
+	utils/adt/ruleutils.c
+	utils/adt/selfuncs.c
+	utils/adt/tid.c
+	utils/adt/timestamp.c
+	utils/adt/trigfuncs.c
+	utils/adt/tsginidx.c
+	utils/adt/tsgistidx.c
+	utils/adt/tsquery.c
+	utils/adt/tsquery_cleanup.c
+	utils/adt/tsquery_gist.c
+	utils/adt/tsquery_op.c
+	utils/adt/tsquery_rewrite.c
+	utils/adt/tsquery_util.c
+	utils/adt/tsrank.c
+	utils/adt/tsvector.c
+	utils/adt/tsvector_op.c
+	utils/adt/tsvector_parser.c
+	utils/adt/txid.c
+	utils/adt/uuid.c
+	utils/adt/varbit.c
+	utils/adt/varchar.c
+	utils/adt/varlena.c
+	utils/adt/amutils.c
+	utils/adt/version.c
+	utils/adt/windowfuncs.c
+	utils/adt/xid.c
+	utils/adt/xml.c
+	utils/adt/network_spgist.c
+	utils/fmgr/dfmgr.c
+	utils/fmgr/fmgr.c
+	utils/fmgr/funcapi.c
+	utils/hash/dynahash.c
+	utils/hash/hashfn.c
+	utils/hash/pg_crc.c
+	utils/init/globals.c
+	utils/init/miscinit.c
+	utils/init/postinit.c
+	utils/resowner/resowner.c
+	utils/sort/logtape.c
+	utils/sort/sortsupport.c
+	utils/sort/tuplesort.c
+	utils/sort/tuplestore.c
+	utils/time/combocid.c
+	utils/time/tqual.c
+	utils/time/snapmgr.c
+	utils/misc/guc.c
+	utils/misc/help_config.c
+	utils/misc/pg_rusage.c
+	utils/misc/pg_controldata.c
+	utils/misc/pg_config.c
+	utils/misc/ps_status.c
+	utils/misc/rls.c
+	utils/misc/sampling.c
+	utils/misc/superuser.c
+	utils/misc/timeout.c
+	utils/misc/tzparser.c
+	utils/misc/backend_random.c
+	utils/mb/encnames.c
+	utils/mb/conv.c
+	utils/mb/mbutils.c
+	utils/mb/wchar.c
+	utils/mb/wstrcmp.c
+	utils/mb/wstrncmp.c
+)
+
+set(nodes_SRCS
+	nodes/nodeFuncs.c
+	nodes/nodes.c
+	nodes/list.c
+	nodes/bitmapset.c
+	nodes/tidbitmap.c
+	nodes/copyfuncs.c
+	nodes/equalfuncs.c
+	nodes/makefuncs.c
+	nodes/outfuncs.c
+	nodes/readfuncs.c
+	nodes/print.c
+	nodes/read.c
+	nodes/params.c
+	nodes/value.c
+	nodes/extensible.c
+)
+
+set(optimizer_SRCS
+	optimizer/geqo/geqo_copy.c
+	optimizer/geqo/geqo_eval.c
+	optimizer/geqo/geqo_main.c
+	optimizer/geqo/geqo_misc.c
+	optimizer/geqo/geqo_mutation.c
+	optimizer/geqo/geqo_pool.c
+	optimizer/geqo/geqo_random.c
+	optimizer/geqo/geqo_recombination.c
+	optimizer/geqo/geqo_selection.c
+	optimizer/geqo/geqo_erx.c
+	optimizer/geqo/geqo_pmx.c
+	optimizer/geqo/geqo_cx.c
+	optimizer/geqo/geqo_px.c
+	optimizer/geqo/geqo_ox1.c
+	optimizer/geqo/geqo_ox2.c
+	optimizer/path/allpaths.c
+	optimizer/path/clausesel.c
+	optimizer/path/costsize.c
+	optimizer/path/equivclass.c
+	optimizer/path/indxpath.c
+	optimizer/path/joinpath.c
+	optimizer/path/joinrels.c
+	optimizer/path/pathkeys.c
+	optimizer/path/tidpath.c
+	optimizer/plan/analyzejoins.c
+	optimizer/plan/createplan.c
+	optimizer/plan/initsplan.c
+	optimizer/plan/planagg.c
+	optimizer/plan/planmain.c
+	optimizer/plan/planner.c
+	optimizer/plan/setrefs.c
+	optimizer/plan/subselect.c
+	optimizer/prep/prepjointree.c
+	optimizer/prep/prepqual.c
+	optimizer/prep/prepsecurity.c
+	optimizer/prep/preptlist.c
+	optimizer/prep/prepunion.c
+	optimizer/util/clauses.c
+	optimizer/util/joininfo.c
+	optimizer/util/orclauses.c
+	optimizer/util/pathnode.c
+	optimizer/util/placeholder.c
+	optimizer/util/plancat.c
+	optimizer/util/predtest.c
+	optimizer/util/relnode.c
+	optimizer/util/restrictinfo.c
+	optimizer/util/tlist.c
+	optimizer/util/var.c
+)
+
+set(rewrite_SRCS
+	rewrite/rewriteRemove.c
+	rewrite/rewriteDefine.c
+	rewrite/rewriteHandler.c
+	rewrite/rewriteManip.c
+	rewrite/rewriteSupport.c
+	rewrite/rowsecurity.c
+)
+
+set(parser_SRCS
+	parser/analyze.c
+	#parser/gram.c
+	parser/parser.c
+	parser/parse_agg.c
+	parser/parse_clause.c
+	parser/parse_coerce.c
+	parser/parse_collate.c
+	parser/parse_cte.c
+	parser/parse_expr.c
+	parser/parse_func.c
+	parser/parse_node.c
+	parser/parse_oper.c
+	parser/parse_param.c
+	parser/parse_relation.c
+	parser/parse_target.c
+	parser/parse_type.c
+	parser/parse_utilcmd.c
+	parser/scansup.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+)
+
+set_source_files_properties(
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.c
+	${PROJECT_SOURCE_DIR}/src/backend/parser/scan.c
+	PROPERTIES GENERATED TRUE
+)
+
+set(tcop_SRCS
+	tcop/dest.c
+	tcop/fastpath.c
+	tcop/postgres.c
+	tcop/pquery.c
+	tcop/utility.c
+)
+
+set(tsearch_SRCS
+	tsearch/ts_locale.c
+	tsearch/ts_parse.c
+	tsearch/wparser.c
+	tsearch/wparser_def.c
+	tsearch/dict.c
+	tsearch/dict_simple.c
+	tsearch/dict_synonym.c
+	tsearch/dict_thesaurus.c
+	tsearch/dict_ispell.c
+	tsearch/regis.c
+	tsearch/spell.c
+	tsearch/to_tsany.c
+	tsearch/ts_selfuncs.c
+	tsearch/ts_typanalyze.c
+	tsearch/ts_utils.c
+)
+
+install(FILES
+			tsearch/dicts/ispell_sample.dict
+			tsearch/dicts/ispell_sample.affix
+			tsearch/dicts/hunspell_sample.affix
+			tsearch/dicts/hunspell_sample_long.affix
+			tsearch/dicts/hunspell_sample_long.dict
+			tsearch/dicts/hunspell_sample_num.affix
+			tsearch/dicts/hunspell_sample_num.dict
+			tsearch/dicts/synonym_sample.syn
+			tsearch/dicts/thesaurus_sample.ths
+		DESTINATION ${PGSHAREDIR}/tsearch_data)
+
+set(regex_SRCS
+	regex/regcomp.c
+	regex/regerror.c
+	regex/regexec.c
+	regex/regfree.c
+	regex/regprefix.c
+	regex/regexport.c
+)
+
+set(postmaster_SRCS
+	postmaster/autovacuum.c
+	postmaster/bgworker.c
+	postmaster/bgwriter.c
+	postmaster/checkpointer.c
+	postmaster/fork_process.c
+	postmaster/pgarch.c
+	postmaster/pgstat.c
+	postmaster/postmaster.c
+	postmaster/startup.c
+	postmaster/syslogger.c
+	postmaster/walwriter.c
+)
+
+if(WIN32 OR CYGWIN OR MINGW)
+	set(backend_port_win32_SRC
+		port/win32/timer.c
+		port/win32/socket.c
+		port/win32/signal.c
+		# I hope it is not necessary for modern MinGW
+		#port/win32/mingwcompat.c
+		port/win32/crashdump.c
+	)
+	if(NAVE_MINIDUMP_TYPE)
+		set(backend_port_win32_SRC
+			${backend_port_win32_SRC}
+			port/win32/crashdump.c
+		)
+	endif(NAVE_MINIDUMP_TYPE)
+endif()
+
+set(gen_lwlocknames_depend
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/generate-lwlocknames.pl
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.txt
+)
+
+set(gen_lwlocknames_output
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.c
+	${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr/lwlocknames.h
+	${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+)
+
+
+add_custom_command(
+	OUTPUT ${gen_lwlocknames_output}
+	MAIN_DEPENDENCY ${gen_lwlocknames_depend}
+	COMMAND ${PERL_EXECUTABLE} generate-lwlocknames.pl lwlocknames.txt
+	COMMAND ${CMAKE_COMMAND} -E copy lwlocknames.h ${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/backend/storage/lmgr
+)
+
+set(backend_port_SRCS
+	port/atomics.c
+	port/tas/${TAS}
+	${backend_port_win32_SRC}
+	${backend_port_darwin_SRC}
+	${dynloader_SRCS}
+	${SEMA_IMPLEMENTATION}
+	${SHMEM_IMPLEMENTATION}
+)
+
+
+set(storage_SRCS
+	${gen_lwlocknames_output}
+	storage/buffer/buf_table.c
+	storage/buffer/buf_init.c
+	storage/buffer/bufmgr.c
+	storage/buffer/freelist.c
+	storage/buffer/localbuf.c
+	storage/file/fd.c
+	storage/file/buffile.c
+	storage/file/copydir.c
+	storage/file/reinit.c
+	storage/freespace/freespace.c
+	storage/freespace/fsmpage.c
+	storage/freespace/indexfsm.c
+	storage/ipc/dsm_impl.c
+	storage/ipc/dsm.c
+	storage/ipc/ipc.c
+	storage/ipc/ipci.c
+	storage/ipc/pmsignal.c
+	storage/ipc/procarray.c
+	storage/ipc/procsignal.c
+	storage/ipc/shmem.c
+	storage/ipc/shmqueue.c
+	storage/ipc/shm_mq.c
+	storage/ipc/shm_toc.c
+	storage/ipc/sinval.c
+	storage/ipc/sinvaladt.c
+	storage/ipc/standby.c
+	storage/ipc/latch.c
+	storage/large_object/inv_api.c
+	storage/lmgr/lmgr.c # Need some for check s_lock
+	storage/lmgr/lock.c
+	storage/lmgr/proc.c
+	storage/lmgr/deadlock.c
+	storage/lmgr/lwlock.c
+	storage/lmgr/spin.c
+	storage/lmgr/s_lock.c
+	storage/lmgr/predicate.c
+	storage/lmgr/condition_variable.c
+	storage/page/bufpage.c
+	storage/page/checksum.c
+	storage/page/itemptr.c
+	storage/smgr/md.c
+	storage/smgr/smgr.c
+	storage/smgr/smgrtype.c
+)
+
+if(NOT MSVC)
+	set_source_files_properties(storage/page/checksum.c
+		PROPERTIES COMPILE_FLAGS ${CFLAGS_VECTOR})
+endif()
+bison_target(REPL_GRAM
+	replication/repl_gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/repl_gram.c
+)
+flex_target(REPL_SCAN
+	replication/repl_scanner.l
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/repl_scanner.c
+)
+set_source_files_properties(${BISON_REPL_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_REPL_SCAN_OUTPUTS})
+
+bison_target(SYNC_GRAM
+	replication/syncrep_gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/syncrep_gram.c
+)
+flex_target(SYNC_SCAN
+	replication/syncrep_scanner.l
+	${CMAKE_CURRENT_SOURCE_DIR}/replication/syncrep_scanner.c
+)
+set_source_files_properties(${BISON_SYNC_GRAM_OUTPUTS}
+	PROPERTIES OBJECT_DEPENDS ${FLEX_SYNC_SCAN_OUTPUTS})
+
+
+set(replication_SRCS
+	replication/walsender.c
+	replication/walreceiverfuncs.c
+	replication/walreceiver.c
+	replication/basebackup.c
+	replication/slot.c
+	replication/slotfuncs.c
+	replication/syncrep.c
+	replication/logical/decode.c
+	replication/logical/logical.c
+	replication/logical/logicalfuncs.c
+	replication/logical/reorderbuffer.c
+	replication/logical/origin.c
+	replication/logical/snapbuild.c
+	replication/logical/message.c
+	${BISON_REPL_GRAM_OUTPUTS}
+	${BISON_SYNC_GRAM_OUTPUTS}
+)
+
+set(timezone_SRCS
+	${PROJECT_SOURCE_DIR}/src/timezone/localtime.c
+	${PROJECT_SOURCE_DIR}/src/timezone/strftime.c
+	${PROJECT_SOURCE_DIR}/src/timezone/pgtz.c
+)
+
+add_custom_command(
+	OUTPUT "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c"
+	#MAIN_DEPENDENCY gen_qsort_tuple.pl
+	COMMAND ${PERL_EXECUTABLE} "gen_qsort_tuple.pl" > "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils/sort
+)
+
+set_source_files_properties(utils/sort/tuplesort.c
+	PROPERTIES OBJECT_DEPENDS "${PROJECT_SOURCE_DIR}/src/backend/utils/sort/qsort_tuple.c")
+
+set(postgres_SRCS
+	${storage_SRCS}
+	${access_SRCS}
+	${bootstrap_SRCS}
+	${commands_SRCS}
+	${catalog_SRCS}
+	${executor_SRCS}
+	foreign/foreign.c
+	${utils_SRCS}
+	${lib_SRCS}
+	${libpq_SRCS}
+	${nodes_SRCS}
+	${optimizer_SRCS}
+	${rewrite_SRCS}
+	${parser_SRCS}
+	${tcop_SRCS}
+	${tsearch_SRCS}
+	${regex_SRCS}
+	${postmaster_SRCS}
+	${backend_port_SRCS}
+	${replication_SRCS}
+	${timezone_SRCS}
+	main/main.c
+)
+
+if(OPENSSL_FOUND)
+	include_directories(BEFORE	${OPENSSL_INCLUDE_DIR})
+endif()
+if(LIBXML2_FOUND)
+	include_directories(BEFORE	${LIBXML2_INCLUDE_DIR})
+endif()
+#include_directories(BEFORE
+#	${OPENSSL_INCLUDE_DIR}
+#	${LIBXML2_INCLUDE_DIR}
+#)
+
+if(MSVC)
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:${WIN32_STACK_RLIMIT}")
+endif()
+
+if(MINGW OR CYGWIN)
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,${WIN32_STACK_RLIMIT} -Wl,--export-all-symbols")
+endif()
+
+add_executable(postgres
+	${postgres_SRCS}
+)
+
+target_link_libraries(postgres
+	pgcommon_srv
+	pgport_srv
+	pq
+	${READLINE_LIBRARY}
+	${CMAKE_THREAD_LIBS_INIT}
+	${DL_LIBRARIES}
+	${LIB_M}
+	${GSS_LIBS}
+)
+
+if(OPENSSL_FOUND)
+	target_link_libraries(postgres ${OPENSSL_LIBRARIES})
+endif()
+
+if(LIBXML2_FOUND)
+	target_link_libraries(postgres ${LIBXML2_LIBRARIES})
+endif()
+
+if(USE_PAM)
+	target_link_libraries(postgres ${PAM_LIB})
+endif()
+
+if(LDAP_FOUND)
+	target_link_libraries(postgres ${LBER_LIBRARIES})
+endif()
+
+add_dependencies(postgres gen_errorcodes generate_parser_gram_h)
+
+if(UNIX AND NOT APPLE)
+	target_link_libraries(postgres rt)
+endif()
+
+
+target_compile_definitions(postgres PRIVATE -DPG_KRB_SRVTAB="${PG_KRB_SRVTAB}")
+
+if(WIN32)
+	target_compile_definitions(postgres PRIVATE -DBUILDING_DLL -DEXEC_BACKEND)
+endif()
+
+if(MINGW)
+	set_target_properties(postgres PROPERTIES LINK_FLAGS -Wl,--out-implib=libpostgres.dll.a)
+endif()
+
+set_target_properties(postgres PROPERTIES ENABLE_EXPORTS 1)
+set_target_properties(postgres PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
+#Realy need?
+add_custom_target(duplicate_oids
+	COMMAND ${PERL_EXECUTABLE} ./duplicate_oids
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/include/catalog
+)
+
+add_library(pqwalreceiver ${PLUGIN_TYPE}
+	${PROJECT_SOURCE_DIR}/src/include/storage/lwlocknames.h
+	replication/libpqwalreceiver/libpqwalreceiver.c
+	${backend_port_win32_SRC}
+	${backend_port_darwin_SRC}
+)
+
+if(MSVC)
+	gen_def(pqwalreceiver)
+	gen_def(postgres)
+endif()
+
+if(WIN32)
+	target_link_libraries(pqwalreceiver postgres)
+endif()
+
+#Strange logic
+if(MINGW)
+	target_compile_definitions(pqwalreceiver PRIVATE -DBUILDING_DLL)
+endif()
+
+target_link_libraries(pqwalreceiver pq)
+
+install(TARGETS postgres pqwalreceiver
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(FILES
+	catalog/postgres.bki
+	catalog/postgres.description
+	catalog/postgres.shdescription
+	catalog/information_schema.sql
+	catalog/sql_features.txt
+	catalog/system_views.sql
+	libpq/pg_hba.conf.sample
+	libpq/pg_ident.conf.sample
+	utils/misc/postgresql.conf.sample
+DESTINATION ${PGSHAREDIR})
+
+add_subdirectory(utils/mb/conversion_procs)
+add_subdirectory(snowball)
+
+if(ENABLE_NLS)
+	MAKE_MO(postgres "de;es;fr;id;it;ja;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/backend/snowball/CMakeLists.txt b/src/backend/snowball/CMakeLists.txt
new file mode 100644
index 0000000000..d39cac1cb5
--- /dev/null
+++ b/src/backend/snowball/CMakeLists.txt
@@ -0,0 +1,126 @@
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/snowball"
+	"${PROJECT_SOURCE_DIR}/src/include/snowball/libstemmer"
+)
+
+set(snow_languages
+	"danish\;danish"
+	"dutch\;dutch"
+	"english\;english"
+	"finnish\;finnish"
+	"french\;french"
+	"german\;german"
+	"hungarian\;hungarian"
+	"italian\;italian"
+	"norwegian\;norwegian"
+	"portuguese\;portuguese"
+	"romanian\;romanian"
+	"russian\;english"
+	"spanish\;spanish"
+	"swedish\;swedish"
+	"turkish\;turkish"
+)
+
+#Create snowball_create.sql
+file(STRINGS snowball.sql.in snowball_sql_tmpl NEWLINE_CONSUME)
+file(STRINGS snowball_func.sql.in snowball_func_sql_tmpl NEWLINE_CONSUME)
+
+file(WRITE "snowball_create.sql" ${snowball_func_sql_tmpl})
+
+foreach(pair_language ${snow_languages})
+	LIST(GET pair_language 0 lang)
+	LIST(GET pair_language 1 ascii_lang)
+	if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/stopwords/${lang}.stop")
+		set(stopwords ", StopWords=${lang}")
+	else()
+		set(stopwords "")
+	endif()
+	string(REPLACE "_LANGNAME_"
+		"${lang}" out_string
+		"${snowball_sql_tmpl}")
+	string(REPLACE "_DICTNAME_"
+		"${lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_CFGNAME_"
+		"${lang}" out_string
+		"${out_string}")
+	string(REPLACE "_ASCDICTNAME_"
+		"${ascii_lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_NONASCDICTNAME_"
+		"${lang}_stem" out_string
+		"${out_string}")
+	string(REPLACE "_STOPWORDS_"
+		"${stopwords}" out_string
+		"${out_string}")
+	file(APPEND "snowball_create.sql" ${out_string})
+endforeach()
+
+
+set(snowball_SRCS
+	dict_snowball.c
+	libstemmer/api.c
+	libstemmer/utilities.c
+	libstemmer/stem_ISO_8859_1_danish.c
+	libstemmer/stem_ISO_8859_1_dutch.c
+	libstemmer/stem_ISO_8859_1_english.c
+	libstemmer/stem_ISO_8859_1_finnish.c
+	libstemmer/stem_ISO_8859_1_french.c
+	libstemmer/stem_ISO_8859_1_german.c
+	libstemmer/stem_ISO_8859_1_hungarian.c
+	libstemmer/stem_ISO_8859_1_italian.c
+	libstemmer/stem_ISO_8859_1_norwegian.c
+	libstemmer/stem_ISO_8859_1_porter.c
+	libstemmer/stem_ISO_8859_1_portuguese.c
+	libstemmer/stem_ISO_8859_1_spanish.c
+	libstemmer/stem_ISO_8859_1_swedish.c
+	libstemmer/stem_ISO_8859_2_romanian.c
+	libstemmer/stem_KOI8_R_russian.c
+	libstemmer/stem_UTF_8_danish.c
+	libstemmer/stem_UTF_8_dutch.c
+	libstemmer/stem_UTF_8_english.c
+	libstemmer/stem_UTF_8_finnish.c
+	libstemmer/stem_UTF_8_french.c
+	libstemmer/stem_UTF_8_german.c
+	libstemmer/stem_UTF_8_hungarian.c
+	libstemmer/stem_UTF_8_italian.c
+	libstemmer/stem_UTF_8_norwegian.c
+	libstemmer/stem_UTF_8_porter.c
+	libstemmer/stem_UTF_8_portuguese.c
+	libstemmer/stem_UTF_8_romanian.c
+	libstemmer/stem_UTF_8_russian.c
+	libstemmer/stem_UTF_8_spanish.c
+	libstemmer/stem_UTF_8_swedish.c
+	libstemmer/stem_UTF_8_turkish.c
+)
+
+add_library(dict_snowball ${PLUGIN_TYPE} ${snowball_SRCS})
+target_link_libraries(dict_snowball postgres)
+if (MSVC)
+	gen_def(dict_snowball)
+	target_link_libraries(dict_snowball pgcommon pgport)
+endif()
+set_target_properties(dict_snowball PROPERTIES PREFIX "")
+install(TARGETS dict_snowball
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(FILES snowball_create.sql
+		DESTINATION ${PGSHAREDIR})
+
+install(FILES
+		stopwords/danish.stop
+		stopwords/dutch.stop
+		stopwords/english.stop
+		stopwords/finnish.stop
+		stopwords/french.stop
+		stopwords/german.stop
+		stopwords/hungarian.stop
+		stopwords/italian.stop
+		stopwords/norwegian.stop
+		stopwords/portuguese.stop
+		stopwords/russian.stop
+		stopwords/spanish.stop
+		stopwords/swedish.stop
+		stopwords/turkish.stop
+		DESTINATION ${PGSHAREDIR}/tsearch_data)
diff --git a/src/backend/utils/mb/conversion_procs/CMakeLists.txt b/src/backend/utils/mb/conversion_procs/CMakeLists.txt
new file mode 100644
index 0000000000..1ffd417056
--- /dev/null
+++ b/src/backend/utils/mb/conversion_procs/CMakeLists.txt
@@ -0,0 +1,201 @@
+set(procs_list
+	ascii_and_mic
+	cyrillic_and_mic
+	euc_cn_and_mic
+	euc_jp_and_sjis
+	euc_kr_and_mic
+	euc_tw_and_big5
+	latin2_and_win1250
+	latin_and_mic
+	utf8_and_ascii
+	utf8_and_big5
+	utf8_and_cyrillic
+	utf8_and_euc_cn
+	utf8_and_euc_jp
+	utf8_and_euc_kr
+	utf8_and_euc_tw
+	utf8_and_gb18030
+	utf8_and_gbk
+	utf8_and_iso8859
+	utf8_and_iso8859_1
+	utf8_and_johab
+	utf8_and_sjis
+	utf8_and_win
+	utf8_and_uhc
+	utf8_and_euc2004
+	utf8_and_sjis2004
+	euc2004_sjis2004
+)
+
+# conversion_name source_encoding destination_encoding function object
+set(conversions_list
+	"ascii_to_mic\;SQL_ASCII\;MULE_INTERNAL\;ascii_to_mic\;ascii_and_mic"
+	"mic_to_ascii\;MULE_INTERNAL\;SQL_ASCII\;mic_to_ascii\;ascii_and_mic"
+	"koi8_r_to_mic\;KOI8R\;MULE_INTERNAL\;koi8r_to_mic\;cyrillic_and_mic"
+	"mic_to_koi8_r\;MULE_INTERNAL\;KOI8R\;mic_to_koi8r\;cyrillic_and_mic"
+	"iso_8859_5_to_mic\;ISO-8859-5\;MULE_INTERNAL\;iso_to_mic\;cyrillic_and_mic"
+	"mic_to_iso_8859_5\;MULE_INTERNAL\;ISO-8859-5\;mic_to_iso\;cyrillic_and_mic"
+	"windows_1251_to_mic\;WIN1251\;MULE_INTERNAL\;win1251_to_mic\;cyrillic_and_mic"
+	"mic_to_windows_1251\;MULE_INTERNAL\;WIN1251\;mic_to_win1251\;cyrillic_and_mic"
+	"windows_866_to_mic\;WIN866\;MULE_INTERNAL\;win866_to_mic\;cyrillic_and_mic"
+	"mic_to_windows_866\;MULE_INTERNAL\;WIN866\;mic_to_win866\;cyrillic_and_mic"
+	"koi8_r_to_windows_1251\;KOI8R\;WIN1251\;koi8r_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_koi8_r\;WIN1251\;KOI8R\;win1251_to_koi8r\;cyrillic_and_mic"
+	"koi8_r_to_windows_866\;KOI8R\;WIN866\;koi8r_to_win866\;cyrillic_and_mic"
+	"windows_866_to_koi8_r\;WIN866\;KOI8R\;win866_to_koi8r\;cyrillic_and_mic"
+	"windows_866_to_windows_1251\;WIN866\;WIN1251\;win866_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_windows_866\;WIN1251\;WIN866\;win1251_to_win866\;cyrillic_and_mic"
+	"iso_8859_5_to_koi8_r\;ISO-8859-5\;KOI8R\;iso_to_koi8r\;cyrillic_and_mic"
+	"koi8_r_to_iso_8859_5\;KOI8R\;ISO-8859-5\;koi8r_to_iso\;cyrillic_and_mic"
+	"iso_8859_5_to_windows_1251\;ISO-8859-5\;WIN1251\;iso_to_win1251\;cyrillic_and_mic"
+	"windows_1251_to_iso_8859_5\;WIN1251\;ISO-8859-5\;win1251_to_iso\;cyrillic_and_mic"
+	"iso_8859_5_to_windows_866\;ISO-8859-5\;WIN866\;iso_to_win866\;cyrillic_and_mic"
+	"windows_866_to_iso_8859_5\;WIN866\;ISO-8859-5\;win866_to_iso\;cyrillic_and_mic"
+	"euc_cn_to_mic\;EUC_CN\;MULE_INTERNAL\;euc_cn_to_mic\;euc_cn_and_mic"
+	"mic_to_euc_cn\;MULE_INTERNAL\;EUC_CN\;mic_to_euc_cn\;euc_cn_and_mic"
+	"euc_jp_to_sjis\;EUC_JP\;SJIS\;euc_jp_to_sjis\;euc_jp_and_sjis"
+	"sjis_to_euc_jp\;SJIS\;EUC_JP\;sjis_to_euc_jp\;euc_jp_and_sjis"
+	"euc_jp_to_mic\;EUC_JP\;MULE_INTERNAL\;euc_jp_to_mic\;euc_jp_and_sjis"
+	"sjis_to_mic\;SJIS\;MULE_INTERNAL\;sjis_to_mic\;euc_jp_and_sjis"
+	"mic_to_euc_jp\;MULE_INTERNAL\;EUC_JP\;mic_to_euc_jp\;euc_jp_and_sjis"
+	"mic_to_sjis\;MULE_INTERNAL\;SJIS\;mic_to_sjis\;euc_jp_and_sjis"
+	"euc_kr_to_mic\;EUC_KR\;MULE_INTERNAL\;euc_kr_to_mic\;euc_kr_and_mic"
+	"mic_to_euc_kr\;MULE_INTERNAL\;EUC_KR\;mic_to_euc_kr\;euc_kr_and_mic"
+	"euc_tw_to_big5\;EUC_TW\;BIG5\;euc_tw_to_big5\;euc_tw_and_big5"
+	"big5_to_euc_tw\;BIG5\;EUC_TW\;big5_to_euc_tw\;euc_tw_and_big5"
+	"euc_tw_to_mic\;EUC_TW\;MULE_INTERNAL\;euc_tw_to_mic\;euc_tw_and_big5"
+	"big5_to_mic\;BIG5\;MULE_INTERNAL\;big5_to_mic\;euc_tw_and_big5"
+	"mic_to_euc_tw\;MULE_INTERNAL\;EUC_TW\;mic_to_euc_tw\;euc_tw_and_big5"
+	"mic_to_big5\;MULE_INTERNAL\;BIG5\;mic_to_big5\;euc_tw_and_big5"
+	"iso_8859_2_to_mic\;LATIN2\;MULE_INTERNAL\;latin2_to_mic\;latin2_and_win1250"
+	"mic_to_iso_8859_2\;MULE_INTERNAL\;LATIN2\;mic_to_latin2\;latin2_and_win1250"
+	"windows_1250_to_mic\;WIN1250\;MULE_INTERNAL\;win1250_to_mic\;latin2_and_win1250"
+	"mic_to_windows_1250\;MULE_INTERNAL\;WIN1250\;mic_to_win1250\;latin2_and_win1250"
+	"iso_8859_2_to_windows_1250\;LATIN2\;WIN1250\;latin2_to_win1250\;latin2_and_win1250"
+	"windows_1250_to_iso_8859_2\;WIN1250\;LATIN2\;win1250_to_latin2\;latin2_and_win1250"
+	"iso_8859_1_to_mic\;LATIN1\;MULE_INTERNAL\;latin1_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_1\;MULE_INTERNAL\;LATIN1\;mic_to_latin1\;latin_and_mic"
+	"iso_8859_3_to_mic\;LATIN3\;MULE_INTERNAL\;latin3_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_3\;MULE_INTERNAL\;LATIN3\;mic_to_latin3\;latin_and_mic"
+	"iso_8859_4_to_mic\;LATIN4\;MULE_INTERNAL\;latin4_to_mic\;latin_and_mic"
+	"mic_to_iso_8859_4\;MULE_INTERNAL\;LATIN4\;mic_to_latin4\;latin_and_mic"
+	"ascii_to_utf8\;SQL_ASCII\;UTF8\;ascii_to_utf8\;utf8_and_ascii"
+	"utf8_to_ascii\;UTF8\;SQL_ASCII\;utf8_to_ascii\;utf8_and_ascii"
+	"big5_to_utf8\;BIG5\;UTF8\;big5_to_utf8\;utf8_and_big5"
+	"utf8_to_big5\;UTF8\;BIG5\;utf8_to_big5\;utf8_and_big5"
+	"utf8_to_koi8_r\;UTF8\;KOI8R\;utf8_to_koi8r\;utf8_and_cyrillic"
+	"koi8_r_to_utf8\;KOI8R\;UTF8\;koi8r_to_utf8\;utf8_and_cyrillic"
+	"utf8_to_koi8_u\;UTF8\;KOI8U\;utf8_to_koi8u\;utf8_and_cyrillic"
+	"koi8_u_to_utf8\;KOI8U\;UTF8\;koi8u_to_utf8\;utf8_and_cyrillic"
+	"utf8_to_windows_866\;UTF8\;WIN866\;utf8_to_win\;utf8_and_win"
+	"windows_866_to_utf8\;WIN866\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_874\;UTF8\;WIN874\;utf8_to_win\;utf8_and_win"
+	"windows_874_to_utf8\;WIN874\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1250\;UTF8\;WIN1250\;utf8_to_win\;utf8_and_win"
+	"windows_1250_to_utf8\;WIN1250\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1251\;UTF8\;WIN1251\;utf8_to_win\;utf8_and_win"
+	"windows_1251_to_utf8\;WIN1251\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1252\;UTF8\;WIN1252\;utf8_to_win\;utf8_and_win"
+	"windows_1252_to_utf8\;WIN1252\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1253\;UTF8\;WIN1253\;utf8_to_win\;utf8_and_win"
+	"windows_1253_to_utf8\;WIN1253\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1254\;UTF8\;WIN1254\;utf8_to_win\;utf8_and_win"
+	"windows_1254_to_utf8\;WIN1254\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1255\;UTF8\;WIN1255\;utf8_to_win\;utf8_and_win"
+	"windows_1255_to_utf8\;WIN1255\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1256\;UTF8\;WIN1256\;utf8_to_win\;utf8_and_win"
+	"windows_1256_to_utf8\;WIN1256\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1257\;UTF8\;WIN1257\;utf8_to_win\;utf8_and_win"
+	"windows_1257_to_utf8\;WIN1257\;UTF8\;win_to_utf8\;utf8_and_win"
+	"utf8_to_windows_1258\;UTF8\;WIN1258\;utf8_to_win\;utf8_and_win"
+	"windows_1258_to_utf8\;WIN1258\;UTF8\;win_to_utf8\;utf8_and_win"
+	"euc_cn_to_utf8\;EUC_CN\;UTF8\;euc_cn_to_utf8\;utf8_and_euc_cn"
+	"utf8_to_euc_cn\;UTF8\;EUC_CN\;utf8_to_euc_cn\;utf8_and_euc_cn"
+	"euc_jp_to_utf8\;EUC_JP\;UTF8\;euc_jp_to_utf8\;utf8_and_euc_jp"
+	"utf8_to_euc_jp\;UTF8\;EUC_JP\;utf8_to_euc_jp\;utf8_and_euc_jp"
+	"euc_kr_to_utf8\;EUC_KR\;UTF8\;euc_kr_to_utf8\;utf8_and_euc_kr"
+	"utf8_to_euc_kr\;UTF8\;EUC_KR\;utf8_to_euc_kr\;utf8_and_euc_kr"
+	"euc_tw_to_utf8\;EUC_TW\;UTF8\;euc_tw_to_utf8\;utf8_and_euc_tw"
+	"utf8_to_euc_tw\;UTF8\;EUC_TW\;utf8_to_euc_tw\;utf8_and_euc_tw"
+	"gb18030_to_utf8\;GB18030\;UTF8\;gb18030_to_utf8\;utf8_and_gb18030"
+	"utf8_to_gb18030\;UTF8\;GB18030\;utf8_to_gb18030\;utf8_and_gb18030"
+	"gbk_to_utf8\;GBK\;UTF8\;gbk_to_utf8\;utf8_and_gbk"
+	"utf8_to_gbk\;UTF8\;GBK\;utf8_to_gbk\;utf8_and_gbk"
+	"utf8_to_iso_8859_2\;UTF8\;LATIN2\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_2_to_utf8\;LATIN2\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_3\;UTF8\;LATIN3\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_3_to_utf8\;LATIN3\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_4\;UTF8\;LATIN4\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_4_to_utf8\;LATIN4\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_9\;UTF8\;LATIN5\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_9_to_utf8\;LATIN5\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_10\;UTF8\;LATIN6\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_10_to_utf8\;LATIN6\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_13\;UTF8\;LATIN7\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_13_to_utf8\;LATIN7\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_14\;UTF8\;LATIN8\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_14_to_utf8\;LATIN8\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_15\;UTF8\;LATIN9\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_15_to_utf8\;LATIN9\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_16\;UTF8\;LATIN10\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_16_to_utf8\;LATIN10\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_5\;UTF8\;ISO-8859-5\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_5_to_utf8\;ISO-8859-5\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_6\;UTF8\;ISO-8859-6\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_6_to_utf8\;ISO-8859-6\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_7\;UTF8\;ISO-8859-7\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_7_to_utf8\;ISO-8859-7\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"utf8_to_iso_8859_8\;UTF8\;ISO-8859-8\;utf8_to_iso8859\;utf8_and_iso8859"
+	"iso_8859_8_to_utf8\;ISO-8859-8\;UTF8\;iso8859_to_utf8\;utf8_and_iso8859"
+	"iso_8859_1_to_utf8\;LATIN1\;UTF8\;iso8859_1_to_utf8\;utf8_and_iso8859_1"
+	"utf8_to_iso_8859_1\;UTF8\;LATIN1\;utf8_to_iso8859_1\;utf8_and_iso8859_1"
+	"johab_to_utf8\;JOHAB\;UTF8\;johab_to_utf8\;utf8_and_johab"
+	"utf8_to_johab\;UTF8\;JOHAB\;utf8_to_johab\;utf8_and_johab"
+	"sjis_to_utf8\;SJIS\;UTF8\;sjis_to_utf8\;utf8_and_sjis"
+	"utf8_to_sjis\;UTF8\;SJIS\;utf8_to_sjis\;utf8_and_sjis"
+	"uhc_to_utf8\;UHC\;UTF8\;uhc_to_utf8\;utf8_and_uhc"
+	"utf8_to_uhc\;UTF8\;UHC\;utf8_to_uhc\;utf8_and_uhc"
+	"euc_jis_2004_to_utf8\;EUC_JIS_2004\;UTF8\;euc_jis_2004_to_utf8\;utf8_and_euc2004"
+	"utf8_to_euc_jis_2004\;UTF8\;EUC_JIS_2004\;utf8_to_euc_jis_2004\;utf8_and_euc2004"
+	"shift_jis_2004_to_utf8\;SHIFT_JIS_2004\;UTF8\;shift_jis_2004_to_utf8\;utf8_and_sjis2004"
+	"utf8_to_shift_jis_2004\;UTF8\;SHIFT_JIS_2004\;utf8_to_shift_jis_2004\;utf8_and_sjis2004"
+	"euc_jis_2004_to_shift_jis_2004\;EUC_JIS_2004\;SHIFT_JIS_2004\;euc_jis_2004_to_shift_jis_2004\;euc2004_sjis2004"
+	"shift_jis_2004_to_euc_jis_2004\;SHIFT_JIS_2004\;EUC_JIS_2004\;shift_jis_2004_to_euc_jis_2004\;euc2004_sjis2004"
+)
+
+file(WRITE "conversion_create.sql" "")
+foreach(pair_conversion ${conversions_list})
+	LIST(GET pair_conversion 0 con_name)
+	LIST(GET pair_conversion 1 se)
+	LIST(GET pair_conversion 2 de)
+	LIST(GET pair_conversion 3 func)
+	LIST(GET pair_conversion 4 obj)
+	
+	file(APPEND "conversion_create.sql" "-- ${se} --> ${de}\n")
+	file(APPEND "conversion_create.sql" "CREATE OR REPLACE FUNCTION ${func} (INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) RETURNS VOID AS '$libdir/${obj}', '${func}' LANGUAGE C STRICT;\n")
+	file(APPEND "conversion_create.sql" "COMMENT ON FUNCTION ${func}(INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) IS 'internal conversion function for ${se} to ${de}';\n")
+	file(APPEND "conversion_create.sql" "DROP CONVERSION pg_catalog.${con_name};\n")
+	file(APPEND "conversion_create.sql" "CREATE DEFAULT CONVERSION pg_catalog.${con_name} FOR '${se}' TO '${de}' FROM ${func};\n")
+	file(APPEND "conversion_create.sql" "COMMENT ON CONVERSION pg_catalog.${con_name} IS 'conversion for ${se} to ${de}';\n")
+endforeach()
+
+foreach(loop_var IN ITEMS ${procs_list})
+	if(loop_var STREQUAL "euc_tw_and_big5")
+		add_library(${loop_var} ${PLUGIN_TYPE} ${loop_var}/${loop_var}.c ${loop_var}/big5.c)
+	else()
+		add_library(${loop_var} ${PLUGIN_TYPE} ${loop_var}/${loop_var}.c)
+	endif()
+	set_target_properties(${loop_var} PROPERTIES PREFIX "")
+	add_dependencies(${loop_var} gen_errorcodes)
+	target_link_libraries(${loop_var} postgres)
+	if(MSVC)
+		gen_def(${loop_var})
+	endif()
+	CMAKE_SET_TARGET_FOLDER(${loop_var} conversion_procs)
+	install(TARGETS ${loop_var}
+			RUNTIME DESTINATION ${PGBINDIR}
+			LIBRARY DESTINATION ${LIBDIR})
+endforeach(loop_var)
+
+install(FILES conversion_create.sql
+		DESTINATION ${PGSHAREDIR})
diff --git a/src/bin/initdb/CMakeLists.txt b/src/bin/initdb/CMakeLists.txt
new file mode 100644
index 0000000000..b6d51a6f2f
--- /dev/null
+++ b/src/bin/initdb/CMakeLists.txt
@@ -0,0 +1,39 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/timezone"
+)
+
+add_executable(initdb
+	initdb.c
+	findtimezone.c
+	"${PROJECT_SOURCE_DIR}/src/timezone/localtime.c"
+	"${PROJECT_SOURCE_DIR}/src/backend/utils/mb/encnames.c"
+)
+
+target_link_libraries(initdb
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+	${GSS_LIBS}
+)
+
+if(UNIX AND NOT APPLE)
+	target_link_libraries(initdb rt)
+endif()
+
+target_compile_definitions(initdb PRIVATE -DFRONTEND)
+CMAKE_SET_TARGET_FOLDER(initdb bin)
+
+install(TARGETS initdb
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(initdb "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("initdb_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/pg_archivecleanup/CMakeLists.txt b/src/bin/pg_archivecleanup/CMakeLists.txt
new file mode 100644
index 0000000000..4535b4221c
--- /dev/null
+++ b/src/bin/pg_archivecleanup/CMakeLists.txt
@@ -0,0 +1,19 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_archivecleanup pg_archivecleanup.c)
+
+target_link_libraries(pg_archivecleanup
+	pgcommon
+	pgport
+	${M_LIB}
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_archivecleanup bin)
+
+install(TARGETS pg_archivecleanup
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/pg_basebackup/CMakeLists.txt b/src/bin/pg_basebackup/CMakeLists.txt
new file mode 100644
index 0000000000..ddc3a7315e
--- /dev/null
+++ b/src/bin/pg_basebackup/CMakeLists.txt
@@ -0,0 +1,54 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	${ZLIB_INCLUDE_DIRS}
+)
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+
+add_library(common_basebackup STATIC
+	receivelog.c
+	streamutil.c
+	walmethods.c
+)
+
+target_link_libraries(common_basebackup
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+)
+
+set(basebackup_list 
+	pg_basebackup
+	pg_receivexlog
+	pg_recvlogical
+)
+
+foreach(loop_var IN ITEMS ${basebackup_list})
+	add_executable(${loop_var} ${loop_var}.c)
+
+	target_link_libraries(${loop_var}
+		common_basebackup
+		${M_LIB}
+	)
+	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
+	if(ZLIB_FOUND)
+		target_link_libraries(${loop_var} ${ZLIB_LIBRARIES})
+	endif()
+endforeach()
+
+install(TARGETS ${basebackup_list}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_basebackup "de;es;fr;it;ko;pl;pt_BR;ru;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("pg_basebackup_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/pg_config/CMakeLists.txt b/src/bin/pg_config/CMakeLists.txt
new file mode 100644
index 0000000000..69fd3db52d
--- /dev/null
+++ b/src/bin/pg_config/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_config
+	pg_config.c
+)
+
+target_link_libraries(pg_config
+	pgcommon
+	pgport
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_config bin)
+
+install(TARGETS pg_config
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_config "cs;de;es;fr;it;ja;ko;nb;pl;pt_BR;ro;ru;sv;ta;tr;zh_CN;zh_TW")
+endif()
+
+if(PROVE)
+	TAP_CHECK("pg_config_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/pg_controldata/CMakeLists.txt b/src/bin/pg_controldata/CMakeLists.txt
new file mode 100644
index 0000000000..1823fbc596
--- /dev/null
+++ b/src/bin/pg_controldata/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_controldata
+	pg_controldata.c
+)
+
+target_link_libraries(pg_controldata
+	pgcommon
+	pgport
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_controldata bin)
+
+install(TARGETS pg_controldata
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_controldata "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("pg_controldata_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/pg_ctl/CMakeLists.txt b/src/bin/pg_ctl/CMakeLists.txt
new file mode 100644
index 0000000000..a3ea72396a
--- /dev/null
+++ b/src/bin/pg_ctl/CMakeLists.txt
@@ -0,0 +1,29 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_ctl
+	pg_ctl.c
+)
+
+target_link_libraries(pg_ctl
+	pgcommon
+	pgport
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_ctl bin)
+
+install(TARGETS pg_ctl
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_ctl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("pg_ctl_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/pg_dump/CMakeLists.txt b/src/bin/pg_dump/CMakeLists.txt
new file mode 100644
index 0000000000..7aa5a4785c
--- /dev/null
+++ b/src/bin/pg_dump/CMakeLists.txt
@@ -0,0 +1,93 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	${ZLIB_INCLUDE_DIRS}
+)
+
+if(ZLIB_FOUND)
+	include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
+endif()
+
+add_library(libdump STATIC
+	pg_backup_archiver.c
+	pg_backup_db.c
+	pg_backup_custom.c
+	pg_backup_null.c
+	pg_backup_tar.c
+	pg_backup_directory.c
+	pg_backup_utils.c
+	parallel.c
+	compress_io.c
+	dumputils.c
+)
+
+add_executable(pg_dump
+	pg_dump.c
+	common.c
+	pg_dump_sort.c
+)
+
+target_link_libraries(pg_dump
+	libdump
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_dump bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_dump ${ZLIB_LIBRARIES})
+endif()
+
+add_executable(pg_restore
+	pg_restore.c
+)
+
+target_link_libraries(pg_restore
+	libdump
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_restore bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_restore ${ZLIB_LIBRARIES})
+endif()
+
+add_executable(pg_dumpall
+	pg_dumpall.c
+	dumputils.c
+)
+
+target_link_libraries(pg_dumpall
+	libdump
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_dumpall bin)
+
+if(ZLIB_FOUND)
+	target_link_libraries(pg_dumpall ${ZLIB_LIBRARIES})
+endif()
+
+install(TARGETS pg_dump pg_restore pg_dumpall
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_dump "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("pg_dump_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
+
diff --git a/src/bin/pg_resetxlog/CMakeLists.txt b/src/bin/pg_resetxlog/CMakeLists.txt
new file mode 100644
index 0000000000..e4e649ee58
--- /dev/null
+++ b/src/bin/pg_resetxlog/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_resetxlog
+	pg_resetxlog.c
+)
+
+target_link_libraries(pg_resetxlog
+	pgcommon
+	pgport
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_resetxlog bin)
+
+install(TARGETS pg_resetxlog
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_resetxlog "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
diff --git a/src/bin/pg_rewind/CMakeLists.txt b/src/bin/pg_rewind/CMakeLists.txt
new file mode 100644
index 0000000000..2297f2d3c4
--- /dev/null
+++ b/src/bin/pg_rewind/CMakeLists.txt
@@ -0,0 +1,41 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_rewind
+	pg_rewind.c
+	parsexlog.c
+	datapagemap.c
+	timeline.c
+	fetch.c
+	file_ops.c
+	copy_fetch.c
+	libpq_fetch.c
+	filemap.c
+	logging.c
+	${PROJECT_SOURCE_DIR}/src/backend/access/transam/xlogreader.c
+)
+
+target_link_libraries(pg_rewind
+	pgcommon
+	pgport
+	pq
+)
+
+target_compile_definitions(pg_rewind PRIVATE -DFRONTEND)
+
+CMAKE_SET_TARGET_FOLDER(pg_rewind bin)
+
+install(TARGETS pg_rewind
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pg_rewind "de;es;fr;it;ko;pl;ru;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("pg_rewind_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/pg_test_fsync/CMakeLists.txt b/src/bin/pg_test_fsync/CMakeLists.txt
new file mode 100644
index 0000000000..331373973c
--- /dev/null
+++ b/src/bin/pg_test_fsync/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_test_fsync
+	pg_test_fsync.c
+	
+)
+
+target_link_libraries(pg_test_fsync
+	pgcommon
+	pgport
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_test_fsync bin)
+
+install(TARGETS pg_test_fsync
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
diff --git a/src/bin/pg_test_timing/CMakeLists.txt b/src/bin/pg_test_timing/CMakeLists.txt
new file mode 100644
index 0000000000..e800a59a54
--- /dev/null
+++ b/src/bin/pg_test_timing/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_test_timing
+	pg_test_timing.c
+	
+)
+
+target_link_libraries(pg_test_timing
+	pgcommon
+	pgport
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_test_timing bin)
+
+install(TARGETS pg_test_timing
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+
diff --git a/src/bin/pg_upgrade/CMakeLists.txt b/src/bin/pg_upgrade/CMakeLists.txt
new file mode 100644
index 0000000000..b0e30b5381
--- /dev/null
+++ b/src/bin/pg_upgrade/CMakeLists.txt
@@ -0,0 +1,39 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_upgrade
+	check.c
+	controldata.c
+	dump.c
+	exec.c
+	file.c
+	function.c
+	info.c
+	option.c
+	parallel.c
+	pg_upgrade.c
+	relfilenode.c
+	server.c
+	tablespace.c
+	util.c
+	version.c 
+)
+
+target_link_libraries(pg_upgrade
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_upgrade bin)
+
+install(TARGETS pg_upgrade
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+
+
diff --git a/src/bin/pg_xlogdump/CMakeLists.txt b/src/bin/pg_xlogdump/CMakeLists.txt
new file mode 100644
index 0000000000..5d09fe7929
--- /dev/null
+++ b/src/bin/pg_xlogdump/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_xlogdump
+	${PROJECT_SOURCE_DIR}/src/backend/access/transam/xlogreader.c
+	pg_xlogdump.c
+	compat.c
+	rmgrdesc.c
+	${rmgrdesc_SRC}
+)
+
+target_link_libraries(pg_xlogdump
+	pgcommon
+	pgport
+	pq
+)
+
+target_compile_definitions(pg_xlogdump PRIVATE -DFRONTEND)
+
+CMAKE_SET_TARGET_FOLDER(pg_xlogdump bin)
+
+install(TARGETS pg_xlogdump
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/bin/pgbench/CMakeLists.txt b/src/bin/pgbench/CMakeLists.txt
new file mode 100644
index 0000000000..e60b7c7421
--- /dev/null
+++ b/src/bin/pgbench/CMakeLists.txt
@@ -0,0 +1,36 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+bison_target(PGBENCH_PARSER exprparse.y ${PROJECT_SOURCE_DIR}/src/bin/pgbench/exprparse.c)
+flex_target(PGBENCH_SCANNER exprscan.l  ${PROJECT_SOURCE_DIR}/src/bin/pgbench/exprscan.c)
+add_flex_bison_dependency(PGBENCH_SCANNER PGBENCH_PARSER)
+
+set_source_files_properties(exprparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_PGBENCH_SCANNER_OUTPUTS})
+
+add_executable(pgbench
+	pgbench.c
+	${BISON_PGBENCH_PARSER_OUTPUTS}
+)
+
+target_link_libraries(pgbench
+	pgfeutils
+	pgport
+	pq
+	pgcommon
+	${M_LIB}
+)
+
+add_dependencies(pgbench postgres)
+
+CMAKE_SET_TARGET_FOLDER(pgbench bin)
+
+install(TARGETS pgbench
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(PROVE)
+	TAP_CHECK("pgbench_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/bin/psql/CMakeLists.txt b/src/bin/psql/CMakeLists.txt
new file mode 100644
index 0000000000..2db2ac1229
--- /dev/null
+++ b/src/bin/psql/CMakeLists.txt
@@ -0,0 +1,72 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_custom_command(
+	MAIN_DEPENDENCY create_help.pl
+	OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/psql/sql_help.c ${PROJECT_SOURCE_DIR}/src/bin/psql/sql_help.h
+	COMMAND ${PERL_EXECUTABLE} create_help.pl ../../../doc/src/sgml/ref sql_help
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/psql
+)
+
+flex_target(SCANSLASH_SCAN
+	psqlscanslash.l
+	${CMAKE_CURRENT_SOURCE_DIR}/psqlscanslash.c
+)
+
+set(psql_SRCS
+	command.c
+	common.c
+	help.c
+	help.h
+	input.c
+	stringutils.c
+	mainloop.c
+	copy.c
+	copy.h
+	startup.c
+	prompt.c
+	variables.c
+	large_obj.c
+	describe.c
+	tab-complete.c
+	../pg_dump/dumputils.c
+	sql_help.c
+	crosstabview.c
+	${FLEX_SCANSLASH_SCAN_OUTPUTS}
+)
+
+add_executable(psql
+	${psql_SRCS}
+)
+
+target_link_libraries(psql
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+	${READLINE_LIBRARY}
+	${CMAKE_THREAD_LIBS_INIT}
+)
+
+if(OPENSSL_FOUND)
+	target_link_libraries(psql ${OPENSSL_LIBRARIES})
+endif()
+if(NOT MSVC)
+	target_link_libraries(psql m)
+endif()
+
+add_dependencies(psql postgres)
+
+CMAKE_SET_TARGET_FOLDER(psql bin)
+
+install(TARGETS psql
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pslq "cs;de;es;fr;it;ja;pl;pt_BR;ru;zh_CN;zh_TW")
+endif()
+
diff --git a/src/bin/scripts/CMakeLists.txt b/src/bin/scripts/CMakeLists.txt
new file mode 100644
index 0000000000..a7afa3e517
--- /dev/null
+++ b/src/bin/scripts/CMakeLists.txt
@@ -0,0 +1,93 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/bin/psql"
+)
+
+add_library(common_dump STATIC
+	common.c
+	${PROJECT_SOURCE_DIR}/src/bin/pg_dump/dumputils.c
+)
+
+add_library(common_print STATIC
+	common.c
+)
+
+set(common_libs
+	pgfeutils
+	pgcommon
+	pgport
+	pq
+	${LIB_M}
+)
+
+add_executable(createlang
+	createlang.c
+)
+
+target_link_libraries(createlang
+	common_print
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(createlang bin)
+
+add_executable(droplang
+	droplang.c
+)
+
+target_link_libraries(droplang
+	common_print
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(droplang bin)
+
+add_executable(pg_isready
+	pg_isready.c
+	common.c
+)
+
+target_link_libraries(pg_isready
+	${common_libs}
+)
+
+CMAKE_SET_TARGET_FOLDER(pg_isready bin)
+
+set(dump_modules_list 
+	createdb
+	createuser
+	dropdb
+	dropuser
+	clusterdb
+	vacuumdb
+	reindexdb
+)
+
+foreach(loop_var IN ITEMS ${dump_modules_list})
+	add_executable(${loop_var}
+		${loop_var}.c
+		${dump_parser_src}
+	)
+
+	target_link_libraries(${loop_var}
+		common_dump
+		${common_libs}
+	)
+
+	CMAKE_SET_TARGET_FOLDER(${loop_var} bin)
+endforeach()
+
+
+install(TARGETS ${dump_modules_list} createlang droplang pg_isready
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(pgscripts "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;sv;zh_CN")
+endif()
+
+if(PROVE)
+	TAP_CHECK("scripts_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
new file mode 100644
index 0000000000..9338482384
--- /dev/null
+++ b/src/common/CMakeLists.txt
@@ -0,0 +1,49 @@
+set(pgcommon_srv_SRCS
+	exec.c
+	pg_lzcompress.c
+	pgfnames.c
+	psprintf.c
+	relpath.c
+	rmtree.c
+	string.c
+	username.c
+	wait_error.c
+	controldata_utils.c
+	config_info.c
+	keywords.c
+	md5.c
+	ip.c
+)
+
+set(pgcommon_SRCS
+	${pgcommon_srv_SRCS}
+	fe_memutils.c
+	file_utils.c
+	restricted_token.c
+	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+)
+
+add_library(pgcommon_srv STATIC ${pgcommon_srv_SRCS})
+add_library(pgcommon STATIC ${pgcommon_SRCS})
+
+set_source_files_properties(
+	${PROJECT_SOURCE_DIR}/src/include/parser/gram.h
+	PROPERTIES GENERATED TRUE
+)
+
+add_dependencies(pgcommon_srv generate_parser_gram_h)
+add_dependencies(pgcommon_srv gen_errorcodes)
+add_dependencies(pgcommon gen_errorcodes)
+
+target_compile_definitions(pgcommon PRIVATE -DFRONTEND)
+
+target_compile_definitions(pgcommon PRIVATE -DVAL_CPPFLAGS="${CMAKE_CXX_FLAGS}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_CFLAGS="${CMAKE_C_FLAGS} ${COMPILE_DEFINITIONS}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_CC="${CMAKE_C_COMPILER}")
+target_compile_definitions(pgcommon PRIVATE -DVAL_LDFLAGS="${CMAKE_SHARED_LINKER_FLAGS}")
+
+# because port used in shared libraries
+set_property(TARGET pgcommon PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+
+install(TARGETS pgcommon
+		ARCHIVE DESTINATION ${LIBDIR})
diff --git a/src/fe_utils/CMakeLists.txt b/src/fe_utils/CMakeLists.txt
new file mode 100644
index 0000000000..6bf3fd3e35
--- /dev/null
+++ b/src/fe_utils/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/bin/psql"
+)
+
+set(psqlscan_flags, "-Cfe -p -p")
+
+flex_target(psqlscan
+	psqlscan.l
+	"${CMAKE_CURRENT_SOURCE_DIR}/psqlscan.c"
+	${psqlscan_flags}
+)
+
+add_library(pgfeutils STATIC
+	mbprint.c
+	print.c
+	psqlscan.c
+	simple_list.c
+	string_utils.c
+	${FLEX_psqlscan_OUTPUTS}
+)
diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt
new file mode 100644
index 0000000000..c084822505
--- /dev/null
+++ b/src/include/CMakeLists.txt
@@ -0,0 +1,78 @@
+set(INCLUDEDIR_INTERNAL ${PKGINCLUDEDIR}/internal)
+
+# These headers are needed by the public headers of the interfaces.
+install(FILES
+	postgres_ext.h
+	pg_config.h
+	pg_config_ext.h
+	pg_config_os.h
+	pg_config_manual.h
+	DESTINATION ${INCLUDEDIR})
+install(FILES
+	libpq/libpq-fs.h
+	DESTINATION ${INCLUDEDIR}/libpq)
+
+# These headers are needed by the not-so-public headers of the interfaces.
+install(FILES
+	c.h
+	port.h
+	postgres_fe.h
+	DESTINATION ${INCLUDEDIR_INTERNAL})
+install(FILES
+	libpq/pqcomm.h
+	DESTINATION ${INCLUDEDIR_INTERNAL}/libpq)
+
+# These headers are needed for server-side development
+set(SUBDIRS
+	access
+	bootstrap
+	catalog
+	commands
+	common
+	datatype
+	executor
+	foreign
+	lib
+	libpq
+	mb
+	nodes
+	optimizer
+	parser
+	postmaster
+	regex
+	replication
+	rewrite
+	storage
+	tcop
+	snowball
+	tsearch
+	utils
+	port
+	portability
+)
+
+install(FILES
+	c.h
+	dynloader.h
+	fmgr.h
+	funcapi.h
+	getaddrinfo.h
+	getopt_long.h
+	miscadmin.h
+	pg_config_ext.h
+	pg_config.h
+	pg_config_manual.h
+	pg_config_os.h
+	pg_getopt.h
+	pgstat.h
+	pgtar.h
+	pgtime.h
+	pg_trace.h
+	port.h
+	postgres_ext.h
+	postgres_fe.h
+	postgres.h
+	rusagestub.h
+	windowapi.h
+	DESTINATION ${INCLUDEDIRSERVER})
+install(DIRECTORY ${SUBDIRS} DESTINATION ${INCLUDEDIRSERVER})
diff --git a/src/include/pg_config_cmake.in b/src/include/pg_config_cmake.in
new file mode 100644
index 0000000000..1daaff4024
--- /dev/null
+++ b/src/include/pg_config_cmake.in
@@ -0,0 +1,944 @@
+#ifndef AUTO_CONFIG_H
+#define AUTO_CONFIG_H
+
+/* Define to the type of arg 1 of 'accept' */
+#define ACCEPT_TYPE_ARG1 @ACCEPT_TYPE_ARG1@
+
+/* Define to the type of arg 2 of 'accept' */
+#define ACCEPT_TYPE_ARG2 @ACCEPT_TYPE_ARG2@
+
+/* Define to the type of arg 3 of 'accept' */
+#define ACCEPT_TYPE_ARG3 @ACCEPT_TYPE_ARG3@
+
+/* Define to the return type of 'accept' */
+#define ACCEPT_TYPE_RETURN @ACCEPT_TYPE_RETURN@
+
+/* The normal alignment of `double', in bytes. */
+#define ALIGNOF_DOUBLE @ALIGNOF_DOUBLE@
+
+/* The normal alignment of `int', in bytes. */
+#define ALIGNOF_INT @ALIGNOF_INT@
+
+/* The normal alignment of `long', in bytes. */
+#define ALIGNOF_LONG @ALIGNOF_LONG@
+
+/* The normal alignment of `long long int', in bytes. */
+#define ALIGNOF_LONG_LONG_INT @ALIGNOF_LONG_LONG_INT@
+
+/* The normal alignment of `short', in bytes. */
+#define ALIGNOF_SHORT @ALIGNOF_SHORT@
+
+/* Size of a disk block --- this also limits the size of a tuple. You can set
+   it bigger if you need bigger tuples (although TOAST should reduce the need
+   to have large tuples, since fields can be spread across multiple tuples).
+   BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is
+   currently 2^15 (32768). This is determined by the 15-bit widths of the
+   lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h).
+   Changing BLCKSZ requires an initdb. */
+#define BLCKSZ @BLCKSZ@
+
+/* Define to the default TCP port number on which the server listens and to
+   which clients will try to connect. This can be overridden at run-time, but
+   it's convenient if your clients have the right default compiled in.
+   (-DPGPORT=PORTNUM) */
+#define DEF_PGPORT @PGPORT@
+
+/* Define to the default TCP port number as a string constant. */
+#define DEF_PGPORT_STR "@PGPORT@"
+
+/* Define to build with GSSAPI support. */
+#cmakedefine ENABLE_GSS
+
+#cmakedefine ENABLE_NLS
+
+#cmakedefine ENABLE_THREAD_SAFETY 1
+
+/* Define to nothing if C supports flexible array members, and to 1 if it does
+   not. That way, with a declaration like `struct s { int n; double
+   d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99
+   compilers. When computing the size of such an object, don't use 'sizeof
+   (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)'
+   instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with
+   MSVC and with C++ compilers. */
+#define FLEXIBLE_ARRAY_MEMBER @FLEXIBLE_ARRAY_MEMBER@
+
+/* float4 values are passed by value if 'true', by reference if 'false' */
+#define FLOAT4PASSBYVAL @FLOAT4PASSBYVAL@
+
+/* float8, int8, and related values are passed by value if 'true', by
+   reference if 'false' */
+#define FLOAT8PASSBYVAL @FLOAT8PASSBYVAL@
+
+#cmakedefine GETTIMEOFDAY_1ARG
+
+#ifdef GETTIMEOFDAY_1ARG
+#	define gettimeofday(a,b) gettimeofday(a)
+#endif
+
+/* Define if you have the `append_history' function. */
+#cmakedefine HAVE_APPEND_HISTORY
+
+/* Define if you want to use atomics if available. */
+#cmakedefine HAVE_ATOMICS
+
+/* Define to 1 if you have the <atomic.h> header file. */
+#cmakedefine HAVE_ATOMIC_H 1
+
+/* Define if you have the `cbrt' function. */
+#cmakedefine HAVE_CBRT 1
+
+/* Define to 1 if you have the `class' function. */
+#cmakedefine HAVE_CLASS 1
+
+/* Define to 1 if you have the <crtdefs.h> header file. */
+#cmakedefine HAVE_CRTDEFS_H 1
+
+/* Define if you have the `crypt' function. */
+#cmakedefine HAVE_CRYPT
+
+/* Define if you have the <crypt.h> header file. */
+#cmakedefine HAVE_CRYPT_H
+
+/* Define to 1 if you have the declaration of `fdatasync' */
+#cmakedefine HAVE_DECL_FDATASYNC 1
+
+/* Define to 1 if you have the declaration of `F_FULLFSYNC' */
+#cmakedefine HAVE_DECL_F_FULLFSYNC 1
+
+/* Define to 1 if you have the declaration of `posix_fadvise' */
+#cmakedefine HAVE_DECL_POSIX_FADVISE 1
+
+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_SNPRINTF @HAVE_DECL_SNPRINTF@
+
+/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRLCAT @HAVE_DECL_STRLCAT@
+
+/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRLCPY @HAVE_DECL_STRLCPY@
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+   don't. */
+#cmakedefine HAVE_DECL_SYS_SIGLIST 1
+
+/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_VSNPRINTF @HAVE_DECL_VSNPRINTF@
+
+/* Define to 1 if you have the <dld.h> header file. */
+#cmakedefine HAVE_DLD_H
+
+/* Define to 1 if you have the `dlopen' function. */
+#cmakedefine HAVE_DLOPEN 1
+
+/* Define to 1 if you have the <editline/history.h> header file. */
+#cmakedefine HAVE_EDITLINE_HISTORY_H
+
+/* Define to 1 if you have the <editline/readline.h> header file. */
+#cmakedefine HAVE_EDITLINE_READLINE_H
+
+/* Define to 1 if you have the `fdatasync' function. */
+#cmakedefine HAVE_FDATASYNC 1
+
+/* Define to 1 if you have the `fls' function. */
+#cmakedefine HAVE_FLS
+
+/* Define to 1 if you have the `fpclass' function. */
+#cmakedefine HAVE_FPCLASS 1
+
+/* Define to 1 if you have the `fp_class' function. */
+#cmakedefine HAVE_FP_CLASS 1
+
+/* Define to 1 if you have the `fp_class_d' function. */
+#cmakedefine HAVE_FP_CLASS_D 1
+
+/* Define to 1 if you have the <fp_class.h> header file. */
+#cmakedefine HAVE_FP_CLASS_H 1
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#cmakedefine HAVE_FSEEKO 1
+
+/* Define to 1 if your compiler understands __func__. */
+#cmakedefine HAVE_FUNCNAME__FUNC
+
+/* Define to 1 if your compiler understands __FUNCTION__. */
+#cmakedefine HAVE_FUNCNAME__FUNCTION
+
+/* Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int). */
+#cmakedefine HAVE_GCC__ATOMIC_INT32_CAS 1
+
+/* Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).
+   */
+#cmakedefine HAVE_GCC__ATOMIC_INT64_CAS 1
+
+/* Define to 1 if you have __sync_lock_test_and_set(char *) and friends. */
+#cmakedefine HAVE_GCC__SYNC_CHAR_TAS 1
+
+/* Define to 1 if you have __sync_compare_and_swap(int *, int, int). */
+#cmakedefine HAVE_GCC__SYNC_INT32_CAS 1
+
+/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */
+#cmakedefine HAVE_GCC__SYNC_INT32_TAS 1
+
+/* Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64). */
+#cmakedefine HAVE_GCC__SYNC_INT64_CAS 1
+
+/* Define to 1 if you have the `getaddrinfo' function. */
+#cmakedefine HAVE_GETADDRINFO 1
+
+/* Define to 1 if you have the `gethostbyname_r' function. */
+#cmakedefine HAVE_GETHOSTBYNAME_R 1
+
+/* Define to 1 if you have the `getifaddrs' function. */
+#cmakedefine HAVE_GETIFADDRS 1
+
+/* Define to 1 if you have the `getopt' function. */
+#cmakedefine HAVE_GETOPT 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#cmakedefine HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
+#cmakedefine HAVE_GETOPT_LONG 1
+
+/* Define to 1 if you have the `getpeereid' function. */
+#cmakedefine HAVE_GETPEEREID 1
+
+/* Define to 1 if you have the `getpeerucred' function. */
+#cmakedefine HAVE_GETPEERUCRED 1
+
+/* Define to 1 if you have the `getpwuid_r' function. */
+#cmakedefine HAVE_GETPWUID_R 1
+
+/* Define to 1 if you have the `getrlimit' function. */
+#cmakedefine HAVE_GETRLIMIT 1
+
+/* Define to 1 if you have the `getrusage' function. */
+#cmakedefine HAVE_GETRUSAGE 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#cmakedefine HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+#cmakedefine HAVE_GSSAPI_GSSAPI_H 1
+
+/* Define to 1 if you have the <gssapi.h> header file. */
+#cmakedefine HAVE_GSSAPI_H 1
+
+/* Define to 1 if you have the <history.h> header file. */
+#cmakedefine HAVE_HISTORY_H 1
+
+/* Define to 1 if you have the `history_truncate_file' function. */
+#cmakedefine HAVE_HISTORY_TRUNCATE_FILE 1
+
+/* Define to 1 if you have the <ieeefp.h> header file. */
+#cmakedefine HAVE_IEEEFP_H @HAVE_IEEEFP_H@
+
+/* Define to 1 if you have the <ifaddrs.h> header file. */
+#cmakedefine HAVE_IFADDRS_H 1
+
+/* Define to 1 if you have the `inet_aton' function. */
+#cmakedefine HAVE_INET_ATON 1
+
+/* Define to 1 if the system has the type `int64'. */
+#cmakedefine HAVE_INT64 1
+
+/* Define to 1 if the system has the type `int8'. */
+#cmakedefine HAVE_INT8 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `intptr_t'. */
+/*#cmakedefine HAVE_INTPTR_T 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <inttypes.h> header file. */
+/*#cmakedefine HAVE_INTTYPES_H 1*/
+
+/* Define to 1 if you have the global variable 'int opterr'. */
+#cmakedefine HAVE_INT_OPTERR 1
+
+/* Define to 1 if you have the global variable 'int optreset'. */
+#cmakedefine HAVE_INT_OPTRESET 1
+
+/* Define to 1 if you have the global variable 'int timezone'. */
+#cmakedefine HAVE_INT_TIMEZONE 1
+
+/* Define to 1 if you have support for IPv6. */
+#cmakedefine HAVE_IPV6 1
+
+/* Define to 1 if you have isinf(). */
+#cmakedefine HAVE_ISINF 1
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#cmakedefine HAVE_LANGINFO_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <ldap.h> header file. */
+/*#cmakedefine HAVE_LDAP_H 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `crypto' library (-lcrypto). */
+/*#cmakedefine HAVE_LIBCRYPTO 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `ldap' library (-lldap). */
+/*#cmakedefine HAVE_LIBLDAP 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `ldap_r' library (-lldap_r). */
+/*#cmakedefine HAVE_LIBLDAP_R 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `m' library (-lm). */
+/*#cmakedefine HAVE_LIBM*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `pam' library (-lpam). */
+/*#cmakedefine HAVE_LIBPAM 1*/
+
+/* Define if you have a function readline library */
+#cmakedefine HAVE_LIBREADLINE 1
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `selinux' library (-lselinux). */
+/*#cmakedefine HAVE_LIBSELINUX 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `ssl' library (-lssl). */
+/*#cmakedefine HAVE_LIBSSL 1*/
+
+/* TODO BUT NOT NEED:Define to 1 if you have the `wldap32' library (-lwldap32). */
+/*#cmakedefine HAVE_LIBWLDAP32 1*/
+
+/* Define to 1 if you have the `xml2' library (-lxml2). */
+#cmakedefine HAVE_LIBXML2 1
+
+/* Define to 1 if you have the `xslt' library (-lxslt). */
+#cmakedefine HAVE_LIBXSLT 1
+
+/* Define to 1 if you have the `z' library (-lz). */
+#cmakedefine HAVE_LIBZ 1
+
+/* Define to 1 if constants of type 'long long int' should have the suffix LL.
+   */
+#cmakedefine HAVE_LL_CONSTANTS 1
+
+/* Define to 1 if the system has the type `locale_t'. */
+#cmakedefine HAVE_LOCALE_T
+
+/* Define to 1 if `long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_INT_64 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if `long long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_LONG_INT_64 1
+
+/* Define to 1 if you have the <mbarrier.h> header file. */
+#cmakedefine HAVE_MBARRIER_H 1
+
+/* Define to 1 if you have the `mbstowcs_l' function. */
+#cmakedefine HAVE_MBSTOWCS_L 1
+
+/* Define to 1 if you have the `memmove' function. */
+#cmakedefine HAVE_MEMMOVE 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <memory.h> header file. */
+/*#cmakedefine HAVE_MEMORY_H 1*/
+
+/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
+#cmakedefine HAVE_MINIDUMP_TYPE 1
+
+/* Define to 1 if you have the `mkdtemp' function. */
+#cmakedefine HAVE_MKDTEMP 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <netinet/in.h> header file. */
+/*#cmakedefine HAVE_NETINET_IN_H 1*/
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#cmakedefine HAVE_NETINET_TCP_H 1
+
+/* Define to 1 if you have the <net/if.h> header file. */
+#cmakedefine HAVE_NET_IF_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <ossp/uuid.h> header file. */
+/*#cmakedefine HAVE_OSSP_UUID_H 1*/
+
+/* Define to 1 if you have the <pam/pam_appl.h> header file. */
+#cmakedefine HAVE_PAM_PAM_APPL_H 1
+
+/* Define to 1 if you have the `poll' function. */
+#cmakedefine HAVE_POLL 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+#cmakedefine HAVE_POLL_H 1
+
+/* Define to 1 if you have the `posix_fadvise' function. */
+#cmakedefine HAVE_POSIX_FADVISE 1
+
+/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */
+#cmakedefine HAVE_PPC_LWARX_MUTEX_HINT 1
+
+/* Define to 1 if you have the `pstat' function. */
+#cmakedefine HAVE_PSTAT 1
+
+/* Define to 1 if the PS_STRINGS thing exists. */
+#cmakedefine HAVE_PS_STRINGS 1
+
+/* TODO BUT DO NOT NEED:Define if you have POSIX threads libraries and header files. */
+/*#cmakedefine HAVE_PTHREAD 1*/
+
+/* Define to 1 if you have the `pthread_is_threaded_np' function. */
+#cmakedefine HAVE_PTHREAD_IS_THREADED_NP 1
+
+/* TODO BUT DO NOT NEED:Have PTHREAD_PRIO_INHERIT. */
+/*#cmakedefine HAVE_PTHREAD_PRIO_INHERIT 1*/
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#cmakedefine HAVE_PWD_H 1
+
+/* Define to 1 if you have the `random' function. */
+#cmakedefine HAVE_RANDOM 1
+
+/* Define to 1 if you have the <readline.h> header file. */
+#cmakedefine HAVE_READLINE_H 1
+
+/* Define to 1 if you have the <readline/history.h> header file. */
+#cmakedefine HAVE_READLINE_HISTORY_H 1
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#cmakedefine HAVE_READLINE_READLINE_H 1
+
+/* Define to 1 if you have the `readlink' function. */
+#cmakedefine HAVE_READLINK 1
+
+/* Define to 1 if you have the `rint' function. */
+#cmakedefine HAVE_RINT 1
+
+/* Define to 1 if you have the global variable
+   'rl_completion_append_character'. */
+#cmakedefine HAVE_RL_COMPLETION_APPEND_CHARACTER 1
+
+/* Define to 1 if you have the `rl_completion_matches' function. */
+#cmakedefine HAVE_RL_COMPLETION_MATCHES 1
+
+/* Define to 1 if you have the `rl_filename_completion_function' function. */
+#cmakedefine HAVE_RL_FILENAME_COMPLETION_FUNCTION 1
+
+/* Define to 1 if you have the `rl_reset_screen_size' function. */
+#cmakedefine HAVE_RL_RESET_SCREEN_SIZE 1
+
+/* Define to 1 if you have the <security/pam_appl.h> header file. */
+#cmakedefine HAVE_SECURITY_PAM_APPL_H 1
+
+/* Define to 1 if you have the `setproctitle' function. */
+#cmakedefine HAVE_SETPROCTITLE 1
+
+/* Define to 1 if you have the `setsid' function. */
+#cmakedefine HAVE_SETSID 1
+
+/* Define to 1 if you have the `shm_open' function. */
+#cmakedefine HAVE_SHM_OPEN 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `snprintf' function. */
+/*#cmakedefine HAVE_SNPRINTF 1*/
+
+/* Define to 1 if you have spinlocks. */
+#cmakedefine HAVE_SPINLOCKS 1
+
+/* Define to 1 if you have the `srandom' function. */
+#cmakedefine HAVE_SRANDOM 1
+
+/* Define to 1 if you have the `SSL_get_current_compression' function. */
+#cmakedefine HAVE_SSL_GET_CURRENT_COMPRESSION 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <stdlib.h> header file. */
+/*#cmakedefine HAVE_STDLIB_H 1*/
+
+/* Define to 1 if you have the `strerror' function. */
+#cmakedefine HAVE_STRERROR 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `strlcat' function. */
+/*#cmakedefine HAVE_STRLCAT 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `strlcpy' function. */
+/*#cmakedefine HAVE_STRLCPY 1*/
+
+/* Define to use have a strong random number source */
+#cmakedefine HAVE_STRONG_RANDOM 1
+
+/* Define to 1 if you have the `strtoll' function. */
+#cmakedefine HAVE_STRTOLL 1
+
+/* Define to 1 if you have the `strtoq' function. */
+#cmakedefine HAVE_STRTOQ 1
+
+/* Define to 1 if you have the `strtoull' function. */
+#cmakedefine HAVE_STRTOULL 1
+
+/* Define to 1 if you have the `strtouq' function. */
+#cmakedefine HAVE_STRTOUQ 1
+
+/* Define to 1 if the system has the type `struct addrinfo'. */
+#cmakedefine HAVE_STRUCT_ADDRINFO 1
+
+/* Define to 1 if the system has the type `struct cmsgcred'. */
+#cmakedefine HAVE_STRUCT_CMSGCRED 1
+
+/* Define to 1 if the system has the type `struct option'. */
+#cmakedefine HAVE_STRUCT_OPTION 1
+
+/* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
+
+/* Define to 1 if the system has the type `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE 1
+
+/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
+
+/* Define to 1 if `ss_len' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
+
+/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY 1
+
+/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#cmakedefine HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define to 1 if you have the `symlink' function. */
+#cmakedefine HAVE_SYMLINK 1
+
+/* Define to 1 if you have the `sync_file_range' function. */
+#cmakedefine HAVE_SYNC_FILE_RANGE 1
+
+/* Define to 1 if you have the syslog interface. */
+#cmakedefine HAVE_SYSLOG 1
+
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#cmakedefine HAVE_SYS_EPOLL_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/ipc.h> header file. */
+#cmakedefine HAVE_SYS_IPC_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#cmakedefine HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/pstat.h> header file. */
+#cmakedefine HAVE_SYS_PSTAT_H 1
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#cmakedefine HAVE_SYS_RESOURCE_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#cmakedefine HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/sem.h> header file. */
+#cmakedefine HAVE_SYS_SEM_H 1
+
+/* Define to 1 if you have the <sys/shm.h> header file. */
+#cmakedefine HAVE_SYS_SHM_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#cmakedefine HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+#cmakedefine HAVE_SYS_SOCKIO_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/tas.h> header file. */
+#cmakedefine HAVE_SYS_TAS_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#cmakedefine HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/ucred.h> header file. */
+#cmakedefine HAVE_SYS_UCRED_H 1
+
+/* Define to 1 if you have the <sys/un.h> header file. */
+#cmakedefine HAVE_SYS_UN_H 1
+
+/* Define to 1 if you have the <termios.h> header file. */
+#cmakedefine HAVE_TERMIOS_H 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#cmakedefine HAVE_TM_ZONE 1
+
+/* Define to 1 if you have the `towlower' function. */
+#cmakedefine HAVE_TOWLOWER 1
+
+/* Define to 1 if you have the external array `tzname'. */
+#cmakedefine HAVE_TZNAME 1
+
+/* Define to 1 if you have the <ucred.h> header file. */
+#cmakedefine HAVE_UCRED_H 1
+
+/* Define to 1 if the system has the type `uint64'. */
+#cmakedefine HAVE_UINT64 1
+
+/* Define to 1 if the system has the type `uint8'. */
+#cmakedefine HAVE_UINT8 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `uintptr_t'. */
+/*#cmakedefine HAVE_UINTPTR_T 1*/
+
+/* Define to 1 if the system has the type `union semun'. */
+#cmakedefine HAVE_UNION_SEMUN 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/* Define to 1 if you have unix sockets. */
+#cmakedefine HAVE_UNIX_SOCKETS 1
+
+/* Define to 1 if you have the `unsetenv' function. */
+#cmakedefine HAVE_UNSETENV 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if the system has the type `unsigned long long int'. */
+/*#cmakedefine HAVE_UNSIGNED_LONG_LONG_INT 1*/
+
+/* Define to 1 if you have the `utime' function. */
+#cmakedefine HAVE_UTIME 1
+
+/* Define to 1 if you have the `utimes' function. */
+#cmakedefine HAVE_UTIMES 1
+
+/* Define to 1 if you have the <utime.h> header file. */
+#cmakedefine HAVE_UTIME_H 1
+
+/* Define to 1 if you have BSD UUID support. */
+#cmakedefine HAVE_UUID_BSD 1
+
+/* Define to 1 if you have E2FS UUID support. */
+#cmakedefine HAVE_UUID_E2FS 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <uuid.h> header file. */
+/*#cmakedefine HAVE_UUID_H 1*/
+
+/* Define to 1 if you have OSSP UUID support. */
+#cmakedefine HAVE_UUID_OSSP 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the <uuid/uuid.h> header file. */
+/*#cmakedefine HAVE_UUID_UUID_H 1*/
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the `vsnprintf' function. */
+/*#cmakedefine HAVE_VSNPRINTF 1*/
+
+/* Define to 1 if you have the <wchar.h> header file. */
+#cmakedefine HAVE_WCHAR_H 1
+
+/* Define to 1 if you have the `wcstombs' function. */
+#cmakedefine HAVE_WCSTOMBS 1
+
+/* Define to 1 if you have the `wcstombs_l' function. */
+#cmakedefine HAVE_WCSTOMBS_L 1
+
+/* Define to 1 if you have the <wctype.h> header file. */
+#cmakedefine HAVE_WCTYPE_H 1
+
+/* Define to 1 if you have the <winldap.h> header file. */
+#cmakedefine HAVE_WINLDAP_H 1
+
+/* Define to 1 if your compiler understands __builtin_bswap32. */
+#cmakedefine HAVE__BUILTIN_BSWAP32 1
+
+/* Define to 1 if your compiler understands __builtin_bswap64. */
+#cmakedefine HAVE__BUILTIN_BSWAP64 1
+
+/* Define to 1 if your compiler understands __builtin_constant_p. */
+#cmakedefine HAVE__BUILTIN_CONSTANT_P 1
+
+/* Define to 1 if your compiler understands __builtin_types_compatible_p. */
+#cmakedefine HAVE__BUILTIN_TYPES_COMPATIBLE_P 1
+
+/* Define to 1 if your compiler understands __builtin_unreachable. */
+#cmakedefine HAVE__BUILTIN_UNREACHABLE 1
+
+/* Define to 1 if you have __cpuid. */
+#cmakedefine HAVE__CPUID 1
+
+/* Define to 1 if you have __cpuid. */
+#cmakedefine HAVE__GET_CPUID 1
+
+/* Define to 1 if your compiler understands _Static_assert. */
+#cmakedefine HAVE__STATIC_ASSERT 1
+
+/* Define to 1 if your compiler understands __VA_ARGS__ in macros. */
+#cmakedefine HAVE__VA_ARGS 1
+
+/* Define to the appropriate snprintf length modifier for 64-bit ints. */
+#define INT64_MODIFIER "@LONG_LONG_INT_MODIFIER@"
+
+/* Define to 1 if `locale_t' requires <xlocale.h>. */
+#cmakedefine LOCALE_T_IN_XLOCALE 1
+
+/* Define as the maximum alignment requirement of any C data type. */
+#define MAXIMUM_ALIGNOF @MAXIMUM_ALIGNOF@
+
+/* Define bytes to use libc memset(). */
+#define MEMSET_LOOP_LIMIT @MEMSET_LOOP_LIMIT@
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
+
+/* TODO BUT DO NOT NEED:Define to the full name of this package. */
+/*#define PACKAGE_NAME "@PACKAGE_NAME@"*/
+
+/* TODO:Define to the full name and version of this package. */
+/*#define PACKAGE_STRING "@PACKAGE_STRING@"*/
+
+/* TODO BUT DO NOT NEED:Define to the one symbol short name of this package. */
+/*#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"*/
+
+/* TODO BUT DO NOT NEED:Define to the home page for this package. */
+/*#define PACKAGE_URL "@PACKAGE_URL@"*/
+
+/* TODO BUT DO NOT NEED:Define to the version of this package. */
+/*#define PACKAGE_VERSION "@PACKAGE_VERSION@"*/
+
+/* Define to the name of a signed 128-bit integer type. */
+#define PG_INT128_TYPE @PG_INT128_TYPE@
+
+/* Define to the name of a signed 64-bit integer type. */
+#define PG_INT64_TYPE @PG_INT64_TYPE@
+
+/* Define to the name of the default PostgreSQL service principal in Kerberos
+   (GSSAPI). */
+#define PG_KRB_SRVNAM "@PG_KRB_SRVNAM@"
+
+/* PostgreSQL major version as a string */
+#define PG_MAJORVERSION "@POSTGRES_MAJOR_VERSION@"
+
+/* Define to gnu_printf if compiler supports it, else printf. */
+#define PG_PRINTF_ATTRIBUTE @PG_PRINTF_ATTRIBUTE@
+
+/* PostgreSQL version as a string */
+#define PG_VERSION "@PG_VERSION@"
+
+/* PostgreSQL version as a number */
+#define PG_VERSION_NUM @PG_VERSION_NUM@
+
+/* A string containing the version number, platform, and C compiler */
+#define PG_VERSION_STR "PostgreSQL @PG_VERSION@ on @CMAKE_SYSTEM_NAME@, compiled by @CMAKE_C_COMPILER_ID@, @VOID_POINTER_SIZE_BIT@-bit"
+
+/* Define to 1 to allow profiling output to be saved separately for each
+   process. */
+#cmakedefine PROFILE_PID_DIR 1
+
+/* TODO BUT DO NOT NEED:Define to necessary symbol if this constant uses a non-standard name on
+   your system. */
+/*#cmakedefine PTHREAD_CREATE_JOINABLE*/
+
+/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus,
+   the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger
+   than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be
+   less than your OS' limit on file size. This is often 2 GB or 4GB in a
+   32-bit operating system, unless you have large file support enabled. By
+   default, we make the limit 1 GB to avoid any possible integer-overflow
+   problems within the OS. A limit smaller than necessary only means we divide
+   a large relation into more chunks than necessary, so it seems best to err
+   in the direction of a small limit. A power-of-2 value is recommended to
+   save a few cycles in md.c, but is not absolutely required. Changing
+   RELSEG_SIZE requires an initdb. */
+#define RELSEG_SIZE @RELSEG_SIZE@
+
+/* The size of `long', as computed by sizeof. */
+#define SIZEOF_LONG @SIZEOF_LONG@
+
+/* TODO BUT DO NOT NEED:The size of `off_t', as computed by sizeof. */
+/*#define SIZEOF_OFF_T @SIZEOF_OFF_T@*/
+
+/* The size of `size_t', as computed by sizeof. */
+#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@
+
+/* The size of `void *', as computed by sizeof. */
+#define SIZEOF_VOID_P @CMAKE_SIZEOF_VOID_P@
+
+/* TODO BUT DO NOT NEED:Define to 1 if you have the ANSI C header files. */
+/*#cmakedefine STDC_HEADERS 1*/
+
+/* Define to 1 if strerror_r() returns a int. */
+#cmakedefine STRERROR_R_INT 1
+
+/* TODO BUT DO NOT NEED:Define to 1 if your <sys/time.h> declares `struct tm'. */
+/*#cmakedefine TM_IN_SYS_TIME 1*/
+
+/* Define to 1 to build with assertion checks. (--enable-cassert) */
+#cmakedefine USE_ASSERT_CHECKING 1
+
+/* Define to 1 to build with Bonjour support. (--with-bonjour) */
+#cmakedefine USE_BONJOUR 1
+
+/* Define to 1 to build with BSD Authentication support. (--with-bsd-auth) */
+#cmakedefine USE_BSD_AUTH 1
+
+/* Define to use /dev/urandom for random number generation */
+#cmakedefine USE_DEV_URANDOM 1
+
+/* Define to 1 if you want float4 values to be passed by value. */
+#cmakedefine USE_FLOAT4_BYVAL 1
+
+/* Define to 1 if you want float8, int8, etc values to be passed by value. */
+#cmakedefine USE_FLOAT8_BYVAL 1
+
+/* Define to 1 if you want 64-bit integer timestamp and interval support. */
+#cmakedefine USE_INTEGER_DATETIMES 1
+
+/* Define to 1 to build with LDAP support. (--with-ldap) */
+#cmakedefine USE_LDAP 1
+
+/* Define to 1 to build with XML support. (-DWITH_LIBXML) */
+#cmakedefine USE_LIBXML 1
+
+/* Define to 1 to use XSLT support when building contrib/xml2. */
+#cmakedefine USE_LIBXSLT 1
+
+/* Define to select named POSIX semaphores. */
+#cmakedefine USE_NAMED_POSIX_SEMAPHORES 1
+
+/* Define to build with OpenSSL support. (--with-openssl) */
+#cmakedefine USE_OPENSSL 1
+
+/* Define to use OpenSSL for random number generation */
+#cmakedefine USE_OPENSSL_RANDOM 1
+
+/* Define to 1 to build with PAM support. (--with-pam) */
+#cmakedefine USE_PAM 1
+
+/* Use replacement snprintf() functions. */
+#cmakedefine USE_REPL_SNPRINTF 1
+
+/* Define to 1 to use Intel SSE 4.2 CRC instructions with a runtime check. */
+#cmakedefine USE_SLICING_BY_8_CRC32C 1
+
+/* Define to 1 use Intel SSE 4.2 CRC instructions. */
+#cmakedefine USE_SSE42_CRC32C 1
+
+/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */
+#cmakedefine USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1
+
+/* Define to build with systemd support. (--with-systemd) */
+#cmakedefine USE_SYSTEMD
+
+/* Define to select SysV-style semaphores. */
+#cmakedefine USE_SYSV_SEMAPHORES
+
+/* Define to select SysV-style shared memory. */
+#cmakedefine USE_SYSV_SHARED_MEMORY
+
+/* Define to select unnamed POSIX semaphores. */
+#cmakedefine USE_UNNAMED_POSIX_SEMAPHORES
+
+/* Define to use native Windows API for random number generation */
+#cmakedefine USE_WIN32_RANDOM 1
+
+/* Define to select Win32-style semaphores. */
+#cmakedefine USE_WIN32_SEMAPHORES
+
+/* TODO BUT DO NOT NEED:Define to select Win32-style shared memory. */
+/*#cmakedefine USE_WIN32_SHARED_MEMORY*/
+
+/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
+#cmakedefine WCSTOMBS_L_IN_XLOCALE 1
+
+/* NOT NEED:Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+/*#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+#  undef WORDS_BIGENDIAN
+# endif
+#endif*/
+
+/* Size of a WAL file block. This need have no particular relation to BLCKSZ.
+   XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O,
+   XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O
+   buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb.
+   */
+#define XLOG_BLCKSZ @XLOG_BLCKSZ@
+
+/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2
+   and larger than XLOG_BLCKSZ (preferably, a great deal larger than
+   XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */
+#define XLOG_SEG_SIZE @XLOG_SEG_SIZE@
+
+/* TODO BUT DO NOT NEED:Number of bits in a file offset, on hosts where this is settable. */
+/*#undef _FILE_OFFSET_BITS*/
+
+/* TODO BUT DO NOT NEED:Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/*#undef _LARGEFILE_SOURCE*/
+
+/* TODO BUT DO NOT NEED:Define for large files, on AIX-style hosts. */
+/*#undef _LARGE_FILES*/
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#undef inline
+#endif
+
+/* Define to the type of a signed integer type wide enough to hold a pointer,
+   if such a type exists, and if the system does not define it. */
+/*#undef intptr_t*/
+
+/* Define to empty if the C compiler does not understand signed types. */
+/*#undef signed*/
+
+/* Define to the type of an unsigned integer type wide enough to hold a
+   pointer, if such a type exists, and if the system does not define it. */
+/*#undef uintptr_t*/
+
+#cmakedefine HAVE_INT128
+
+#ifdef WIN32
+#undef PG_INT128_TYPE
+#endif
+
+#define LONG_LONG_INT_MODIFIER @LONG_LONG_INT_MODIFIER@
+
+#define POSTGRES_MAJOR_VERSION @POSTGRES_MAJOR_VERSION@
+
+#define POSTGRES_MINOR_VERSION @POSTGRES_MINOR_VERSION@
+
+#define POSTGRES_PATCH_VERSION @POSTGRES_PATCH_VERSION@
+
+#ifdef __APPLE__
+#	if __BIG_ENDIAN
+#		define WORDS_BIGENDIAN 1
+#	endif
+#else
+#cmakedefine WORDS_BIGENDIAN 1
+#endif
+
+#define DLSUFFIX "@CMAKE_SHARED_MODULE_SUFFIX@"
+
+#cmakedefine HAVE_MKSTEMP 1
+
+#cmakedefine HAVE_NBTOOL_CONFIG_H 1
+
+/*#include "@pgos_include_SRCS@"*/
+
+#cmakedefine USE_FP_STRICT 1
+
+#endif  // AUTO_CONFIG_H
diff --git a/src/include/pg_config_ext_cmake.in b/src/include/pg_config_ext_cmake.in
new file mode 100644
index 0000000000..a73f04bcc3
--- /dev/null
+++ b/src/include/pg_config_ext_cmake.in
@@ -0,0 +1 @@
+#define PG_INT64_TYPE @PG_INT64_TYPE@
\ No newline at end of file
diff --git a/src/include/pg_config_paths_cmake.in b/src/include/pg_config_paths_cmake.in
new file mode 100644
index 0000000000..f1b3c084eb
--- /dev/null
+++ b/src/include/pg_config_paths_cmake.in
@@ -0,0 +1,12 @@
+#define PGBINDIR "@PGBINDIR@"
+#define PGSHAREDIR "@PGSHAREDIR@"
+#define SYSCONFDIR "@SYSCONFDIR@" 
+#define INCLUDEDIR "@INCLUDEDIR@"
+#define PKGINCLUDEDIR "@PKGINCLUDEDIR@"
+#define INCLUDEDIRSERVER "@INCLUDEDIRSERVER@"
+#define LIBDIR "@LIBDIR@"
+#define PKGLIBDIR "@PKGLIBDIR@"
+#define LOCALEDIR "@LOCALEDIR@"
+#define DOCDIR "@DOCDIR@"
+#define HTMLDIR "@HTMLDIR@"
+#define MANDIR "@MANDIR@"
\ No newline at end of file
diff --git a/src/interfaces/ecpg/compatlib/CMakeLists.txt b/src/interfaces/ecpg/compatlib/CMakeLists.txt
new file mode 100644
index 0000000000..3214951b66
--- /dev/null
+++ b/src/interfaces/ecpg/compatlib/CMakeLists.txt
@@ -0,0 +1,27 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+set(ecpg_compat_SRC
+	informix.c
+)
+if(USE_REPL_SNPRINTF)
+	set(ecpg_compat_SRC
+		${ecpg_compat_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+add_library(ecpg_compat SHARED ${ecpg_compat_SRC})
+if (MSVC)
+	gen_def(ecpg_compat)
+endif()
+target_link_libraries(ecpg_compat ${LIB_M} pgtypes pq ecpg)
+target_compile_definitions(ecpg_compat PRIVATE -DFRONTEND)
+set_target_properties(ecpg_compat PROPERTIES VERSION "3.8")
+
+install(TARGETS ecpg_compat
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/interfaces/ecpg/ecpglib/CMakeLists.txt b/src/interfaces/ecpg/ecpglib/CMakeLists.txt
new file mode 100644
index 0000000000..158ec62616
--- /dev/null
+++ b/src/interfaces/ecpg/ecpglib/CMakeLists.txt
@@ -0,0 +1,76 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+set(ecpg_SRC
+	execute.c
+	typename.c
+	descriptor.c
+	sqlda.c
+	data.c
+	error.c
+	prepare.c
+	memory.c
+	connect.c
+	misc.c
+	${PROJECT_SOURCE_DIR}/src/port/path.c
+	${PROJECT_SOURCE_DIR}/src/port/pgstrcasecmp.c
+)
+
+if(USE_REPL_SNPRINTF)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/rint.c
+	)
+endif()
+
+if(NOT HAVE_DECL_STRLCPY)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/strlcpy.c
+	)
+endif()
+
+if(NOT HAVE_ISINF)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/isinf.c
+	)
+endif()
+
+if(WIN32)
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/win32setlocale.c
+	)
+else()
+	set(ecpg_SRC
+		${ecpg_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/thread.c
+	)
+endif()
+
+add_library(ecpg SHARED ${ecpg_SRC})
+if (MSVC)
+	gen_def(ecpg)
+endif()
+target_link_libraries(ecpg ${LIB_M} pgtypes pq)
+target_compile_definitions(ecpg PRIVATE -DFRONTEND)
+set_target_properties(ecpg PROPERTIES VERSION "6.8")
+
+install(TARGETS ecpg
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(ecpg "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;tr;zh_CN")
+endif()
diff --git a/src/interfaces/ecpg/include/CMakeLists.txt b/src/interfaces/ecpg/include/CMakeLists.txt
new file mode 100644
index 0000000000..63c42e8f26
--- /dev/null
+++ b/src/interfaces/ecpg/include/CMakeLists.txt
@@ -0,0 +1,25 @@
+set(INCLUDEDIR_INTERNAL ${PKGINCLUDEDIR}/internal)
+
+install(FILES
+	ecpgerrno.h
+	ecpglib.h
+	ecpgtype.h
+	sqlca.h
+	sql3types.h
+	ecpg_informix.h
+	pgtypes_error.h
+	pgtypes_numeric.h
+	pgtypes_timestamp.h
+	pgtypes_date.h
+	pgtypes_interval.h
+	sqlda.h
+	sqlda-compat.h
+	sqlda-native.h
+	ecpg_config.h
+	DESTINATION ${INCLUDEDIR})
+
+install(FILES
+	datetime.h
+	decimal.h
+	sqltypes.h
+	DESTINATION ${PKGINCLUDEDIR}/informix/esql)
diff --git a/src/interfaces/ecpg/include/ecpg_config_cmake.in b/src/interfaces/ecpg/include/ecpg_config_cmake.in
new file mode 100644
index 0000000000..1f3fcb83a2
--- /dev/null
+++ b/src/interfaces/ecpg/include/ecpg_config_cmake.in
@@ -0,0 +1,19 @@
+/* Define to 1 if the system has the type `int64'. */
+#cmakedefine HAVE_INT64 1
+
+/* Define to 1 if `long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_INT_64 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if `long long int' works and is 64 bits. */
+#cmakedefine HAVE_LONG_LONG_INT_64 1
+
+/* Define to 1 if you want 64-bit integer timestamp and interval support.
+   (--enable-integer-datetimes) */
+#cmakedefine USE_INTEGER_DATETIMES 1
+
+/* Define to 1 to build client libraries as thread-safe code.
+ *    (--enable-thread-safety) */
+#cmakedefine ENABLE_THREAD_SAFETY 1
diff --git a/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt b/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt
new file mode 100644
index 0000000000..a36ddcaeac
--- /dev/null
+++ b/src/interfaces/ecpg/pgtypeslib/CMakeLists.txt
@@ -0,0 +1,41 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+)
+set(pgtypes_SRC
+	numeric.c
+	datetime.c
+	common.c
+	dt_common.c
+	timestamp.c
+	interval.c
+	${PROJECT_SOURCE_DIR}/src/port/pgstrcasecmp.c
+)
+if(USE_REPL_SNPRINTF)
+	set(pgtypes_SRC
+		${pgtypes_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(pgtypes_SRC
+		${pgtypes_SRC}
+		${PROJECT_SOURCE_DIR}/src/port/rint.c
+	)
+endif()
+
+add_library(pgtypes SHARED ${pgtypes_SRC})
+if (MSVC)
+	gen_def(pgtypes)
+endif()
+
+target_link_libraries(pgtypes ${LIB_M})
+target_compile_definitions(pgtypes PRIVATE -DFRONTEND)
+set_target_properties(pgtypes PROPERTIES VERSION "3.7")
+
+
+install(TARGETS pgtypes
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/interfaces/ecpg/preproc/CMakeLists.txt b/src/interfaces/ecpg/preproc/CMakeLists.txt
new file mode 100644
index 0000000000..56e0ce6791
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/CMakeLists.txt
@@ -0,0 +1,59 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+)
+
+set(preproc_parser_DEP
+	${PROJECT_SOURCE_DIR}/src/backend/parser/gram.y
+	${CMAKE_CURRENT_SOURCE_DIR}/parse.pl
+)
+
+add_custom_command(
+	DEPENDS ${preproc_parser_DEP}
+	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/preproc.y
+	COMMAND ${PERL_EXECUTABLE} parse.pl . < ${PROJECT_SOURCE_DIR}/src/backend/parser/gram.y > preproc.y
+	COMMAND ${PERL_EXECUTABLE} check_rules.pl . ${PROJECT_SOURCE_DIR}/src/backend/parser/gram.y
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+bison_target(PREPROC_PARSER ${CMAKE_CURRENT_SOURCE_DIR}/preproc.y ${CMAKE_CURRENT_SOURCE_DIR}/preproc.c)
+flex_target(PREPROC_SCANNER pgc.l  ${CMAKE_CURRENT_SOURCE_DIR}/pgc.c)
+add_flex_bison_dependency(PREPROC_SCANNER PREPROC_PARSER)
+
+
+set(preproc_SRC
+	preproc.c
+	pgc.c
+	type.c
+	ecpg.c
+	output.c
+	parser.c
+	keywords.c
+	c_keywords.c
+	ecpg_keywords.c
+	${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/ecpglib/typename.c
+	descriptor.c
+	variable.c
+)
+
+
+add_executable(ecpg_preproc
+	${preproc_SRC}
+)
+
+target_link_libraries(ecpg_preproc
+	#pq
+	pgcommon
+	pgport
+)
+
+target_compile_definitions(ecpg_preproc PRIVATE
+	-DECPG_COMPILE
+)
+
+SET_TARGET_PROPERTIES(ecpg_preproc
+	PROPERTIES OUTPUT_NAME ecpg
+	RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}
+	RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/src/interfaces/ecpg/test/CMakeLists.txt b/src/interfaces/ecpg/test/CMakeLists.txt
new file mode 100644
index 0000000000..6b3e742750
--- /dev/null
+++ b/src/interfaces/ecpg/test/CMakeLists.txt
@@ -0,0 +1,178 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/test/regress"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include"
+)
+
+add_executable(pg_ecpg_regress
+	${PROJECT_SOURCE_DIR}/src/test/regress/pg_regress.c
+	pg_regress_ecpg.c
+)
+
+target_link_libraries(pg_ecpg_regress
+	pq
+	pgcommon
+	pgport
+)
+
+target_compile_definitions(pg_ecpg_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}"
+)
+
+set(connect_tests
+	test1
+	test2
+	test3
+	test4
+	test5
+)
+
+set(compat_informix_tests
+	test_informix
+	test_informix2
+	dec_test
+	rfmtdate
+	rfmtlong
+	rnull
+	sqlda
+	describe
+	charfuncs
+)
+
+set(pgtypeslib_tests
+	dt_test
+	dt_test2
+	num_test
+	num_test2
+	nan_test
+)
+
+set(preproc_tests
+	array_of_struct
+	autoprep
+	comment
+	cursor
+	define
+	init
+	strings
+	outofscope
+	type
+	variable
+	whenever
+	pointer_to_struct
+)
+
+set(sql_tests
+	array
+	binary
+	code100
+	copystdout
+	define
+	desc
+	sqlda
+	describe
+	dyntest
+	dynalloc
+	dynalloc2
+	execute
+	fetch
+	func
+	indicators
+	oldexec
+	parser
+	quote
+	show
+	insupd
+)
+
+set(thread_tests
+	thread_implicit
+	thread
+	prep
+	descriptor
+	alloc
+)
+
+set(ecpg_preproc_bin ${CMAKE_BINARY_DIR}/src/interfaces/ecpg/preproc/ecpg${CMAKE_EXECUTABLE_SUFFIX})
+
+macro(ECPG_CHECK TARGET_LIST FOLDER PREPROC_OPTS)
+	foreach(test ${TARGET_LIST})
+		if(${test} STREQUAL "rnull")
+			set(PREPROC_OPTS2 "-r;no_indicator")
+		elseif(${test} STREQUAL "array_of_struct")
+			set(PREPROC_OPTS2 "-c")
+		elseif(${test} STREQUAL "pointer_to_struct")
+			set(PREPROC_OPTS2 "-c")
+		elseif(${test} STREQUAL "autoprep")
+			set(PREPROC_OPTS2 "-r;prepare")
+		elseif(${test} STREQUAL "strings")
+			set(PREPROC_OPTS2 "-i")
+		elseif(${test} STREQUAL "oldexec")
+			set(PREPROC_OPTS2 "-r;questionmarks")
+		else()
+			set(PREPROC_OPTS2 "")
+		endif()
+		add_custom_command(
+			DEPENDS ecpg_preproc
+			OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${FOLDER}/${test}.c
+			COMMAND ${ecpg_preproc_bin} --regression ${PREPROC_OPTS} ${PREPROC_OPTS2} -I${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include -I${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/test/${FOLDER} ${FOLDER}/${test}.pgc
+			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+		)
+		add_executable(ecpg_regress_${FOLDER}_${test}
+			${CMAKE_CURRENT_SOURCE_DIR}/${FOLDER}/${test}.c
+		)
+		target_link_libraries(ecpg_regress_${FOLDER}_${test}
+			ecpg
+			ecpg_compat
+			pgtypes
+			pq
+			#pgcommon
+			#port
+		)
+		set_target_properties(ecpg_regress_${FOLDER}_${test}
+			PROPERTIES
+			RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${FOLDER}"
+			OUTPUT_NAME ${test}
+		)
+	endforeach()
+endmacro(ECPG_CHECK TARGET_LIST FOLDER PREPROC_OPTS)
+
+ecpg_check("${compat_informix_tests}" "compat_informix" "-C;INFORMIX")
+ecpg_check("${connect_tests}" "connect" "")
+ecpg_check("${pgtypeslib_tests}" "pgtypeslib" "")
+ecpg_check("${preproc_tests}" "preproc" "")
+ecpg_check("${sql_tests}" "sql" "")
+ecpg_check("${thread_tests}" "thread" "")
+
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(ecpg_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ecpg_installcheck_tmp
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(ecpg_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} ecpg_installcheck_tmp DESTDIR=${tmp_check_folder}
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+
+set(REGRESS_OPTS "${REGRESS_OPTS};--dbname=ecpg1_regression,ecpg2_regression;--create-role=regress_ecpg_user1,regress_ecpg_user2")
+
+add_custom_target(ecpg_installcheck
+	COMMAND ${pg_ecpg_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/ecpg_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(ecpg_installcheck_tmp
+	COMMAND ${pg_ecpg_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/ecpg_schedule --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
diff --git a/src/interfaces/libpq/CMakeLists.txt b/src/interfaces/libpq/CMakeLists.txt
new file mode 100644
index 0000000000..8afcc6c932
--- /dev/null
+++ b/src/interfaces/libpq/CMakeLists.txt
@@ -0,0 +1,108 @@
+include_directories(BEFORE
+	"${CMAKE_CURRENT_SOURCE_DIR}"
+	"${PROJECT_SOURCE_DIR}/src/port"
+)
+
+if(USE_OPENSSL)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+	set(pq_ssl_SRCS fe-secure-openssl.c)
+endif(USE_OPENSSL)
+
+set(pq_SRCS
+	fe-auth.c
+	fe-connect.c
+	fe-exec.c
+	fe-misc.c
+	fe-print.c
+	fe-lobj.c
+	fe-protocol2.c
+	fe-protocol3.c
+	pqexpbuffer.c
+	fe-secure.c
+	libpq-events.c
+
+	${PORT_DIR}/chklocale.c
+	${PORT_DIR}/inet_net_ntop.c
+	${PORT_DIR}/noblock.c
+	${PORT_DIR}/pgstrcasecmp.c
+	${PORT_DIR}/pqsignal.c
+	${PORT_DIR}/thread.c
+
+	${PROJECT_SOURCE_DIR}/src/common/ip.c
+	${PROJECT_SOURCE_DIR}/src/common/md5.c
+	${MB_UTILS_BACKEND_DIR}/encnames.c
+	${MB_UTILS_BACKEND_DIR}/wchar.c
+
+	${fallback_SRCS}
+	${pq_ssl_SRCS}
+)
+
+if(USE_REPL_SNPRINTF)
+	set(pq_SRCS ${pq_SRCS} ${PORT_DIR}/snprintf.c)
+endif()
+
+set(RES_FILES "")
+if(WIN32)
+	set(pq_SRCS ${pq_SRCS}
+		win32.c
+		${PORT_DIR}/win32error.c
+		${PORT_DIR}/win32setlocale.c
+		${PORT_DIR}/pgsleep.c
+		${PORT_DIR}/open.c
+		${PORT_DIR}/system.c
+		${PORT_DIR}/inet_aton.c
+		${PORT_DIR}/thread.c
+		${PORT_DIR}/getaddrinfo.c
+	)
+	if (Threads_FOUND)
+		set(pq_SRCS ${pq_SRCS} pthread-win32.c)
+	endif()
+	set(RES_FILES "libpq.rc")
+	set(CMAKE_RC_COMPILER_INIT windres)
+	ENABLE_LANGUAGE(RC)
+	SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
+endif()
+
+add_library(pq SHARED ${pq_SRCS} ${RES_FILES})
+target_link_libraries(pq
+	${CMAKE_THREAD_LIBS_INIT}
+	${LIBSOCKET_LIBRARIES}
+	${GSS_LIBS}
+)
+if(USE_OPENSSL)
+	target_link_libraries(pq ${OPENSSL_LIBRARIES})
+endif()
+if (MSVC)
+	gen_def(pq)
+endif()
+if(CRYPT_LIB)
+	target_link_libraries(pq ${CRYPT_LIB})
+endif()
+if(WIN32)
+	target_link_libraries(pq
+		#port
+		Secur32
+		ws2_32
+	)
+endif()
+
+if(LDAP_FOUND)
+	target_link_libraries(pq ${LDAP_LIBRARIES})
+endif()
+
+if(USE_OPENSSL)
+	target_include_directories(pq PUBLIC ${OPENSSL_INCLUDE_DIR})
+endif()
+
+
+target_compile_definitions(pq PRIVATE -DFRONTEND -DUNSAFE_STAT_OK)
+install(TARGETS pq
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+if(ENABLE_NLS)
+	MAKE_MO(libpq "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;tr;zh_CN;zh_TW")
+endif()
+
+#TODO 
+#set_target_properties(pq PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.list")
diff --git a/src/pl/plperl/CMakeLists.txt b/src/pl/plperl/CMakeLists.txt
new file mode 100644
index 0000000000..a2a92f92b0
--- /dev/null
+++ b/src/pl/plperl/CMakeLists.txt
@@ -0,0 +1,100 @@
+if(WIN32)
+	add_definitions(-DPLPERL_HAVE_UID_GID)
+endif()
+
+execute_process(
+	COMMAND ${PERL_EXECUTABLE} -e "use List::Util qw(first); print first { -r \"$_/ExtUtils/xsubpp\" } @INC"
+	OUTPUT_VARIABLE XSUBPPDIR
+)
+execute_process(
+	COMMAND ${PERL_EXECUTABLE} -V:usemultiplicity
+	OUTPUT_VARIABLE PERL_MULTIPLICITY
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/SPI.c"
+	MAIN_DEPENDENCY SPI.xs plperl_helpers.h
+	COMMAND ${PERL_EXECUTABLE} ${XSUBPPDIR}/ExtUtils/xsubpp -typemap ${PERL_PRIVLIB}/ExtUtils/typemap SPI.xs > "${CMAKE_CURRENT_SOURCE_DIR}/SPI.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/Util.c"
+	MAIN_DEPENDENCY Util.xs plperl_helpers.h
+	COMMAND ${PERL_EXECUTABLE} ${XSUBPPDIR}/ExtUtils/xsubpp -typemap ${PERL_PRIVLIB}/ExtUtils/typemap Util.xs > "${CMAKE_CURRENT_SOURCE_DIR}/Util.c"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	MAIN_DEPENDENCY plc_perlboot.pl plc_trusted.pl
+	COMMAND ${PERL_EXECUTABLE} text2macro.pl "--strip='^(\\#.*|\\s*)$$'" plc_perlboot.pl plc_trusted.pl > "${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	MAIN_DEPENDENCY plperl_opmask.pl
+	COMMAND ${PERL_EXECUTABLE} plperl_opmask.pl "${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plname "plperl")
+
+set(plperl_SRCS
+	"${CMAKE_CURRENT_SOURCE_DIR}/perlchunks.h"
+	"${CMAKE_CURRENT_SOURCE_DIR}/plperl_opmask.h"
+	plperl.c
+	SPI.c
+	Util.c
+)
+
+include_directories(${PERL_INCLUDE_PATH})
+add_library(${plname} ${PLUGIN_TYPE} ${plperl_SRCS})
+target_link_libraries(${plname} postgres ${PERL_LIBRARY} ${PERL_LDFLAGS})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} pgport)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+		plperl.control
+		plperl--1.0.sql
+		plperl--unpackaged--1.0.sql
+		plperlu.control
+		plperlu--1.0.sql
+		plperlu--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+install(FILES
+	plperl.h
+	ppport.h
+	DESTINATION ${INCLUDEDIRSERVER})
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB} --load-extension=plperl --load-extension=plperlu)
+set(plregres_files
+	plperl
+	plperl_lc
+	plperl_trigger
+	plperl_shared
+	plperl_elog
+	plperl_util
+	plperl_init
+	plperlu
+	plperl_array
+)
+
+if(PERL_MULTIPLICITY STREQUAL "usemultiplicity='define'")
+	set(plregres_files ${plregres_files} plperl_plperlu)
+endif()
+
+REGRESS_CHECK(plperl "${REGRESS_OPTS}" "${plregres_files}")
+
+if(ENABLE_NLS)
+	MAKE_MO(plperl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;sv;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/pl/plpgsql/src/CMakeLists.txt b/src/pl/plpgsql/src/CMakeLists.txt
new file mode 100644
index 0000000000..1dd9cc6a85
--- /dev/null
+++ b/src/pl/plpgsql/src/CMakeLists.txt
@@ -0,0 +1,37 @@
+BISON_TARGET(PLPGSQL_PARSER pl_gram.y ${CMAKE_CURRENT_SOURCE_DIR}/pl_gram.c COMPILE_FLAGS "-d")
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/plerrcodes.h"
+	MAIN_DEPENDENCY generate-plerrcodes.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-plerrcodes.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/plerrcodes.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plpgsql_SRCS
+	pl_handler.c
+	pl_comp.c
+	plerrcodes.h
+	pl_exec.c
+	pl_funcs.c
+	pl_scanner.c
+	${BISON_PLPGSQL_PARSER_OUTPUT_SOURCE}
+)
+
+add_library(plpgsql ${PLUGIN_TYPE} ${plpgsql_SRCS})
+target_link_libraries(plpgsql postgres)
+if (MSVC)
+	gen_def(plpgsql)
+	target_link_libraries(plpgsql pgport pgcommon)
+endif()
+set_target_properties(plpgsql PROPERTIES PREFIX "")
+add_dependencies(plpgsql postgres)
+
+install(TARGETS plpgsql
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+
+if(ENABLE_NLS)
+	MAKE_MO(plpgsql "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;zh_CN;zh_TW")
+endif()
diff --git a/src/pl/plpython/CMakeLists.txt b/src/pl/plpython/CMakeLists.txt
new file mode 100644
index 0000000000..4a7abd9423
--- /dev/null
+++ b/src/pl/plpython/CMakeLists.txt
@@ -0,0 +1,92 @@
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	MAIN_DEPENDENCY generate-spiexceptions.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-spiexceptions.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(plname "plpython${PYTHON_VERSION_MAJOR}")
+
+set(plpython_SRCS
+	"${CMAKE_CURRENT_SOURCE_DIR}/spiexceptions.h"
+	plpy_cursorobject.c
+	plpy_elog.c
+	plpy_exec.c
+	plpy_main.c
+	plpy_planobject.c
+	plpy_plpymodule.c
+	plpy_procedure.c
+	plpy_resultobject.c
+	plpy_spi.c
+	plpy_subxactobject.c
+	plpy_typeio.c
+	plpy_util.c
+)
+
+include_directories(${PYTHON_INCLUDE_DIRS})
+add_library(${plname} ${PLUGIN_TYPE} ${plpython_SRCS})
+target_link_libraries(${plname} postgres ${PYTHON_LIBRARIES})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} pgport)
+endif()
+if(MINGW)
+	set_target_properties(${plname} PROPERTIES LINK_FLAGS -Wl,--out-implib=libmin${plname}.dll.a)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	plpython2u.control
+	plpython2u--1.0.sql
+	plpython2u--unpackaged--1.0.sql
+	plpython3u.control
+	plpython3u--1.0.sql
+	plpython3u--unpackaged--1.0.sql
+	plpythonu.control
+	plpythonu--1.0.sql
+	plpythonu--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB})
+if (PYTHON_VERSION_MAJOR EQUAL 2)
+	set(REGRESS_OPTS ${REGRESS_OPTS} --load-extension=plpythonu)
+endif()
+
+set(plregres_files
+	plpython_schema
+	plpython_populate
+	plpython_test
+	plpython_do
+	plpython_global
+	plpython_import
+	plpython_spi
+	plpython_newline
+	plpython_void
+	plpython_params
+	plpython_setof
+	plpython_record
+	plpython_trigger
+	plpython_types
+	plpython_error
+	plpython_unicode
+	plpython_quote
+	plpython_composite
+	plpython_subtransaction
+	plpython_drop
+)
+
+if(PYTHON_VERSION_MAJOR EQUAL 3)
+	replace_python_files("${plregres_files}")
+	REGRESS_CHECK(plpython "${REGRESS_OPTS}" "${regress_files3}")
+else()
+	REGRESS_CHECK(plpython "${REGRESS_OPTS}" "${plregres_files}")
+endif()
+
+if(ENABLE_NLS)
+	MAKE_MO(plpython "cs;de;es;fr;it;ja;ko;pl;pt_BR;ru;zh_CN")
+endif()
diff --git a/src/pl/tcl/CMakeLists.txt b/src/pl/tcl/CMakeLists.txt
new file mode 100644
index 0000000000..d72ad69372
--- /dev/null
+++ b/src/pl/tcl/CMakeLists.txt
@@ -0,0 +1,49 @@
+set(plname "pltcl")
+
+include_directories(${TCL_INCLUDE_PATH})
+
+add_custom_command(
+	OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h"
+	MAIN_DEPENDENCY generate-pltclerrcodes.pl
+	COMMAND ${PERL_EXECUTABLE} "generate-pltclerrcodes.pl" "${PROJECT_SOURCE_DIR}/src/backend/utils/errcodes.txt" > "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h"
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(gen_pltclerrcodes DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/pltclerrcodes.h")
+
+add_library(${plname} ${PLUGIN_TYPE}
+	pltcl.c
+)
+
+target_link_libraries(${plname} postgres ${TCL_LIBRARY})
+if (MSVC)
+	gen_def(${plname})
+	target_link_libraries(${plname} pgport)
+endif()
+set_target_properties(${plname} PROPERTIES PREFIX "")
+add_dependencies(${plname} postgres gen_pltclerrcodes)
+
+install(TARGETS ${plname}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+		${plname}.control
+		${plname}--1.0.sql
+		${plname}--unpackaged--1.0.sql
+		${plname}u.control
+		${plname}u--1.0.sql
+		${plname}u--unpackaged--1.0.sql
+		DESTINATION ${PGSHAREDIR}/extension)
+
+set(PL_TESTDB pl_regression)
+set(REGRESS_OPTS --dbname=${PL_TESTDB} --load-extension=pltcl)
+set(plregres_files
+	pltcl_setup
+	pltcl_queries
+	pltcl_unicode
+)
+REGRESS_CHECK(pltcl "${REGRESS_OPTS}" "${plregres_files}")
+
+if(ENABLE_NLS)
+	MAKE_MO(pltcl "cs;de;es;fr;it;ja;ko;pl;pt_BR;ro;ru;tr;zh_CN;zh_TW")
+endif()
diff --git a/src/port/CMakeLists.txt b/src/port/CMakeLists.txt
new file mode 100644
index 0000000000..68cb5bdcc4
--- /dev/null
+++ b/src/port/CMakeLists.txt
@@ -0,0 +1,175 @@
+if(OPENSSL_FOUND)
+	include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
+endif()
+
+if(USE_SSE42_CRC32C)
+	SET(PG_CRC32C_OBJS pg_crc32c_sse42.c)
+elseif(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK)
+	SET(PG_CRC32C_OBJS
+		pg_crc32c_sse42.c
+		pg_crc32c_sb8.c
+		pg_crc32c_choose.c
+	)
+elseif(USE_SLICING_BY_8_CRC32C)
+	SET(PG_CRC32C_OBJS pg_crc32c_sb8.c)
+endif()
+
+set_source_files_properties(pg_crc32c_sse42.c PROPERTIES COMPILE_FLAGS "${CFLAGS_SSE42}")
+
+set(port_SRCS
+	chklocale.c
+	erand48.c
+	inet_net_ntop.c
+	noblock.c
+	path.c
+	pgcheckdir.c
+	pgmkdirp.c
+	pgsleep.c
+	pgstrcasecmp.c
+	pqsignal.c
+	qsort.c
+	qsort_arg.c
+	quotes.c
+	sprompt.c
+	tar.c
+	thread.c
+	${fallback_SRCS}
+	${PG_CRC32C_OBJS}
+)
+
+if(STRONG_RANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		pg_strong_random.c
+	)
+endif()
+
+if(NOT HAVE_FLS)
+	set(port_SRCS
+		${port_SRCS}
+		fls.c
+	)
+endif(NOT HAVE_FLS)
+
+if(NOT HAVE_ISINF)
+	set(port_SRCS
+		${port_SRCS}
+		isinf.c
+	)
+endif()
+
+if(NOT HAVE_MKDTEMP)
+	set(port_SRCS
+		${port_SRCS}
+		mkdtemp.c
+	)
+endif()
+
+if(NOT HAVE_GETOPT)
+	set(port_SRCS
+		${port_SRCS}
+		getopt.c
+	)
+endif()
+
+if(NOT (HAVE_STRUCT_OPTION AND HAVE_GETOPT_LONG))
+	set(port_SRCS
+		${port_SRCS}
+		getopt_long.c
+	)
+endif()
+
+if(NOT HAVE_GETTIMEOFDAY)
+	set(port_SRCS
+		${port_SRCS}
+		gettimeofday.c
+	)
+endif()
+
+if(NOT HAVE_INET_ATON)
+	set(port_SRCS
+		${port_SRCS}
+		inet_aton.c
+	)
+endif()
+
+if(NOT HAVE_RANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		random.c
+	)
+endif()
+
+if(NOT HAVE_SRANDOM)
+	set(port_SRCS
+		${port_SRCS}
+		srandom.c
+	)
+endif()
+
+if(USE_REPL_SNPRINTF)
+	set(port_SRCS
+		${port_SRCS}
+		snprintf.c
+	)
+endif()
+
+if(NOT HAVE_RINT)
+	set(port_SRCS
+		${port_SRCS}
+		rint.c
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(port_SRCS
+		${port_SRCS}
+		dirmod.c
+		kill.c
+		open.c
+		getrusage.c
+		system.c
+		win32security.c
+		win32env.c
+		win32error.c
+		win32setlocale.c
+	)
+endif()
+
+if(MSVC)
+	set(port_SRCS
+		${port_SRCS}
+		dirent.c
+	)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+	# Solaris' getopt() doesn't do what we want for long options, so always use
+	# our version on that platform.
+	set(port_SRCS
+		${port_SRCS}
+		getopt.c
+	)
+endif()
+
+if(NOT HAVE_CRYPT)
+	set(port_SRCS
+		${port_SRCS}
+		crypt.c
+	)
+endif()
+
+add_library(pgport_srv STATIC ${port_SRCS})
+add_library(pgport STATIC ${port_SRCS})
+
+add_dependencies(pgport_srv gen_errorcodes)
+add_dependencies(pgport gen_errorcodes)
+
+# because port used in shared libraries
+set_property(TARGET pgport PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+
+
+target_compile_definitions(pgport PRIVATE -DFRONTEND)
+set_source_files_properties(thread.c PROPERTIES COMPILE_FLAGS ${PTHREAD_CFLAGS})
+install(TARGETS pgport
+		ARCHIVE DESTINATION ${LIBDIR})
diff --git a/src/test/isolation/CMakeLists.txt b/src/test/isolation/CMakeLists.txt
new file mode 100644
index 0000000000..66d0529a7f
--- /dev/null
+++ b/src/test/isolation/CMakeLists.txt
@@ -0,0 +1,73 @@
+include_directories(BEFORE
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/port"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+	"${PROJECT_SOURCE_DIR}/src/test/regress"
+)
+
+add_executable(pg_isolation_regress
+	${PROJECT_SOURCE_DIR}/src/test/regress/pg_regress.c
+	isolation_main.c
+)
+
+target_link_libraries(pg_isolation_regress
+	pq
+	pgcommon
+	pgport
+)
+
+target_compile_definitions(pg_isolation_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}"
+)
+
+bison_target(SPEC_PARSER specparse.y ${CMAKE_CURRENT_SOURCE_DIR}/specparse.c)
+flex_target(SPEC_SCANNER specscanner.l  ${CMAKE_CURRENT_SOURCE_DIR}/specscanner.c)
+add_flex_bison_dependency(SPEC_SCANNER SPEC_PARSER)
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/specparse.c PROPERTIES OBJECT_DEPENDS ${FLEX_SPEC_SCANNER_OUTPUTS})
+
+add_executable(isolationtester
+	isolationtester.c
+	${BISON_SPEC_PARSER_OUTPUTS}
+)
+
+target_link_libraries(isolationtester
+	pgcommon
+	pgport
+	pq
+)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(isolation_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} isolation_installcheck_tmp
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(isolation_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} isolation_installcheck_tmp DESTDIR=${tmp_check_folder}
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+
+add_custom_target(isolation_installcheck
+	COMMAND ${pg_isolation_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/isolation_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(isolation_installcheck_tmp
+	COMMAND ${pg_isolation_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/isolation_schedule --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+install(TARGETS isolationtester
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(TARGETS pg_isolation_regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/test/modules/CMakeLists.txt b/src/test/modules/CMakeLists.txt
new file mode 100644
index 0000000000..f40b717856
--- /dev/null
+++ b/src/test/modules/CMakeLists.txt
@@ -0,0 +1,69 @@
+set(modules_libs postgres)
+
+#TODO: need test under mingw or cygwin
+if(WIN32)
+	set(modules_libs
+		pgport
+		pgcommon
+	)
+endif()
+
+if(MSVC OR MINGW)
+	set(modules_libs
+		pgport
+		postgres
+		pgcommon_srv
+	)
+endif()
+
+
+set(modules_check_targets "")
+set(modules_installcheck_targets "")
+
+# Tests
+add_subdirectory(brin)
+add_subdirectory(commit_ts)
+add_subdirectory(dummy_seclabel)
+add_subdirectory(snapshot_too_old)
+add_subdirectory(test_ddl_deparse)
+add_subdirectory(test_extensions)
+add_subdirectory(test_parser)
+add_subdirectory(test_pg_dump)
+add_subdirectory(test_rls_hooks)
+add_subdirectory(test_shm_mq)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(modules_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+		COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${modules_check_targets}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(modules_check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+		COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+		COMMAND ${check_make_command} ${modules_check_targets} DESTDIR=${tmp_check_folder}
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+
+# Make chain for run tests in strict order
+# TODO: we can't run tests separately now
+set(first_element "")
+list(GET modules_installcheck_targets 0 first_element)
+add_custom_target(modules_installcheck
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+	DEPENDS tablespace-setup ${first_element}
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)
+
+set(last_element OFF)
+foreach(loop_var IN ITEMS ${modules_installcheck_targets})
+	if(last_element)
+		add_dependencies(${last_element} ${loop_var})
+	endif()
+	set(last_element ${loop_var})
+endforeach()
diff --git a/src/test/modules/brin/CMakeLists.txt b/src/test/modules/brin/CMakeLists.txt
new file mode 100644
index 0000000000..186626c20a
--- /dev/null
+++ b/src/test/modules/brin/CMakeLists.txt
@@ -0,0 +1 @@
+MODULES_ISOLATION_CHECK("brin" "" "summarization-and-inprogress-insertion")
diff --git a/src/test/modules/commit_ts/CMakeLists.txt b/src/test/modules/commit_ts/CMakeLists.txt
new file mode 100644
index 0000000000..cb709dc558
--- /dev/null
+++ b/src/test/modules/commit_ts/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+MODULES_REGRESS_CHECK("commit_ts" "--temp-config=${CMAKE_SOURCE_DIR}/src/test/modules/commit_ts/commit_ts.conf" "commit_timestamp")
+if(PROVE)
+	MODULES_TAP_CHECK("commit_ts" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/test/modules/dummy_seclabel/CMakeLists.txt b/src/test/modules/dummy_seclabel/CMakeLists.txt
new file mode 100644
index 0000000000..02a333ed86
--- /dev/null
+++ b/src/test/modules/dummy_seclabel/CMakeLists.txt
@@ -0,0 +1,30 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name dummy_seclabel)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	dummy_seclabel.c
+)
+target_link_libraries(${extension_name} ${modules_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} modules)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+MODULES_REGRESS_CHECK(${extension_name} "" "${extension_name}")
diff --git a/src/test/modules/snapshot_too_old/CMakeLists.txt b/src/test/modules/snapshot_too_old/CMakeLists.txt
new file mode 100644
index 0000000000..91ea3ef863
--- /dev/null
+++ b/src/test/modules/snapshot_too_old/CMakeLists.txt
@@ -0,0 +1,2 @@
+
+MODULES_ISOLATION_CHECK("snapshot_too_old" "--temp-config=${CMAKE_SOURCE_DIR}/src/test/modules/snapshot_too_old/sto.conf" "sto_using_cursor;sto_using_select")
diff --git a/src/test/modules/test_ddl_deparse/CMakeLists.txt b/src/test/modules/test_ddl_deparse/CMakeLists.txt
new file mode 100644
index 0000000000..74cb041144
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/CMakeLists.txt
@@ -0,0 +1,53 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_ddl_deparse)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	test_ddl_deparse.c
+)
+target_link_libraries(${extension_name} ${modules_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} modules)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control ${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(tests_list
+	test_ddl_deparse
+	create_extension
+	create_schema
+	create_type
+	create_conversion
+	create_domain
+	create_sequence_1
+	create_table
+	create_transform
+	alter_table
+	create_view
+	create_trigger
+	create_rule
+	comment_on
+	alter_function
+	alter_sequence
+	alter_type_enum
+	opfamily
+	defprivs
+	matviews
+)
+
+MODULES_REGRESS_CHECK(${extension_name} "--dbname=contrib_regression" "${tests_list}")
diff --git a/src/test/modules/test_extensions/CMakeLists.txt b/src/test/modules/test_extensions/CMakeLists.txt
new file mode 100644
index 0000000000..36324651bd
--- /dev/null
+++ b/src/test/modules/test_extensions/CMakeLists.txt
@@ -0,0 +1,41 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_extensions)
+
+install(FILES
+	test_ext1--1.0.sql
+	test_ext1.control
+	test_ext2--1.0.sql
+	test_ext2.control
+	test_ext3--1.0.sql
+	test_ext3.control
+	test_ext4--1.0.sql
+	test_ext4.control
+	test_ext5--1.0.sql
+	test_ext5.control
+	test_ext6--1.0.sql
+	test_ext6.control
+	test_ext7--1.0.sql
+	test_ext7--1.0--2.0.sql
+	test_ext7.control
+	test_ext8--1.0.sql
+	test_ext8.control
+	test_ext_cyclic1--1.0.sql
+	test_ext_cyclic1.control
+	test_ext_cyclic2--1.0.sql
+	test_ext_cyclic2.control
+	DESTINATION ${PGSHAREDIR}/extension)
+
+set(tests_list
+	test_extensions
+	test_extdepend
+)
+
+MODULES_REGRESS_CHECK(${extension_name} "" "${tests_list}")
diff --git a/src/test/modules/test_parser/CMakeLists.txt b/src/test/modules/test_parser/CMakeLists.txt
new file mode 100644
index 0000000000..c1fb33a962
--- /dev/null
+++ b/src/test/modules/test_parser/CMakeLists.txt
@@ -0,0 +1,33 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_parser)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	test_parser.c
+)
+target_link_libraries(${extension_name} ${modules_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} modules)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	${extension_name}--unpackaged--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+MODULES_REGRESS_CHECK(${extension_name} "" "${extension_name}")
diff --git a/src/test/modules/test_pg_dump/CMakeLists.txt b/src/test/modules/test_pg_dump/CMakeLists.txt
new file mode 100644
index 0000000000..95b0082c33
--- /dev/null
+++ b/src/test/modules/test_pg_dump/CMakeLists.txt
@@ -0,0 +1,21 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_pg_dump)
+
+install(FILES
+	test_pg_dump--1.0.sql
+	test_pg_dump.control
+	DESTINATION ${PGSHAREDIR}/extension)
+
+
+MODULES_REGRESS_CHECK(${extension_name} "" "${extension_name}")
+if(PROVE)
+	MODULES_TAP_CHECK(${extension_name} "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/test/modules/test_rls_hooks/CMakeLists.txt b/src/test/modules/test_rls_hooks/CMakeLists.txt
new file mode 100644
index 0000000000..5a3bdfdd52
--- /dev/null
+++ b/src/test/modules/test_rls_hooks/CMakeLists.txt
@@ -0,0 +1,30 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_rls_hooks)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	test_rls_hooks.c
+)
+target_link_libraries(${extension_name} ${modules_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} modules)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES ${extension_name}.control
+	DESTINATION ${PGSHAREDIR}/extension)
+
+MODULES_REGRESS_CHECK(${extension_name} "--temp-config=${CMAKE_SOURCE_DIR}/src/test/modules/test_rls_hooks/rls_hooks.conf" "${extension_name}")
diff --git a/src/test/modules/test_shm_mq/CMakeLists.txt b/src/test/modules/test_shm_mq/CMakeLists.txt
new file mode 100644
index 0000000000..6ad93b768d
--- /dev/null
+++ b/src/test/modules/test_shm_mq/CMakeLists.txt
@@ -0,0 +1,34 @@
+option(PGXS "Separate build" OFF)
+if(PGXS)
+	cmake_minimum_required(VERSION 2.8)
+	find_package(PostgreSQL)
+	include(${PostgreSQL_LIBRARY_DIRS}/cmake/PGXS.cmake)
+else()
+	include_directories("${PROJECT_SOURCE_DIR}/src/include")
+endif()
+
+set(extension_name test_shm_mq)
+
+add_library(${extension_name} ${PLUGIN_TYPE}
+	test.c
+	setup.c
+	worker.c
+)
+target_link_libraries(${extension_name} ${modules_libs})
+set_target_properties(${extension_name} PROPERTIES PREFIX "")
+if (MSVC)
+	gen_def(${extension_name})
+endif()
+if(NOT PGXS)
+	add_dependencies(${extension_name} postgres)
+	CMAKE_SET_TARGET_FOLDER(${extension_name} modules)
+endif()
+install(TARGETS ${extension_name}
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+install(FILES
+	${extension_name}.control
+	${extension_name}--1.0.sql
+	DESTINATION ${PGSHAREDIR}/extension)
+
+MODULES_REGRESS_CHECK(${extension_name} "" "${extension_name}")
diff --git a/src/test/recovery/CMakeLists.txt b/src/test/recovery/CMakeLists.txt
new file mode 100644
index 0000000000..080cb34183
--- /dev/null
+++ b/src/test/recovery/CMakeLists.txt
@@ -0,0 +1,3 @@
+if(PROVE)
+	TAP_CHECK("recovery_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/test/regress/CMakeLists.txt b/src/test/regress/CMakeLists.txt
new file mode 100644
index 0000000000..c98bc4de24
--- /dev/null
+++ b/src/test/regress/CMakeLists.txt
@@ -0,0 +1,81 @@
+include_directories(BEFORE
+ 	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/port"
+ 	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+ 	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+add_executable(pg_regress
+	pg_regress.c
+	pg_regress_main.c
+)
+
+target_link_libraries(pg_regress
+	pq
+	pgcommon
+	pgport
+)
+
+target_compile_definitions(pg_regress PRIVATE
+	-DHOST_TUPLE="${HOST_TUPLE}"
+	-DSHELLPROG="$ENV{SHELL}")
+
+
+add_library(regress ${PLUGIN_TYPE} regress.c)
+#target_link_libraries(regress
+#	pq
+#)
+if (MSVC)
+	gen_def(regress)
+endif()
+
+if(MSVC OR MINGW)
+	target_link_libraries(regress postgres pgport pgcommon)
+endif()
+
+set_target_properties(regress PROPERTIES PREFIX "")
+add_dependencies(regress postgres)
+
+add_custom_target(tablespace-setup
+	COMMAND ${CMAKE_COMMAND} -E remove_directory ./testtablespace
+	COMMAND ${CMAKE_COMMAND} -E make_directory ./testtablespace
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+	add_custom_target(check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install ${check_make_command} install
+		COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/ ${check_make_command} installcheck_tmp
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+else()
+	add_custom_target(check
+		COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} install DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/tmp_install
+		COMMAND ${check_make_command} installcheck_tmp DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/
+		DEPENDS tablespace-setup
+		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+	)
+endif()
+
+add_custom_target(installcheck
+	COMMAND ${pg_regress_check} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/parallel_schedule --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(installcheck_tmp
+	COMMAND ${pg_regress_check_tmp} ${REGRESS_OPTS} --schedule=${CMAKE_CURRENT_SOURCE_DIR}/parallel_schedule --dlpath=${CMAKE_CURRENT_BINARY_DIR}/tmp_install${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${EXTRA_TESTS}
+	DEPENDS tablespace-setup
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+install(TARGETS pg_regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
+
+install(TARGETS regress
+		RUNTIME DESTINATION ${PGBINDIR}
+		LIBRARY DESTINATION ${LIBDIR})
diff --git a/src/test/ssl/CMakeLists.txt b/src/test/ssl/CMakeLists.txt
new file mode 100644
index 0000000000..a6df3f2dda
--- /dev/null
+++ b/src/test/ssl/CMakeLists.txt
@@ -0,0 +1,5 @@
+# We must will add generate target
+
+if(PROVE)
+	TAP_CHECK("ssl_tap" "${TAP_FLAGS}" "t/*.pl")
+endif()
diff --git a/src/timezone/CMakeLists.txt b/src/timezone/CMakeLists.txt
new file mode 100644
index 0000000000..0441276988
--- /dev/null
+++ b/src/timezone/CMakeLists.txt
@@ -0,0 +1,81 @@
+#TODO compile timezones
+
+include_directories(
+	"${PROJECT_SOURCE_DIR}/src/include/libpq"
+	"${PROJECT_SOURCE_DIR}/src/interfaces/libpq"
+	"${PROJECT_SOURCE_DIR}/src/bin/pg_dump"
+)
+
+
+
+set(tzdata 
+	${CMAKE_CURRENT_SOURCE_DIR}/data/africa
+	${CMAKE_CURRENT_SOURCE_DIR}/data/antarctica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/asia
+	${CMAKE_CURRENT_SOURCE_DIR}/data/australasia
+	${CMAKE_CURRENT_SOURCE_DIR}/data/europe
+	${CMAKE_CURRENT_SOURCE_DIR}/data/northamerica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/southamerica
+	${CMAKE_CURRENT_SOURCE_DIR}/data/pacificnew
+	${CMAKE_CURRENT_SOURCE_DIR}/data/etcetera
+	${CMAKE_CURRENT_SOURCE_DIR}/data/factory
+	${CMAKE_CURRENT_SOURCE_DIR}/data/backward
+	${CMAKE_CURRENT_SOURCE_DIR}/data/systemv
+)
+
+add_executable(zic
+	zic.c
+)
+target_link_libraries(zic
+	pgport
+)
+
+if(MSVC)
+	foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
+		string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
+		set_target_properties(zic PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+		set_target_properties(zic PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+		set_target_properties(zic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR} )
+	endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
+endif(MSVC)
+
+
+install(FILES 
+	tznames/Africa.txt
+	tznames/America.txt
+	tznames/Antarctica.txt
+	tznames/Asia.txt
+	tznames/Atlantic.txt
+	tznames/Australia.txt
+	tznames/Etc.txt
+	tznames/Europe.txt
+	tznames/Indian.txt
+	tznames/Pacific.txt
+	tznames/Default
+	tznames/Australia
+	tznames/India
+DESTINATION ${PGSHAREDIR}/timezonesets)
+
+function(JOIN VALUES GLUE OUTPUT)
+  string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
+  string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
+  set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
+endfunction()
+
+if(MINGW)
+	string(SUBSTRING ${PGSHAREDIR} 1 1 CHAR_POS)
+	if(CHAR_POS STREQUAL ":")
+		string(SUBSTRING ${PGSHAREDIR} 2 -1 PGSHAREDIR_ZIC)
+	else()
+		set(PGSHAREDIR_ZIC ${PGSHAREDIR})
+	endif()
+else()
+	set(PGSHAREDIR_ZIC ${PGSHAREDIR})
+endif()
+
+JOIN("${tzdata}" " " tzdata_string)
+install(
+	CODE "message('${CMAKE_CURRENT_BINARY_DIR}/zic${CMAKE_EXECUTABLE_SUFFIX} \$ENV{DESTDIR}${PGSHAREDIR_ZIC}/timezone -p US/Eastern ${tzdata_string}')"
+	CODE "execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/zic${CMAKE_EXECUTABLE_SUFFIX} -d \"\$ENV{DESTDIR}${PGSHAREDIR_ZIC}/timezone\" -p \"US/Eastern\" ${tzdata_string})"
+)
+
cmake_v2_2_c_define.patchtext/x-patch; charset=US-ASCII; name=cmake_v2_2_c_define.patchDownload
diff --git a/src/include/c.h b/src/include/c.h
index 672e21e03e..b435d07498 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -72,6 +72,10 @@
 #undef errcode
 #endif
 
+#if _MSC_VER >= 1800 && defined(USE_FP_STRICT)
+#pragma fenv_access (off)
+#endif
+
 /*
  * We have to include stdlib.h here because it defines many of these macros
  * on some platforms, and we only want our definitions used if stdlib.h doesn't
@@ -317,8 +321,7 @@ typedef unsigned long long int uint64;
  *		There currently is only a limited support for the type. E.g. 128bit
  *		literals and snprintf are not supported; but math is.
  */
-#if defined(PG_INT128_TYPE)
-#define HAVE_INT128
+#if defined(HAVE_INT128)
 typedef PG_INT128_TYPE int128;
 typedef unsigned PG_INT128_TYPE uint128;
 #endif
cmake_v2_3_rijndael.patchtext/x-patch; charset=US-ASCII; name=cmake_v2_3_rijndael.patchDownload
diff --git a/contrib/pgcrypto/rijndael.c b/contrib/pgcrypto/rijndael.c
index 4adbcc1f91..af7b87c5ef 100644
--- a/contrib/pgcrypto/rijndael.c
+++ b/contrib/pgcrypto/rijndael.c
@@ -78,8 +78,9 @@ static void gen_tabs(void);
 #endif
 
 #ifdef PRE_CALC_TABLES
-
-#include "rijndael.tbl"
+/* WRAP_INCLUDE for remove CMake circular dependency */
+#define WRAP_INCLUDE(x) x
+#include WRAP_INCLUDE("rijndael.tbl")
 #define tab_gen		1
 #else							/* !PRE_CALC_TABLES */
 
diff --git a/contrib/pgcrypto/rijndael.tbl b/contrib/pgcrypto/rijndael.tbl
deleted file mode 100644
index c7610c0134..0000000000
--- a/contrib/pgcrypto/rijndael.tbl
+++ /dev/null
@@ -1,1138 +0,0 @@
-/* Generated by rijndael.c */
-
-static const u1byte  pow_tab[256] = {
-  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
-  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
-  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
-  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
-  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
-  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
-  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
-  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
-  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
-  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
-  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
-  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
-  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
-  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
-  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
-  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
-};
-
-static const u1byte  log_tab[256] = {
-  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
-  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
-  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
-  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
-  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
-  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
-  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
-  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
-  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
-  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
-  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
-  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
-  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
-  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
-  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
-  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
-};
-
-static const u1byte  sbx_tab[256] = {
-  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
-  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
-  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
-  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
-  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
-  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
-  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
-  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
-  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
-  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
-  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
-  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
-  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
-  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
-  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
-  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
-};
-
-static const u1byte  isb_tab[256] = {
-  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
-  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
-  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
-  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
-  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
-  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
-  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
-  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
-  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
-  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
-  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
-  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
-  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
-  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
-  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
-  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
-};
-
-static const u4byte  ft_tab[4][256] = {
-{
-  0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6,
-  0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591,
-  0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56,
-  0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec,
-  0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa,
-  0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb,
-  0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45,
-  0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b,
-  0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c,
-  0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83,
-  0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9,
-  0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a,
-  0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d,
-  0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f,
-  0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df,
-  0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea,
-  0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34,
-  0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b,
-  0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d,
-  0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413,
-  0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1,
-  0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6,
-  0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972,
-  0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85,
-  0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed,
-  0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511,
-  0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe,
-  0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b,
-  0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05,
-  0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
-  0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142,
-  0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf,
-  0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3,
-  0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e,
-  0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a,
-  0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6,
-  0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3,
-  0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b,
-  0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428,
-  0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad,
-  0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14,
-  0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8,
-  0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4,
-  0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2,
-  0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda,
-  0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949,
-  0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf,
-  0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810,
-  0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c,
-  0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697,
-  0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e,
-  0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f,
-  0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc,
-  0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c,
-  0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969,
-  0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27,
-  0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122,
-  0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433,
-  0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9,
-  0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
-  0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a,
-  0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0,
-  0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e,
-  0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c
-}, {
-  0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d,
-  0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154,
-  0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d,
-  0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a,
-  0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87,
-  0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b,
-  0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea,
-  0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b,
-  0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a,
-  0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f,
-  0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908,
-  0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f,
-  0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e,
-  0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5,
-  0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d,
-  0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f,
-  0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e,
-  0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb,
-  0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce,
-  0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397,
-  0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c,
-  0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed,
-  0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b,
-  0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a,
-  0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16,
-  0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194,
-  0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81,
-  0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3,
-  0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a,
-  0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104,
-  0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263,
-  0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d,
-  0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f,
-  0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39,
-  0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47,
-  0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695,
-  0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f,
-  0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83,
-  0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c,
-  0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76,
-  0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e,
-  0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4,
-  0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6,
-  0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b,
-  0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7,
-  0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0,
-  0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25,
-  0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018,
-  0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72,
-  0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751,
-  0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21,
-  0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85,
-  0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa,
-  0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12,
-  0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0,
-  0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9,
-  0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233,
-  0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7,
-  0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920,
-  0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a,
-  0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17,
-  0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8,
-  0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11,
-  0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a
-}, {
-  0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b,
-  0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5,
-  0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b,
-  0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76,
-  0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d,
-  0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0,
-  0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf,
-  0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0,
-  0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26,
-  0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc,
-  0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1,
-  0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15,
-  0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3,
-  0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a,
-  0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2,
-  0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75,
-  0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a,
-  0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0,
-  0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3,
-  0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784,
-  0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced,
-  0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b,
-  0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39,
-  0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf,
-  0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb,
-  0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485,
-  0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f,
-  0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8,
-  0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f,
-  0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5,
-  0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321,
-  0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2,
-  0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec,
-  0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917,
-  0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d,
-  0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573,
-  0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc,
-  0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388,
-  0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14,
-  0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db,
-  0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a,
-  0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c,
-  0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662,
-  0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79,
-  0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d,
-  0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9,
-  0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea,
-  0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808,
-  0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e,
-  0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6,
-  0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f,
-  0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a,
-  0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66,
-  0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e,
-  0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9,
-  0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e,
-  0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311,
-  0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794,
-  0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9,
-  0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf,
-  0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d,
-  0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868,
-  0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f,
-  0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16
-}, {
-  0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b,
-  0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5,
-  0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b,
-  0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676,
-  0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d,
-  0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0,
-  0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf,
-  0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0,
-  0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626,
-  0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc,
-  0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1,
-  0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515,
-  0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3,
-  0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a,
-  0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2,
-  0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575,
-  0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a,
-  0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0,
-  0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3,
-  0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484,
-  0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded,
-  0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b,
-  0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939,
-  0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf,
-  0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb,
-  0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585,
-  0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f,
-  0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8,
-  0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f,
-  0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5,
-  0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121,
-  0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2,
-  0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec,
-  0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717,
-  0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d,
-  0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373,
-  0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc,
-  0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888,
-  0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414,
-  0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb,
-  0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a,
-  0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c,
-  0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262,
-  0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979,
-  0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d,
-  0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9,
-  0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea,
-  0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808,
-  0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e,
-  0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6,
-  0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f,
-  0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a,
-  0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666,
-  0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e,
-  0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9,
-  0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e,
-  0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111,
-  0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494,
-  0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9,
-  0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf,
-  0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d,
-  0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868,
-  0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f,
-  0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616
-}
-};
-
-static const u4byte  it_tab[4][256] = {
-{
-  0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a,
-  0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b,
-  0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5,
-  0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5,
-  0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d,
-  0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b,
-  0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295,
-  0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e,
-  0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927,
-  0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d,
-  0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362,
-  0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9,
-  0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52,
-  0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566,
-  0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3,
-  0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed,
-  0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e,
-  0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4,
-  0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4,
-  0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd,
-  0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d,
-  0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060,
-  0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967,
-  0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879,
-  0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000,
-  0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c,
-  0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36,
-  0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624,
-  0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b,
-  0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c,
-  0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12,
-  0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14,
-  0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3,
-  0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b,
-  0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8,
-  0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684,
-  0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7,
-  0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177,
-  0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947,
-  0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322,
-  0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498,
-  0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f,
-  0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54,
-  0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382,
-  0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf,
-  0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb,
-  0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83,
-  0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef,
-  0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029,
-  0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235,
-  0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733,
-  0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117,
-  0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4,
-  0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546,
-  0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb,
-  0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d,
-  0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb,
-  0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a,
-  0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773,
-  0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478,
-  0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2,
-  0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff,
-  0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664,
-  0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0
-}, {
-  0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96,
-  0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93,
-  0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525,
-  0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f,
-  0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1,
-  0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6,
-  0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da,
-  0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44,
-  0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd,
-  0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4,
-  0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245,
-  0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994,
-  0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7,
-  0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a,
-  0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5,
-  0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c,
-  0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1,
-  0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a,
-  0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475,
-  0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51,
-  0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46,
-  0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff,
-  0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777,
-  0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db,
-  0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000,
-  0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e,
-  0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627,
-  0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a,
-  0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e,
-  0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16,
-  0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d,
-  0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8,
-  0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd,
-  0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34,
-  0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863,
-  0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420,
-  0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d,
-  0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0,
-  0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722,
-  0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef,
-  0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836,
-  0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4,
-  0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462,
-  0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5,
-  0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3,
-  0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b,
-  0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8,
-  0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6,
-  0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6,
-  0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0,
-  0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315,
-  0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f,
-  0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df,
-  0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f,
-  0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e,
-  0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13,
-  0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89,
-  0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c,
-  0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf,
-  0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886,
-  0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f,
-  0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41,
-  0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490,
-  0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042
-}, {
-  0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e,
-  0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303,
-  0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c,
-  0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3,
-  0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0,
-  0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9,
-  0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59,
-  0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8,
-  0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71,
-  0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a,
-  0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f,
-  0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b,
-  0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8,
-  0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab,
-  0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508,
-  0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82,
-  0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2,
-  0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe,
-  0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb,
-  0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110,
-  0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd,
-  0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15,
-  0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e,
-  0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee,
-  0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000,
-  0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72,
-  0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739,
-  0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e,
-  0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91,
-  0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a,
-  0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17,
-  0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9,
-  0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60,
-  0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e,
-  0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1,
-  0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011,
-  0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1,
-  0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3,
-  0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264,
-  0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90,
-  0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b,
-  0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf,
-  0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246,
-  0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af,
-  0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312,
-  0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb,
-  0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a,
-  0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8,
-  0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c,
-  0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066,
-  0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8,
-  0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6,
-  0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04,
-  0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51,
-  0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41,
-  0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347,
-  0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c,
-  0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1,
-  0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37,
-  0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db,
-  0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40,
-  0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195,
-  0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1,
-  0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257
-}, {
-  0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27,
-  0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3,
-  0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02,
-  0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362,
-  0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe,
-  0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3,
-  0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952,
-  0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9,
-  0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9,
-  0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace,
-  0x63184adf, 0xe582311a, 0x97603351, 0x62457f53,
-  0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08,
-  0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b,
-  0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55,
-  0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837,
-  0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216,
-  0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269,
-  0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6,
-  0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6,
-  0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e,
-  0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6,
-  0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550,
-  0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9,
-  0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8,
-  0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000,
-  0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a,
-  0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d,
-  0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36,
-  0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b,
-  0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12,
-  0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b,
-  0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e,
-  0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f,
-  0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb,
-  0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4,
-  0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6,
-  0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129,
-  0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1,
-  0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9,
-  0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033,
-  0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4,
-  0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad,
-  0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e,
-  0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3,
-  0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225,
-  0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b,
-  0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f,
-  0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815,
-  0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0,
-  0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2,
-  0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7,
-  0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691,
-  0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496,
-  0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165,
-  0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b,
-  0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6,
-  0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13,
-  0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147,
-  0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7,
-  0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44,
-  0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3,
-  0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d,
-  0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156,
-  0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8
-}
-};
-
-static const u4byte  fl_tab[4][256] = {
-{
-  0x00000063, 0x0000007c, 0x00000077, 0x0000007b,
-  0x000000f2, 0x0000006b, 0x0000006f, 0x000000c5,
-  0x00000030, 0x00000001, 0x00000067, 0x0000002b,
-  0x000000fe, 0x000000d7, 0x000000ab, 0x00000076,
-  0x000000ca, 0x00000082, 0x000000c9, 0x0000007d,
-  0x000000fa, 0x00000059, 0x00000047, 0x000000f0,
-  0x000000ad, 0x000000d4, 0x000000a2, 0x000000af,
-  0x0000009c, 0x000000a4, 0x00000072, 0x000000c0,
-  0x000000b7, 0x000000fd, 0x00000093, 0x00000026,
-  0x00000036, 0x0000003f, 0x000000f7, 0x000000cc,
-  0x00000034, 0x000000a5, 0x000000e5, 0x000000f1,
-  0x00000071, 0x000000d8, 0x00000031, 0x00000015,
-  0x00000004, 0x000000c7, 0x00000023, 0x000000c3,
-  0x00000018, 0x00000096, 0x00000005, 0x0000009a,
-  0x00000007, 0x00000012, 0x00000080, 0x000000e2,
-  0x000000eb, 0x00000027, 0x000000b2, 0x00000075,
-  0x00000009, 0x00000083, 0x0000002c, 0x0000001a,
-  0x0000001b, 0x0000006e, 0x0000005a, 0x000000a0,
-  0x00000052, 0x0000003b, 0x000000d6, 0x000000b3,
-  0x00000029, 0x000000e3, 0x0000002f, 0x00000084,
-  0x00000053, 0x000000d1, 0x00000000, 0x000000ed,
-  0x00000020, 0x000000fc, 0x000000b1, 0x0000005b,
-  0x0000006a, 0x000000cb, 0x000000be, 0x00000039,
-  0x0000004a, 0x0000004c, 0x00000058, 0x000000cf,
-  0x000000d0, 0x000000ef, 0x000000aa, 0x000000fb,
-  0x00000043, 0x0000004d, 0x00000033, 0x00000085,
-  0x00000045, 0x000000f9, 0x00000002, 0x0000007f,
-  0x00000050, 0x0000003c, 0x0000009f, 0x000000a8,
-  0x00000051, 0x000000a3, 0x00000040, 0x0000008f,
-  0x00000092, 0x0000009d, 0x00000038, 0x000000f5,
-  0x000000bc, 0x000000b6, 0x000000da, 0x00000021,
-  0x00000010, 0x000000ff, 0x000000f3, 0x000000d2,
-  0x000000cd, 0x0000000c, 0x00000013, 0x000000ec,
-  0x0000005f, 0x00000097, 0x00000044, 0x00000017,
-  0x000000c4, 0x000000a7, 0x0000007e, 0x0000003d,
-  0x00000064, 0x0000005d, 0x00000019, 0x00000073,
-  0x00000060, 0x00000081, 0x0000004f, 0x000000dc,
-  0x00000022, 0x0000002a, 0x00000090, 0x00000088,
-  0x00000046, 0x000000ee, 0x000000b8, 0x00000014,
-  0x000000de, 0x0000005e, 0x0000000b, 0x000000db,
-  0x000000e0, 0x00000032, 0x0000003a, 0x0000000a,
-  0x00000049, 0x00000006, 0x00000024, 0x0000005c,
-  0x000000c2, 0x000000d3, 0x000000ac, 0x00000062,
-  0x00000091, 0x00000095, 0x000000e4, 0x00000079,
-  0x000000e7, 0x000000c8, 0x00000037, 0x0000006d,
-  0x0000008d, 0x000000d5, 0x0000004e, 0x000000a9,
-  0x0000006c, 0x00000056, 0x000000f4, 0x000000ea,
-  0x00000065, 0x0000007a, 0x000000ae, 0x00000008,
-  0x000000ba, 0x00000078, 0x00000025, 0x0000002e,
-  0x0000001c, 0x000000a6, 0x000000b4, 0x000000c6,
-  0x000000e8, 0x000000dd, 0x00000074, 0x0000001f,
-  0x0000004b, 0x000000bd, 0x0000008b, 0x0000008a,
-  0x00000070, 0x0000003e, 0x000000b5, 0x00000066,
-  0x00000048, 0x00000003, 0x000000f6, 0x0000000e,
-  0x00000061, 0x00000035, 0x00000057, 0x000000b9,
-  0x00000086, 0x000000c1, 0x0000001d, 0x0000009e,
-  0x000000e1, 0x000000f8, 0x00000098, 0x00000011,
-  0x00000069, 0x000000d9, 0x0000008e, 0x00000094,
-  0x0000009b, 0x0000001e, 0x00000087, 0x000000e9,
-  0x000000ce, 0x00000055, 0x00000028, 0x000000df,
-  0x0000008c, 0x000000a1, 0x00000089, 0x0000000d,
-  0x000000bf, 0x000000e6, 0x00000042, 0x00000068,
-  0x00000041, 0x00000099, 0x0000002d, 0x0000000f,
-  0x000000b0, 0x00000054, 0x000000bb, 0x00000016
-}, {
-  0x00006300, 0x00007c00, 0x00007700, 0x00007b00,
-  0x0000f200, 0x00006b00, 0x00006f00, 0x0000c500,
-  0x00003000, 0x00000100, 0x00006700, 0x00002b00,
-  0x0000fe00, 0x0000d700, 0x0000ab00, 0x00007600,
-  0x0000ca00, 0x00008200, 0x0000c900, 0x00007d00,
-  0x0000fa00, 0x00005900, 0x00004700, 0x0000f000,
-  0x0000ad00, 0x0000d400, 0x0000a200, 0x0000af00,
-  0x00009c00, 0x0000a400, 0x00007200, 0x0000c000,
-  0x0000b700, 0x0000fd00, 0x00009300, 0x00002600,
-  0x00003600, 0x00003f00, 0x0000f700, 0x0000cc00,
-  0x00003400, 0x0000a500, 0x0000e500, 0x0000f100,
-  0x00007100, 0x0000d800, 0x00003100, 0x00001500,
-  0x00000400, 0x0000c700, 0x00002300, 0x0000c300,
-  0x00001800, 0x00009600, 0x00000500, 0x00009a00,
-  0x00000700, 0x00001200, 0x00008000, 0x0000e200,
-  0x0000eb00, 0x00002700, 0x0000b200, 0x00007500,
-  0x00000900, 0x00008300, 0x00002c00, 0x00001a00,
-  0x00001b00, 0x00006e00, 0x00005a00, 0x0000a000,
-  0x00005200, 0x00003b00, 0x0000d600, 0x0000b300,
-  0x00002900, 0x0000e300, 0x00002f00, 0x00008400,
-  0x00005300, 0x0000d100, 0x00000000, 0x0000ed00,
-  0x00002000, 0x0000fc00, 0x0000b100, 0x00005b00,
-  0x00006a00, 0x0000cb00, 0x0000be00, 0x00003900,
-  0x00004a00, 0x00004c00, 0x00005800, 0x0000cf00,
-  0x0000d000, 0x0000ef00, 0x0000aa00, 0x0000fb00,
-  0x00004300, 0x00004d00, 0x00003300, 0x00008500,
-  0x00004500, 0x0000f900, 0x00000200, 0x00007f00,
-  0x00005000, 0x00003c00, 0x00009f00, 0x0000a800,
-  0x00005100, 0x0000a300, 0x00004000, 0x00008f00,
-  0x00009200, 0x00009d00, 0x00003800, 0x0000f500,
-  0x0000bc00, 0x0000b600, 0x0000da00, 0x00002100,
-  0x00001000, 0x0000ff00, 0x0000f300, 0x0000d200,
-  0x0000cd00, 0x00000c00, 0x00001300, 0x0000ec00,
-  0x00005f00, 0x00009700, 0x00004400, 0x00001700,
-  0x0000c400, 0x0000a700, 0x00007e00, 0x00003d00,
-  0x00006400, 0x00005d00, 0x00001900, 0x00007300,
-  0x00006000, 0x00008100, 0x00004f00, 0x0000dc00,
-  0x00002200, 0x00002a00, 0x00009000, 0x00008800,
-  0x00004600, 0x0000ee00, 0x0000b800, 0x00001400,
-  0x0000de00, 0x00005e00, 0x00000b00, 0x0000db00,
-  0x0000e000, 0x00003200, 0x00003a00, 0x00000a00,
-  0x00004900, 0x00000600, 0x00002400, 0x00005c00,
-  0x0000c200, 0x0000d300, 0x0000ac00, 0x00006200,
-  0x00009100, 0x00009500, 0x0000e400, 0x00007900,
-  0x0000e700, 0x0000c800, 0x00003700, 0x00006d00,
-  0x00008d00, 0x0000d500, 0x00004e00, 0x0000a900,
-  0x00006c00, 0x00005600, 0x0000f400, 0x0000ea00,
-  0x00006500, 0x00007a00, 0x0000ae00, 0x00000800,
-  0x0000ba00, 0x00007800, 0x00002500, 0x00002e00,
-  0x00001c00, 0x0000a600, 0x0000b400, 0x0000c600,
-  0x0000e800, 0x0000dd00, 0x00007400, 0x00001f00,
-  0x00004b00, 0x0000bd00, 0x00008b00, 0x00008a00,
-  0x00007000, 0x00003e00, 0x0000b500, 0x00006600,
-  0x00004800, 0x00000300, 0x0000f600, 0x00000e00,
-  0x00006100, 0x00003500, 0x00005700, 0x0000b900,
-  0x00008600, 0x0000c100, 0x00001d00, 0x00009e00,
-  0x0000e100, 0x0000f800, 0x00009800, 0x00001100,
-  0x00006900, 0x0000d900, 0x00008e00, 0x00009400,
-  0x00009b00, 0x00001e00, 0x00008700, 0x0000e900,
-  0x0000ce00, 0x00005500, 0x00002800, 0x0000df00,
-  0x00008c00, 0x0000a100, 0x00008900, 0x00000d00,
-  0x0000bf00, 0x0000e600, 0x00004200, 0x00006800,
-  0x00004100, 0x00009900, 0x00002d00, 0x00000f00,
-  0x0000b000, 0x00005400, 0x0000bb00, 0x00001600
-}, {
-  0x00630000, 0x007c0000, 0x00770000, 0x007b0000,
-  0x00f20000, 0x006b0000, 0x006f0000, 0x00c50000,
-  0x00300000, 0x00010000, 0x00670000, 0x002b0000,
-  0x00fe0000, 0x00d70000, 0x00ab0000, 0x00760000,
-  0x00ca0000, 0x00820000, 0x00c90000, 0x007d0000,
-  0x00fa0000, 0x00590000, 0x00470000, 0x00f00000,
-  0x00ad0000, 0x00d40000, 0x00a20000, 0x00af0000,
-  0x009c0000, 0x00a40000, 0x00720000, 0x00c00000,
-  0x00b70000, 0x00fd0000, 0x00930000, 0x00260000,
-  0x00360000, 0x003f0000, 0x00f70000, 0x00cc0000,
-  0x00340000, 0x00a50000, 0x00e50000, 0x00f10000,
-  0x00710000, 0x00d80000, 0x00310000, 0x00150000,
-  0x00040000, 0x00c70000, 0x00230000, 0x00c30000,
-  0x00180000, 0x00960000, 0x00050000, 0x009a0000,
-  0x00070000, 0x00120000, 0x00800000, 0x00e20000,
-  0x00eb0000, 0x00270000, 0x00b20000, 0x00750000,
-  0x00090000, 0x00830000, 0x002c0000, 0x001a0000,
-  0x001b0000, 0x006e0000, 0x005a0000, 0x00a00000,
-  0x00520000, 0x003b0000, 0x00d60000, 0x00b30000,
-  0x00290000, 0x00e30000, 0x002f0000, 0x00840000,
-  0x00530000, 0x00d10000, 0x00000000, 0x00ed0000,
-  0x00200000, 0x00fc0000, 0x00b10000, 0x005b0000,
-  0x006a0000, 0x00cb0000, 0x00be0000, 0x00390000,
-  0x004a0000, 0x004c0000, 0x00580000, 0x00cf0000,
-  0x00d00000, 0x00ef0000, 0x00aa0000, 0x00fb0000,
-  0x00430000, 0x004d0000, 0x00330000, 0x00850000,
-  0x00450000, 0x00f90000, 0x00020000, 0x007f0000,
-  0x00500000, 0x003c0000, 0x009f0000, 0x00a80000,
-  0x00510000, 0x00a30000, 0x00400000, 0x008f0000,
-  0x00920000, 0x009d0000, 0x00380000, 0x00f50000,
-  0x00bc0000, 0x00b60000, 0x00da0000, 0x00210000,
-  0x00100000, 0x00ff0000, 0x00f30000, 0x00d20000,
-  0x00cd0000, 0x000c0000, 0x00130000, 0x00ec0000,
-  0x005f0000, 0x00970000, 0x00440000, 0x00170000,
-  0x00c40000, 0x00a70000, 0x007e0000, 0x003d0000,
-  0x00640000, 0x005d0000, 0x00190000, 0x00730000,
-  0x00600000, 0x00810000, 0x004f0000, 0x00dc0000,
-  0x00220000, 0x002a0000, 0x00900000, 0x00880000,
-  0x00460000, 0x00ee0000, 0x00b80000, 0x00140000,
-  0x00de0000, 0x005e0000, 0x000b0000, 0x00db0000,
-  0x00e00000, 0x00320000, 0x003a0000, 0x000a0000,
-  0x00490000, 0x00060000, 0x00240000, 0x005c0000,
-  0x00c20000, 0x00d30000, 0x00ac0000, 0x00620000,
-  0x00910000, 0x00950000, 0x00e40000, 0x00790000,
-  0x00e70000, 0x00c80000, 0x00370000, 0x006d0000,
-  0x008d0000, 0x00d50000, 0x004e0000, 0x00a90000,
-  0x006c0000, 0x00560000, 0x00f40000, 0x00ea0000,
-  0x00650000, 0x007a0000, 0x00ae0000, 0x00080000,
-  0x00ba0000, 0x00780000, 0x00250000, 0x002e0000,
-  0x001c0000, 0x00a60000, 0x00b40000, 0x00c60000,
-  0x00e80000, 0x00dd0000, 0x00740000, 0x001f0000,
-  0x004b0000, 0x00bd0000, 0x008b0000, 0x008a0000,
-  0x00700000, 0x003e0000, 0x00b50000, 0x00660000,
-  0x00480000, 0x00030000, 0x00f60000, 0x000e0000,
-  0x00610000, 0x00350000, 0x00570000, 0x00b90000,
-  0x00860000, 0x00c10000, 0x001d0000, 0x009e0000,
-  0x00e10000, 0x00f80000, 0x00980000, 0x00110000,
-  0x00690000, 0x00d90000, 0x008e0000, 0x00940000,
-  0x009b0000, 0x001e0000, 0x00870000, 0x00e90000,
-  0x00ce0000, 0x00550000, 0x00280000, 0x00df0000,
-  0x008c0000, 0x00a10000, 0x00890000, 0x000d0000,
-  0x00bf0000, 0x00e60000, 0x00420000, 0x00680000,
-  0x00410000, 0x00990000, 0x002d0000, 0x000f0000,
-  0x00b00000, 0x00540000, 0x00bb0000, 0x00160000
-}, {
-  0x63000000, 0x7c000000, 0x77000000, 0x7b000000,
-  0xf2000000, 0x6b000000, 0x6f000000, 0xc5000000,
-  0x30000000, 0x01000000, 0x67000000, 0x2b000000,
-  0xfe000000, 0xd7000000, 0xab000000, 0x76000000,
-  0xca000000, 0x82000000, 0xc9000000, 0x7d000000,
-  0xfa000000, 0x59000000, 0x47000000, 0xf0000000,
-  0xad000000, 0xd4000000, 0xa2000000, 0xaf000000,
-  0x9c000000, 0xa4000000, 0x72000000, 0xc0000000,
-  0xb7000000, 0xfd000000, 0x93000000, 0x26000000,
-  0x36000000, 0x3f000000, 0xf7000000, 0xcc000000,
-  0x34000000, 0xa5000000, 0xe5000000, 0xf1000000,
-  0x71000000, 0xd8000000, 0x31000000, 0x15000000,
-  0x04000000, 0xc7000000, 0x23000000, 0xc3000000,
-  0x18000000, 0x96000000, 0x05000000, 0x9a000000,
-  0x07000000, 0x12000000, 0x80000000, 0xe2000000,
-  0xeb000000, 0x27000000, 0xb2000000, 0x75000000,
-  0x09000000, 0x83000000, 0x2c000000, 0x1a000000,
-  0x1b000000, 0x6e000000, 0x5a000000, 0xa0000000,
-  0x52000000, 0x3b000000, 0xd6000000, 0xb3000000,
-  0x29000000, 0xe3000000, 0x2f000000, 0x84000000,
-  0x53000000, 0xd1000000, 0x00000000, 0xed000000,
-  0x20000000, 0xfc000000, 0xb1000000, 0x5b000000,
-  0x6a000000, 0xcb000000, 0xbe000000, 0x39000000,
-  0x4a000000, 0x4c000000, 0x58000000, 0xcf000000,
-  0xd0000000, 0xef000000, 0xaa000000, 0xfb000000,
-  0x43000000, 0x4d000000, 0x33000000, 0x85000000,
-  0x45000000, 0xf9000000, 0x02000000, 0x7f000000,
-  0x50000000, 0x3c000000, 0x9f000000, 0xa8000000,
-  0x51000000, 0xa3000000, 0x40000000, 0x8f000000,
-  0x92000000, 0x9d000000, 0x38000000, 0xf5000000,
-  0xbc000000, 0xb6000000, 0xda000000, 0x21000000,
-  0x10000000, 0xff000000, 0xf3000000, 0xd2000000,
-  0xcd000000, 0x0c000000, 0x13000000, 0xec000000,
-  0x5f000000, 0x97000000, 0x44000000, 0x17000000,
-  0xc4000000, 0xa7000000, 0x7e000000, 0x3d000000,
-  0x64000000, 0x5d000000, 0x19000000, 0x73000000,
-  0x60000000, 0x81000000, 0x4f000000, 0xdc000000,
-  0x22000000, 0x2a000000, 0x90000000, 0x88000000,
-  0x46000000, 0xee000000, 0xb8000000, 0x14000000,
-  0xde000000, 0x5e000000, 0x0b000000, 0xdb000000,
-  0xe0000000, 0x32000000, 0x3a000000, 0x0a000000,
-  0x49000000, 0x06000000, 0x24000000, 0x5c000000,
-  0xc2000000, 0xd3000000, 0xac000000, 0x62000000,
-  0x91000000, 0x95000000, 0xe4000000, 0x79000000,
-  0xe7000000, 0xc8000000, 0x37000000, 0x6d000000,
-  0x8d000000, 0xd5000000, 0x4e000000, 0xa9000000,
-  0x6c000000, 0x56000000, 0xf4000000, 0xea000000,
-  0x65000000, 0x7a000000, 0xae000000, 0x08000000,
-  0xba000000, 0x78000000, 0x25000000, 0x2e000000,
-  0x1c000000, 0xa6000000, 0xb4000000, 0xc6000000,
-  0xe8000000, 0xdd000000, 0x74000000, 0x1f000000,
-  0x4b000000, 0xbd000000, 0x8b000000, 0x8a000000,
-  0x70000000, 0x3e000000, 0xb5000000, 0x66000000,
-  0x48000000, 0x03000000, 0xf6000000, 0x0e000000,
-  0x61000000, 0x35000000, 0x57000000, 0xb9000000,
-  0x86000000, 0xc1000000, 0x1d000000, 0x9e000000,
-  0xe1000000, 0xf8000000, 0x98000000, 0x11000000,
-  0x69000000, 0xd9000000, 0x8e000000, 0x94000000,
-  0x9b000000, 0x1e000000, 0x87000000, 0xe9000000,
-  0xce000000, 0x55000000, 0x28000000, 0xdf000000,
-  0x8c000000, 0xa1000000, 0x89000000, 0x0d000000,
-  0xbf000000, 0xe6000000, 0x42000000, 0x68000000,
-  0x41000000, 0x99000000, 0x2d000000, 0x0f000000,
-  0xb0000000, 0x54000000, 0xbb000000, 0x16000000
-}
-};
-
-static const u4byte  il_tab[4][256] = {
-{
-  0x00000052, 0x00000009, 0x0000006a, 0x000000d5,
-  0x00000030, 0x00000036, 0x000000a5, 0x00000038,
-  0x000000bf, 0x00000040, 0x000000a3, 0x0000009e,
-  0x00000081, 0x000000f3, 0x000000d7, 0x000000fb,
-  0x0000007c, 0x000000e3, 0x00000039, 0x00000082,
-  0x0000009b, 0x0000002f, 0x000000ff, 0x00000087,
-  0x00000034, 0x0000008e, 0x00000043, 0x00000044,
-  0x000000c4, 0x000000de, 0x000000e9, 0x000000cb,
-  0x00000054, 0x0000007b, 0x00000094, 0x00000032,
-  0x000000a6, 0x000000c2, 0x00000023, 0x0000003d,
-  0x000000ee, 0x0000004c, 0x00000095, 0x0000000b,
-  0x00000042, 0x000000fa, 0x000000c3, 0x0000004e,
-  0x00000008, 0x0000002e, 0x000000a1, 0x00000066,
-  0x00000028, 0x000000d9, 0x00000024, 0x000000b2,
-  0x00000076, 0x0000005b, 0x000000a2, 0x00000049,
-  0x0000006d, 0x0000008b, 0x000000d1, 0x00000025,
-  0x00000072, 0x000000f8, 0x000000f6, 0x00000064,
-  0x00000086, 0x00000068, 0x00000098, 0x00000016,
-  0x000000d4, 0x000000a4, 0x0000005c, 0x000000cc,
-  0x0000005d, 0x00000065, 0x000000b6, 0x00000092,
-  0x0000006c, 0x00000070, 0x00000048, 0x00000050,
-  0x000000fd, 0x000000ed, 0x000000b9, 0x000000da,
-  0x0000005e, 0x00000015, 0x00000046, 0x00000057,
-  0x000000a7, 0x0000008d, 0x0000009d, 0x00000084,
-  0x00000090, 0x000000d8, 0x000000ab, 0x00000000,
-  0x0000008c, 0x000000bc, 0x000000d3, 0x0000000a,
-  0x000000f7, 0x000000e4, 0x00000058, 0x00000005,
-  0x000000b8, 0x000000b3, 0x00000045, 0x00000006,
-  0x000000d0, 0x0000002c, 0x0000001e, 0x0000008f,
-  0x000000ca, 0x0000003f, 0x0000000f, 0x00000002,
-  0x000000c1, 0x000000af, 0x000000bd, 0x00000003,
-  0x00000001, 0x00000013, 0x0000008a, 0x0000006b,
-  0x0000003a, 0x00000091, 0x00000011, 0x00000041,
-  0x0000004f, 0x00000067, 0x000000dc, 0x000000ea,
-  0x00000097, 0x000000f2, 0x000000cf, 0x000000ce,
-  0x000000f0, 0x000000b4, 0x000000e6, 0x00000073,
-  0x00000096, 0x000000ac, 0x00000074, 0x00000022,
-  0x000000e7, 0x000000ad, 0x00000035, 0x00000085,
-  0x000000e2, 0x000000f9, 0x00000037, 0x000000e8,
-  0x0000001c, 0x00000075, 0x000000df, 0x0000006e,
-  0x00000047, 0x000000f1, 0x0000001a, 0x00000071,
-  0x0000001d, 0x00000029, 0x000000c5, 0x00000089,
-  0x0000006f, 0x000000b7, 0x00000062, 0x0000000e,
-  0x000000aa, 0x00000018, 0x000000be, 0x0000001b,
-  0x000000fc, 0x00000056, 0x0000003e, 0x0000004b,
-  0x000000c6, 0x000000d2, 0x00000079, 0x00000020,
-  0x0000009a, 0x000000db, 0x000000c0, 0x000000fe,
-  0x00000078, 0x000000cd, 0x0000005a, 0x000000f4,
-  0x0000001f, 0x000000dd, 0x000000a8, 0x00000033,
-  0x00000088, 0x00000007, 0x000000c7, 0x00000031,
-  0x000000b1, 0x00000012, 0x00000010, 0x00000059,
-  0x00000027, 0x00000080, 0x000000ec, 0x0000005f,
-  0x00000060, 0x00000051, 0x0000007f, 0x000000a9,
-  0x00000019, 0x000000b5, 0x0000004a, 0x0000000d,
-  0x0000002d, 0x000000e5, 0x0000007a, 0x0000009f,
-  0x00000093, 0x000000c9, 0x0000009c, 0x000000ef,
-  0x000000a0, 0x000000e0, 0x0000003b, 0x0000004d,
-  0x000000ae, 0x0000002a, 0x000000f5, 0x000000b0,
-  0x000000c8, 0x000000eb, 0x000000bb, 0x0000003c,
-  0x00000083, 0x00000053, 0x00000099, 0x00000061,
-  0x00000017, 0x0000002b, 0x00000004, 0x0000007e,
-  0x000000ba, 0x00000077, 0x000000d6, 0x00000026,
-  0x000000e1, 0x00000069, 0x00000014, 0x00000063,
-  0x00000055, 0x00000021, 0x0000000c, 0x0000007d
-}, {
-  0x00005200, 0x00000900, 0x00006a00, 0x0000d500,
-  0x00003000, 0x00003600, 0x0000a500, 0x00003800,
-  0x0000bf00, 0x00004000, 0x0000a300, 0x00009e00,
-  0x00008100, 0x0000f300, 0x0000d700, 0x0000fb00,
-  0x00007c00, 0x0000e300, 0x00003900, 0x00008200,
-  0x00009b00, 0x00002f00, 0x0000ff00, 0x00008700,
-  0x00003400, 0x00008e00, 0x00004300, 0x00004400,
-  0x0000c400, 0x0000de00, 0x0000e900, 0x0000cb00,
-  0x00005400, 0x00007b00, 0x00009400, 0x00003200,
-  0x0000a600, 0x0000c200, 0x00002300, 0x00003d00,
-  0x0000ee00, 0x00004c00, 0x00009500, 0x00000b00,
-  0x00004200, 0x0000fa00, 0x0000c300, 0x00004e00,
-  0x00000800, 0x00002e00, 0x0000a100, 0x00006600,
-  0x00002800, 0x0000d900, 0x00002400, 0x0000b200,
-  0x00007600, 0x00005b00, 0x0000a200, 0x00004900,
-  0x00006d00, 0x00008b00, 0x0000d100, 0x00002500,
-  0x00007200, 0x0000f800, 0x0000f600, 0x00006400,
-  0x00008600, 0x00006800, 0x00009800, 0x00001600,
-  0x0000d400, 0x0000a400, 0x00005c00, 0x0000cc00,
-  0x00005d00, 0x00006500, 0x0000b600, 0x00009200,
-  0x00006c00, 0x00007000, 0x00004800, 0x00005000,
-  0x0000fd00, 0x0000ed00, 0x0000b900, 0x0000da00,
-  0x00005e00, 0x00001500, 0x00004600, 0x00005700,
-  0x0000a700, 0x00008d00, 0x00009d00, 0x00008400,
-  0x00009000, 0x0000d800, 0x0000ab00, 0x00000000,
-  0x00008c00, 0x0000bc00, 0x0000d300, 0x00000a00,
-  0x0000f700, 0x0000e400, 0x00005800, 0x00000500,
-  0x0000b800, 0x0000b300, 0x00004500, 0x00000600,
-  0x0000d000, 0x00002c00, 0x00001e00, 0x00008f00,
-  0x0000ca00, 0x00003f00, 0x00000f00, 0x00000200,
-  0x0000c100, 0x0000af00, 0x0000bd00, 0x00000300,
-  0x00000100, 0x00001300, 0x00008a00, 0x00006b00,
-  0x00003a00, 0x00009100, 0x00001100, 0x00004100,
-  0x00004f00, 0x00006700, 0x0000dc00, 0x0000ea00,
-  0x00009700, 0x0000f200, 0x0000cf00, 0x0000ce00,
-  0x0000f000, 0x0000b400, 0x0000e600, 0x00007300,
-  0x00009600, 0x0000ac00, 0x00007400, 0x00002200,
-  0x0000e700, 0x0000ad00, 0x00003500, 0x00008500,
-  0x0000e200, 0x0000f900, 0x00003700, 0x0000e800,
-  0x00001c00, 0x00007500, 0x0000df00, 0x00006e00,
-  0x00004700, 0x0000f100, 0x00001a00, 0x00007100,
-  0x00001d00, 0x00002900, 0x0000c500, 0x00008900,
-  0x00006f00, 0x0000b700, 0x00006200, 0x00000e00,
-  0x0000aa00, 0x00001800, 0x0000be00, 0x00001b00,
-  0x0000fc00, 0x00005600, 0x00003e00, 0x00004b00,
-  0x0000c600, 0x0000d200, 0x00007900, 0x00002000,
-  0x00009a00, 0x0000db00, 0x0000c000, 0x0000fe00,
-  0x00007800, 0x0000cd00, 0x00005a00, 0x0000f400,
-  0x00001f00, 0x0000dd00, 0x0000a800, 0x00003300,
-  0x00008800, 0x00000700, 0x0000c700, 0x00003100,
-  0x0000b100, 0x00001200, 0x00001000, 0x00005900,
-  0x00002700, 0x00008000, 0x0000ec00, 0x00005f00,
-  0x00006000, 0x00005100, 0x00007f00, 0x0000a900,
-  0x00001900, 0x0000b500, 0x00004a00, 0x00000d00,
-  0x00002d00, 0x0000e500, 0x00007a00, 0x00009f00,
-  0x00009300, 0x0000c900, 0x00009c00, 0x0000ef00,
-  0x0000a000, 0x0000e000, 0x00003b00, 0x00004d00,
-  0x0000ae00, 0x00002a00, 0x0000f500, 0x0000b000,
-  0x0000c800, 0x0000eb00, 0x0000bb00, 0x00003c00,
-  0x00008300, 0x00005300, 0x00009900, 0x00006100,
-  0x00001700, 0x00002b00, 0x00000400, 0x00007e00,
-  0x0000ba00, 0x00007700, 0x0000d600, 0x00002600,
-  0x0000e100, 0x00006900, 0x00001400, 0x00006300,
-  0x00005500, 0x00002100, 0x00000c00, 0x00007d00
-}, {
-  0x00520000, 0x00090000, 0x006a0000, 0x00d50000,
-  0x00300000, 0x00360000, 0x00a50000, 0x00380000,
-  0x00bf0000, 0x00400000, 0x00a30000, 0x009e0000,
-  0x00810000, 0x00f30000, 0x00d70000, 0x00fb0000,
-  0x007c0000, 0x00e30000, 0x00390000, 0x00820000,
-  0x009b0000, 0x002f0000, 0x00ff0000, 0x00870000,
-  0x00340000, 0x008e0000, 0x00430000, 0x00440000,
-  0x00c40000, 0x00de0000, 0x00e90000, 0x00cb0000,
-  0x00540000, 0x007b0000, 0x00940000, 0x00320000,
-  0x00a60000, 0x00c20000, 0x00230000, 0x003d0000,
-  0x00ee0000, 0x004c0000, 0x00950000, 0x000b0000,
-  0x00420000, 0x00fa0000, 0x00c30000, 0x004e0000,
-  0x00080000, 0x002e0000, 0x00a10000, 0x00660000,
-  0x00280000, 0x00d90000, 0x00240000, 0x00b20000,
-  0x00760000, 0x005b0000, 0x00a20000, 0x00490000,
-  0x006d0000, 0x008b0000, 0x00d10000, 0x00250000,
-  0x00720000, 0x00f80000, 0x00f60000, 0x00640000,
-  0x00860000, 0x00680000, 0x00980000, 0x00160000,
-  0x00d40000, 0x00a40000, 0x005c0000, 0x00cc0000,
-  0x005d0000, 0x00650000, 0x00b60000, 0x00920000,
-  0x006c0000, 0x00700000, 0x00480000, 0x00500000,
-  0x00fd0000, 0x00ed0000, 0x00b90000, 0x00da0000,
-  0x005e0000, 0x00150000, 0x00460000, 0x00570000,
-  0x00a70000, 0x008d0000, 0x009d0000, 0x00840000,
-  0x00900000, 0x00d80000, 0x00ab0000, 0x00000000,
-  0x008c0000, 0x00bc0000, 0x00d30000, 0x000a0000,
-  0x00f70000, 0x00e40000, 0x00580000, 0x00050000,
-  0x00b80000, 0x00b30000, 0x00450000, 0x00060000,
-  0x00d00000, 0x002c0000, 0x001e0000, 0x008f0000,
-  0x00ca0000, 0x003f0000, 0x000f0000, 0x00020000,
-  0x00c10000, 0x00af0000, 0x00bd0000, 0x00030000,
-  0x00010000, 0x00130000, 0x008a0000, 0x006b0000,
-  0x003a0000, 0x00910000, 0x00110000, 0x00410000,
-  0x004f0000, 0x00670000, 0x00dc0000, 0x00ea0000,
-  0x00970000, 0x00f20000, 0x00cf0000, 0x00ce0000,
-  0x00f00000, 0x00b40000, 0x00e60000, 0x00730000,
-  0x00960000, 0x00ac0000, 0x00740000, 0x00220000,
-  0x00e70000, 0x00ad0000, 0x00350000, 0x00850000,
-  0x00e20000, 0x00f90000, 0x00370000, 0x00e80000,
-  0x001c0000, 0x00750000, 0x00df0000, 0x006e0000,
-  0x00470000, 0x00f10000, 0x001a0000, 0x00710000,
-  0x001d0000, 0x00290000, 0x00c50000, 0x00890000,
-  0x006f0000, 0x00b70000, 0x00620000, 0x000e0000,
-  0x00aa0000, 0x00180000, 0x00be0000, 0x001b0000,
-  0x00fc0000, 0x00560000, 0x003e0000, 0x004b0000,
-  0x00c60000, 0x00d20000, 0x00790000, 0x00200000,
-  0x009a0000, 0x00db0000, 0x00c00000, 0x00fe0000,
-  0x00780000, 0x00cd0000, 0x005a0000, 0x00f40000,
-  0x001f0000, 0x00dd0000, 0x00a80000, 0x00330000,
-  0x00880000, 0x00070000, 0x00c70000, 0x00310000,
-  0x00b10000, 0x00120000, 0x00100000, 0x00590000,
-  0x00270000, 0x00800000, 0x00ec0000, 0x005f0000,
-  0x00600000, 0x00510000, 0x007f0000, 0x00a90000,
-  0x00190000, 0x00b50000, 0x004a0000, 0x000d0000,
-  0x002d0000, 0x00e50000, 0x007a0000, 0x009f0000,
-  0x00930000, 0x00c90000, 0x009c0000, 0x00ef0000,
-  0x00a00000, 0x00e00000, 0x003b0000, 0x004d0000,
-  0x00ae0000, 0x002a0000, 0x00f50000, 0x00b00000,
-  0x00c80000, 0x00eb0000, 0x00bb0000, 0x003c0000,
-  0x00830000, 0x00530000, 0x00990000, 0x00610000,
-  0x00170000, 0x002b0000, 0x00040000, 0x007e0000,
-  0x00ba0000, 0x00770000, 0x00d60000, 0x00260000,
-  0x00e10000, 0x00690000, 0x00140000, 0x00630000,
-  0x00550000, 0x00210000, 0x000c0000, 0x007d0000
-}, {
-  0x52000000, 0x09000000, 0x6a000000, 0xd5000000,
-  0x30000000, 0x36000000, 0xa5000000, 0x38000000,
-  0xbf000000, 0x40000000, 0xa3000000, 0x9e000000,
-  0x81000000, 0xf3000000, 0xd7000000, 0xfb000000,
-  0x7c000000, 0xe3000000, 0x39000000, 0x82000000,
-  0x9b000000, 0x2f000000, 0xff000000, 0x87000000,
-  0x34000000, 0x8e000000, 0x43000000, 0x44000000,
-  0xc4000000, 0xde000000, 0xe9000000, 0xcb000000,
-  0x54000000, 0x7b000000, 0x94000000, 0x32000000,
-  0xa6000000, 0xc2000000, 0x23000000, 0x3d000000,
-  0xee000000, 0x4c000000, 0x95000000, 0x0b000000,
-  0x42000000, 0xfa000000, 0xc3000000, 0x4e000000,
-  0x08000000, 0x2e000000, 0xa1000000, 0x66000000,
-  0x28000000, 0xd9000000, 0x24000000, 0xb2000000,
-  0x76000000, 0x5b000000, 0xa2000000, 0x49000000,
-  0x6d000000, 0x8b000000, 0xd1000000, 0x25000000,
-  0x72000000, 0xf8000000, 0xf6000000, 0x64000000,
-  0x86000000, 0x68000000, 0x98000000, 0x16000000,
-  0xd4000000, 0xa4000000, 0x5c000000, 0xcc000000,
-  0x5d000000, 0x65000000, 0xb6000000, 0x92000000,
-  0x6c000000, 0x70000000, 0x48000000, 0x50000000,
-  0xfd000000, 0xed000000, 0xb9000000, 0xda000000,
-  0x5e000000, 0x15000000, 0x46000000, 0x57000000,
-  0xa7000000, 0x8d000000, 0x9d000000, 0x84000000,
-  0x90000000, 0xd8000000, 0xab000000, 0x00000000,
-  0x8c000000, 0xbc000000, 0xd3000000, 0x0a000000,
-  0xf7000000, 0xe4000000, 0x58000000, 0x05000000,
-  0xb8000000, 0xb3000000, 0x45000000, 0x06000000,
-  0xd0000000, 0x2c000000, 0x1e000000, 0x8f000000,
-  0xca000000, 0x3f000000, 0x0f000000, 0x02000000,
-  0xc1000000, 0xaf000000, 0xbd000000, 0x03000000,
-  0x01000000, 0x13000000, 0x8a000000, 0x6b000000,
-  0x3a000000, 0x91000000, 0x11000000, 0x41000000,
-  0x4f000000, 0x67000000, 0xdc000000, 0xea000000,
-  0x97000000, 0xf2000000, 0xcf000000, 0xce000000,
-  0xf0000000, 0xb4000000, 0xe6000000, 0x73000000,
-  0x96000000, 0xac000000, 0x74000000, 0x22000000,
-  0xe7000000, 0xad000000, 0x35000000, 0x85000000,
-  0xe2000000, 0xf9000000, 0x37000000, 0xe8000000,
-  0x1c000000, 0x75000000, 0xdf000000, 0x6e000000,
-  0x47000000, 0xf1000000, 0x1a000000, 0x71000000,
-  0x1d000000, 0x29000000, 0xc5000000, 0x89000000,
-  0x6f000000, 0xb7000000, 0x62000000, 0x0e000000,
-  0xaa000000, 0x18000000, 0xbe000000, 0x1b000000,
-  0xfc000000, 0x56000000, 0x3e000000, 0x4b000000,
-  0xc6000000, 0xd2000000, 0x79000000, 0x20000000,
-  0x9a000000, 0xdb000000, 0xc0000000, 0xfe000000,
-  0x78000000, 0xcd000000, 0x5a000000, 0xf4000000,
-  0x1f000000, 0xdd000000, 0xa8000000, 0x33000000,
-  0x88000000, 0x07000000, 0xc7000000, 0x31000000,
-  0xb1000000, 0x12000000, 0x10000000, 0x59000000,
-  0x27000000, 0x80000000, 0xec000000, 0x5f000000,
-  0x60000000, 0x51000000, 0x7f000000, 0xa9000000,
-  0x19000000, 0xb5000000, 0x4a000000, 0x0d000000,
-  0x2d000000, 0xe5000000, 0x7a000000, 0x9f000000,
-  0x93000000, 0xc9000000, 0x9c000000, 0xef000000,
-  0xa0000000, 0xe0000000, 0x3b000000, 0x4d000000,
-  0xae000000, 0x2a000000, 0xf5000000, 0xb0000000,
-  0xc8000000, 0xeb000000, 0xbb000000, 0x3c000000,
-  0x83000000, 0x53000000, 0x99000000, 0x61000000,
-  0x17000000, 0x2b000000, 0x04000000, 0x7e000000,
-  0xba000000, 0x77000000, 0xd6000000, 0x26000000,
-  0xe1000000, 0x69000000, 0x14000000, 0x63000000,
-  0x55000000, 0x21000000, 0x0c000000, 0x7d000000
-}
-};
-
-static const u4byte rco_tab[10] = {
-  0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010,
-  0x00000020, 0x00000040, 0x00000080, 0x0000001b, 0x00000036
-};
cmake_v2_4_uuid.patchtext/x-patch; charset=US-ASCII; name=cmake_v2_4_uuid.patchDownload
diff --git a/contrib/uuid-ossp/uuid-ossp.c b/contrib/uuid-ossp/uuid-ossp.c
index fca39d7937..1dab0ddbf3 100644
--- a/contrib/uuid-ossp/uuid-ossp.c
+++ b/contrib/uuid-ossp/uuid-ossp.c
@@ -29,16 +29,7 @@
  * builtins.h; we #define it out of the way.
  */
 #define uuid_hash bsd_uuid_hash
-
-#if defined(HAVE_UUID_H)
 #include <uuid.h>
-#elif defined(HAVE_OSSP_UUID_H)
-#include <ossp/uuid.h>
-#elif defined(HAVE_UUID_UUID_H)
-#include <uuid/uuid.h>
-#else
-#error "please use configure's --with-uuid switch to select a UUID library"
-#endif
 
 #undef uuid_hash
 
cmake_v2_5_readme.patchtext/x-patch; charset=US-ASCII; name=cmake_v2_5_readme.patchDownload
diff --git a/README.cmake b/README.cmake
new file mode 100644
index 0000000000..4ec5a42416
--- /dev/null
+++ b/README.cmake
@@ -0,0 +1,224 @@
+Requirements
+============
+For Unix system you can build postgres with CMake 3.0 and higher.
+For Windows build you must use CMake 3.7.1 and higher.
+If you don't have CMake on your system (Solaris, AIX or old Linux),
+you can build it from source without any problems.
+
+
+Basic commands
+==============
+Full documentations you can find here:
+https://cmake.org/cmake/help/latest/
+and small but usefull tutorial here:
+https://cmake.org/cmake-tutorial/
+
+Very basic usage in Unix systems:
+cmake ..
+
+where .. is path to postgres source dir. To use Ninja instead
+of GNU Make you must write:
+
+cmake .. -G "Ninja"
+
+To explore other generators use:
+cmake .. -G help
+
+Once you have generated Makefile or Ninja you should run
+make or ninja commands to build postgres. If you want to show all compiler
+option you must set env variable VERBOSE. Example:
+VERBOSE=1 make
+
+Choose configure options
+========================
+All options can be set via -DNAME_OPTION=(ON|OFF|NUMBER|STRING) param in command line.
+Example:
+cmake .. -DCMAKE_INSTALL_PREFIX="/usr/local" -DWITH_LIBXML=ON
+
+here we set install prefix and enable build with libXML.
+
+Set CFLAGS or LDFLAGS
+=====================
+CFLAGS or LDFLAGS you can set only on the generation stage as
+environment variable. Example:
+CFLAGS="-s -O2" cmake ..
+
+you can't change CFLAGS if project has been generated.
+This example won't work:
+CFLAGS="-s -O3" make
+
+You must remove cache and generate project again:
+rm ./CMakeCache.txt
+CFLAGS="-s -O3" cmake ..
+
+Targets
+=======
+In CMake you can have only one main target other targets cannot be installed.
+Also we have only one enter point to the project.
+To build postgres input:
+make
+
+or
+make all
+
+All test targets implemented as optional targets:
+make check
+make isolation_check
+make contrib_check
+make ecpg_check
+make modules_check
+
+also you can use installcheck insted check in target name to run tests for installed postgres.
+Example:
+make installcheck
+make isolation_installcheck
+
+Some tests we can run only if corresponding option is enabled:
+make plperl_check
+make pltcl_check
+make plpython_check
+
+And experemental TAP tests:
+make commit_ts_tap_check
+make bloom_tap_check
+make initdb_tap_check
+make pg_basebackup_tap_check
+make pg_config_tap_check
+make pg_controldata_tap_check
+make pg_ctl_tap_check
+make pg_dump_tap_check
+make pg_rewind_tap_check
+make pgbench_tap_check
+make scripts_tap_check
+make test_pg_dump_tap_check
+make recovery_tap_check
+make ssl_tap_check
+
+Postgres CMake build options
+============================
+**-DWITH_PERL** default OFF, optional
+
+**-DWITH_OPENSSL** default OFF, optional
+
+**-DOPENSSL_ROOT_DIR** Set this variable to the root installation of OpenSSL
+
+**-DWITH_PYTHON** default OFF, optional
+
+**-DWITH_LIBXML** default OFF, optional
+
+**-DWITH_TCL** default OFF, optional
+
+**-DENABLE_NLS** default OFF
+
+**-DENABLE_GSS** default OFF
+
+**-DUSE_PAM** default OFF
+
+**-DUSE_ASSERT_CHECKING** default OFF
+
+**-DUSE_BONJOUR** default OFF
+
+**-DUSE_SYSTEMD** default OFF
+
+**-DUSE_BSD_AUTH** default OFF
+
+**-DUSE_LDAP** default OFF
+
+**-DPROFILE_PID_DIR** default OFF, only for GCC, enable to allow profiling output to be saved separately for each process
+
+**-DUSE_FLOAT4_BYVAL** default ON
+
+**-DUSE_FLOAT8_BYVAL** default ON for 64bit system
+
+**-DHAVE_ATOMICS** default ON
+
+**-DHAVE_SPINLOCKS** default ON
+
+**-DUSE_INTEGER_DATETIMES** default ON, 64-bit integer timestamp and interval support
+
+**-DHAVE_SYMLINK** only for WIN32, default ON
+
+**-DPG_KRB_SRVNAM** default 'postgres', the name of the default PostgreSQL service principal in Kerberos (GSSAPI)
+
+**-DCMAKE_USE_FOLDERS** default ON, folder grouping of projects in IDEs, actual for MSVC
+
+**-DUSE_REPL_SNPRINTF** default not use but if ON you can switch OFF
+
+**-DWITH_TAP** default OFF, experemental support TAP tests
+
+**-DSTRONG_RANDOM** default ON, strong random number source
+
+**-DSTRONG_RANDOM_SOURCE** default OFF (autodetect), which random number source to use - openssl, win32, dev
+
+Only **MSVC** options:
+
+**-DUSE_FP_STRICT** default ON, if we use /fp:stirct compiler option we much closer to C99 standart in float part
+
+CMake options for modules
+=========================
+To find some libraries we use standard CMake modules and you can read documentation
+on the CMake site.
+
+For example setup for python2.7:
+-DPython_ADDITIONAL_VERSIONS=2.7 -DPYTHON_EXECUTABLE=/usr/bin/python2.7
+
+For details you can read:
+Python lib options: https://cmake.org/cmake/help/latest/module/FindPythonLibs.html
+Python interpreter options: https://cmake.org/cmake/help/latest/module/FindPythonInterp.html
+Perl libs: https://cmake.org/cmake/help/latest/module/FindPerlLibs.html
+OpenSSL: https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
+Curses: https://cmake.org/cmake/help/latest/module/FindCurses.htm
+
+Uncommon CMake Examples
+=======================
+
+Solaris 10, Sun-Fire-V210:
+CFLAGS="-m64 -mcpu=v9" cmake .. -DFIND_LIBRARY_USE_LIB64_PATHS=ON -DCURSES_LIBRARY=/usr/ccs/lib/sparcv9/libcurses.so -DCURSES_FORM_LIBRARY=/usr/ccs/lib/sparcv9/libform.so -DCMAKE_INSTALL_PREFIX="/home/stalkerg/postgresql_bin"
+
+AIX 7.1, Power8, gcc 4.8:
+CFLAGS="-std=c11 -mcpu=power8 -mtune=power8 -mveclibabi=mass -maix64" LDFLAGS="-Wl,-bbigtoc"  cmake ..
+
+
+CMake build and test howto
+==========================
+git clone https://github.com/stalkerg/postgres_cmake.git
+cd ./postgres_cmake
+#build dir is optional but best way for CMake
+mkdir build
+cd build
+CFLAGS="-s -O2" cmake .. -DCMAKE_INSTALL_PREFIX="/usr/local" -DWITH_PERL=ON -DWITH_LIBXML=ON
+#strip binary + O2 optimisation, for CLang you must use -strip-all insted -s
+#also you can use -G Ninja for Ninja make system
+make -j2
+make check
+make isolation_check
+make contrib_check
+
+#Optional:
+make ecpg_check
+make modules_check
+make plperl_check
+make pltcl_check
+
+#For example setup for python2.7:
+#-DPython_ADDITIONAL_VERSIONS=2.7 -DPYTHON_EXECUTABLE=/usr/bin/python2.7
+make plpython_check
+
+#TAP tests (experimental):
+make commit_ts_tap_check
+make bloom_tap_check
+make initdb_tap_check
+make pg_basebackup_tap_check
+make pg_config_tap_check
+make pg_controldata_tap_check
+make pg_ctl_tap_check
+make pg_dump_tap_check
+make pg_rewind_tap_check
+make pgbench_tap_check
+make scripts_tap_check
+make test_pg_dump_tap_check
+make recovery_tap_check
+make ssl_tap_check
+
+make install
+make installcheck
#123Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Yuriy Zhuravlev (#122)
Re: WIP: About CMake v2

On 12/30/16 9:10 AM, Yuriy Zhuravlev wrote:

cmake_v2_2_c_define.patch

Small chages in c.h . At first it is �#pragma fenv_access (off)� it is
necessary if we use /fp:strict for MSVC compiler. Without this pragma we
can�t calc floats for const variables in compiller time (2 * M_PI for
example). Strict mode important if we want to be close with ieee754
float format on MSVC (1.0 / 0.0 = inf for example). Detail info here:
https://msdn.microsoft.com/en-us/library/e7s85ffb.aspx

I don't understand what this has to do with cmake. If this is a
worthwhile improvement for the Windows build, then please explain why,
with a "before" and "after" output and a patch for the existing build
system as well.

Second change is because I find and set HAVE_INT128 directly from CMake.
PG_INT128_TYPE used only for autoconfig scripts.

It might also be worth refactoring the existing Autoconf code here to
make this consistent.

(My assumption is that if we were to move forward with cmake or any
other build system change, we would have to keep the old one alongside
at least for a little while. So any changes to the C code would need to
be side-ported.)

cmake_v2_3_rijndael.patch

First I added special wraparound because here CMake have circular
dependency (cmake very smart here). Second I removed rijndael.tbl
because it generated during build process every time.

Please explain what the circular dependency is. If there is one, we
should also side-port this change.

cmake_v2_4_uuid.patch

Another small patch. Right place for uuid.h I find by CMake and not
necessary this ifdef hell.

This patch removes the uuid.h include but doesn't add it anywhere else.
How does it work?

Questions for discussion:

In generated project by CMake we always have only one enter point. Also
INSTALL macross support only including to �all� targets. It follows that
it is impossible build contrib modules separately only with �all�
target. Here write about this behavior:
https://cmake.org/cmake/help/v3.7/prop_tgt/EXCLUDE_FROM_ALL.html

Yeah, I think this is how the MSVC stuff effectively works right now as
well.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#124Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#123)
Re: WIP: About CMake v2

On Tue, Jan 3, 2017 at 11:11 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 12/30/16 9:10 AM, Yuriy Zhuravlev wrote:

cmake_v2_2_c_define.patch

Small chages in c.h . At first it is “#pragma fenv_access (off)” it is
necessary if we use /fp:strict for MSVC compiler. Without this pragma we
can’t calc floats for const variables in compiller time (2 * M_PI for
example). Strict mode important if we want to be close with ieee754
float format on MSVC (1.0 / 0.0 = inf for example). Detail info here:
https://msdn.microsoft.com/en-us/library/e7s85ffb.aspx

I don't understand what this has to do with cmake. If this is a
worthwhile improvement for the Windows build, then please explain why,
with a "before" and "after" output and a patch for the existing build
system as well.

Second change is because I find and set HAVE_INT128 directly from CMake.
PG_INT128_TYPE used only for autoconfig scripts.

It might also be worth refactoring the existing Autoconf code here to
make this consistent.

(My assumption is that if we were to move forward with cmake or any
other build system change, we would have to keep the old one alongside
at least for a little while. So any changes to the C code would need to
be side-ported.)

cmake_v2_3_rijndael.patch

First I added special wraparound because here CMake have circular
dependency (cmake very smart here). Second I removed rijndael.tbl
because it generated during build process every time.

Please explain what the circular dependency is. If there is one, we
should also side-port this change.

cmake_v2_4_uuid.patch

Another small patch. Right place for uuid.h I find by CMake and not
necessary this ifdef hell.

This patch removes the uuid.h include but doesn't add it anywhere else.
How does it work?

Questions for discussion:

In generated project by CMake we always have only one enter point. Also
INSTALL macross support only including to “all” targets. It follows that
it is impossible build contrib modules separately only with “all”
target. Here write about this behavior:
https://cmake.org/cmake/help/v3.7/prop_tgt/EXCLUDE_FROM_ALL.html

Yeah, I think this is how the MSVC stuff effectively works right now as
well.

I am marking this patch as "returned with feedback". That's quite a
heavy change and it looks to be too late in the development cycle of
PG10 to consider it. Peter's commit bits, who is also the reviewer,
are beginning to smoke as well after everything that has happened for
the logical replication changes.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#125Andres Freund
andres@anarazel.de
In reply to: Michael Paquier (#124)
Re: WIP: About CMake v2

On 2017-01-24 15:50:47 +0900, Michael Paquier wrote:

I am marking this patch as "returned with feedback". That's quite a
heavy change and it looks to be too late in the development cycle of
PG10 to consider it. Peter's commit bits, who is also the reviewer,
are beginning to smoke as well after everything that has happened for
the logical replication changes.

I'm doubtful about this being ready in time too, but it seems a might
heavyhanded to make that call on your own. Including the judgement about
Peter's capability to handle more.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#126Michael Paquier
michael.paquier@gmail.com
In reply to: Andres Freund (#125)
Re: WIP: About CMake v2

On Tue, Jan 24, 2017 at 3:58 PM, Andres Freund <andres@anarazel.de> wrote:

On 2017-01-24 15:50:47 +0900, Michael Paquier wrote:

I am marking this patch as "returned with feedback". That's quite a
heavy change and it looks to be too late in the development cycle of
PG10 to consider it. Peter's commit bits, who is also the reviewer,
are beginning to smoke as well after everything that has happened for
the logical replication changes.

I'm doubtful about this being ready in time too, but it seems a might
heavyhanded to make that call on your own. Including the judgement about
Peter's capability to handle more.

Sure, sorry for that. I am switching back the patch, let's see what
happens by the end of the CF.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#127Craig Ringer
craig.ringer@2ndquadrant.com
In reply to: Andres Freund (#125)
Re: WIP: About CMake v2

On 24 Jan. 2017 18:00, "Andres Freund" <andres@anarazel.de> wrote:

On 2017-01-24 15:50:47 +0900, Michael Paquier wrote:

I am marking this patch as "returned with feedback". That's quite a
heavy change and it looks to be too late in the development cycle of
PG10 to consider it. Peter's commit bits, who is also the reviewer,
are beginning to smoke as well after everything that has happened for
the logical replication changes.

I'm doubtful about this being ready in time too, but it seems a might
heavyhanded to make that call on your own. Including the judgement about
Peter's capability to handle more.

Personally I think we should aim to have this in as a non default build
mode in pg10 if it can be made ready, and aim to make it default in pg11 at
least for Windows.

#128Tom Lane
tgl@sss.pgh.pa.us
In reply to: Craig Ringer (#127)
Re: WIP: About CMake v2

Craig Ringer <craig.ringer@2ndquadrant.com> writes:

Personally I think we should aim to have this in as a non default build
mode in pg10 if it can be made ready, and aim to make it default in pg11 at
least for Windows.

AFAIK we haven't committed to accepting this at all, let alone trying
to do so on a tight schedule. And I believe there was general agreement
that we would not accept it as something to maintain in parallel with
the existing makefiles. If we have to maintain two build systems, we
have that already.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#129Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#128)
Re: WIP: About CMake v2

On 1/24/17 8:37 AM, Tom Lane wrote:

Craig Ringer <craig.ringer@2ndquadrant.com> writes:

Personally I think we should aim to have this in as a non default build
mode in pg10 if it can be made ready, and aim to make it default in pg11 at
least for Windows.

AFAIK we haven't committed to accepting this at all, let alone trying
to do so on a tight schedule. And I believe there was general agreement
that we would not accept it as something to maintain in parallel with
the existing makefiles. If we have to maintain two build systems, we
have that already.

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

I don't foresee replacing the Autoconf build system by this immediately.

Right now, however, the patch isn't moving at all, and I don't see it
going into PG10, so I'm fine with returning with feedback.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#130Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Peter Eisentraut (#129)
Re: WIP: About CMake v2

Peter Eisentraut wrote:

Right now, however, the patch isn't moving at all, and I don't see it
going into PG10, so I'm fine with returning with feedback.

There are a bunch of side patches that we should apply separately, such
as the pgcrypto fix. I don't understand why they are part of this patch
series, really, given that they seem largely independent prerequisites.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#131Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#129)
Re: WIP: About CMake v2

On Fri, Jan 27, 2017 at 11:09 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 1/24/17 8:37 AM, Tom Lane wrote:

Craig Ringer <craig.ringer@2ndquadrant.com> writes:

Personally I think we should aim to have this in as a non default build
mode in pg10 if it can be made ready, and aim to make it default in pg11 at
least for Windows.

AFAIK we haven't committed to accepting this at all, let alone trying
to do so on a tight schedule. And I believe there was general agreement
that we would not accept it as something to maintain in parallel with
the existing makefiles. If we have to maintain two build systems, we
have that already.

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

This looks like a really good plan to me.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#132Andres Freund
andres@anarazel.de
In reply to: Peter Eisentraut (#129)
Re: WIP: About CMake v2

On 2017-01-27 09:09:36 -0500, Peter Eisentraut wrote:

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

I don't foresee replacing the Autoconf build system by this immediately.

I'm very strongly against this path, it seems way too likely that we'll
end up with yet another fragile thing that nobody from the *nix side
will be able to test.

- Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#133Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Andres Freund (#132)
Re: WIP: About CMake v2

On 1/27/17 6:11 PM, Andres Freund wrote:

On 2017-01-27 09:09:36 -0500, Peter Eisentraut wrote:

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

I don't foresee replacing the Autoconf build system by this immediately.

I'm very strongly against this path, it seems way too likely that we'll
end up with yet another fragile thing that nobody from the *nix side
will be able to test.

That's a fair concern, but at least with CMake, someone from the *nix
side *can* test it, whereas right now it's completely separate.

What kind of strategy do you have in mind?

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#134Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#133)
Re: WIP: About CMake v2

On Sat, Jan 28, 2017 at 12:20 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 1/27/17 6:11 PM, Andres Freund wrote:

On 2017-01-27 09:09:36 -0500, Peter Eisentraut wrote:

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

I don't foresee replacing the Autoconf build system by this immediately.

I'm very strongly against this path, it seems way too likely that we'll
end up with yet another fragile thing that nobody from the *nix side
will be able to test.

That's a fair concern, but at least with CMake, someone from the *nix
side *can* test it, whereas right now it's completely separate.

And people complain all the time that the MSVC build scripts are hacky
and complicated.. So by beginning from there we switch from one build
to the other, not increasing the number of builds that need to be
maintained. Based on that Peter's strategy looks appealing to me. By
the way, I am marking the patch as returned with feedback for this CF.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#135Andres Freund
andres@anarazel.de
In reply to: Peter Eisentraut (#133)
Re: WIP: About CMake v2

On 2017-01-27 22:20:41 -0500, Peter Eisentraut wrote:

On 1/27/17 6:11 PM, Andres Freund wrote:

On 2017-01-27 09:09:36 -0500, Peter Eisentraut wrote:

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

I don't foresee replacing the Autoconf build system by this immediately.

I'm very strongly against this path, it seems way too likely that we'll
end up with yet another fragile thing that nobody from the *nix side
will be able to test.

That's a fair concern, but at least with CMake, someone from the *nix
side *can* test it, whereas right now it's completely separate.

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially. Either we're able to properly test it -
i.e. it runs all tests - on *nix or we're not. There's not a a whole of
effort between those if you also want to do the windows side of things
properly.

What kind of strategy do you have in mind?

Do all of it. I'm unconvinced that a windows only version buys us
meaningful savings, and I think the dangers of adding more duplication
(msvc stuff after all gets some information from the makefiles) and
long-term coexistence are quite severe.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#136Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Andres Freund (#135)
Re: WIP: About CMake v2

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at once, then
you will have to dedicate the following 3 months to fixing complaints
from developers and build farmers.

Either we're able to properly test it - i.e. it runs all tests - on *nix or we're not.

That would work if there were a single entry point into the build
system. But in practice there are many, and every one of them is
someone's favorite. It's unlikely that we will be able to enumerate all
of them during patch review.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#137Yuriy Zhuravlev
stalkerg@gmail.com
In reply to: Peter Eisentraut (#123)
Re: WIP: About CMake v2

I don't understand what this has to do with cmake. If this is a
worthwhile improvement for the Windows build, then please explain why,
with a "before" and "after" output and a patch for the existing build
system as well.

During the porting process, I meet such situations when I should fix
something. It's happening because I build with different way also current
build system is trying to avoid many sharp corners.
If talk about this situation - without strict mode many "floats" checks
don't work correctly. You can read the link above. Besides this option puts
by build system. I think we can make a new thread for this approach. (with
patch for current perl system)

It might also be worth refactoring the existing Autoconf code here to

make this consistent.

I do it because it's convenient in CMake. I can change this it's not big
deal.

Please explain what the circular dependency is. If there is one, we

should also side-port this change.

It's an important part. I have a rule for generate rijndael.tbl by
gen-rtab who make from rijndael.c (with special define) who include
rijndael.tbl .
If I generate rijndael.tbl it's to force build gen-rtab and generate
rijndael.tbl again.
CMake knows about "includes" in files but we can make the wraparound macro
to hide include.

This patch removes the uuid.h include but doesn't add it anywhere else.

How does it work?

CMake sends to compiler right place for uuid.h (I mean -I/usr/include and
etc for gcc).

Yeah, I think this is how the MSVC stuff effectively works right now as
well.

I glad to hear it.

2017-01-03 17:11 GMT+03:00 Peter Eisentraut <
peter.eisentraut@2ndquadrant.com>:

Show quoted text

On 12/30/16 9:10 AM, Yuriy Zhuravlev wrote:

cmake_v2_2_c_define.patch

Small chages in c.h . At first it is “#pragma fenv_access (off)” it is
necessary if we use /fp:strict for MSVC compiler. Without this pragma we
can’t calc floats for const variables in compiller time (2 * M_PI for
example). Strict mode important if we want to be close with ieee754
float format on MSVC (1.0 / 0.0 = inf for example). Detail info here:
https://msdn.microsoft.com/en-us/library/e7s85ffb.aspx

I don't understand what this has to do with cmake. If this is a
worthwhile improvement for the Windows build, then please explain why,
with a "before" and "after" output and a patch for the existing build
system as well.

Second change is because I find and set HAVE_INT128 directly from CMake.
PG_INT128_TYPE used only for autoconfig scripts.

It might also be worth refactoring the existing Autoconf code here to
make this consistent.

(My assumption is that if we were to move forward with cmake or any
other build system change, we would have to keep the old one alongside
at least for a little while. So any changes to the C code would need to
be side-ported.)

cmake_v2_3_rijndael.patch

First I added special wraparound because here CMake have circular
dependency (cmake very smart here). Second I removed rijndael.tbl
because it generated during build process every time.

Please explain what the circular dependency is. If there is one, we
should also side-port this change.

cmake_v2_4_uuid.patch

Another small patch. Right place for uuid.h I find by CMake and not
necessary this ifdef hell.

This patch removes the uuid.h include but doesn't add it anywhere else.
How does it work?

Questions for discussion:

In generated project by CMake we always have only one enter point. Also
INSTALL macross support only including to “all” targets. It follows that
it is impossible build contrib modules separately only with “all”
target. Here write about this behavior:
https://cmake.org/cmake/help/v3.7/prop_tgt/EXCLUDE_FROM_ALL.html

Yeah, I think this is how the MSVC stuff effectively works right now as
well.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#138Yuriy Zhuravlev
stalkerg@gmail.com
In reply to: Michael Paquier (#131)
Re: WIP: About CMake v2

2017-01-28 1:50 GMT+03:00 Michael Paquier <michael.paquier@gmail.com>:

On Fri, Jan 27, 2017 at 11:09 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 1/24/17 8:37 AM, Tom Lane wrote:

Craig Ringer <craig.ringer@2ndquadrant.com> writes:

Personally I think we should aim to have this in as a non default build
mode in pg10 if it can be made ready, and aim to make it default in

pg11 at

least for Windows.

AFAIK we haven't committed to accepting this at all, let alone trying
to do so on a tight schedule. And I believe there was general agreement
that we would not accept it as something to maintain in parallel with
the existing makefiles. If we have to maintain two build systems, we
have that already.

My preferred scenario would be to replace the Windows build system by
this first, then refine it, then get rid of Autoconf.

The ideal timeline would be to have a ready patch to commit early in a
development cycle, then get rid of the Windows build system by the end
of it. Naturally, this would need buy-in from Windows developers.

This looks like a really good plan to me.

I think it's best plan because when this patch will be in Postgres guys
from community can test it for Unix systems too.
Support two build systems it's not big deal really. I have been working on
this past year without any big troubles.
Also we have second perl build system...

#139Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Yuriy Zhuravlev (#138)
Re: WIP: About CMake v2

On 2/8/17 6:21 AM, Yuriy Zhuravlev wrote:

Support two build systems it's not big deal really. I have been working
on this past year without any big troubles.
Also we have second perl build system...

The perl/msvc build system pulls in information from the makefiles. So
when you add a file or something basic like that, you don't have to
update it. So it's really more like 1.5 build systems.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#140Andres Freund
andres@anarazel.de
In reply to: Peter Eisentraut (#136)
Re: WIP: About CMake v2

Hi,

On 2017-01-30 10:26:18 -0500, Peter Eisentraut wrote:

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at once, then
you will have to dedicate the following 3 months to fixing complaints
from developers and build farmers.

That'll be the case just as well if we spread it out over two cycles,
except that we'll have it in multiple phases, and we run into the danger
of a half-done conversion.

I'd rather not change systems at all than run into the danger of that.

Either we're able to properly test it - i.e. it runs all tests - on *nix or we're not.

That would work if there were a single entry point into the build
system. But in practice there are many, and every one of them is
someone's favorite. It's unlikely that we will be able to enumerate all
of them during patch review.

Not sure what you mean with "entry point"?

- Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#141Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#139)
Re: WIP: About CMake v2

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 2/8/17 6:21 AM, Yuriy Zhuravlev wrote:

Support two build systems it's not big deal really. I have been working
on this past year without any big troubles.
Also we have second perl build system...

The perl/msvc build system pulls in information from the makefiles. So
when you add a file or something basic like that, you don't have to
update it. So it's really more like 1.5 build systems.

Really it's more like 1.1 build systems, in that the MSVC scripts do that
just well enough that you *usually* don't have to think about them. But
then when they fail, and you have to figure out why, it can be a pain.

For my own purposes, the only thing that I find seriously annoying about
the status quo is the amount of time required to run "configure". For
me, that step is usually comparable to or even more than the time to
do the build proper, because (a) ccache and (b) multiple CPUs.
configure isn't parallelizable, and there's probably nothing that
can be done about that. If CMake offers a substantial improvement
in configuration time then that would be attractive. Otherwise I'd
just as soon see us put the effort into making the MSVC scripts more
robust and able to pull more data from the makefiles.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#142Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Tom Lane (#141)
Re: WIP: About CMake v2

On 2/8/17 3:52 PM, Tom Lane wrote:

For my own purposes, the only thing that I find seriously annoying about
the status quo is the amount of time required to run "configure". For
me, that step is usually comparable to or even more than the time to
do the build proper, because (a) ccache and (b) multiple CPUs.
configure isn't parallelizable, and there's probably nothing that
can be done about that. If CMake offers a substantial improvement
in configuration time then that would be attractive. Otherwise I'd
just as soon see us put the effort into making the MSVC scripts more
robust and able to pull more data from the makefiles.

FWIW, I've had good luck adding -C to configure to cache the output. I'd
guess it's at least 10x faster on my laptop.

Obviously doesn't help if you're doing where you're testing something
that alters config output. In those cases I'll either edit config.cache
and delete the relevant lines or just temporarily move it out of the way
(or just nuke it...).
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#143Andres Freund
andres@anarazel.de
In reply to: Tom Lane (#141)
Re: WIP: About CMake v2

Hi,

On 2017-02-08 16:52:19 -0500, Tom Lane wrote:

For my own purposes, the only thing that I find seriously annoying about
the status quo is the amount of time required to run "configure". For
me, that step is usually comparable to or even more than the time to
do the build proper, because (a) ccache and (b) multiple CPUs.
configure isn't parallelizable, and there's probably nothing that
can be done about that.

I use autoconf caching feature to make that a bit less painful (plus
some scripting about when to scrap the cache file...). I find that
seriously annoying too.

If CMake offers a substantial improvement
in configuration time then that would be attractive. Otherwise I'd
just as soon see us put the effort into making the MSVC scripts more
robust and able to pull more data from the makefiles.

Some of the build-tooling in cmake is quite nice, I have to admit. I've
e.g. grown to like using ninja instead of make to build the resulting
files. Primarily in projects that take longer than pg to compile - a
clean build in llvm with ninja takes like 0.1 seconds.

Being more able to rely on things working on windows when doing them on
linux does seem like an advantage to me - fiddlin with Mkvcbuild.pm is
quite annoying.

- Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#144Robert Haas
robertmhaas@gmail.com
In reply to: Peter Eisentraut (#136)
Re: WIP: About CMake v2

On Mon, Jan 30, 2017 at 10:26 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at once, then
you will have to dedicate the following 3 months to fixing complaints
from developers and build farmers.

I agree with that. I think replacing the Windows build system first
and then the non-Windows build system later is a better plan than
replacing both at the same time.

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better. If nothing
else, everybody who has to learn the new system either to use it for
development or because they are doing packaging will have to do some
amount of extra work as a result of any switch.

I do agree that - in theory - one build system is better than two.
But two well-tested, reliable build systems could easily be better
than one system with a bunch of problems. And the points downthread
about our two existing systems being not entirely separate are on
point, too.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#145Andres Freund
andres@anarazel.de
In reply to: Robert Haas (#144)
Re: WIP: About CMake v2

On 2017-02-10 12:07:15 -0500, Robert Haas wrote:

On Mon, Jan 30, 2017 at 10:26 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at once, then
you will have to dedicate the following 3 months to fixing complaints
from developers and build farmers.

I agree with that. I think replacing the Windows build system first
and then the non-Windows build system later is a better plan than
replacing both at the same time.

Obviously I disagree ;)

But I'm more replying because of:

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better.

I do think it's kinda ok for people who've dealt with this for some
time. But for the first few times having to write autoconf macros is
quite intimidating. A somewhat less obscure way to deal with that is
worth something. As is better file dependency management, across
different environments. As is the IDE integration cmake is more and
more getting. As is properly builtin working caching of configure tests
(llvm first cmake run, 7.7s, second 2.54s). As is the fact that a lot of
big projects (llvm, kde, qt, and a lot of others) migrated to it.

For me personally those benefits aren't worth that much. I've learned
autoconf stuff. I've scripting around autoconf caching. But for newer
people that's not true.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#146Magnus Hagander
magnus@hagander.net
In reply to: Robert Haas (#144)
Re: WIP: About CMake v2

On Fri, Feb 10, 2017 at 6:07 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Mon, Jan 30, 2017 at 10:26 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at once, then
you will have to dedicate the following 3 months to fixing complaints
from developers and build farmers.

I agree with that. I think replacing the Windows build system first
and then the non-Windows build system later is a better plan than
replacing both at the same time.

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better. If nothing
else, everybody who has to learn the new system either to use it for
development or because they are doing packaging will have to do some
amount of extra work as a result of any switch.

For me a killer feature would be if/when we can get to a point where we can
have something pgxs-style on cmake that also works on windows.

Our homemade Windows build system works OK for postgres, and while ugly it
is as you say well tested by now. But it doesn't do *anything* to help
people build extensions on Windows.

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#147Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Magnus Hagander (#146)
Re: WIP: About CMake v2

On 02/10/2017 08:27 PM, Magnus Hagander wrote:

For me a killer feature would be if/when we can get to a point where we can
have something pgxs-style on cmake that also works on windows.

Our homemade Windows build system works OK for postgres, and while ugly it
is as you say well tested by now. But it doesn't do *anything* to help
people build extensions on Windows.

Do we need to build PostgreSQL itself using cmake, to achieve that?
Could we write something like pgxs for cmake, only for extensions?

- Heikki

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#148Andres Freund
andres@anarazel.de
In reply to: Magnus Hagander (#146)
Re: WIP: About CMake v2

On 2017-02-10 19:27:55 +0100, Magnus Hagander wrote:

For me a killer feature would be if/when we can get to a point where we can
have something pgxs-style on cmake that also works on windows.

That should be quite possible. The ugliest part will be to determine
where to include a cmake file from (since that'll be copied in every
such project), but after that it should be nearly trivial.

- Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#149Magnus Hagander
magnus@hagander.net
In reply to: Heikki Linnakangas (#147)
Re: WIP: About CMake v2

On Fri, Feb 10, 2017 at 7:31 PM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:

On 02/10/2017 08:27 PM, Magnus Hagander wrote:

For me a killer feature would be if/when we can get to a point where we
can
have something pgxs-style on cmake that also works on windows.

Our homemade Windows build system works OK for postgres, and while ugly it
is as you say well tested by now. But it doesn't do *anything* to help
people build extensions on Windows.

Do we need to build PostgreSQL itself using cmake, to achieve that? Could
we write something like pgxs for cmake, only for extensions?

I guess we wouldn't, but we'd still need the "replacement for autoconf"
part. So then we're back to maintaining multiple buildsystems.

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#150Andres Freund
andres@anarazel.de
In reply to: Heikki Linnakangas (#147)
Re: WIP: About CMake v2

On 2017-02-10 20:31:12 +0200, Heikki Linnakangas wrote:

On 02/10/2017 08:27 PM, Magnus Hagander wrote:

For me a killer feature would be if/when we can get to a point where we can
have something pgxs-style on cmake that also works on windows.

Our homemade Windows build system works OK for postgres, and while ugly it
is as you say well tested by now. But it doesn't do *anything* to help
people build extensions on Windows.

Do we need to build PostgreSQL itself using cmake, to achieve that? Could we
write something like pgxs for cmake, only for extensions?

I don't see why it'd need to be done together. The minimal version
would be a simple cmake file that just sets a bunch of variables from
pg_config, provides a few rules for specifying the current pgxs stuff,
and an example stanza how to include that file. We'd have to duplicate
some of the pgxs specific logic, but that's probably not too bad.

- Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#151Andres Freund
andres@anarazel.de
In reply to: Magnus Hagander (#149)
Re: WIP: About CMake v2

On 2017-02-10 19:33:18 +0100, Magnus Hagander wrote:

I guess we wouldn't, but we'd still need the "replacement for autoconf"
part. So then we're back to maintaining multiple buildsystems.

Hm? Do we really need that? Most of the things in an extension you do
*not* want to determine separately from the backend. It's not like pgxs
atm really allows to differ wildly from autoconf's results. And most of
the relevant determinations made by autoconf are available in headers
and/or we can generate a cmake include file with the results of
autoconf.

- Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#152Magnus Hagander
magnus@hagander.net
In reply to: Andres Freund (#151)
Re: WIP: About CMake v2

On Feb 10, 2017 19:41, "Andres Freund" <andres@anarazel.de> wrote:

On 2017-02-10 19:33:18 +0100, Magnus Hagander wrote:

I guess we wouldn't, but we'd still need the "replacement for autoconf"
part. So then we're back to maintaining multiple buildsystems.

Hm? Do we really need that? Most of the things in an extension you do
*not* want to determine separately from the backend. It's not like pgxs
atm really allows to differ wildly from autoconf's results. And most of
the relevant determinations made by autoconf are available in headers
and/or we can generate a cmake include file with the results of
autoconf.

Yeah, you're right. You need the output from the process, it mot the
process itself.

/Magnus

#153Andrew Dunstan
andrew.dunstan@2ndquadrant.com
In reply to: Magnus Hagander (#146)
Re: WIP: About CMake v2

On 02/10/2017 01:27 PM, Magnus Hagander wrote:

On Fri, Feb 10, 2017 at 6:07 PM, Robert Haas <robertmhaas@gmail.com
<mailto:robertmhaas@gmail.com>> wrote:

On Mon, Jan 30, 2017 at 10:26 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com
<mailto:peter.eisentraut@2ndquadrant.com>> wrote:

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at

once, then

you will have to dedicate the following 3 months to fixing

complaints

from developers and build farmers.

I agree with that. I think replacing the Windows build system first
and then the non-Windows build system later is a better plan than
replacing both at the same time.

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better. If nothing
else, everybody who has to learn the new system either to use it for
development or because they are doing packaging will have to do some
amount of extra work as a result of any switch.

For me a killer feature would be if/when we can get to a point where
we can have something pgxs-style on cmake that also works on windows.

Our homemade Windows build system works OK for postgres, and while
ugly it is as you say well tested by now. But it doesn't do *anything*
to help people build extensions on Windows.

Watch this space. There is work being done on building extensions out of
tree using CMake on Windows. It's pretty neat, and I'm hoping to demo it
publicly soon. But it's not reliant on CMake in core.

cheers

andrew

--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#154Craig Ringer
craig.ringer@2ndquadrant.com
In reply to: Andrew Dunstan (#153)
Re: WIP: About CMake v2

On 11 Feb. 2017 08:42, "Andrew Dunstan" <andrew.dunstan@2ndquadrant.com>
wrote:

On 02/10/2017 01:27 PM, Magnus Hagander wrote:

On Fri, Feb 10, 2017 at 6:07 PM, Robert Haas <robertmhaas@gmail.com
<mailto:robertmhaas@gmail.com>> wrote:

On Mon, Jan 30, 2017 at 10:26 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com
<mailto:peter.eisentraut@2ndquadrant.com>> wrote:

On 1/30/17 1:28 AM, Andres Freund wrote:

Given that fact, I just don't buy why it's a good idea to not also
replace autoconf initially.

Well, I find it a bit scary. If you do the big switch all at

once, then

you will have to dedicate the following 3 months to fixing

complaints

from developers and build farmers.

I agree with that. I think replacing the Windows build system first
and then the non-Windows build system later is a better plan than
replacing both at the same time.

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better. If nothing
else, everybody who has to learn the new system either to use it for
development or because they are doing packaging will have to do some
amount of extra work as a result of any switch.

For me a killer feature would be if/when we can get to a point where
we can have something pgxs-style on cmake that also works on windows.

Our homemade Windows build system works OK for postgres, and while
ugly it is as you say well tested by now. But it doesn't do *anything*
to help people build extensions on Windows.

Watch this space. There is work being done on building extensions out of
tree using CMake on Windows. It's pretty neat, and I'm hoping to demo it
publicly soon. But it's not reliant on CMake in core.

Yeah. In fact it's completely independent of core's build system it and
works with any supported Pg, using pg_config for discovery.

We don't need cmake in core for pgxs-like functionality on Windows.

I'd like to use it instead of our Perl windows stuff msbuild stuff in core
though. I wonder if it's practical to generate the cmake file lists etc
from our Makefiles initialy like we do for the current system, and just
replace the MSVC/msbuild project generators with cmake initially.

#155Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#145)
Re: WIP: About CMake v2

On 2017-02-10 10:22:34 -0800, Andres Freund wrote:

On 2017-02-10 12:07:15 -0500, Robert Haas wrote:

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better.

I do think it's kinda ok for people who've dealt with this for some
time. But for the first few times having to write autoconf macros is
quite intimidating. A somewhat less obscure way to deal with that is
worth something. As is better file dependency management, across
different environments. As is the IDE integration cmake is more and
more getting. As is properly builtin working caching of configure tests
(llvm first cmake run, 7.7s, second 2.54s). As is the fact that a lot of
big projects (llvm, kde, qt, and a lot of others) migrated to it.

For me personally those benefits aren't worth that much. I've learned
autoconf stuff. I've scripting around autoconf caching. But for newer
people that's not true.

Craig's email just now reminded me of another advantage: Using cmake
across the board, would mean we'd use the same ./configure alike logic
on both windows and linux. To me that seems quite and advantage over
managing pg_config.h.win32/config_default.pl manually/separately - we
obviously have screwed up quite badly there in the past
(cf376a4adc0805b0).

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#156Vladimir Rusinov
vrusinov@google.com
In reply to: Robert Haas (#144)
1 attachment(s)
Re: WIP: About CMake v2

On Fri, Feb 10, 2017 at 5:07 PM, Robert Haas <robertmhaas@gmail.com> wrote:

But also, I'm not really sure whether this conversion makes sense. I
mean, any build system is going to require some work, and accordingly
our present build systems require some work. cmake will require
different work, but not necessarily less. The current system has a
long history; we pretty much know it works. Switching will inevitably
break some things. Maybe we'll end up better off in the long term,
but maybe we won't. Things are pretty good now, so it seems like it
would be easy for them to get worse rather than better. If nothing
else, everybody who has to learn the new system either to use it for
development or because they are doing packaging will have to do some
amount of extra work as a result of any switch.

For what it's worth (even well-maintained) cmake is a usability regression
from well-maintained autotools from syseng/packager perspective.

Two anecdotes:

- ./configure is much nicer from user perspective. Compare:
./configure --prefix=/bla --enable-foo --disable-bar --with-ssl=/opt/myssl
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BLAH -DCMAKE_FOO
-DCMAKE_WHO_KNOWS_WHAT:PATH=/opt/myssl

- Things like set(_PYTHON3_VERSIONS 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
<https://github.com/Kitware/CMake/blob/master/Modules/FindPythonInterp.cmake#L43&gt;
Guess what, on older cmake versions this list did not include anything
older that 3.3, so it was failing with in-comprehensive generic "not found"
error even though 3.4 was installed.
With this "fix" somebody somewhere will be banging their head against the
wall again once 3.8 is out.
Overall, when things go wrong debugging cmake requires cmake knowledge,
while autotools mostly require shell knowledge which is much more common
(again, for sysadmins/packagers).

So while cmake is better for developers it is usually worse off for
packagers and advanced users. I'm not saying migration is not worth it, I'm
pointing out costs of such migration.

PS: I personally like Google's internal version of https://bazel.build/ a
lot. I've never used open-source version but I presume it's similar. While
it has many problems (Java, lack of popular IDE support, lack of popularity
and, again, Java) good parts are rules are both machine- and human-
readable and writable and generally easy to debug. I'm not bold enough to
propose PostgreSQL to use it, but I'd be happy to see ideas from it to be
used elsewhere.

--
Vladimir Rusinov
Storage SRE, Google Ireland

Google Ireland Ltd.,Gordon House, Barrow Street, Dublin 4, Ireland
Registered in Dublin, Ireland
Registration Number: 368047

Attachments:

smime.p7sapplication/pkcs7-signature; name=smime.p7sDownload
#157Yuriy Zhuravlev
stalkerg@gmail.com
In reply to: Vladimir Rusinov (#156)
Re: WIP: About CMake v2

2017-02-12 20:55 GMT+03:00 Vladimir Rusinov <vrusinov@google.com>:

Overall, when things go wrong debugging cmake requires cmake knowledge,
while autotools mostly require shell knowledge which is much more common
(again, for sysadmins/packagers).

It's not really true because of CMake scripts much easier than tons of crap
bash (configure) and m4 scripts in Autotools, also please don't forget
Windows MSVC, Xcode and etc usage.

PS: I personally like Google's internal version of https://bazel.build/ a

lot. I've never used open-source version but I presume it's similar. While
it has many problems (Java, lack of popular IDE support, lack of popularity
and, again, Java) good parts are rules are both machine- and human-
readable and writable and generally easy to debug. I'm not bold enough to
propose PostgreSQL to use it, but I'd be happy to see ideas from it to be
used elsewhere.

We have many build systems, for example, another one http://mesonbuild.com/
but CMake the best today as meta build system.

#158Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Andres Freund (#140)
Re: WIP: About CMake v2

On 2/8/17 4:44 PM, Andres Freund wrote:

Well, I find it a bit scary. If you do the big switch all at once, then
you will have to dedicate the following 3 months to fixing complaints
from developers and build farmers.

That'll be the case just as well if we spread it out over two cycles,
except that we'll have it in multiple phases, and we run into the danger
of a half-done conversion.

They key term is "dedicated". I don't think anyone wants to spend 3
months doing nothing but fixing the build system. If we spread it over
several releases and bring more people up to speed along the way, that
looks more manageable.

That would work if there were a single entry point into the build
system. But in practice there are many, and every one of them is
someone's favorite. It's unlikely that we will be able to enumerate all
of them during patch review.

Not sure what you mean with "entry point"?

People have all kinds of expectations on how the build system behaves.
It's not just ./configure; make; make install. All kinds of niche and
edge cases have evolved over the years. Variables you can set,
overrides, targets in some subdirectories, building in subdirectories
and having it build another subdirectory first, testing this way and
testing that way, testing with a custom locale or a custom database
name, building before testing or not, testing without reinstalling, and
so on and so on. You'd have to make sure at least some of that
continues to work or be able to explain it away. And most of it is not
really documented.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#159Robert Haas
robertmhaas@gmail.com
In reply to: Peter Eisentraut (#158)
Re: WIP: About CMake v2

On Mon, Feb 13, 2017 at 10:52 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

People have all kinds of expectations on how the build system behaves.
It's not just ./configure; make; make install. All kinds of niche and
edge cases have evolved over the years. Variables you can set,
overrides, targets in some subdirectories, building in subdirectories
and having it build another subdirectory first, testing this way and
testing that way, testing with a custom locale or a custom database
name, building before testing or not, testing without reinstalling, and
so on and so on. You'd have to make sure at least some of that
continues to work or be able to explain it away. And most of it is not
really documented.

...which is another argument for just not changing anything. I mean,
again, the current Windows build system is unbeautiful and
occasionally takes some work, but if we switch to cmake, that has to
get enough better to make up for all of the things that get worse.
And it's far from obvious than this will be so, especially when you
consider the fact that many people have detailed knowledge of how to
tweak the current system to do what they want. As you point out here,
a lot of that stuff may stop working if we replace the system
wholesale.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#160Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#141)
Re: WIP: About CMake v2

On Wed, Feb 8, 2017 at 04:52:19PM -0500, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 2/8/17 6:21 AM, Yuriy Zhuravlev wrote:

Support two build systems it's not big deal really. I have been working
on this past year without any big troubles.
Also we have second perl build system...

The perl/msvc build system pulls in information from the makefiles. So
when you add a file or something basic like that, you don't have to
update it. So it's really more like 1.5 build systems.

Really it's more like 1.1 build systems, in that the MSVC scripts do that
just well enough that you *usually* don't have to think about them. But
then when they fail, and you have to figure out why, it can be a pain.

If cmake isn't going to be able to query the Makefiles and adjust to
changes we make there, changing our Windows build system from MSVC to
cmake takes us from maintaining 1.1 build systems to two build systems,
and I don't think anyone wants that.

If we go to cmake, I think we need to agree we will eventually _only_
use cmake. I don't think having two build systems we have to maintain
is better than 1.1 build systems where we can mostly ignore 0.1 of that.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers