| 1 |
#!/bin/sh |
| 2 |
# Convenience wrapper for easily viewing/setting options that |
| 3 |
# the project's CMake scripts will recognize |
| 4 |
set -e |
| 5 |
command="$0 $*" |
| 6 |
|
| 7 |
usage="\ |
| 8 |
Usage: $0 [OPTION]... [VAR=VALUE]... |
| 9 |
|
| 10 |
Build Options: |
| 11 |
--cmake=PATH custom path to a CMake binary |
| 12 |
--generator=GENERATOR CMake generator to use (see 'cmake --help') |
| 13 |
--build-dir=DIR place build files in directory [build] |
| 14 |
--build-type=TYPE set CMake build type [RelWithDebInfo]: |
| 15 |
- Debug: optimizations off, debug symbols + flags |
| 16 |
- MinSizeRel: size optimizations, debugging off |
| 17 |
- Release: optimizations on, debugging off |
| 18 |
- RelWithDebInfo: optimizations on, |
| 19 |
debug symbols on, debug flags off |
| 20 |
--ccache use ccache to speed up recompilation (requires |
| 21 |
ccache installation and CMake 3.10+) |
| 22 |
--enable-debug compile in debugging mode (like --build-type=Debug) |
| 23 |
--enable-static build static libraries (in addition to shared) |
| 24 |
--enable-static-only only build static libraries, not shared |
| 25 |
--with-log-level=LVL build embedded CAF with debugging output. Levels: |
| 26 |
ERROR, WARNING, INFO, DEBUG, TRACE |
| 27 |
--sanitizers=LIST comma-separated list of sanitizer names to enable |
| 28 |
|
| 29 |
Installation Directories: |
| 30 |
--prefix=PREFIX installation directory [/usr/local] |
| 31 |
--libdir=DIR installation directory for static and dynamic |
| 32 |
libraries [PREFIX/lib] |
| 33 |
--python-home=PATH explicit installation method for optional Python |
| 34 |
bindings [PATH/lib/python], the path tracks |
| 35 |
--prefix if that option is used. |
| 36 |
--python-prefix=PATH explicit install directory for Python bindings |
| 37 |
[PATH/lib/python<Python Version>/site-packages] |
| 38 |
|
| 39 |
Optional Features: |
| 40 |
--disable-python don't try to build python bindings |
| 41 |
--disable-docs don't try to build local documentation |
| 42 |
--disable-tests don't try to build unit tests |
| 43 |
--enable-rocksdb try to find and a RocksDB installation and use it |
| 44 |
--with-rocksdb=PATH path to RocksDB installation, implies --enable-rocksdb |
| 45 |
--with-python=PATH path to Python executable |
| 46 |
--with-python-config=PATH |
| 47 |
path to python-config executable |
| 48 |
--with-zeek=PATH path to Zeek executable for interoperability tests |
| 49 |
|
| 50 |
Required Packages in Non-Standard Locations: |
| 51 |
--with-caf=PATH path to C++ Actor Framework installation |
| 52 |
--with-openssl=PATH path to OpenSSL install root |
| 53 |
|
| 54 |
Influential Environment Variables (only on first invocation |
| 55 |
per build directory): |
| 56 |
CC C compiler command |
| 57 |
CFLAGS C compiler flags |
| 58 |
CXX C++ compiler command |
| 59 |
CXXFLAGS C++ compiler flags |
| 60 |
" |
| 61 |
|
| 62 |
sourcedir="$( cd "$( dirname "$0" )" && pwd )" |
| 63 |
|
| 64 |
# Function to append a CMake cache entry definition to the |
| 65 |
# CMakeCacheEntries variable |
| 66 |
# $1 is the cache entry variable name |
| 67 |
# $2 is the cache entry variable type |
| 68 |
# $3 is the cache entry variable value |
| 69 |
append_cache_entry () { |
| 70 |
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3" |
| 71 |
} |
| 72 |
|
| 73 |
# set defaults |
| 74 |
builddir=build |
| 75 |
prefix=/usr/local |
| 76 |
CMakeCacheEntries="" |
| 77 |
append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix |
| 78 |
append_cache_entry BROKER_DISABLE_DOCS BOOL false |
| 79 |
|
| 80 |
# parse arguments |
| 81 |
while [ $# -ne 0 ]; do |
| 82 |
case "$1" in |
| 83 |
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; |
| 84 |
*) optarg= ;; |
| 85 |
esac |
| 86 |
|
| 87 |
case "$1" in |
| 88 |
--help|-h) |
| 89 |
echo "${usage}" 1>&2 |
| 90 |
exit 1 |
| 91 |
;; |
| 92 |
--cmake=*) |
| 93 |
CMakeCommand=$optarg |
| 94 |
;; |
| 95 |
--generator=*) |
| 96 |
CMakeGenerator="$optarg" |
| 97 |
;; |
| 98 |
--ccache) |
| 99 |
append_cache_entry ENABLE_CCACHE BOOL true |
| 100 |
;; |
| 101 |
--build-dir=*) |
| 102 |
builddir=$optarg |
| 103 |
;; |
| 104 |
# backwards compatibility |
| 105 |
--builddir=*) |
| 106 |
builddir=$optarg |
| 107 |
;; |
| 108 |
--prefix=*) |
| 109 |
append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg |
| 110 |
append_cache_entry CMAKE_INSTALL_LIBDIR PATH $optarg/lib |
| 111 |
append_cache_entry BROKER_PYTHON_HOME PATH $optarg |
| 112 |
;; |
| 113 |
--libdir=*) |
| 114 |
append_cache_entry CMAKE_INSTALL_LIBDIR PATH $optarg |
| 115 |
;; |
| 116 |
--python-home=*) |
| 117 |
append_cache_entry BROKER_PYTHON_HOME PATH $optarg |
| 118 |
;; |
| 119 |
--python-prefix=*) |
| 120 |
append_cache_entry BROKER_PYTHON_PREFIX PATH $optarg |
| 121 |
;; |
| 122 |
--build-type=*) |
| 123 |
append_cache_entry CMAKE_BUILD_TYPE STRING $optarg |
| 124 |
;; |
| 125 |
--enable-debug) |
| 126 |
append_cache_entry ENABLE_DEBUG BOOL true |
| 127 |
;; |
| 128 |
--enable-static) |
| 129 |
append_cache_entry ENABLE_STATIC BOOL true |
| 130 |
;; |
| 131 |
--sanitizers=*) |
| 132 |
append_cache_entry BROKER_SANITIZERS STRING $optarg |
| 133 |
;; |
| 134 |
--enable-static-only) |
| 135 |
append_cache_entry ENABLE_STATIC_ONLY BOOL true |
| 136 |
;; |
| 137 |
--with-log-level=*) |
| 138 |
append_cache_entry CAF_LOG_LEVEL STRING $optarg |
| 139 |
;; |
| 140 |
--disable-python) |
| 141 |
append_cache_entry DISABLE_PYTHON_BINDINGS BOOL true |
| 142 |
;; |
| 143 |
--disable-docs) |
| 144 |
append_cache_entry BROKER_DISABLE_DOCS BOOL true |
| 145 |
;; |
| 146 |
--disable-tests) |
| 147 |
append_cache_entry BROKER_DISABLE_TESTS BOOL true |
| 148 |
;; |
| 149 |
--with-caf=*) |
| 150 |
append_cache_entry CAF_ROOT_DIR PATH $optarg |
| 151 |
;; |
| 152 |
--with-openssl=*) |
| 153 |
append_cache_entry OPENSSL_ROOT_DIR PATH $optarg |
| 154 |
;; |
| 155 |
--enable-rocksdb) |
| 156 |
append_cache_entry BROKER_ENABLE_ROCKSDB BOOL true |
| 157 |
;; |
| 158 |
--with-rocksdb=*) |
| 159 |
append_cache_entry BROKER_ENABLE_ROCKSDB BOOL true |
| 160 |
append_cache_entry ROCKSDB_ROOT_DIR PATH $optarg |
| 161 |
;; |
| 162 |
--with-python=*) |
| 163 |
append_cache_entry PYTHON_EXECUTABLE PATH $optarg |
| 164 |
;; |
| 165 |
--with-python-config=*) |
| 166 |
append_cache_entry PYTHON_CONFIG PATH $optarg |
| 167 |
;; |
| 168 |
--with-zeek=*) |
| 169 |
append_cache_entry ZEEK_EXECUTABLE PATH $optarg |
| 170 |
;; |
| 171 |
*) |
| 172 |
echo "Invalid option '$1'. Try $0 --help to see available options." |
| 173 |
exit 1 |
| 174 |
;; |
| 175 |
esac |
| 176 |
shift |
| 177 |
done |
| 178 |
|
| 179 |
if [ -z "$CMakeCommand" ]; then |
| 180 |
# prefer cmake3 over "regular" cmake (cmake == cmake2 on RHEL) |
| 181 |
if command -v cmake3 >/dev/null 2>&1 ; then |
| 182 |
CMakeCommand="cmake3" |
| 183 |
elif command -v cmake >/dev/null 2>&1 ; then |
| 184 |
CMakeCommand="cmake" |
| 185 |
else |
| 186 |
echo "This package requires CMake, please install it first." |
| 187 |
echo "Then you may use this script to configure the CMake build." |
| 188 |
echo "Note: pass --cmake=PATH to use cmake in non-standard locations." |
| 189 |
exit 1; |
| 190 |
fi |
| 191 |
fi |
| 192 |
|
| 193 |
if [ -d $builddir ]; then |
| 194 |
# If build directory exists, check if it has a CMake cache |
| 195 |
if [ -f $builddir/CMakeCache.txt ]; then |
| 196 |
# If the CMake cache exists, delete it so that this configuration |
| 197 |
# is not tainted by a previous one |
| 198 |
rm -f $builddir/CMakeCache.txt |
| 199 |
fi |
| 200 |
else |
| 201 |
# Create build directory |
| 202 |
mkdir -p $builddir |
| 203 |
fi |
| 204 |
|
| 205 |
echo "Build Directory : $builddir" |
| 206 |
echo "Source Directory: $sourcedir" |
| 207 |
cd $builddir |
| 208 |
|
| 209 |
if [ -n "$CMakeGenerator" ]; then |
| 210 |
"$CMakeCommand" -G "$CMakeGenerator" $CMakeCacheEntries $sourcedir |
| 211 |
else |
| 212 |
"$CMakeCommand" $CMakeCacheEntries $sourcedir |
| 213 |
fi |
| 214 |
|
| 215 |
printf "#!/bin/sh\n\n" > config.status |
| 216 |
printf "# Switch to the source of this build directory.\n" >> config.status |
| 217 |
printf "cd \"$sourcedir\"\n\n" >> config.status |
| 218 |
printf "# Invoke the command to configure this build.\n" >> config.status |
| 219 |
if [ -n "$CC" ]; then |
| 220 |
printf 'CC="%s" ' "$CC" >> config.status |
| 221 |
fi |
| 222 |
if [ -n "$CXX" ]; then |
| 223 |
printf 'CXX="%s" ' "$CXX" >> config.status |
| 224 |
fi |
| 225 |
if [ -n "$CXXFLAGS" ]; then |
| 226 |
printf 'CXXFLAGS="%s" ' "$CXXFLAGS" >> config.status |
| 227 |
fi |
| 228 |
printf "$command\n" $@ >> config.status |
| 229 |
chmod u+x config.status |