Compare commits
18 Commits
6c31d9f67e
...
master
Author | SHA1 | Date | |
---|---|---|---|
74d499b9cb | |||
c015300d63 | |||
b01bc7a52e | |||
6630d0c232 | |||
9952d86269 | |||
c04395ef98 | |||
138e8774f4 | |||
a9d38e1ca6 | |||
4c57e48a3d | |||
f8d79f8c2b | |||
5b2635867d | |||
120458b69c | |||
9217079b4a | |||
1ff29c5c87 | |||
565f79f5ba | |||
36487b07d2 | |||
e15e1fb505 | |||
dc15c6ea8b |
162
cmake.sh
162
cmake.sh
@@ -21,16 +21,11 @@ LONGOPTS=generator:,type:,qtcreator,cmake,force,source-dir:,build-dir:,output-di
|
|||||||
eval set -- "$PARSED"
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
# Default generator
|
# Default generator
|
||||||
GENERATOR="Unix Makefiles"
|
[ -x "$(command -v make)" ] && GENERATOR="Unix Makefiles"
|
||||||
|
[ -x "$(command -v ninja)" ] && GENERATOR=Ninja
|
||||||
|
|
||||||
# Generate single build type
|
# Build types list separated with comma
|
||||||
SINGLE_TYPE="n"
|
TYPES="Release"
|
||||||
|
|
||||||
# Generate QtCreator build types
|
|
||||||
QTCREATOR="n"
|
|
||||||
|
|
||||||
# Generate CMake build types
|
|
||||||
CMAKE="n"
|
|
||||||
|
|
||||||
# Force destructive actions
|
# Force destructive actions
|
||||||
FORCE="n"
|
FORCE="n"
|
||||||
@@ -50,18 +45,10 @@ while true; do
|
|||||||
GENERATOR="$2"
|
GENERATOR="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-t|--type)
|
-t|--types)
|
||||||
SINGLE_TYPE="$2"
|
TYPES="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-q|--qtcreator)
|
|
||||||
QTCREATOR="y"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-c|--cmake)
|
|
||||||
CMAKE="y"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-f|--force)
|
-f|--force)
|
||||||
FORCE="y"
|
FORCE="y"
|
||||||
shift
|
shift
|
||||||
@@ -83,121 +70,102 @@ while true; do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Programming error"
|
echo "Wrong argument is set"
|
||||||
exit 3
|
exit 3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
CMAKE_ARGS=()
|
if [ "x${GENERATOR}" = "x" ]; then
|
||||||
[ ${#@} -gt 0 ] && CMAKE_ARGS=("${@}")
|
echo "Build command is not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CMAKE_ARGS=""
|
||||||
|
[ ${#@} -gt 0 ] && CMAKE_ARGS=${@}
|
||||||
|
|
||||||
[ ! -f "${SOURCE_DIR}/CMakeLists.txt" ] && { echo "Source directory does not contain CMakeLists.txt"; exit 4; }
|
[ ! -f "${SOURCE_DIR}/CMakeLists.txt" ] && { echo "Source directory does not contain CMakeLists.txt"; exit 4; }
|
||||||
|
|
||||||
if [ -d "${BUILD_DIR}" ]; then
|
if grep -i ^"project.*fortran" "${SOURCE_DIR}/CMakeLists.txt" >/dev/null 2>&1 ; then
|
||||||
if [ "x${FORCE}" == "xy" ]; then
|
if [ -x "$(command -v make)" ]; then
|
||||||
rm -rf "${BUILD_DIR}"
|
GENERATOR="Unix Makefiles"
|
||||||
else
|
else
|
||||||
echo "Build directory already exists. Use --force to remove this directory or do it manually"
|
echo "Projects with Fortran sources need Make to build"
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x${SINGLE_TYPE}" != "xn" ]; then
|
|
||||||
case "${SINGLE_TYPE}" in
|
|
||||||
None|Debug|Release|Profile|RelWithDebInfo|MinSizeRel)
|
|
||||||
true
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Wrong CMake build type"
|
|
||||||
exit 6
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
export CMAKE
|
|
||||||
export QTCREATOR
|
|
||||||
export GENERATOR
|
export GENERATOR
|
||||||
export SOURCE_DIR
|
export SOURCE_DIR
|
||||||
export BUILD_DIR
|
export BUILD_DIR
|
||||||
export OUTPUT_DIR
|
export OUTPUT_DIR
|
||||||
export CMAKE_ARGS
|
export CMAKE_ARGS
|
||||||
|
export FORCE
|
||||||
CMAKE_BUILD_TYPES=(None Debug Release RelWithDebInfo MinSizeRel)
|
|
||||||
QTCREATOR_BUILD_TYPES=(qtNone qtDebug qtRelease qtProfile)
|
|
||||||
|
|
||||||
generate_configuration() {
|
generate_configuration() {
|
||||||
local BUILD_TYPE="${!#}"
|
local BUILD_TYPE="${!#}"
|
||||||
local BUILD="$BUILD_TYPE"
|
local BUILD="$BUILD_TYPE"
|
||||||
|
|
||||||
if [ "x$QTCREATOR" == "xy" ]; then
|
case "$BUILD_TYPE" in
|
||||||
case "$BUILD_TYPE" in
|
qtNone)
|
||||||
qtNone)
|
BUILD="unknown"
|
||||||
BUILD="unknown"
|
BUILD_TYPE="None"
|
||||||
BUILD_TYPE="None"
|
;;
|
||||||
;;
|
qtDebug)
|
||||||
qtDebug)
|
BUILD="debug"
|
||||||
BUILD="debug"
|
BUILD_TYPE="Debug"
|
||||||
BUILD_TYPE="Debug"
|
;;
|
||||||
;;
|
qtRelease)
|
||||||
qtRelease)
|
BUILD="release"
|
||||||
BUILD="release"
|
BUILD_TYPE="Release"
|
||||||
BUILD_TYPE="Release"
|
;;
|
||||||
;;
|
qtProfile)
|
||||||
qtProfile)
|
BUILD="profile"
|
||||||
BUILD="profile"
|
BUILD_TYPE="Profile"
|
||||||
BUILD_TYPE="Profile"
|
;;
|
||||||
;;
|
esac
|
||||||
esac
|
|
||||||
|
GEN_DIR="${BUILD_DIR}/${BUILD}"
|
||||||
|
|
||||||
|
if [ -d "${GEN_DIR}" ]; then
|
||||||
|
if [ "x${FORCE}" == "xy" ]; then
|
||||||
|
rm -rf "${GEN_DIR}"
|
||||||
|
else
|
||||||
|
echo "Build directory '${GEN_DIR}' already exists. Use --force to remove this directory or do it manually"
|
||||||
|
return
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GEN_DIR="${BUILD_DIR}"
|
cmake -B"${GEN_DIR}" -H"${SOURCE_DIR}" -G "${GENERATOR}" -DCMAKE_INSTALL_PREFIX="${OUTPUT_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${CMAKE_ARGS}
|
||||||
[ "x${SINGLE_TYPE}" == "xn" ] && GEN_DIR="${BUILD_DIR}/${BUILD}"
|
|
||||||
[ -d "${GEN_DIR}" ] && return 0
|
|
||||||
mkdir -p "${GEN_DIR}"
|
|
||||||
pushd "${GEN_DIR}" 2>/dev/null
|
|
||||||
cmake -G "${GENERATOR}" -DCMAKE_INSTALL_PREFIX="${OUTPUT_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" "${CMAKE_ARGS[@]}" "${SOURCE_DIR}"
|
|
||||||
if [ "x$GENERATOR" == "xNinja" ]; then
|
|
||||||
# Generate fake Makefile, so make can run ninja build
|
|
||||||
cat > Makefile <<EOF
|
|
||||||
.PHONY: build
|
|
||||||
%:
|
|
||||||
@ninja \$@
|
|
||||||
build:
|
|
||||||
@ninja
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
popd 2>/dev/null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export -f generate_configuration
|
export -f generate_configuration
|
||||||
|
set -f
|
||||||
|
|
||||||
BUILD_TYPES=()
|
BUILD_TYPES=(${TYPES//,/ })
|
||||||
|
|
||||||
if [ "x$SINGLE_TYPE" != "xn" ]; then
|
for i in "${!BUILD_TYPES[@]}"; do
|
||||||
BUILD_TYPES=("${SINGLE_TYPE}")
|
case ${BUILD_TYPES[i]} in
|
||||||
else
|
None|Debug|Release|Profile|RelWithDebInfo|MinSizeRel|qtNone|qtDebug|qtRelease|qtProfile)
|
||||||
[ "x$QTCREATOR" == "xy" ] && BUILD_TYPES=("${BUILD_TYPES[@]}" "${QTCREATOR_BUILD_TYPES[@]}")
|
true
|
||||||
[ "x$CMAKE" == "xy" ] && BUILD_TYPES=("${BUILD_TYPES[@]}" "${CMAKE_BUILD_TYPES[@]}")
|
;;
|
||||||
fi
|
*)
|
||||||
|
echo "Wrong CMake build type. Possible value are:"
|
||||||
if [ ${#BUILD_TYPES[@]} -eq 0 ]; then
|
echo "None,Debug,Release,Profile,RelWithDebInfo,MinSizeRel,qtNone,qtDebug,qtRelease,qtProfile"
|
||||||
echo "No build type selected."
|
exit 6
|
||||||
echo "Use -c for default CMake build types"
|
;;
|
||||||
echo "Use -q for build types for QtCreator"
|
esac
|
||||||
echo "Use -t name for build with type 'name'"
|
done
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to work in parallel
|
# Try to work in parallel
|
||||||
if [ -x "$(command -v parallel)" ]; then
|
if [ -x "$(command -v parallel)" ]; then
|
||||||
PV=$(parallel --version | head -n 1 | awk '{ print $3; }')
|
PV=$(parallel --version | head -n 1 | awk '{ print $3; }')
|
||||||
if [ "$PV" -lt "20131121" ]; then
|
if [ "$PV" -lt "20131121" ]; then
|
||||||
parallel generate_configuration ::: "${BUILD_TYPES[@]}"
|
parallel --delay 2 -r generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||||
elif [ "$PV" -lt "20141023" ]; then
|
elif [ "$PV" -lt "20141023" ]; then
|
||||||
parallel --no-notice generate_configuration ::: "${BUILD_TYPES[@]}"
|
parallel --delay 2 -r --no-notice generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||||
else
|
else
|
||||||
parallel --will-cite generate_configuration ::: "${BUILD_TYPES[@]}"
|
parallel --delay 2 -r --will-cite generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
for T in "${BUILD_TYPES[@]}"; do generate_configuration "${T}"; done
|
for T in "${BUILD_TYPES[@]}"; do generate_configuration "${T}"; done
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
GENERATOR=make
|
PROJECT=$(grep -i "^Project" "$(dirname -- "$(dirname -- "$(pwd)")")/CMakeLists.txt" | awk -F'[( )]' '{print $2}')
|
||||||
[ -x "$(command -v ninja)" ] && GENERATOR=Ninja
|
|
||||||
PROJECT=$(grep -i "^Project" "$(dirname -- "$(dirname -- "$(pwd)")")/CMakeLists.txt" | awk -F'[()]' '{print $2}')
|
|
||||||
|
|
||||||
"$(dirname $0)/cmake.sh" -g "${GENERATOR}" -f -t Debug
|
"$(dirname $0)/cmake.sh" -f -t qtDebug
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user