From 7e85ab6f9e7114ba05264005172e41fb1c47532c Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Thu, 7 Mar 2024 13:07:59 +0800 Subject: Change into cmake --- .gitignore | 10 +++++----- CMakeLists.txt | 7 +++++++ build.sh | 11 ----------- src/CMakeLists.txt | 14 ++++++++++++++ src/makefile | 12 ------------ test.sh | 37 ------------------------------------- 6 files changed, 26 insertions(+), 65 deletions(-) create mode 100644 CMakeLists.txt delete mode 100755 build.sh create mode 100644 src/CMakeLists.txt delete mode 100644 src/makefile delete mode 100755 test.sh diff --git a/.gitignore b/.gitignore index a029ac1..c78e2d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,17 @@ * !*.* -# Unignore all makefiles named Makefile or makefile -!Makefile -!makefile #Unignore all dirs !*/ -#Ignore swp *.swp -#Ignore res *.txt +!CMakeLists.txt push.sh !test.sh *.o #Ignore dir data/vsop87 data/vsop87/* data/vsop87 + +bin/* +lib/* +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 @@ +cmake_minimum_required(VERSION 3.0) +project(calendar) + +add_subdirectory(src) + +# 去除可执行文件的符号表 +# 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 @@ -#!/bin/bash -# Exit with nonzero exit code if anything fails -set -e -cd src -make -# if main exists in ../, remove it -if [ -f ../main ]; then - rm ../main -fi -# move main to ../ -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 @@ +# 设置编译选项 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") +add_definitions(-w) +message("Project root: ${PROJECT_SOURCE_DIR}") + +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) + +# 将Julian.cpp与parameters.cpp编译为一个动态库 +add_library(parameters SHARED Julian.cpp parameters.cpp) +# 将calendar.cpp与List.cpp编译为可执行文件,链接动态库 +add_executable(calendar calendar.cpp List.cpp) +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 @@ -main:calendar.o Julian.o parameters.o List.o - g++ -g -o main calendar.o Julian.o parameters.o List.o -calendar.o:calendar.cpp calendar.h - g++ -g -c calendar.cpp -Julian.o:Julian.cpp calendar.h - g++ -g -c Julian.cpp -parameters.o:parameters.cpp calendar.h - g++ -g -c parameters.cpp -List.o:List.cpp calendar.h - g++ -g -c List.cpp -clean: - 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 @@ -#!/bin/bash - -########################################################################## -# File Name : test.sh -# Encoding : utf-8 -# Author : We-unite -# Email : weunite1848@gmail.com -# Created Time : 2023-10-06 -########################################################################## - -# 如果未出现段错误就重定向输出到res.txt,否则输出到err.txt,并在屏幕上显示出错的年份 - -# 设置要测试的可执行文件 -executable="main" - -echo "" > res.txt - -start_time=$(date +%s) -for year in {1800..2200}; do - echo "==================测试年份 $year=====================" - - output=$(./$executable "$year" 2>&1) - - exit_code=$? - if [ $exit_code -eq 0 ]; then - echo -e "$year:\n$output" >> res.txt - else - # 执行异常,将错误信息重定向到err.txt - echo -e "$year:\n$output" >> err.txt - echo "执行异常(退出码: $exit_code)" - exit 1 - fi -done -end_time=$(date +%s) - -echo "测试成功!" -echo "总用时:$((end_time - start_time))秒" -- cgit v1.2.3-70-g09d2