Taylor Bockman
2 years ago
4 changed files with 238 additions and 10 deletions
@ -0,0 +1,109 @@
|
||||
#! /usr/bin/env bash |
||||
|
||||
name=$1 |
||||
cmake_version=$2 |
||||
c_standard=$3 |
||||
|
||||
# Finds the directory of this script |
||||
if [[ "$OS_TYPE" == "linux-gnu" ]]; then |
||||
script_dir=$(cd "$( dirname "`readlink -f ${BASH_SOURCE[0]}`")" && pwd) |
||||
else |
||||
script_dir=$(cd "$( dirname "`greadlink -f ${BASH_SOURCE[0]}`")" && pwd) |
||||
fi |
||||
|
||||
if [ -z $name ] |
||||
then |
||||
echo "Name must be specified" |
||||
echo "" |
||||
echo "./cgen.sh <name> [cmake version] [C Standard]" |
||||
exit -1 |
||||
fi |
||||
|
||||
if [ -z $cmake_version ] |
||||
then |
||||
echo "No CMake version supplied...defaulting to 3.15" |
||||
cmake_version="3.15" |
||||
fi |
||||
|
||||
if [ -z $c_standard ] |
||||
then |
||||
echo "No C Standard supplied...defaulting to 11" |
||||
c_standard="11" |
||||
fi |
||||
|
||||
mkdir $name |
||||
mkdir $name/src |
||||
mkdir $name/include |
||||
|
||||
cmake_config=$name/CMakeLists.txt |
||||
|
||||
touch $cmake_config |
||||
|
||||
echo "cmake_minimum_required(VERSION $cmake_version)" >> $cmake_config |
||||
echo "project($name)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "set (CMAKE_C_STANDARD $c_standard)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "# Output to bin and lib" >> $cmake_config |
||||
echo "set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY \${CMAKE_BINARY_DIR}/lib)" >> $cmake_config |
||||
echo "set(CMAKE_LIBRARY_OUTPUT_DIRECTORY \${CMAKE_BINARY_DIR}/lib)" >> $cmake_config |
||||
echo "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \${CMAKE_BINARY_DIR}/bin)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "# The following lines enable compile_commands.json and dump it in the root of the project" >> $cmake_config |
||||
echo "# This is needed for clangd and lsp to work" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "set(CMAKE_EXPORT_COMPILE_COMMANDS ON)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "if(EXISTS \"\${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json\")" >> $cmake_config |
||||
echo " execute_process(COMMAND \${CMAKE_COMMAND} -E copy_if_different" >> $cmake_config |
||||
echo " \${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json" >> $cmake_config |
||||
echo " \${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json" >> $cmake_config |
||||
echo " )" >> $cmake_config |
||||
echo "endif()" >> $cmake_config |
||||
echo "#-------- END COMPILE_COMMANDS.JSON SECTION --------#" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "file(GLOB SOURCE \${PROJECT_SOURCE_DIR}/src/*.c)" >> $cmake_config |
||||
echo "file(GLOB INCLUDE \${PROJECT_SOURCE_DIR}/include/*.h)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "include_directories(\${PROJECT_SOURCE_DIR}/include)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "# Controls debug printing based on the compiled binary mode - check with #ifdef DEBUG_BUILD" >> $cmake_config |
||||
echo "IF(CMAKE_BUILD_TYPE MATCHES DEBUG)" >> $cmake_config |
||||
echo "message(\"-- Configuring debug build...\")" >> $cmake_config |
||||
echo "add_compile_definitions(DEBUG_BUILD)" >> $cmake_config |
||||
echo "ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)" >> $cmake_config |
||||
echo "" >> $cmake_config |
||||
echo "add_executable(\${PROJECT_NAME} \${SOURCE} \${INCLUDE})" >> $cmake_config |
||||
|
||||
|
||||
echo "Copying .clang-format..." |
||||
cp $script_dir/cgen_etc/clang_format_template $name/.clang-format |
||||
|
||||
echo "Copying .gitignore..." |
||||
cp $script_dir/cgen_etc/gitignore_template $name/.gitignore |
||||
|
||||
sample_file=$name/src/main.c |
||||
|
||||
echo "#include <stdio.h>" >> $sample_file |
||||
echo "" >> $sample_file |
||||
echo "" >> $sample_file |
||||
echo "int main(int argc, char **argv)" >> $sample_file |
||||
echo "{" >> $sample_file |
||||
echo " printf(\"Hello, world!\\n\");" >> $sample_file |
||||
echo " return 0;" >> $sample_file |
||||
echo "}" >> $sample_file |
||||
echo "" >> $sample_file |
||||
|
||||
git --version 2>&1 >/dev/null |
||||
GIT_IS_AVAILABLE=$? |
||||
|
||||
if [ $GIT_IS_AVAILABLE -eq 0 ] |
||||
then |
||||
git init $name |
||||
fi |
||||
|
||||
echo "Created project $name." |
@ -0,0 +1,16 @@
|
||||
AlignAfterOpenBracket: Align |
||||
AlignConsecutiveMacros: 'true' |
||||
AlignConsecutiveAssignments: 'true' |
||||
AlignConsecutiveDeclarations: 'true' |
||||
AlignTrailingComments: 'true' |
||||
BreakBeforeBraces: Allman |
||||
IndentCaseLabels: 'true' |
||||
IndentWidth: '4' |
||||
Language: Cpp |
||||
PointerAlignment: Right |
||||
SortIncludes: 'true' |
||||
SpaceBeforeParens: ControlStatements |
||||
SpaceBeforeRangeBasedForLoopColon: 'true' |
||||
SpaceInEmptyParentheses: 'false' |
||||
UseTab: Never |
||||
ColumnLimit: 80 |
@ -0,0 +1,97 @@
|
||||
# Prerequisites |
||||
*.d |
||||
|
||||
# Object files |
||||
*.o |
||||
*.ko |
||||
*.obj |
||||
*.elf |
||||
|
||||
# Linker output |
||||
*.ilk |
||||
*.map |
||||
*.exp |
||||
|
||||
# Precompiled Headers |
||||
*.gch |
||||
*.pch |
||||
|
||||
# Libraries |
||||
*.lib |
||||
*.a |
||||
*.la |
||||
*.lo |
||||
|
||||
# Shared objects (inc. Windows DLLs) |
||||
*.dll |
||||
*.so |
||||
*.so.* |
||||
*.dylib |
||||
|
||||
# Executables |
||||
*.exe |
||||
*.out |
||||
*.app |
||||
*.i*86 |
||||
*.x86_64 |
||||
*.hex |
||||
|
||||
# Debug files |
||||
*.dSYM/ |
||||
*.su |
||||
*.idb |
||||
*.pdb |
||||
|
||||
# Kernel Module Compile Results |
||||
*.mod* |
||||
*.cmd |
||||
.tmp_versions/ |
||||
modules.order |
||||
Module.symvers |
||||
Mkfile.old |
||||
dkms.conf |
||||
|
||||
# VSCode |
||||
|
||||
.vscode/* |
||||
!.vscode/settings.json |
||||
!.vscode/tasks.json |
||||
!.vscode/launch.json |
||||
!.vscode/extensions.json |
||||
*.code-workspace |
||||
|
||||
# Vim |
||||
|
||||
# Swap |
||||
[._]*.s[a-v][a-z] |
||||
!*.svg # comment out if you don't need vector files |
||||
[._]*.sw[a-p] |
||||
[._]s[a-rt-v][a-z] |
||||
[._]ss[a-gi-z] |
||||
[._]sw[a-p] |
||||
|
||||
# Session |
||||
Session.vim |
||||
Sessionx.vim |
||||
|
||||
# Temporary |
||||
.netrwhist |
||||
*~ |
||||
# Auto-generated tag files |
||||
tags |
||||
# Persistent undo |
||||
[._]*.un~ |
||||
|
||||
# CMake |
||||
|
||||
CMakeLists.txt.user |
||||
CMakeCache.txt |
||||
CMakeFiles |
||||
CMakeScripts |
||||
Testing |
||||
Makefile |
||||
cmake_install.cmake |
||||
install_manifest.txt |
||||
compile_commands.json |
||||
CTestTestfile.cmake |
||||
_deps |
Loading…
Reference in new issue