xo-cmake: + xo-build assistant

This commit is contained in:
Roland Conybeare 2024-06-14 15:13:53 -04:00
commit 4b8fab54c3
4 changed files with 224 additions and 1 deletions

View file

@ -23,6 +23,12 @@ configure_file(
@ONLY
)
configure_file(
${PROJECT_SOURCE_DIR}/bin/xo-build.in
${PROJECT_BINARY_DIR}/xo-build
@ONLY
)
install(
FILES
"cmake/xo_macros/xo-project-macros.cmake"
@ -36,6 +42,7 @@ install(
FILES
"${PROJECT_BINARY_DIR}/xo-cmake-lcov-harness"
"${PROJECT_BINARY_DIR}/xo-cmake-config"
"${PROJECT_BINARY_DIR}/xo-build"
PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View file

@ -42,6 +42,8 @@ $ cp $PREFIX/share/xo-macros/xo-bootstrap-macros.cmake cmake/
then in `foo/CMakeLists.txt`:
```
include(cmake/xo-bootstrap-macros.cmake)
xo_cxx_toplevel_options3()
```
Now as long as `$PREFIX/bin` is in `PATH`:

214
bin/xo-build.in Normal file
View file

@ -0,0 +1,214 @@
#!/usr/bin/env bash
usage() {
echo "$0 [-u|--usage|-h|--help] [--xoname=NAME] [--repo]"
}
help() {
usage
cat <<EOF
fetch and/or build xo component libraries
Options:
-u | --usage brief help message
-h | --help this help message
--list list known xo library
-n dry-run: don't actually invoke state-changing commands
--xoname=NAME operate on xo subsystem NAME
--repo report github repo for NAME
--clone git clone xo library NAME in current directory
--configure run cmake for xo library NAME in immediate subdir
Will use NAME/.build as build directory
--build run cmake build for xo library NAME in immediate subdir
--install run cmake install for xo library NAME in immediate subdir
EOF
}
noop_flag=0
xoname=
repo_flag=0
clone_flag=0
configure_flag=0
build_flag=0
install_flag=0
while [[ $# > 0 ]]; do
case "$1" in
-u | --usage)
cmd='usage'
;;
-h | --help)
cmd='help'
;;
-n)
noop_flag=1
;;
--list)
cmd='list'
;;
--xoname=*)
xoname="${1#*=}"
;;
--repo)
repo_flag=1
;;
--clone)
clone_flag=1
;;
--configure|--config)
configure_flag=1
;;
--build)
build_flag=1
;;
--install)
install_flag=1
;;
xo-*)
xoname="$1"
;;
*)
usage
exit 1
;;
esac
shift
done
subsystem_list() {
cat <<EOF
xo-cmake
xo-indentlog
xo-refcnt
xo-subsys
xo-reflect
xo-pyutil
xo-pyreflect
xo-expression
xo-pyexpression
xo-jit
xo-pyjit
EOF
}
XO_REPO_STEM="https://github.com/Rconybea"
repo() {
xoname=$1
case "$xoname" in
xo-cmake)
echo "${XO_REPO_STEM}/xo-cmake.git"
;;
xo-indentlog)
echo "${XO_REPO_STEM}/indentlog.git"
;;
xo-refcnt)
echo "${XO_REPO_STEM}/refcnt.git"
;;
xo-subsys)
echo "${XO_REPO_STEM}/subsys.git"
;;
xo-reflect)
echo "${XO_REPO_STEM}/reflect.git"
;;
xo-pyutil)
echo "${XO_REPO_STEM}/xo-pyutil.git"
;;
xo-pyreflect)
echo "${XO_REPO_STEM}/xo-pyreflect.git"
;;
xo-expression)
echo "${XO_REPO_STEM}/xo-expression.git"
;;
xo-pyexpression)
echo "${XO_REPO_STEM}/xo-pyexpression.git"
;;
xo-jit)
echo "${XO_REPO_STEM}/xo-jit.git"
;;
xo-pyjit)
echo "${XO_REPO_STEM}/xo-pyjit.git"
;;
*)
echo "$0: unknown xo component [${xoname}]"
return 1
esac
return 0
}
if [[ $cmd == 'usage' ]]; then
echo -n "usage: "
usage
exit 0
elif [[ $cmd == 'help' ]]; then
echo -n "help; "
help
exit 0
fi
set -e
if [[ $cmd == 'list' ]]; then
subsystem_list
fi
if [[ $repo_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
repo $xoname
fi
fi
if [[ $clone_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
url=$(repo $xoname)
cmd="git clone $url"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $configure_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
cmd="cmake -DCMAKE_INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@ -S $xoname -B $xoname/.build"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $build_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
cmd="cmake --build $xoname/.build -j"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $install_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
cmd="cmake --install $xoname/.build"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi

View file

@ -13,7 +13,7 @@ display xo-cmake configuration variables
Options:
-u | --usage brief help message
--help this help message
-h | --help this help message
--cmake-module-path report directory providing xo-cmake macros (will use/appear-in CMAKE_MODULE_PATH)
--lcov-exe report path to 'lcov' executable
--genhtml-exe report path to 'genhtml' executable