3 # Autotools-style (./configure) wrapper for CMake
4 # <https://github.com/nemequ/configure-cmake>
8 # You must include the GNUInstallDirs module (which comes with
9 # CMake) in your project. Just put "include (GNUInstallDirs)" in
10 # you CMakeLists.txt and you should be good.
12 # This script was originally written for Squash
13 # <https://quixdb.github.io/squash/> by Evan Nemerson
14 # <evan@nemerson.com>, but has been spun off into a separate
15 # repository. Please feel free to copy it into your own repository,
16 # though I would appreciate it if you would post improvements, bugs,
17 # feature requests, etc. to the issue tracker at
18 # <https://github.com/nemequ/configure-cmake/issues>.
20 # To the extent possible under law, the author(s) hereby waive all
21 # copyright and related or neighboring rights to this work. For
22 # details, see <https://creativecommons.org/publicdomain/zero/1.0/>
24 TOP_SRCDIR="$(dirname $0)"
25 CMAKE_CMD="cmake ${TOP_SRCDIR}"
29 DATA_DIR=${PREFIX}/share
30 INCLUDE_DIR=include/roojspacker
34 if [ -e "${TOP_SRCDIR}/.configure-custom.sh" ]; then
35 . "${TOP_SRCDIR}/.configure-custom.sh"
39 echo "$1" | sed -e "s|'|'\\\\''|g; 1s/^/'/; \$s/\$/'/"
42 extract_var_string() {
44 VAR_NAME=$(echo $1 | sed -e 's/[ \t]*$//')
45 if [ "x$2" != "x" ]; then
51 if [ "x$3" != "x" ]; then
54 VAR_UC_NAME=$(echo "$1" | tr '[:lower:]' '[:upper:]' | tr -c '[:alnum:]' '_' | sed 's/_$//g')
66 name="${1#--disable-}";
67 cfg="${DISABLE_VARS}";
70 # IFS="=" read -ra WITHARGS <<< "${1}"
78 for varstring in $cfg; do
79 extract_var_string $(echo "${varstring}" | tr '|' ' ')
80 if [ "x$VAR_NAME" = "x$name" ]; then
86 if [ "$found" = "y" ]; then
87 if [ "x$is_with" = "xy" ]; then
88 CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "$2")"
90 CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "${VAR_VALUE}")"
93 echo "Unknown parameter: ${1}"
99 expr $(echo "${1}" | awk '{ print length }') + 1
104 -h, --help display this help and exit
105 --disable-debug disable debugging mode
106 --pass-thru pass remaining arguments through to CMake
107 --prefix=PREFIX install architecture-independent files in PREFIX
109 --bindir=DIR user executables [PREFIX/bin]
110 --sbindir=DIR system admin executables [PREFIX/sbin]
111 --libexecdir=DIR program executables [PREFIX/libexec]
112 --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
113 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
114 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
115 --libdir=DIR object code libraries [PREFIX/lib]
116 --includedir=DIR C header files [PREFIX/include]
117 --oldincludedir=DIR C header files for non-gcc [/usr/include]
118 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
119 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
120 --infodir=DIR info documentation [DATAROOTDIR/info]
121 --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
122 --mandir=DIR man documentation [DATAROOTDIR/man]
123 --docdir=DIR documentation root [DATAROOTDIR/doc/PROJECT_NAME]
127 for varstring in ${ENABLE_VARS}; do
128 if [ $first = 'y' ]; then
132 extract_var_string $(echo "${varstring}" | tr '|' ' ')
133 var_doc_name="ENABLE_${VAR_UC_NAME}_DOC"
134 eval "docstring=\$$var_doc_name"
135 if [ "x${docstring}" = "x" ]; then
136 printf " --enable-%-14s enable %s support\n" "${VAR_NAME}" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
138 printf " --enable-%-14s %s\n" "${VAR_NAME}" "$docstring"
143 for varstring in ${DISABLE_VARS}; do
144 if [ $first = 'y' ]; then
148 extract_var_string $(echo "${varstring}" | tr '|' ' ')
149 var_doc_name="DISABLE_${VAR_UC_NAME}_DOC"
150 eval "docstring=\$$var_doc_name"
151 if [ "x${docstring}" = "x" ]; then
152 printf " --disable-%-13s disable %s support\n" "${VAR_NAME}" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
154 printf " --disable-%-13s %s\n" "${VAR_NAME}" "$docstring"
159 for varstring in ${WITH_VARS}; do
160 if [ $first = 'y' ]; then
164 extract_var_string $(echo "${varstring}" | tr '|' ' ')
165 var_doc_name="WITH_${VAR_UC_NAME}_DOC"
166 eval "docstring=\$$var_doc_name"
167 paraminfo="${VAR_NAME}=${VAR_VALUE}"
168 if [ "x${docstring}" = "x" ]; then
169 printf " --with-%-16s enable %s support\n" "$paraminfo" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
171 printf " --with-%-16s %s\n" "$paraminfo" "$docstring"
178 while [ $# != 0 ]; do
183 PREFIX="${2}"; shift;;
185 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_BINDIR=$(quote "${1#*=}")";;
187 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_BINDIR=$(quote "$2")"; shift;;
189 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SBINDIR=$(quote "${1#*=}")";;
191 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SBINDIR=$(quote "$2")"; shift;;
193 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBEXECDIR=$(quote "${1#*=}")";;
195 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBEXECDIR=$(quote "$2")"; shift;;
197 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SYSCONFDIR=$(quote "${1#*=}")";;
199 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SYSCONFDIR=$(quote "$2")"; shift;;
200 "--sharedstatedir="*)
201 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SHAREDSTATEDIR=$(quote "${1#*=}")";;
203 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SHAREDSTATEDIR=$(quote "$2")"; shift;;
205 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALSTATEDIR=$(quote "${1#*=}")";;
207 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALSTATEDIR=$(quote "$2")"; shift;;
211 LIBDIR="${2}"; shift;;
213 INCLUDE_DIR="${1#*=}";;
215 INCLUDE_DIR="${2}"; shift;;
217 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_OLDINCLUDEDIR=$(quote "${1#*=}")";;
219 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_OLDINCLUDEDIR=$(quote "$2")"; shift;;
221 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATAROOTDIR=$(quote "${1#*=}")";;
223 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATAROOTDIR=$(quote "$2")"; shift;;
225 DATA_DIR="$(quote "${1#*=}")"; shift;;
227 DATA_DIR="$(quote "$2")"; shift;;
229 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INFODIR=$(quote "${1#*=}")";;
231 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INFODIR=$(quote "$2")"; shift;;
233 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALEDIR=$(quote "${1#*=}")";;
235 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALEDIR=$(quote "$2")"; shift;;
237 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_MANDIR=$(quote "${1#*=}")";;
239 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_MANDIR=$(quote "$2")"; shift;;
241 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "${1#*=}")";;
243 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "$2")"; shift;;
246 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "${1#*=}")";;
248 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER=$(quote "${1#*=}")";;
250 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_FLAGS=$(quote "${1#*=}")";;
252 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_FLAGS=$(quote "${1#*=}")";;
254 LDFLAGS="$LDFLAGS ${1#*=}";;
261 # This flag is the only one which may be a bit surprising to
262 # people. Autotools always builds with debugging symbols enabled
263 # (AFAIK), but for cmake you have to do -DCMAKE_BUILD_TYPE=Debug.
264 # Unfortunately this can change other things as well, so although
265 # I realize there is no --disable-debug flag I thought it would be
266 # prudent to support one here.
268 BUILD_TYPE="Release";;
272 while [ $# != 0 ]; do
273 CMAKE_ARGS="$CMAKE_ARGS $(quote "${1}")";
286 name=$(echo "${1#--with-}" | awk '{split($1,v,"="); print v[1]}')
289 set_config_var "--with-${name}" "${1#--with-${name}=}";;
291 set_config_var "$1" "$2";
297 echo "$0: error: unrecognized option: \`$1'" >&2
298 echo "Try \`$0 --help' for more information" >&2
304 if [ "x${LIBDIR}" = "x" ]; then
305 LIBDIR="${PREFIX}/lib"
308 # Unlike CFLAGS/CXXFLAGS/CC/CXX, LDFLAGS isn't handled by CMake, so we
309 # need to parse it here.
310 if [ "x${LDFLAGS}" != "x" ]; then
311 for varname in EXE MODULE SHARED STATIC; do
312 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_${varname}_LINKER_FLAGS=$(quote "$LDFLAGS")"
316 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
317 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${PREFIX}"
318 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATADIR=${DATA_DIR}"
319 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INCLUDEDIR=${INCLUDE_DIR}"
320 CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBDIR=${LIBDIR} ${CMAKE_ARGS}"
322 eval "cmake -Bbuild -H${TOP_SRCDIR} ${CMAKE_ARGS}"