Reputation: 31
I know Qt Creator support to build single file from Menu "Build" -> “Build
File”,or right click one source file in project tree to build single file,
but when I load a Cmake Project, Menu “Build File” and “right click” are both
disappeared.
Does it mean build single file functionality is only available for qmake?
Does cmake project support build single file, if so, how to do it? if not
is there any workaround?
Thanks, Le
Upvotes: 2
Views: 912
Reputation: 11
QT currently doesn't support this feature. However you can add the following hack that works quite well. (This hack will replace the clean project command with build command. but you can easily restore it when needed)
sudo apt-get install sed
Add the following bash script somewhere on your computer under the name "CompileSingle.sh"
CppPath=$1
BuildPath=$2
Target=$(sed -E 's/.(/|^)([^/].)\w+/\2o/g' <<< $CppPath)
MakePath=${BuildPath}/$(sed -E 's/./Src/(.)/[^/]*$/\1/g' <<< $CppPath)>
pushd ${MakePath} > /dev/null
make -B ${Target}
if [ $? -eq 0 ]
then
echo "^^^^^^^^^^^^^^ Build Succesfully ^^^^^^^^^^^^^^^"
else
echo "!!!!!!!!!!!! Build Failed !!!!!!!!!!!!!!!!"
fi
popd > /dev/null
Enable running the script:
chmod +x CompileSingle.sh
Go to qt creator and load your project
Set the following values:
Command: bash
Arguments: CompileSingle.sh "%{CurrentDocument:FilePath}" "%{CurrentProject:BuildPath}"
Working Directory: [Path to where you placed CompileSingle.sh]
Go to Tools->Option->Environment->Keyboard
You should now be able to select a file and press the key you mapped the clean function to end it will compile it.
Upvotes: 1