From 23d9ce59faff9972d4b9a7463e33e7c437dd65cb Mon Sep 17 00:00:00 2001 From: chenlongzan <15312731439@163.com> Date: Wed, 23 Oct 2024 10:53:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=B7=A5=E5=85=B7=E4=B8=BAcmake=202.=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5vcpkg=E4=BD=9C=E4=B8=BA=E5=8C=85=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=B7=A5=E5=85=B7=EF=BC=8C=E5=AE=89=E8=A3=85=E4=BE=9D?= =?UTF-8?q?=E8=B5=96sundials=203.=20=E5=BC=95=E5=85=A5GTest=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E6=B5=8B=E8=AF=95=E6=A1=86=E6=9E=B6=EF=BC=8C=E7=BB=99?= =?UTF-8?q?=E5=87=BA=E7=AE=80=E5=8D=95=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 11 +++ CMakeLists.txt | 31 +++++++ Makefile | 157 ---------------------------------- Script/installSundials.sh | 51 ----------- configure | 55 ------------ src/CMakeLists.txt | 25 ++++++ src/classes/River.hpp | 2 +- test/CMakeLists.txt | 20 +++++ test/TestCase.cpp | 23 +++++ test/TestMain.cpp | 7 ++ vcpkg.json | 17 ++++ "\350\257\264\346\230\216.md" | 4 + 12 files changed, 139 insertions(+), 264 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile delete mode 100755 Script/installSundials.sh delete mode 100755 configure create mode 100644 src/CMakeLists.txt create mode 100644 test/CMakeLists.txt create mode 100644 test/TestCase.cpp create mode 100644 test/TestMain.cpp create mode 100644 vcpkg.json create mode 100644 "\350\257\264\346\230\216.md" diff --git a/.gitignore b/.gitignore index 298b31e..748e9e7 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,14 @@ forcing rAnalysis/test.R *.*.swp *.DS_Store +/vcpkg/ +/Testing/ +/dist/ +/build/ + +/.idea/.gitignore +/.idea/deployment.xml +/.idea/material_theme_project_new.xml +/.idea/misc.xml +/.idea/modules.xml +/.idea/vcs.xml diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3f78305 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.28) +set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") + +project(SHUD) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_EXE_LINKER_FLAGS -static) +option(BUILD_SHARED_LIBS "" OFF) +if (WIN32) +# set(CMAKE_C_COMPILER gcc) +# set(CMAKE_CXX_COMPILER g++) +# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "" FORCE) +# add_compile_options("$<$:/utf-8>") # msvc 编码问题 +else () + set(VCPKG_TARGET_TRIPLET "x64-linux" CACHE STRING "" FORCE) +endif () + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) + +find_package (OpenMP) +find_package(SUNDIALS CONFIG REQUIRED) + +add_subdirectory(src) +enable_testing() +add_subdirectory(test) + + + + diff --git a/Makefile b/Makefile deleted file mode 100644 index 1e60633..0000000 --- a/Makefile +++ /dev/null @@ -1,157 +0,0 @@ -# ----------------------------------------------------------------- -# Version: 1.0 -# Date: Nov 2019 -# Makefile for SHUD v 1.0 -# ----------------------------------------------------------------- -# Programmer: Lele Shu (lele.shu@gmail.com) -# SHUD model is a heritage of Penn State Integrated Hydrologic Model (PIHM). -# ----------------------------------------------------------------- -# Prerequisite: -# 1 install sundials 5.0+ via https://computation.llnl.gov/projects/sundials/sundials-software. -# 2 If parallel-computing is prefered, please install OpenMP. -# For mac: -# 
 brew install llvm clang -# brew install libomp -# compile flags for OpenMP: -# -Xpreprocessor -fopenmp -lomp -# Library/Include paths: -# -L/usr/local/opt/libomp/lib -# -I/usr/local/opt/libomp/include -# -# ----------------------------------------------------------------- -# Configure this File: -# 1 Path of SUNDIALS_DIR. [CRITICAL] -# 2 Path of OpenMP if parallel is preffered. -# 3 Path of SRC_DIR, default is "SRC_DIR = ." -# 4 Path of BUILT_DIR, default is "BUILT_DIR = ." -# ----------------------------------------------------------------- -SUNDIALS_DIR = $(HOME)/sundials -# SUNDIALS_DIR = /usr/local/sundials - - -SHELL = /bin/sh -BUILDDIR = . -SRC_DIR = src - -LIB_SYS = /usr/local/lib/ -INC_OMP = /usr/local/opt/libomp/include -LIB_OMP = /usr/local/opt/libomp/lib -LIB_SUN = ${SUNDIALS_DIR}/lib - -INC_MPI = /usr/local/opt/open-mpi - -TARGET_EXEC = ${BUILDDIR}/shud -TARGET_OMP = ${BUILDDIR}/shud_omp -TARGET_DEBUG = ${BUILDDIR}/shud_debug - -MAIN_shud = ${SRC_DIR}/main.cpp -MAIN_OMP = ${SRC_DIR}/main.cpp -MAIN_DEBUG = ${SRC_DIR}/main.cpp - -# If compile on Cluster -# CC = g++ -# MPICC = mpic++ -# LK_OMP = -fopenmp -lsundials_nvecopenmp -# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${SUNDIALS_DIR}/lib - -CC = /usr/bin/g++ -MPICC = /usr/local/bin/mpic++ -CFLAGS = -O3 -g -std=c++14 -#STCFLAG = -static - -SRC = ${SRC_DIR}/classes/*.cpp \ - ${SRC_DIR}/ModelData/*.cpp \ - ${SRC_DIR}/Model/*.cpp \ - ${SRC_DIR}/Equations/*.cpp - -SRC_H = ${SRC_DIR}/classes/*.hpp \ - ${SRC_DIR}/ModelData/*.hpp \ - ${SRC_DIR}/Model/*.hpp \ - ${SRC_DIR}/Equations/*.hpp - - -INCLUDES = -I ${SUNDIALS_DIR}/include \ - -I ${INC_OMP} \ - -I ${SRC_DIR}/Model \ - -I ${SRC_DIR}/ModelData \ - -I ${SRC_DIR}/classes \ - -I ${SRC_DIR}/Equations - - -LIBRARIES = -L ${LIB_OMP} \ - -L ${LIB_SUN} \ - -L ${LIB_SYS} - -RPATH = '-Wl,-rpath,${LIB_SUN}' - -LK_FLAGS = -lm -lsundials_cvode -lsundials_nvecserial -LK_OMP = -Xpreprocessor -fopenmp -lomp -lsundials_nvecopenmp -LK_DYLN = "LD_LIBRARY_PATH=${LIB_SUN}" - -all: - make clean - make shud - @echo -check: - ls ${SUNDIALS_DIR} - ls ${SUNDIALS_DIR}/lib - ./shud - @echo -help: - @(echo) - @echo "Usage:" - @(echo ' make all - make both shud and shud_omp') - @(echo ' make cvode - install SUNDIALS/CVODE to ~/sundials') - @(echo ' make shud - make shud executable') - @(echo ' make shud_omp - make shud_omp with OpenMP support') - @(echo) - @(echo ' make clean - remove all executable files') - @(echo) -cvode CVODE: - @echo '...Install SUNDIALS/CVODE for your ...' - chmod +x configure - ./configure - @echo - -shud SHUD: ${MAIN_shud} $(SRC) $(SRC_H) - @echo '...Compiling shud ...' - @echo $(CC) $(CFLAGS) ${STCFLAG} ${INCLUDES} ${LIBRARIES} ${RPATH} -o ${TARGET_EXEC} ${MAIN_shud} $(SRC) $(LK_FLAGS) - @echo - @echo - $(CC) $(CFLAGS) ${INCLUDES} ${STCFLAG} ${LIBRARIES} ${RPATH} -o ${TARGET_EXEC} ${MAIN_shud} $(SRC) $(LK_FLAGS) - @echo - @echo - @echo " ${TARGET_EXEC} is compiled successfully!" - @echo - -shud_omp: ${MAIN_OMP} $(SRC) $(SRC_H) - @echo '...Compiling shud_OpenMP ...' - @echo $(CC) $(CFLAGS) ${STCFLAG} ${RPATH} -D_OPENMP_ON ${INCLUDES} ${LIBRARIES} -o ${TARGET_OMP} ${MAIN_OMP} $(SRC) $(LK_FLAGS) $(LK_OMP) - @echo - @echo - $(CC) $(CFLAGS) ${STCFLAG} ${RPATH} -D_OPENMP_ON ${INCLUDES} ${LIBRARIES} -o ${TARGET_OMP} ${MAIN_OMP} $(SRC) $(LK_FLAGS) $(LK_OMP) - @echo - @echo " ${TARGET_OMP} is compiled successfully!" - @echo - @echo - -clean: - @echo "Cleaning ... " - @echo - @echo " rm -f *.o" - @rm -f *.o - - @echo " rm -f ${TARGET_EXEC}" - @rm -f ${TARGET_EXEC} - - @echo " rm -f ${TARGET_OMP}" - @rm -f ${TARGET_OMP} - - @echo - @echo "Done." - @echo - - - - - diff --git a/Script/installSundials.sh b/Script/installSundials.sh deleted file mode 100755 index c2a25ed..0000000 --- a/Script/installSundials.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -path="~/sundials" -installPath="InstallSundials" -echo "Trying to download and install SUNDIALS/CVODE solver for you." -echo "" -read -p "Where to install?(Default: $path) :" path -path=${path:-~/sundials} -echo $path - -echo "Installing SUNDIALS to $path" -echo "Installing examples to $path/example" -echo "" - -rm -rf $installPath -rm -rf sundials-master - -echo "download from github: \n wget https://codeload.github.com/LLNL/sundials/zip/master" -wget -c https://codeload.github.com/LLNL/sundials/zip/master -O sundials-master.zip - -echo "unzip sundials-master.zip" -unzip sundials-master.zip - -mkdir $installPath -echo "cd $installPath" -cd $installPath -rm -rf builddir - -echo "makedir builddir" -mkdir builddir -echo "cd builddir" -cd builddir/ - -#ccmake ../../sundials/ -echo "start configure...." -cmake -DCMAKE_INSTALL_PREFIX=$path \ - -DEXAMPLES_INSTALL_PATH="$path/example" \ - -DBUILD_CVODE=ON \ - -DBUILD_CVODES=OFF \ - -DBUILD_ARKODE=OFF \ - -DBUILD_CVODES=OFF \ - -DBUILD_IDA=OFF \ - -DBUILD_IDAS=OFF \ - -DBUILD_KINSOL=OFF \ - -DOPENMP_ENABLE=OFF \ - ../../sundials-master - -echo "make" -make - -echo "make install" -make install diff --git a/configure b/configure deleted file mode 100755 index 40b1b93..0000000 --- a/configure +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -path="~/sundials" -installPath="InstallSundials" -echo "Trying to download and install SUNDIALS/CVODE solver for you." -echo "" -#read -p "Where to install?(Default: $path) :" path -#path=${path:-~/sundials} -echo $path - -echo "Installing SUNDIALS to $path" -echo "Installing examples to $path/example" -echo "" - -rm -rf $installPath -#rm -rf sundials-master - -echo wget -c https://github.com/LLNL/sundials/releases/download/v6.0.0/cvode-6.0.0.tar.gz -O cvode.tar.gz -#wget -c https://github.com/LLNL/sundials/releases/download/v6.0.0/cvode-6.0.0.tar.gz -O cvode.tar.gz - -echo tar xvf cvode.tar.gz -tar xvf cvode.tar.gz - - -mkdir $installPath - -echo "cd $installPath" -cd $installPath - -rm -rf builddir - -echo "makedir builddir" -mkdir builddir - -echo "cd builddir" -cd builddir/ - -#ccmake ../../sundials/ -echo "start configure...." -cmake -DCMAKE_INSTALL_PREFIX=$path \ - -DEXAMPLES_INSTALL_PATH="$path/example" \ - -DBUILD_CVODE=ON \ - -DBUILD_CVODES=OFF \ - -DBUILD_ARKODE=OFF \ - -DBUILD_CVODES=OFF \ - -DBUILD_IDA=OFF \ - -DBUILD_IDAS=OFF \ - -DBUILD_KINSOL=OFF \ - -DOPENMP_ENABLE=ON \ - ../../cvode-6.0.0 - -echo "make" -make - -echo "make install" -make install diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..a168db2 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.28) + +aux_source_directory(./classes MAIN_CLASSES) +aux_source_directory(./Equations MAIN_EQUATIONS) +aux_source_directory(./Model MAIN_MODEL) +aux_source_directory(./ModelData MAIN_MODEL_DATA) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + . + classes + Equations + Model + ModelData +) + + +add_library(${PROJECT_NAME}_lib STATIC ${MAIN_CLASSES} ${MAIN_EQUATIONS} ${MAIN_MODEL} ${MAIN_MODEL_DATA}) +target_link_libraries(${PROJECT_NAME}_lib SUNDIALS::cvode_static OpenMP::OpenMP_CXX) + +#target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) + + +add_executable(${PROJECT_NAME} main.cpp ) +target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_lib) \ No newline at end of file diff --git a/src/classes/River.hpp b/src/classes/River.hpp index 06bdd7f..1d93bf8 100644 --- a/src/classes/River.hpp +++ b/src/classes/River.hpp @@ -6,7 +6,7 @@ #ifndef River_hpp #define River_hpp -#include +#include #include "Macros.hpp" #include "Node.hpp" #include "functions.hpp" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..a697a47 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.28) +project(SHUDTest) +add_definitions(-DTestDataPath="${CMAKE_SOURCE_DIR}/") + +FIND_PACKAGE(OpenMP REQUIRED) +find_package(GTest) + + +aux_source_directory(. SRC_LIST) + +add_executable(${PROJECT_NAME} + ${SRC_LIST} +) +target_link_libraries(${PROJECT_NAME} + GTest::gtest + SUNDIALS::cvode_static + SHUD_lib +) + +add_test(${PROJECT_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} -maxwarnings 10000) diff --git a/test/TestCase.cpp b/test/TestCase.cpp new file mode 100644 index 0000000..21e041e --- /dev/null +++ b/test/TestCase.cpp @@ -0,0 +1,23 @@ +// +// Created by clz on 2024/10/23. +// + +#include "gtest/gtest.h" + +class TestCase : public ::testing::Test { + +protected: + void SetUp() override { + filePath = TestDataPath; + } + + void TearDown() override { + } +public: + std::string filePath ; +}; + +TEST_F(TestCase, CCW) { + std::cout<<"ccw case test"<=" : "6.2.0" + }, + { + "name" : "gtest", + "version>=" : "1.14.0#1" + }], + "builtin-baseline" : "c8582b4d83dbd36e1bebc08bf166b5eb807996b0", + "overrides" : [ { + "name" : "sundials", + "version" : "6.2.0#0" + } ] +} diff --git "a/\350\257\264\346\230\216.md" "b/\350\257\264\346\230\216.md" new file mode 100644 index 0000000..eca330b --- /dev/null +++ "b/\350\257\264\346\230\216.md" @@ -0,0 +1,4 @@ +cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G "Unix Makefiles" +cmake --build build + +ctest -V --test-dir build From 2b22fdec1ef20210618d7001de4671d1c886fc19 Mon Sep 17 00:00:00 2001 From: chenlongzan <15312731439@163.com> Date: Wed, 23 Oct 2024 11:06:17 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9cmake=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f78305..fcd88d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.26) set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") project(SHUD) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a168db2..f6654dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.26) aux_source_directory(./classes MAIN_CLASSES) aux_source_directory(./Equations MAIN_EQUATIONS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a697a47..3f549dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.26) project(SHUDTest) add_definitions(-DTestDataPath="${CMAKE_SOURCE_DIR}/") From e3e2297b50ffb427375a0fb38ae115d00d0baf97 Mon Sep 17 00:00:00 2001 From: chenlongzan <15312731439@163.com> Date: Wed, 23 Oct 2024 12:15:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AF=B9=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84=E5=88=A4=E6=96=AD=EF=BC=8Cwindow=E4=B8=8A?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E4=B8=BAmingw=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 ++------- CMakeLists.txt | 11 +++-------- test/CMakeLists.txt | 1 - 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 748e9e7..ac07c89 100644 --- a/.gitignore +++ b/.gitignore @@ -28,10 +28,5 @@ rAnalysis/test.R /Testing/ /dist/ /build/ - -/.idea/.gitignore -/.idea/deployment.xml -/.idea/material_theme_project_new.xml -/.idea/misc.xml -/.idea/modules.xml -/.idea/vcs.xml +/.idea/ +/cmake-build-debug-msys2/ diff --git a/CMakeLists.txt b/CMakeLists.txt index fcd88d3..5e542d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,11 @@ cmake_minimum_required(VERSION 3.26) set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") - project(SHUD) set(CMAKE_CXX_STANDARD 11) -set(CMAKE_EXE_LINKER_FLAGS -static) -option(BUILD_SHARED_LIBS "" OFF) -if (WIN32) -# set(CMAKE_C_COMPILER gcc) -# set(CMAKE_CXX_COMPILER g++) -# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + +if (MINGW) + set(CMAKE_EXE_LINKER_FLAGS -static) set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "" FORCE) -# add_compile_options("$<$:/utf-8>") # msvc 编码问题 else () set(VCPKG_TARGET_TRIPLET "x64-linux" CACHE STRING "" FORCE) endif () diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3f549dd..7493090 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.26) project(SHUDTest) add_definitions(-DTestDataPath="${CMAKE_SOURCE_DIR}/") -FIND_PACKAGE(OpenMP REQUIRED) find_package(GTest) From 11572baaa3a20d5e95afd56ba61393a9bd9b3497 Mon Sep 17 00:00:00 2001 From: chenlongzan <15312731439@163.com> Date: Wed, 23 Oct 2024 12:27:46 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9macos=20?= =?UTF-8?q?=E7=9A=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 18 +++++++++++++----- "\350\257\264\346\230\216.md" | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e542d9..4b86ad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,20 @@ set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems project(SHUD) set(CMAKE_CXX_STANDARD 11) -if (MINGW) - set(CMAKE_EXE_LINKER_FLAGS -static) - set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "" FORCE) -else () + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(VCPKG_TARGET_TRIPLET "x64-linux" CACHE STRING "" FORCE) -endif () +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(VCPKG_TARGET_TRIPLET "x64-osx" CACHE STRING "" FORCE) +else() + if (MINGW) + set(CMAKE_EXE_LINKER_FLAGS -static) + set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "" FORCE) + else () + message(FATAL_ERROR "please use mingw environment in windows ") + endif () +endif() + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) diff --git "a/\350\257\264\346\230\216.md" "b/\350\257\264\346\230\216.md" index eca330b..6cb5a30 100644 --- "a/\350\257\264\346\230\216.md" +++ "b/\350\257\264\346\230\216.md" @@ -1,4 +1,4 @@ cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G "Unix Makefiles" -cmake --build build +cmake --build build -j 4 ctest -V --test-dir build From 5de8a2fbfe7efa7354258863a3dc634dc094bb39 Mon Sep 17 00:00:00 2001 From: chenlongzan <15312731439@163.com> Date: Wed, 13 Nov 2024 21:35:12 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1.=20=E7=BB=9F=E4=B8=80mingw=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=92=8Clinux=E4=B8=8Agcc=E7=8E=AF=E5=A2=83=202.=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BC=96=E8=AF=91=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 ++---- src/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- test/TestCase.cpp | 1 - ...26\350\257\221\350\257\264\346\230\216.md" | 32 +++++++++++++++++++ "\350\257\264\346\230\216.md" | 4 --- 6 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 "\347\274\226\350\257\221\350\257\264\346\230\216.md" delete mode 100644 "\350\257\264\346\230\216.md" diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b86ad1..e64fe39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,13 @@ cmake_minimum_required(VERSION 3.26) set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") project(SHUD) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 11) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(VCPKG_TARGET_TRIPLET "x64-linux" CACHE STRING "" FORCE) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(VCPKG_TARGET_TRIPLET "x64-osx" CACHE STRING "" FORCE) -else() - if (MINGW) - set(CMAKE_EXE_LINKER_FLAGS -static) - set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "" FORCE) - else () - message(FATAL_ERROR "please use mingw environment in windows ") - endif () endif() @@ -24,6 +17,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) find_package (OpenMP) find_package(SUNDIALS CONFIG REQUIRED) +set(COVDE_LIB "SUNDIALS::cvode_static") add_subdirectory(src) enable_testing() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6654dd..7995c0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories( add_library(${PROJECT_NAME}_lib STATIC ${MAIN_CLASSES} ${MAIN_EQUATIONS} ${MAIN_MODEL} ${MAIN_MODEL_DATA}) -target_link_libraries(${PROJECT_NAME}_lib SUNDIALS::cvode_static OpenMP::OpenMP_CXX) +target_link_libraries(${PROJECT_NAME}_lib ${COVDE_LIB} OpenMP::OpenMP_CXX) #target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7493090..f7cbe02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,7 +12,7 @@ add_executable(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} GTest::gtest - SUNDIALS::cvode_static + ${COVDE_LIB} SHUD_lib ) diff --git a/test/TestCase.cpp b/test/TestCase.cpp index 21e041e..2bea413 100644 --- a/test/TestCase.cpp +++ b/test/TestCase.cpp @@ -10,7 +10,6 @@ class TestCase : public ::testing::Test { void SetUp() override { filePath = TestDataPath; } - void TearDown() override { } public: diff --git "a/\347\274\226\350\257\221\350\257\264\346\230\216.md" "b/\347\274\226\350\257\221\350\257\264\346\230\216.md" new file mode 100644 index 0000000..06de239 --- /dev/null +++ "b/\347\274\226\350\257\221\350\257\264\346\230\216.md" @@ -0,0 +1,32 @@ +# 编译说明 + +## 编译环境准备 + +### windows +1. 安装Mingw开发环境,推荐使用Msys2,具体参考官网:https://www.msys2.org/ +2. 将Mingw开发环境添加到系统路径,cmd中可以使用gcc命令 +3. 安装CMake构建工具 +4. 安装vcpkg至源代码根路径并运行启动脚本,具体参考vcpkg官网: https://learn.microsoft.com/zh-cn/vcpkg/get_started/get-started?pivots=shell-bash + +### linux +1. 安装GCC开发套件(gcc g++ gdb 等) +2. 安装CMake构建工具 +3. 安装vcpkg至源代码根路径并运行启动脚本,具体参考vcpkg官网: https://learn.microsoft.com/zh-cn/vcpkg/get_started/get-started?pivots=shell-bash + +## 编译步骤 +命令行进入到源代码的根路径 + +### windows +```shell +cmake -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET="x64-mingw-static" -S . -B build -G "Unix Makefiles" +cmake --build build -j 4 +``` +### linux +```shell +cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G "Unix Makefiles" +cmake --build build -j 4 +``` + +## 编译成果 + +编译形成的可执行文件位于源代码根路径下的 /dist/bin/ 下 \ No newline at end of file diff --git "a/\350\257\264\346\230\216.md" "b/\350\257\264\346\230\216.md" deleted file mode 100644 index 6cb5a30..0000000 --- "a/\350\257\264\346\230\216.md" +++ /dev/null @@ -1,4 +0,0 @@ -cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G "Unix Makefiles" -cmake --build build -j 4 - -ctest -V --test-dir build