-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateProject
executable file
·106 lines (81 loc) · 1.48 KB
/
CreateProject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
ScriptName="CreateProject"
ProjectName=$1
Usage="Usage: ${ScriptName} ProjectName"
if [ $# -eq 0 ]; then
echo "Project Name not specified."
echo ${Usage}
exit 1
fi
if [ $# -gt 1 ]; then
echo "Too many arguments."
echo ${Usage}
exit 1
fi
mkdir ${ProjectName}
retval=$?
if [ $retval -eq 1 ]; then
exit 1
fi
cd ${ProjectName}
printf "cmake_minimum_required(VERSION 3.0)
project(${ProjectName})
set(SRC_DIR code/src)
set(HDR_DIR code/include)
set(
DIRS
\${SRC_DIR}
\${HDR_DIR}
)
include_directories(\${DIRS})
set(
SRCS
\${SRC_DIR}/test.cpp
)
set(
HDRS
\${HDR_DIR}/test.hpp
)
set(
SOURCE_LIST
\${SRCS}
\${HDRS}
)
add_library(${ProjectName}-static STATIC \${SOURCE_LIST})
add_executable(${ProjectName} \${SRC_DIR}/main.cpp)
target_link_libraries(${ProjectName}
PRIVATE
${ProjectName}-static
)
" >> CMakeLists.txt
mkdir code
cd code
mkdir include src
cd include
printf "#pragma once
void HelloWorld();
" >> test.hpp
cd ../src
printf "#include \"../include/test.hpp\"
#include <iostream>
void HelloWorld() {
std::cout << \"Hello world!\" << std::endl;
}
" >> test.cpp
printf "#include \"../include/test.hpp\"
int main() {
HelloWorld();
return 0;
}" >> main.cpp
cd ../..
mkdir build
cd build
mkdir release debug
cd debug
cmake ../.. -DCMAKE_BUILD_TYPE=Debug
make -j4
./${ProjectName}
cd ../release
cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
make -j4
./${ProjectName}