Skip to content

Instantly share code, notes, and snippets.

@Inkering
Last active May 3, 2018 01:04
Show Gist options
  • Save Inkering/110ecac8e496c1bab2acbb0deef574f4 to your computer and use it in GitHub Desktop.
Save Inkering/110ecac8e496c1bab2acbb0deef574f4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script allows for the quick creation of project directories for quick c++ practicing
#create directory structure
if [ ! -d practice-$1 ]; then
git init practice-$1
mkdir practice-$1/src practice-$1/build practice-$1/includes
cd practice-$1
else
echo "directory already exists"
exit 1
fi
#make cmakelists.txt so that we can later run cmake
echo -e "
Cmake_minimum_required (VERSION 2.8.9)\n
Set(PROJECTNUM $1)\n
project (practice-\${PROJECTNUM})\n
set (CMAKE_CXX_STANDARD 14)\n
include_directories(include)\n
file(GLOB SOURCES \"src/*.cpp\")\n
add_executable(practice-\${PROJECTNUM} \${SOURCES})" > CMakeLists.txt
#create main so that cmake will correctly generate the compile_commands.json
echo -e '
#include <iostream>
int main()
{
return 0;
}
' > src/main.cpp
#run initial cmake so that we can get compile_commands
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES ..
#go back a directory
cd ..
#link the compile_commands.json file to project root for autocomplete
ln -s build/compile_commands.json compile_commands.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment