Compare commits

...

8 Commits

2 changed files with 49 additions and 96 deletions

141
cmake.sh
View File

@@ -24,14 +24,8 @@ eval set -- "$PARSED"
[ -x "$(command -v make)" ] && GENERATOR="Unix Makefiles" [ -x "$(command -v make)" ] && GENERATOR="Unix Makefiles"
[ -x "$(command -v ninja)" ] && GENERATOR=Ninja [ -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"
@@ -51,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
@@ -84,7 +70,7 @@ while true; do
break break
;; ;;
*) *)
echo "Programming error" echo "Wrong argument is set"
exit 3 exit 3
;; ;;
esac esac
@@ -96,66 +82,50 @@ if [ "x${GENERATOR}" = "x" ]; then
fi fi
CMAKE_ARGS="" CMAKE_ARGS=""
[ ${#@} -gt 0 ] && 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 [ "x${SINGLE_TYPE}" != "xn" ]; then if grep -i ^"project.*fortran" "${SOURCE_DIR}/CMakeLists.txt" >/dev/null 2>&1 ; then
case "${SINGLE_TYPE}" in if [ -x "$(command -v make)" ]; then
None|Debug|Release|Profile|RelWithDebInfo|MinSizeRel) GENERATOR="Unix Makefiles"
true else
;; echo "Projects with Fortran sources need Make to build"
*) exit 5
echo "Wrong CMake build type" fi
exit 6
;;
esac
fi 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 SINGLE_TYPE
export FORCE export FORCE
CMAKE_BUILD_TYPES=(None Debug Release Profile 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
fi
GEN_DIR="${BUILD_DIR}" GEN_DIR="${BUILD_DIR}/${BUILD}"
if [ "x${SINGLE_TYPE}" == "xn" ]; then
GEN_DIR="${BUILD_DIR}/${BUILD}"
else
GEN_DIR="${BUILD_DIR}/${SINGLE_TYPE}"
fi
if [ -d "${GEN_DIR}" ]; then if [ -d "${GEN_DIR}" ]; then
if [ "x${FORCE}" == "xy" ]; then if [ "x${FORCE}" == "xy" ]; then
@@ -166,43 +136,26 @@ generate_configuration() {
fi fi
fi fi
mkdir -p "${GEN_DIR}" cmake -B"${GEN_DIR}" -H"${SOURCE_DIR}" -G "${GENERATOR}" -DCMAKE_INSTALL_PREFIX="${OUTPUT_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${CMAKE_ARGS}
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
if [ "x$SINGLE_TYPE" != "xn" ]; then BUILD_TYPES=(${TYPES//,/ })
BUILD_TYPES=("${SINGLE_TYPE}")
else
if [ "x$QTCREATOR" == "xy" ]; then
BUILD_TYPES=("${QTCREATOR_BUILD_TYPES[@]}")
elif [ "x$CMAKE" == "xy" ]; then
BUILD_TYPES=("${CMAKE_BUILD_TYPES[@]}")
else
BUILD_TYPES=("Release")
fi
fi
if [ ${#BUILD_TYPES[@]} -eq 0 ]; then for i in "${!BUILD_TYPES[@]}"; do
echo "No build type selected." case ${BUILD_TYPES[i]} in
echo "Use -c for default CMake build types" None|Debug|Release|Profile|RelWithDebInfo|MinSizeRel|qtNone|qtDebug|qtRelease|qtProfile)
echo "Use -q for build types for QtCreator" true
echo "Use -t name for build with type 'name'" ;;
exit 0 *)
fi 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 # Try to work in parallel
if [ -x "$(command -v parallel)" ]; then if [ -x "$(command -v parallel)" ]; then

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
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" -f -t Debug "$(dirname $0)/cmake.sh" -f -t qtDebug