Skip to content

Instantly share code, notes, and snippets.

@codemercenary
Last active August 16, 2016 21:36
Show Gist options
  • Save codemercenary/90a739d546ab061c0d4aee7ac0ce5aac to your computer and use it in GitHub Desktop.
Save codemercenary/90a739d546ab061c0d4aee7ac0ce5aac to your computer and use it in GitHub Desktop.
Script I use to build Leap libraries on Windows
#!/usr/bin/env bash
set -e
PREFIX_PATH="C:"
INSTALL_PREFIX="C:"
MAKEINSTALLER=false
PERFORMINSTALL=false
DO_COMPILE=true
print_usage() {
echo "Usage: $1 [-p|--prefix <prefixpath>] [-i|--make_installer] [--install] [--dryrun]"
echo " -p The CMAKE_PREFIX_PATH where external libraries are located"
echo " -i Build the installer/MSI"
}
while [[ $# > 0 ]]; do
case "$1" in
-p|--prefix)
PREFIX_PATH="$2"
shift
;;
-i|--make-installer)
MAKEINSTALLER=true
;;
--install)
MAKEINSTALLER=true
PERFORMINSTALL=true
INSTALL_PREFIX="$2"
shift
;;
--dryrun)
DO_COMPILE=false
;;
--)
shift
break
;;
*)
echo "Unknown option $1"
print_usage
exit 1
;;
esac
shift
done
EXTRA_ARGS=()
while [[ $# > 1 ]]; do
EXTRA_ARGS+=($1)
shift
done
# Retrieve project name and version number
a_project=$(grep -oP "(?<=project\()\w+" CMakeLists.txt)
a_version=$(grep -o "[0-9]\+.[0-9]\+.[0-9]\+" version.cmake)
echo "Building $a_project version $a_version"
build_with() {
MY_PREFIX_PATH=$PREFIX_PATH/$3
MY_INSTALL_PREFIX=$INSTALL_PREFIX/$3
mkdir -p "$1"
pushd "$1"
cmake ../.. -G "$2" -DCMAKE_PREFIX_PATH:PATH="$MY_PREFIX_PATH" -DCMAKE_INSTALL_PREFIX:PATH="$MY_INSTALL_PREFIX" "${EXTRA_ARGS[@]}"
if [ $DO_COMPILE = true ]; then
for cfg in Debug Release; do
cmake --build . --config $cfg -- -m
echo "Testing $cfg"
if ! ctest . -C $cfg --output-on-failure; then
echo "While running $cfg $2"
exit 1
fi
done
if [ "$MAKEINSTALLER" = true ]; then
rm -f *.zip *.msi
cpack .
if [ "$PERFORMINSTALL" = true ]; then
unzip -o *.zip -d "$MY_INSTALL_PREFIX"
fi
fi
fi
popd
}
build_with 'b/vs2013_x86' "Visual Studio 12 2013" "Libraries-x86_vc12" "-win32"
build_with 'b/vs2013_x64' "Visual Studio 12 2013 Win64" "Libraries-x64_vc12" "-win64"
build_with 'b/vs2015_x86' "Visual Studio 14 2015" "Libraries-x86_vc14" "-win32"
build_with 'b/vs2015_x64' "Visual Studio 14 2015 Win64" "Libraries-x64_vc14" "-win64"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment