Skip to content

Instantly share code, notes, and snippets.

@Henningstone
Created December 16, 2016 22:09
Show Gist options
  • Save Henningstone/63500e85a3452dc4daea1864866deea2 to your computer and use it in GitHub Desktop.
Save Henningstone/63500e85a3452dc4daea1864866deea2 to your computer and use it in GitHub Desktop.
A bashscript which generates the CMakeLists.txt that CLion requires for indexing your files [made for teeworlds]
#!/bin/bash
#
# (c) 2016 Henritees
# https://github.com/Henningstone
#
FORCE=0
BASEDIR="."
CML="CMakeLists.txt"
OLDDIR=$(pwd)
# include directories to be searched for
include_directories=(
"other/sdl2/include"
"other/sdl/include"
"other/freetype/include"
"other/glew/include"
"other/curl/include"
"other/luajit/include"
"other/mysql/include"
"other/opus/include"
"src/engine/external"
"src"
)
# helper functions
function newline(){
printf "\n" >> $CML
}
function append {
echo $@ >> $CML
}
function appendf {
printf "$@\n" >> $CML
}
# parse arguments
for arg in "$@"; do
if [ $arg == "-f" ] || [ $arg == "--force" ]; then
FORCE=1
else
BASEDIR=$arg
fi
done
# check if we'd overwrite something that we shouldn't
echo ––––––––––––––––––––––––––––––––––––––––––––––––––
if [ ! $BASEDIR == "." ]; then
echo Changing to directory $BASEDIR
cd $BASEDIR
fi
if [[ $FORCE == 0 ]]; then
if [ -e $CML ]; then
echo "$BASEDIR/$CML already exists. Use --force"
exit
fi
fi
# Start to generate the file
if [ -e $CML ]; then
rm $CML
fi
append "# TODO: set project name"
append "# TODO: set executable name"
newline
# Check if we have success writing to that file
if [ -w $CML ]; then
echo "Generating $CML"
else
echo "Failed to write to $CML"
exit
fi
append "cmake_minimum_required(VERSION 3.4)"
append "project(XXX_PROJECT_NAME_HERE)"
newline
append "set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -std=c++11")"
append "add_definitions("-DCONF_FAMILY_UNIX")"
append "add_definitions("-DCONF_DEBUG")"
newline
append "include_directories("
for line in ${include_directories[@]}; do # Add all existsing include directories
if [ -d $line ]; then
appendf " $line"
echo "Adding include directory '$line'"
fi
done
append ")"
newline
append "set(SOURCE_FILES"
filesListed=0
for f in $(find src -name '*.c*' -or -name '*.h*'); do # Loop through everything
#echo $f
appendf " $f"
let "filesListed = $filesListed+1"
done
append ")"
newline
append "add_executable(XXX_EXECUTABLE_NAME \${SOURCE_FILES})"
echo Added $filesListed files to the SOURCE_FILES
if [ ! $(pwd) == $OLDDIR ]; then
echo Changing directory back to $OLDDIR
cd $OLDDIR
fi
echo ––––––––––––––––––––––––––––––––––––––––––––––––––
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment