Skip to content
Snippets Groups Projects
Commit 6dc74faf authored by Fernando Herrero's avatar Fernando Herrero
Browse files

Add usage text. Check name has no whitespaces. Do not create bin and lib...

Add usage text. Check name has no whitespaces. Do not create bin and lib directories. Add CMakeLists plural variables _DIRS, _LIBRARIES, add gitlab-ci.yml file.
parent 3b07dcde
No related branches found
No related tags found
1 merge request!1Install path
...@@ -6,6 +6,18 @@ PROJECT_DESC= ...@@ -6,6 +6,18 @@ PROJECT_DESC=
NAME= NAME=
TEST=0 TEST=0
# usage="Usage:
# \tnew_project.sh -t <library/application> -n project_name -p \"project description\" [-d dependency1,dependency2,dependency3][-g]
# Parameters:
# \t-d: comma separated dependencies (optional).
# \t-g: include test structure (optional)."
usage="Usage:
\tnew_project.sh -t <library/application> -n project_name -p \"project description\" [-d dependency1,dependency2,dependency3]
Parameters:
\t-d: comma separated dependencies (optional)."
##\t-g: include test structure (optional).
while getopts “t:p:n:d:g” OPTION while getopts “t:p:n:d:g” OPTION
do do
case $OPTION in case $OPTION in
...@@ -25,7 +37,8 @@ do ...@@ -25,7 +37,8 @@ do
TEST=1 TEST=1
;; ;;
?) ?)
echo invalid argument $OPTION echo "ERROR: invalid argument: $OPTION"
echo "${usage}"
exit exit
;; ;;
esac esac
...@@ -36,46 +49,58 @@ case $TYPE in ...@@ -36,46 +49,58 @@ case $TYPE in
;; ;;
library) echo Generating a library project ... library) echo Generating a library project ...
;; ;;
*) echo Unknown project type "$TYPE" *) echo "ERROR: unknown project type: $TYPE"
exit echo "${usage}"
exit
;; ;;
esac esac
if [ "$NAME" ] if [ "$NAME" ]
then then
echo "Generating folder structure for project $NAME ..." case $NAME in
*\ * )
echo "ERROR: project name cannot have whitespaces, aborting..."
exit
;;
*)
echo "Generating folder structure for project $NAME ..."
NAME=$(echo $NAME | tr '[:upper:]' '[:lower:]')
echo "Using library name $NAME ..."
;;
esac
else else
echo "No project name provided, aborting ..." echo "ERROR: No project name provided, aborting..."
echo "${usage}"
exit exit
fi fi
if [ $NAME ] if [ ! "$PROJECT_DESC" ]
then then
NAME=$(echo $NAME | tr '[:upper:]' '[:lower:]') echo "ERROR: No project description provided, aborting..."
echo "Using library name $NAME ..." echo "${usage}"
else
echo "No library name provided, aborting ..."
exit exit
fi fi
#create the bin directory # #create the bin directory
BIN_DIR="./bin" # BIN_DIR="./bin"
if [ -e "$BIN_DIR" ] # if [ -e "$BIN_DIR" ]
then # then
echo "$BIN_DIR directory already exists, skipping ..." # echo "$BIN_DIR directory already exists, skipping ..."
else # else
echo "Creating $BIN_DIR directory" # echo "Creating $BIN_DIR directory"
mkdir $BIN_DIR # mkdir $BIN_DIR
fi # fi
# create the lib directory
LIB_DIR="./lib" # # create the lib directory
if [ -e "$LIB_DIR" ] # LIB_DIR="./lib"
then # if [ -e "$LIB_DIR" ]
echo "$LIB_DIR directory already exists, skipping ..." # then
else # echo "$LIB_DIR directory already exists, skipping ..."
echo "Creating $LIB_DIR directory" # else
mkdir $LIB_DIR # echo "Creating $LIB_DIR directory"
fi # mkdir $LIB_DIR
# fi
# create the src directory # create the src directory
SRC_DIR="./src" SRC_DIR="./src"
if [ -e "$SRC_DIR" ] if [ -e "$SRC_DIR" ]
...@@ -147,30 +172,38 @@ fi ...@@ -147,30 +172,38 @@ fi
#parse the dependencies and create the dependencies file #parse the dependencies and create the dependencies file
arr=$(echo $DEP | tr "," "\n") arr=$(echo $DEP | tr "," "\n")
NAME_WITH_DASHES=$(echo $NAME | sed 's/_/-/g')
#Set the author's email on the ReadMe.md disclaimer file #Set the author's email on the ReadMe.md disclaimer file
sed 's/author_email/labrobotica@iri.upc.edu/g' <ReadMe_template.md >tmp1.md sed 's/author_email/labrobotica@iri.upc.edu/g' <ReadMe_template.md >tmp1.md
#set the author's name on the ReadMe.txt disclaimer file #set the author's name on the ReadMe.txt disclaimer file
sed 's/author_name/IRI labrobotics/g' <tmp1.md >tmp2.md sed 's/author_name/IRI labrobotica/g' <tmp1.md >tmp2.md
#Set the project name on the ReadMe.txt disclaimer file #Set the project name on the ReadMe.txt disclaimer file
sed 's/project_description/'"$PROJECT_DESC"'/g' <tmp2.md >tmp3.md sed 's/project_description/'"$PROJECT_DESC"'/g' <tmp2.md >tmp3.md
sed 's/project_name/'"$NAME"'/g' <tmp3.md >./ReadMe.md sed 's/project_name/'"$NAME"'/g' <tmp3.md >tmp4.md
sed 's/project-name/'"$NAME_WITH_DASHES"'/g' <tmp4.md >./ReadMe.md
for x in $arr
do
DEP_LINE=" - $x"
sed -i '/^This package also requires of the following dependencies:/a'"${DEP_LINE}" ./ReadMe.md
done
rm tmp1.md rm tmp1.md
rm tmp2.md rm tmp2.md
rm tmp3.md rm tmp3.md
rm tmp4.md
rm ReadMe_template.md rm ReadMe_template.md
#Set the project name on the CMakeLists.txt script file
#NEW_NAME=$(echo $NAME | sed 's/_/-/g')
NEW_NAME=$NAME
NEW_NAME_WITH_DASHES=$(echo $NAME | sed 's/_/-/g')
if [ $TEST = 1 ] if [ $TEST = 1 ]
then then
sed 's/project_name/'$NEW_NAME'/g' <CMakeLists_test_template.txt >./CMakeLists.txt sed 's/project_name/'$NAME'/g' <CMakeLists_test_template.txt >./CMakeLists.txt
else else
sed 's/project_name/'$NEW_NAME'/g' <CMakeLists_template.txt >./temp1.txt sed 's/project_name/'$NAME'/g' <CMakeLists_template.txt >temp1.txt
sed 's/project-name/'$NEW_NAME_WITH_DASHES'/g' <temp1.txt >./CMakeLists.txt sed 's/project-name/'$NAME_WITH_DASHES'/g' <temp1.txt >./CMakeLists.txt
rm temp1.txt
fi fi
rm temp1.txt
rm CMakeLists_test_template.txt rm CMakeLists_test_template.txt
rm CMakeLists_template.txt rm CMakeLists_template.txt
...@@ -188,69 +221,104 @@ then ...@@ -188,69 +221,104 @@ then
do do
echo "FIND_PACKAGE($x REQUIRED)" >> CMakeLists.tmp echo "FIND_PACKAGE($x REQUIRED)" >> CMakeLists.tmp
done done
echo "" >> CMakeLists.tmp
echo "# add the necessary include directories" >> CMakeLists.tmp echo "# add the necessary include directories" >> CMakeLists.tmp
echo "INCLUDE_DIRECTORIES(../include)" >> CMakeLists.tmp echo "INCLUDE_DIRECTORIES(../include)" >> CMakeLists.tmp
for x in $arr for x in $arr
do do
echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIR"'}'")" >> CMakeLists.tmp echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIRS"'}'")" >> CMakeLists.tmp
done done
echo "" >> CMakeLists.tmp
echo "# application source files" >> CMakeLists.tmp echo "# application source files" >> CMakeLists.tmp
echo "SET(sources ${PROJECT_NAME_VAR}.cpp)" >> CMakeLists.tmp echo "SET(sources ${PROJECT_NAME_VAR}.cpp)" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "# application header files" >> CMakeLists.tmp echo "# application header files" >> CMakeLists.tmp
echo "SET(headers ../include/${PROJECT_NAME_VAR}.h)" >> CMakeLists.tmp echo "SET(headers ../include/${PROJECT_NAME_VAR}.h)" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "# create the executable file" >> CMakeLists.tmp echo "# create the executable file" >> CMakeLists.tmp
echo "ADD_EXECUTABLE(${PROJECT_NAME_VAR} "'${'"sources"'}'")" >> CMakeLists.tmp echo "ADD_EXECUTABLE(${PROJECT_NAME_VAR} "'${'"sources"'}'")" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "# link necessary libraries" >> CMakeLists.tmp echo "# link necessary libraries" >> CMakeLists.tmp
echo "#TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} \${my_example_library_LIBRARIES})">>CMakeLists.tmp echo "#TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} \${my_example_library_LIBRARIES})">>CMakeLists.tmp
for x in $arr for x in $arr
do do
echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARIES"'}'")" >> CMakeLists.tmp
done done
echo "" >> CMakeLists.tmp
echo "#ADD_DEPENDENCIES(${PROJECT_NAME_VAR} my_example_library_target)">>CMakeLists.tmp echo "#ADD_DEPENDENCIES(${PROJECT_NAME_VAR} my_example_library_target)">>CMakeLists.tmp
mv CMakeLists.tmp ./src/CMakeLists.txt mv CMakeLists.tmp ./src/CMakeLists.txt
mv application_src_template.cpp ./src/$NAME.cpp mv application_src_template.cpp ./src/$NAME.cpp
else else
echo "# driver source files" >> CMakeLists.tmp echo "# driver source files" >> CMakeLists.tmp
echo "SET(sources ${PROJECT_NAME_VAR}.cpp)" >> CMakeLists.tmp echo "SET(sources ${PROJECT_NAME_VAR}.cpp)" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "# application header files" >> CMakeLists.tmp echo "# application header files" >> CMakeLists.tmp
echo "SET(headers ../include/${PROJECT_NAME_VAR}.h)" >> CMakeLists.tmp echo "SET(headers ../include/${PROJECT_NAME_VAR}.h)" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "# locate the necessary dependencies" >> CMakeLists.tmp echo "# locate the necessary dependencies" >> CMakeLists.tmp
for x in $arr for x in $arr
do do
echo "FIND_PACKAGE($x REQUIRED)" >> CMakeLists.tmp echo "FIND_PACKAGE($x REQUIRED)" >> CMakeLists.tmp
done done
echo "" >> CMakeLists.tmp
echo "# add the necessary include directories" >> CMakeLists.tmp echo "# add the necessary include directories" >> CMakeLists.tmp
echo "INCLUDE_DIRECTORIES(../include)" >> CMakeLists.tmp echo "INCLUDE_DIRECTORIES(../include)" >> CMakeLists.tmp
for x in $arr for x in $arr
do do
echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIR"'}'")" >> CMakeLists.tmp echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIRS"'}'")" >> CMakeLists.tmp
done done
echo "" >> CMakeLists.tmp
echo "# create the shared library" >> CMakeLists.tmp echo "# create the shared library" >> CMakeLists.tmp
echo "ADD_LIBRARY(${PROJECT_NAME_VAR} SHARED "'${'"sources"'}'")" >> CMakeLists.tmp echo "ADD_LIBRARY(${PROJECT_NAME_VAR} SHARED "'${'"sources"'}'")" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "# link necessary libraries" >> CMakeLists.tmp echo "# link necessary libraries" >> CMakeLists.tmp
echo "#TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} \${my_example_library_LIBRARIES})">>CMakeLists.tmp echo "#TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} \${my_example_library_LIBRARIES})">>CMakeLists.tmp
for x in $arr for x in $arr
do do
echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARIES"'}'")" >> CMakeLists.tmp
done done
echo "" >> CMakeLists.tmp
echo "#ADD_DEPENDENCIES(${PROJECT_NAME_VAR} my_example_library_target)">>CMakeLists.tmp echo "#ADD_DEPENDENCIES(${PROJECT_NAME_VAR} my_example_library_target)">>CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "INSTALL(TARGETS $PROJECT_NAME_VAR" >> CMakeLists.tmp echo "INSTALL(TARGETS $PROJECT_NAME_VAR" >> CMakeLists.tmp
echo " RUNTIME DESTINATION bin" >> CMakeLists.tmp echo " RUNTIME DESTINATION bin" >> CMakeLists.tmp
echo " LIBRARY DESTINATION lib/iri/${PROJECT_NAME_VAR}" >> CMakeLists.tmp echo " LIBRARY DESTINATION lib/iri/${PROJECT_NAME_VAR}" >> CMakeLists.tmp
echo " ARCHIVE DESTINATION lib/iri/${PROJECT_NAME_VAR})" >> CMakeLists.tmp echo " ARCHIVE DESTINATION lib/iri/${PROJECT_NAME_VAR})" >> CMakeLists.tmp
echo "INSTALL(FILES "'${'"headers"'}' "DESTINATION include/iri/${PROJECT_NAME_VAR})" >> CMakeLists.tmp echo "INSTALL(FILES "'${'"headers"'}' "DESTINATION include/iri/${PROJECT_NAME_VAR})" >> CMakeLists.tmp
echo "INSTALL(FILES ../Find$PROJECT_NAME_VAR.cmake DESTINATION "'${'"CMAKE_ROOT"'}'"/Modules/)" >> CMakeLists.tmp echo "INSTALL(FILES ../Find$PROJECT_NAME_VAR.cmake DESTINATION "'${'"CMAKE_ROOT"'}'"/Modules/)" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "#Install script files if needed" >> CMakeLists.tmp
echo "#INSTALL(FILES ../scripts/<script_name> " >> CMakeLists.tmp
echo "# DESTINATION share/iri" >> CMakeLists.tmp
echo "# PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)" >> CMakeLists.tmp
echo "" >> CMakeLists.tmp
echo "ADD_SUBDIRECTORY(examples)" >> CMakeLists.tmp echo "ADD_SUBDIRECTORY(examples)" >> CMakeLists.tmp
mv CMakeLists.tmp ./src/CMakeLists.txt mv CMakeLists.tmp ./src/CMakeLists.txt
echo "# create an example application" >> CMakeLists.tmp echo "# create an example application" >> CMakeLists.tmp
echo "ADD_EXECUTABLE(${PROJECT_NAME_VAR}_test ${PROJECT_NAME_VAR}_test.cpp)" >> CMakeLists.tmp echo "ADD_EXECUTABLE(${PROJECT_NAME_VAR}_test ${PROJECT_NAME_VAR}_test.cpp)" >> CMakeLists.tmp
echo "# link necessary libraries" >> CMakeLists.tmp echo "# link necessary libraries" >> CMakeLists.tmp
echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test $PROJECT_NAME_VAR)" >> CMakeLists.tmp echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test $PROJECT_NAME_VAR)" >> CMakeLists.tmp
for x in $arr # for x in $arr
do # do
echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp # echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp
done # done
mv CMakeLists.tmp ./src/examples/CMakeLists.txt mv CMakeLists.tmp ./src/examples/CMakeLists.txt
sed 's/library_name/'$NAME'/g' <Findlib_template.cmake >./Find$NAME.cmake sed 's/library_name/'$NAME'/g' <Findlib_template.cmake >./Find$NAME.cmake
...@@ -271,12 +339,12 @@ else ...@@ -271,12 +339,12 @@ else
rm application_src_template.cpp rm application_src_template.cpp
fi fi
sed 's/library-name/'$NEW_NAME_WITH_DASHES'/g' <.gitlab-ci_template.yml >./.gitlab-ci.yml sed 's/library-name/'$NAME_WITH_DASHES'/g' <.gitlab-ci_template.yml >./.gitlab-ci.yml
if [ $TEST = 1 ] if [ $TEST = 1 ]
then then
Library_name=$(echo $NAME | sed 's/\([a-zA-Z]\)\([a-zA-Z0-9]*\)/\u\1\2/g') Library_name=$(echo $NAME | sed 's/\([a-zA-Z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')
sed 's/library_name/'$NEW_NAME'/g' <./test/CMakeLists_template.txt >./test/tmp.txt sed 's/library_name/'$NAME'/g' <./test/CMakeLists_template.txt >./test/tmp.txt
sed 's/Library_name/'$Library_name'/g' <./test/tmp.txt >./test/CMakeLists.txt sed 's/Library_name/'$Library_name'/g' <./test/tmp.txt >./test/CMakeLists.txt
rm ./test/CMakeLists_template.txt rm ./test/CMakeLists_template.txt
rm ./test/tmp.txt rm ./test/tmp.txt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment