summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-03-07 13:07:59 +0800
committerWe-unite <3205135446@qq.com>2024-03-07 13:19:06 +0800
commit7e85ab6f9e7114ba05264005172e41fb1c47532c (patch)
tree47f530ea33faf42c63b67bc25ac387e54e20b2a6
parent644f678387cd81a87bd0c73ea0123c825bc99e59 (diff)
downloadcalendar-7e85ab6f9e7114ba05264005172e41fb1c47532c.tar.gz
calendar-7e85ab6f9e7114ba05264005172e41fb1c47532c.zip
Change into cmake
-rw-r--r--.gitignore10
-rw-r--r--CMakeLists.txt7
-rwxr-xr-xbuild.sh11
-rw-r--r--src/CMakeLists.txt14
-rw-r--r--src/makefile12
-rwxr-xr-xtest.sh37
6 files changed, 26 insertions, 65 deletions
diff --git a/.gitignore b/.gitignore
index a029ac1..c78e2d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
12push.sh 8push.sh
13!test.sh 9!test.sh
14*.o 10*.o
15#Ignore dir data/vsop87 11#Ignore dir data/vsop87
16data/vsop87/* 12data/vsop87/*
17data/vsop87 13data/vsop87
14
15bin/*
16lib/*
17build/*
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..c0b6c71
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,7 @@
1cmake_minimum_required(VERSION 3.0)
2project(calendar)
3
4add_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
3set -e
4cd src
5make
6# if main exists in ../, remove it
7if [ -f ../main ]; then
8 rm ../main
9fi
10# move main to ../
11cp 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# 设置编译选项
2set(CMAKE_CXX_STANDARD 11)
3set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
4add_definitions(-w)
5message("Project root: ${PROJECT_SOURCE_DIR}")
6
7set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
8set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
9
10# 将Julian.cpp与parameters.cpp编译为一个动态库
11add_library(parameters SHARED Julian.cpp parameters.cpp)
12# 将calendar.cpp与List.cpp编译为可执行文件,链接动态库
13add_executable(calendar calendar.cpp List.cpp)
14target_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 @@
1main:calendar.o Julian.o parameters.o List.o
2 g++ -g -o main calendar.o Julian.o parameters.o List.o
3calendar.o:calendar.cpp calendar.h
4 g++ -g -c calendar.cpp
5Julian.o:Julian.cpp calendar.h
6 g++ -g -c Julian.cpp
7parameters.o:parameters.cpp calendar.h
8 g++ -g -c parameters.cpp
9List.o:List.cpp calendar.h
10 g++ -g -c List.cpp
11clean:
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# 设置要测试的可执行文件
14executable="main"
15
16echo "" > res.txt
17
18start_time=$(date +%s)
19for 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
33done
34end_time=$(date +%s)
35
36echo "测试成功!"
37echo "总用时:$((end_time - start_time))秒"