3 # Copyright (C) 2004-2024 ZNC, see the NOTICE file for details.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
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
21 which python3
>/dev
/null
2>&1 && exec python3
"$0" "$@"
22 which python
>/dev
/null
2>&1 && exec python
"$0" "$@"
23 which python2
>/dev
/null
2>&1 && exec python2
"$0" "$@"
24 echo "Error: configure wrapper requires python"
25 exec echo "Either install python, or use cmake directly"
35 extra_args
= [os.path.
dirname(sys.argv
[0])]
36 parser
= argparse.ArgumentParser
()
38 def gnu_install_dir
(name
, cmake
=None
):
41 parser.add_argument
('--' + name
, action
='append', metavar
=cmake
,
43 type=lambda s
: '-DCMAKE_INSTALL_{}={}'.format
(cmake
, s
))
45 gnu_install_dir
('prefix')
46 gnu_install_dir
('bindir')
47 gnu_install_dir
('sbindir')
48 gnu_install_dir
('libexecdir')
49 gnu_install_dir
('sysconfdir')
50 gnu_install_dir
('sharedstatedir')
51 gnu_install_dir
('localstatedir')
52 gnu_install_dir
('libdir')
53 gnu_install_dir
('includedir')
54 gnu_install_dir
('oldincludedir')
55 gnu_install_dir
('datarootdir')
56 gnu_install_dir
('datadir')
57 gnu_install_dir
('infodir')
58 gnu_install_dir
('localedir')
59 gnu_install_dir
('mandir')
60 gnu_install_dir
('docdir')
63 group
= parser.add_mutually_exclusive_group
()
64 group.add_argument
('--enable-debug', action
='store_const', dest
='build_type',
65 const
='Debug', default
='Release')
66 group.add_argument
('--disable-debug', action
='store_const', dest
='build_type',
67 const
='Release', default
='Release')
69 def tristate
(name
, cmake
=None
):
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
))
84 tristate
('charset', 'ICU')
89 class 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
)
95 group
= parser.add_mutually_exclusive_group
()
96 group.add_argument
('--enable-python', action
=HandlePython
, nargs
='?',
97 metavar
='PYTHON_VERSION')
98 group.add_argument
('--disable-python', action
='append_const', dest
='cm_args',
99 const
='-DWANT_PYTHON=NO')
101 parser.add_argument
('--with-gtest', action
='store', dest
='gtest')
102 parser.add_argument
('--with-gmock', action
='store', dest
='gmock')
104 class 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
)
110 parser.add_argument
('--with-systemdsystemunitdir', action
=HandleSystemd
,
111 nargs
='?', metavar
='UNITDIR')
114 name
, value
= s.
split('=', 1)
117 parser.add_argument
('env', nargs
='*', type=env_type
, metavar
='ENV_VAR=VALUE')
119 args
= parser.parse_args
()
121 if 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/')
126 cm_args
= args.cm_args or
[]
128 for env_key
, env_value
in args.env
:
129 os.environ
[env_key
] = env_value
131 os.environ
['GTEST_ROOT'] = args.gtest
133 os.environ
['GMOCK_ROOT'] = args.gmock
135 if os.environ.get
('CXX') is not None
:
136 extra_args.append
('-DCMAKE_CXX_COMPILER=' + os.environ
['CXX'])
139 os.remove
('CMakeCache.txt')
142 subprocess.check_call
(['cmake', '-DCMAKE_BUILD_TYPE=' + args.build_type
]
143 + cm_args
+ extra_args
)