classes/cmake: not working getopts
Closed this issue · 8 comments
Line 58 in 6878d4e
I guess this implementation will not work, if u want to use -i, -m, -o or -O
.
Currently $1 have to be source-path and everything else will be added in the end of the command. So if i use -i
, i get the error:
The "cmake -i" wizard mode is no longer supported.
Maybe we could use something like that. if we need a option for source-path, we have to add this.
usage for this implementation: cmakeBuild -i install -m all -- -DCMAKE_SOMETHING:BOOL=OFF
diff --git a/classes/cmake.yaml b/classes/cmake.yaml
index 1bbce92..f7372c0 100644
--- a/classes/cmake.yaml
+++ b/classes/cmake.yaml
@@ -3,6 +3,8 @@ inherit: [cpackage, make, install]
buildTools: [cmake]
buildVars: [CC, CXX]
buildScript: |
+ _CMAKE_SOURCE_PATH=$1
+
# Make sure CMake finds other stuff by its own logic too
CMAKE_FIND_ROOT_PATH=
for i in "${@:2}" ; do
@@ -49,16 +51,16 @@ buildScript: |
{
local MAKE_TARGET=
local MAKE_OPTIONS=( )
- local INSTALL_TAGET=install
+ local INSTALL_TARGET=install
local INSTALL_OPTIONS=( )
# parse arguments
- OPTIND=1
+ local OPTIND=1
local opt
- while getopts "i:m:o:O:s" opt ; do
+ while getopts "i:m:o:O:" opt ; do
case "$opt" in
i)
- INSTALL_TAGET="$OPTARG"
+ INSTALL_TARGET="$OPTARG"
;;
m)
MAKE_TARGET="$OPTARG"
@@ -69,23 +71,26 @@ buildScript: |
O)
INSTALL_OPTIONS+=( "$OPTARG" )
;;
+ --)
+ break
+ ;;
\?)
- echo "Invalid option: -$OPTARG" >&2
- exit 1
- ;;
- esac
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ esac
done
shift $(( OPTIND -1 ))
mkdir -p build install
pushd build
- cmake "$1" \
+ cmake "${_CMAKE_SOURCE_PATH}" \
${CMAKE_TOOLCHAIN_FILE:+-DCMAKE_TOOLCHAIN_FILE="$CMAKE_TOOLCHAIN_FILE"} \
-DCMAKE_FIND_ROOT_PATH="$CMAKE_FIND_ROOT_PATH" \
-DCMAKE_BUILD_TYPE=Bob \
-DCMAKE_INSTALL_PREFIX="/usr" \
-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \
- "${@:2}"
+ $@
makeParallel $MAKE_TARGET ${MAKE_OPTIONS:+"${MAKE_OPTIONS[@]}"}
if [[ -n "$INSTALL_TAGET" ]] ; then
i would prefer to use bobs $1
source path, if no -s
(comeback of the -s option :) ) option is set and we break on --
to passthrough the additional cmake arguments
I'm AFK for the next week. I'll look into it when I'm back...
Hmm, cmakeBuild -i install -m all "$1" -DCMAKE_SOMETHING:BOOL=OFF
should work AFAICT? The recipes/devel/ninja.yaml
recipe even uses the -i
option. It just has to be passed before the mandatory source path...
so i missunderstood this!
# $1 : source path
cmakeBuild()
i used cmakeBuild $SRCDIR -i install -m all -- -D...
so $1 of the function is $SRCDIR xD
i confirm: if i do it correct, it'll work!
cmakeBuild -i install -m all -- $SRCDIR -D..
or cmakeBuild -i install -m all $SRCDIR -D...
works fine.
just one thing, we could make this available:
cmakeBuild -- -D..
by using the _CMAKE_SRC_PATH
just one thing, we could make this available:
cmakeBuild -- -D..
by using the _CMAKE_SRC_PATH
Yes, but as I wrote in #27 the mandatory source path argument should be converted to an optional argument and not removed completely. The install...
functions already use this schema...
okay, i am not sure, if that will work, if we want to use this:
cmakeBuild -- -D..
because $1 will not be empty.
just using cmakeBuild
would work. i guess we can close this. giving the source-dir isn't a problem at all.
feel free to close this ticket :)
No, cmakeBuild -- -D..
won't work. Given the _CMAKE_SRC_PATH
change you could either use plain cmakeBuild
or must pass the source path cmakeBuild $SRCDIR -D...
if you want to pass cmake options.
i guess there is no use-case to just use cmakeBuild
plainly.