]> jfr.im git - irc/znc/znc.git/blame - configure
Merge branch '1.9.x'
[irc/znc/znc.git] / configure
CommitLineData
84d8375a
AS
1#!/bin/sh
2#
17a004aa 3# Copyright (C) 2004-2024 ZNC, see the NOTICE file for details.
84d8375a
AS
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18# http://stackoverflow.com/questions/18993438/shebang-env-preferred-python-version
19# http://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python
20""":"
21which python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
22which python >/dev/null 2>&1 && exec python "$0" "$@"
23which python2 >/dev/null 2>&1 && exec python2 "$0" "$@"
24echo "Error: configure wrapper requires python"
25exec echo "Either install python, or use cmake directly"
26":"""
27
28import argparse
29import os
4202b3ac 30import shutil
84d8375a
AS
31import subprocess
32import sys
33import re
34
35extra_args = [os.path.dirname(sys.argv[0])]
36parser = argparse.ArgumentParser()
37
38def gnu_install_dir(name, cmake=None):
39 if cmake is None:
40 cmake = name.upper()
41 parser.add_argument('--' + name, action='append', metavar=cmake,
42 dest='cm_args',
43 type=lambda s: '-DCMAKE_INSTALL_{}={}'.format(cmake, s))
44
45gnu_install_dir('prefix')
46gnu_install_dir('bindir')
47gnu_install_dir('sbindir')
48gnu_install_dir('libexecdir')
49gnu_install_dir('sysconfdir')
50gnu_install_dir('sharedstatedir')
51gnu_install_dir('localstatedir')
52gnu_install_dir('libdir')
53gnu_install_dir('includedir')
54gnu_install_dir('oldincludedir')
55gnu_install_dir('datarootdir')
56gnu_install_dir('datadir')
57gnu_install_dir('infodir')
58gnu_install_dir('localedir')
59gnu_install_dir('mandir')
60gnu_install_dir('docdir')
61
62
63group = parser.add_mutually_exclusive_group()
64group.add_argument('--enable-debug', action='store_const', dest='build_type',
65 const='Debug', default='Release')
66group.add_argument('--disable-debug', action='store_const', dest='build_type',
67 const='Release', default='Release')
68
69def tristate(name, cmake=None):
70 if cmake is None:
71 cmake = name.upper()
72 group = parser.add_mutually_exclusive_group()
73 group.add_argument('--enable-' + name, action='append_const',
74 dest='cm_args', const='-DWANT_{}=YES'.format(cmake))
75 group.add_argument('--disable-' + name, action='append_const',
76 dest='cm_args', const='-DWANT_{}=NO'.format(cmake))
77
78tristate('ipv6')
79tristate('openssl')
80tristate('zlib')
81tristate('perl')
82tristate('swig')
83tristate('cyrus')
84tristate('charset', 'ICU')
85tristate('tcl')
86tristate('i18n')
a1a254be 87tristate('argon')
84d8375a
AS
88
89class HandlePython(argparse.Action):
90 def __call__(self, parser, namespace, values, option_string=None):
91 extra_args.append('-DWANT_PYTHON=YES')
92 if values is not None:
93 extra_args.append('-DWANT_PYTHON_VERSION=' + values)
94
95group = parser.add_mutually_exclusive_group()
96group.add_argument('--enable-python', action=HandlePython, nargs='?',
97 metavar='PYTHON_VERSION')
98group.add_argument('--disable-python', action='append_const', dest='cm_args',
99 const='-DWANT_PYTHON=NO')
100
101parser.add_argument('--with-gtest', action='store', dest='gtest')
102parser.add_argument('--with-gmock', action='store', dest='gmock')
103
104class HandleSystemd(argparse.Action):
105 def __call__(self, parser, namespace, values, option_string=None):
106 extra_args.append('-DWANT_SYSTEMD=YES')
107 if values is not None:
108 extra_args.append('-DWANT_SYSTEMD_DIR=' + values)
109
110parser.add_argument('--with-systemdsystemunitdir', action=HandleSystemd,
111 nargs='?', metavar='UNITDIR')
112
113def env_type(s):
114 name, value = s.split('=', 1)
115 return (name, value)
116
117parser.add_argument('env', nargs='*', type=env_type, metavar='ENV_VAR=VALUE')
118
119args = parser.parse_args()
120
4202b3ac
AS
121if not shutil.which('cmake'):
122 print('CMake is required to proceed. Please install it via package manager,\n'
123 'or download the binary from https://cmake.org/')
124 sys.exit(1)
125
84d8375a
AS
126cm_args = args.cm_args or []
127
128for env_key, env_value in args.env:
129 os.environ[env_key] = env_value
130if args.gtest:
131 os.environ['GTEST_ROOT'] = args.gtest
132if args.gmock:
133 os.environ['GMOCK_ROOT'] = args.gmock
134
135if os.environ.get('CXX') is not None:
136 extra_args.append('-DCMAKE_CXX_COMPILER=' + os.environ['CXX'])
137
138try:
139 os.remove('CMakeCache.txt')
140except OSError:
141 pass
142subprocess.check_call(['cmake', '-DCMAKE_BUILD_TYPE=' + args.build_type]
143 + cm_args + extra_args)