diff options
author | 2024-03-07 13:07:59 +0800 | |
---|---|---|
committer | 2024-03-07 13:19:06 +0800 | |
commit | 7e85ab6f9e7114ba05264005172e41fb1c47532c (patch) | |
tree | 47f530ea33faf42c63b67bc25ac387e54e20b2a6 | |
parent | 644f678387cd81a87bd0c73ea0123c825bc99e59 (diff) | |
download | calendar-7e85ab6f9e7114ba05264005172e41fb1c47532c.tar.gz calendar-7e85ab6f9e7114ba05264005172e41fb1c47532c.zip |
Change into cmake
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rwxr-xr-x | build.sh | 11 | ||||
-rw-r--r-- | src/CMakeLists.txt | 14 | ||||
-rw-r--r-- | src/makefile | 12 | ||||
-rwxr-xr-x | test.sh | 37 |
6 files changed, 26 insertions, 65 deletions
@@ -1,17 +1,17 @@ | |||
1 | * | 1 | * |
2 | !*.* | 2 | !*.* |
3 | # Unignore all makefiles named Makefile or makefile | ||
4 | !Makefile | ||
5 | !makefile | ||
6 | #Unignore all dirs | 3 | #Unignore all dirs |
7 | !*/ | 4 | !*/ |
8 | #Ignore swp | ||
9 | *.swp | 5 | *.swp |
10 | #Ignore res | ||
11 | *.txt | 6 | *.txt |
7 | !CMakeLists.txt | ||
12 | push.sh | 8 | push.sh |
13 | !test.sh | 9 | !test.sh |
14 | *.o | 10 | *.o |
15 | #Ignore dir data/vsop87 | 11 | #Ignore dir data/vsop87 |
16 | data/vsop87/* | 12 | data/vsop87/* |
17 | data/vsop87 | 13 | data/vsop87 |
14 | |||
15 | bin/* | ||
16 | lib/* | ||
17 | build/* | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c0b6c71 --- /dev/null +++ b/CMakeLists.txt | |||
@@ -0,0 +1,7 @@ | |||
1 | cmake_minimum_required(VERSION 3.0) | ||
2 | project(calendar) | ||
3 | |||
4 | add_subdirectory(src) | ||
5 | |||
6 | # 去除可执行文件的符号表 | ||
7 | # add_custom_command(TARGET calendar POST_BUILD COMMAND strip bin/calendar) | ||
diff --git a/build.sh b/build.sh deleted file mode 100755 index 5182390..0000000 --- a/build.sh +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | # Exit with nonzero exit code if anything fails | ||
3 | set -e | ||
4 | cd src | ||
5 | make | ||
6 | # if main exists in ../, remove it | ||
7 | if [ -f ../main ]; then | ||
8 | rm ../main | ||
9 | fi | ||
10 | # move main to ../ | ||
11 | cp main ../main | ||
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..c48a058 --- /dev/null +++ b/src/CMakeLists.txt | |||
@@ -0,0 +1,14 @@ | |||
1 | # 设置编译选项 | ||
2 | set(CMAKE_CXX_STANDARD 11) | ||
3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") | ||
4 | add_definitions(-w) | ||
5 | message("Project root: ${PROJECT_SOURCE_DIR}") | ||
6 | |||
7 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) | ||
8 | set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) | ||
9 | |||
10 | # 将Julian.cpp与parameters.cpp编译为一个动态库 | ||
11 | add_library(parameters SHARED Julian.cpp parameters.cpp) | ||
12 | # 将calendar.cpp与List.cpp编译为可执行文件,链接动态库 | ||
13 | add_executable(calendar calendar.cpp List.cpp) | ||
14 | target_link_libraries(calendar PRIVATE parameters) | ||
diff --git a/src/makefile b/src/makefile deleted file mode 100644 index 5eacb44..0000000 --- a/src/makefile +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | main:calendar.o Julian.o parameters.o List.o | ||
2 | g++ -g -o main calendar.o Julian.o parameters.o List.o | ||
3 | calendar.o:calendar.cpp calendar.h | ||
4 | g++ -g -c calendar.cpp | ||
5 | Julian.o:Julian.cpp calendar.h | ||
6 | g++ -g -c Julian.cpp | ||
7 | parameters.o:parameters.cpp calendar.h | ||
8 | g++ -g -c parameters.cpp | ||
9 | List.o:List.cpp calendar.h | ||
10 | g++ -g -c List.cpp | ||
11 | clean: | ||
12 | rm -f *.o main | ||
diff --git a/test.sh b/test.sh deleted file mode 100755 index 645eabe..0000000 --- a/test.sh +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | ########################################################################## | ||
4 | # File Name : test.sh | ||
5 | # Encoding : utf-8 | ||
6 | # Author : We-unite | ||
7 | # Email : weunite1848@gmail.com | ||
8 | # Created Time : 2023-10-06 | ||
9 | ########################################################################## | ||
10 | |||
11 | # 如果未出现段错误就重定向输出到res.txt,否则输出到err.txt,并在屏幕上显示出错的年份 | ||
12 | |||
13 | # 设置要测试的可执行文件 | ||
14 | executable="main" | ||
15 | |||
16 | echo "" > res.txt | ||
17 | |||
18 | start_time=$(date +%s) | ||
19 | for year in {1800..2200}; do | ||
20 | echo "==================测试年份 $year=====================" | ||
21 | |||
22 | output=$(./$executable "$year" 2>&1) | ||
23 | |||
24 | exit_code=$? | ||
25 | if [ $exit_code -eq 0 ]; then | ||
26 | echo -e "$year:\n$output" >> res.txt | ||
27 | else | ||
28 | # 执行异常,将错误信息重定向到err.txt | ||
29 | echo -e "$year:\n$output" >> err.txt | ||
30 | echo "执行异常(退出码: $exit_code)" | ||
31 | exit 1 | ||
32 | fi | ||
33 | done | ||
34 | end_time=$(date +%s) | ||
35 | |||
36 | echo "测试成功!" | ||
37 | echo "总用时:$((end_time - start_time))秒" | ||