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 |
126
cmake.sh
126
cmake.sh
@@ -21,16 +21,11 @@ LONGOPTS=generator:,type:,qtcreator,cmake,force,source-dir:,build-dir:,output-di
|
||||
eval set -- "$PARSED"
|
||||
|
||||
# Default generator
|
||||
GENERATOR="Unix Makefiles"
|
||||
[ -x "$(command -v make)" ] && GENERATOR="Unix Makefiles"
|
||||
[ -x "$(command -v ninja)" ] && GENERATOR=Ninja
|
||||
|
||||
# Generate single build type
|
||||
SINGLE_TYPE="n"
|
||||
|
||||
# Generate QtCreator build types
|
||||
QTCREATOR="n"
|
||||
|
||||
# Generate CMake build types
|
||||
CMAKE="n"
|
||||
# Build types list separated with comma
|
||||
TYPES="Release"
|
||||
|
||||
# Force destructive actions
|
||||
FORCE="n"
|
||||
@@ -50,18 +45,10 @@ while true; do
|
||||
GENERATOR="$2"
|
||||
shift 2
|
||||
;;
|
||||
-t|--type)
|
||||
SINGLE_TYPE="$2"
|
||||
-t|--types)
|
||||
TYPES="$2"
|
||||
shift 2
|
||||
;;
|
||||
-q|--qtcreator)
|
||||
QTCREATOR="y"
|
||||
shift
|
||||
;;
|
||||
-c|--cmake)
|
||||
CMAKE="y"
|
||||
shift
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE="y"
|
||||
shift
|
||||
@@ -83,54 +70,42 @@ while true; do
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Programming error"
|
||||
echo "Wrong argument is set"
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
CMAKE_ARGS=()
|
||||
[ ${#@} -gt 0 ] && CMAKE_ARGS=("${@}")
|
||||
if [ "x${GENERATOR}" = "x" ]; then
|
||||
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; }
|
||||
|
||||
if [ -d "${BUILD_DIR}" ]; then
|
||||
if [ "x${FORCE}" == "xy" ]; then
|
||||
rm -rf "${BUILD_DIR}"
|
||||
if grep -i ^"project.*fortran" "${SOURCE_DIR}/CMakeLists.txt" >/dev/null 2>&1 ; then
|
||||
if [ -x "$(command -v make)" ]; then
|
||||
GENERATOR="Unix Makefiles"
|
||||
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
|
||||
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 SOURCE_DIR
|
||||
export BUILD_DIR
|
||||
export OUTPUT_DIR
|
||||
export CMAKE_ARGS
|
||||
|
||||
CMAKE_BUILD_TYPES=(None Debug Release RelWithDebInfo MinSizeRel)
|
||||
QTCREATOR_BUILD_TYPES=(qtNone qtDebug qtRelease qtProfile)
|
||||
export FORCE
|
||||
|
||||
generate_configuration() {
|
||||
local BUILD_TYPE="${!#}"
|
||||
local BUILD="$BUILD_TYPE"
|
||||
|
||||
if [ "x$QTCREATOR" == "xy" ]; then
|
||||
case "$BUILD_TYPE" in
|
||||
qtNone)
|
||||
BUILD="unknown"
|
||||
@@ -149,55 +124,48 @@ generate_configuration() {
|
||||
BUILD_TYPE="Profile"
|
||||
;;
|
||||
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
|
||||
|
||||
GEN_DIR="${BUILD_DIR}"
|
||||
[ "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
|
||||
cmake -B"${GEN_DIR}" -H"${SOURCE_DIR}" -G "${GENERATOR}" -DCMAKE_INSTALL_PREFIX="${OUTPUT_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${CMAKE_ARGS}
|
||||
}
|
||||
|
||||
export -f generate_configuration
|
||||
set -f
|
||||
|
||||
BUILD_TYPES=()
|
||||
BUILD_TYPES=(${TYPES//,/ })
|
||||
|
||||
if [ "x$SINGLE_TYPE" != "xn" ]; then
|
||||
BUILD_TYPES=("${SINGLE_TYPE}")
|
||||
else
|
||||
[ "x$QTCREATOR" == "xy" ] && BUILD_TYPES=("${BUILD_TYPES[@]}" "${QTCREATOR_BUILD_TYPES[@]}")
|
||||
[ "x$CMAKE" == "xy" ] && BUILD_TYPES=("${BUILD_TYPES[@]}" "${CMAKE_BUILD_TYPES[@]}")
|
||||
fi
|
||||
|
||||
if [ ${#BUILD_TYPES[@]} -eq 0 ]; then
|
||||
echo "No build type selected."
|
||||
echo "Use -c for default CMake build types"
|
||||
echo "Use -q for build types for QtCreator"
|
||||
echo "Use -t name for build with type 'name'"
|
||||
exit 0
|
||||
fi
|
||||
for i in "${!BUILD_TYPES[@]}"; do
|
||||
case ${BUILD_TYPES[i]} in
|
||||
None|Debug|Release|Profile|RelWithDebInfo|MinSizeRel|qtNone|qtDebug|qtRelease|qtProfile)
|
||||
true
|
||||
;;
|
||||
*)
|
||||
echo "Wrong CMake build type. Possible value are:"
|
||||
echo "None,Debug,Release,Profile,RelWithDebInfo,MinSizeRel,qtNone,qtDebug,qtRelease,qtProfile"
|
||||
exit 6
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Try to work in parallel
|
||||
if [ -x "$(command -v parallel)" ]; then
|
||||
PV=$(parallel --version | head -n 1 | awk '{ print $3; }')
|
||||
if [ "$PV" -lt "20131121" ]; then
|
||||
parallel generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||
parallel --delay 2 -r generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||
elif [ "$PV" -lt "20141023" ]; then
|
||||
parallel --no-notice generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||
parallel --delay 2 -r --no-notice generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||
else
|
||||
parallel --will-cite generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||
parallel --delay 2 -r --will-cite generate_configuration ::: "${BUILD_TYPES[@]}"
|
||||
fi
|
||||
else
|
||||
for T in "${BUILD_TYPES[@]}"; do generate_configuration "${T}"; done
|
||||
|
@@ -1,8 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
GENERATOR=make
|
||||
[ -x "$(command -v ninja)" ] && GENERATOR=Ninja
|
||||
PROJECT=$(grep -i "^Project" "$(dirname -- "$(dirname -- "$(pwd)")")/CMakeLists.txt" | awk -F'[()]' '{print $2}')
|
||||
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