From 5b42b1e32c546310d1e2c5f065b7bf1211e79811 Mon Sep 17 00:00:00 2001 From: Brad Eck Date: Fri, 28 Oct 2016 14:13:05 +0100 Subject: [PATCH 1/2] use multiple CMakeList.txt files --- CMakeLists.txt | 138 +----------------------------------------- src/CMakeLists.txt | 142 ++++++++++++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 9 +++ 3 files changed, 154 insertions(+), 135 deletions(-) create mode 100644 src/CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 368b1a0..41a06e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,4 @@ cmake_minimum_required (VERSION 2.8) -SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) -SET (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) project ("EPANET") set_property( GLOBAL PROPERTY USE_FOLDERS ON) @@ -15,137 +13,7 @@ else() SET (CMAKE_CXX_FLAGS "-Wall -std=c++11") endif(MSVC) -SET (epanet_lib_sources -src/Core/datamanager.cpp -src/Core/diagnostics.cpp -src/Core/epanet3.cpp -src/Core/error.cpp -src/Core/hydbalance.cpp -src/Core/hydengine.cpp -src/Core/network.cpp -src/Core/options.cpp -src/Core/project.cpp -src/Core/qualbalance.cpp -src/Core/qualengine.cpp -src/Core/units.cpp -src/Elements/control.cpp -src/Elements/curve.cpp -src/Elements/demand.cpp -src/Elements/element.cpp -src/Elements/emitter.cpp -src/Elements/junction.cpp -src/Elements/link.cpp -src/Elements/node.cpp -src/Elements/pattern.cpp -src/Elements/pipe.cpp -src/Elements/pump.cpp -src/Elements/pumpcurve.cpp -src/Elements/qualsource.cpp -src/Elements/reservoir.cpp -src/Elements/tank.cpp -src/Elements/valve.cpp -src/Input/controlparser.cpp -src/Input/curveparser.cpp -src/Input/inputparser.cpp -src/Input/inputreader.cpp -src/Input/linkparser.cpp -src/Input/nodeparser.cpp -src/Input/optionparser.cpp -src/Input/patternparser.cpp -src/Models/demandmodel.cpp -src/Models/headlossmodel.cpp -src/Models/leakagemodel.cpp -src/Models/pumpenergy.cpp -src/Models/qualmodel.cpp -src/Models/tankmixmodel.cpp -src/Output/outputfile.cpp -src/Output/projectwriter.cpp -src/Output/reportfields.cpp -src/Output/reportwriter.cpp -src/Solvers/ggasolver.cpp -src/Solvers/hydsolver.cpp -src/Solvers/ltdsolver.cpp -src/Solvers/matrixsolver.cpp -src/Solvers/qualsolver.cpp -src/Solvers/sparspak.cpp -src/Solvers/sparspaksolver.cpp -src/Utilities/graph.cpp -src/Utilities/mempool.cpp -src/Utilities/segpool.cpp -src/Utilities/utilities.cpp -) +add_subdirectory (src) +enable_testing() +add_subdirectory (test) -SET (epanet_lib_headers -src/Core/constants.h -src/Core/datamanager.h -src/Core/diagnostics.h -src/Core/error.h -src/Core/hydbalance.h -src/Core/hydengine.h -src/Core/network.h -src/Core/options.h -src/Core/project.h -src/Core/qualbalance.h -src/Core/qualengine.h -src/Core/units.h -src/Elements/control.h -src/Elements/curve.h -src/Elements/demand.h -src/Elements/element.h -src/Elements/emitter.h -src/Elements/junction.h -src/Elements/link.h -src/Elements/node.h -src/Elements/pattern.h -src/Elements/pipe.h -src/Elements/pump.h -src/Elements/pumpcurve.h -src/Elements/qualsource.h -src/Elements/reservoir.h -src/Elements/tank.h -src/Elements/valve.h -src/Input/controlparser.h -src/Input/curveparser.h -src/Input/inputparser.h -src/Input/inputreader.h -src/Input/linkparser.h -src/Input/nodeparser.h -src/Input/optionparser.h -src/Input/patternparser.h -src/Models/demandmodel.h -src/Models/headlossmodel.h -src/Models/leakagemodel.h -src/Models/pumpenergy.h -src/Models/qualmodel.h -src/Models/tankmixmodel.h -src/Output/outputfile.h -src/Output/projectwriter.h -src/Output/reportfields.h -src/Output/reportwriter.h -src/Solvers/ggasolver.h -src/Solvers/hydsolver.h -src/Solvers/ltdsolver.h -src/Solvers/matrixsolver.h -src/Solvers/qualsolver.h -src/Solvers/sparspak.h -src/Solvers/sparspaksolver.h -src/Utilities/graph.h -src/Utilities/mempool.h -src/Utilities/segpool.h -src/Utilities/utilities.h -) - -source_group("Core" REGULAR_EXPRESSION "src/Core/.*") -source_group("Elements" REGULAR_EXPRESSION "src/Elements/.*") -source_group("Input" REGULAR_EXPRESSION "src/Input/.*") -source_group("Models" REGULAR_EXPRESSION "src/Models/.*") -source_group("Output" REGULAR_EXPRESSION "src/Output/.*") -source_group("Solvers" REGULAR_EXPRESSION "src/Solvers/.*") -source_group("Utilities" REGULAR_EXPRESSION "src/Utilities/.*") - -include_directories(src src/Core src/Elements src/Input src/Output src/Utilities src/Solvers) - -add_library(epanet3 SHARED ${epanet_lib_sources} ${epanet_lib_headers}) - -add_executable(run-epanet3 src/CLI/main.cpp) -target_link_libraries(run-epanet3 LINK_PUBLIC epanet3) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..5c40bb1 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,142 @@ +# cmakelists.txt for epanet3 src + +SET (epanet_lib_sources +Core/datamanager.cpp +Core/diagnostics.cpp +Core/epanet3.cpp +Core/error.cpp +Core/hydbalance.cpp +Core/hydengine.cpp +Core/network.cpp +Core/options.cpp +Core/project.cpp +Core/qualbalance.cpp +Core/qualengine.cpp +Core/units.cpp +Elements/control.cpp +Elements/curve.cpp +Elements/demand.cpp +Elements/element.cpp +Elements/emitter.cpp +Elements/junction.cpp +Elements/link.cpp +Elements/node.cpp +Elements/pattern.cpp +Elements/pipe.cpp +Elements/pump.cpp +Elements/pumpcurve.cpp +Elements/qualsource.cpp +Elements/reservoir.cpp +Elements/tank.cpp +Elements/valve.cpp +Input/controlparser.cpp +Input/curveparser.cpp +Input/inputparser.cpp +Input/inputreader.cpp +Input/linkparser.cpp +Input/nodeparser.cpp +Input/optionparser.cpp +Input/patternparser.cpp +Models/demandmodel.cpp +Models/headlossmodel.cpp +Models/leakagemodel.cpp +Models/pumpenergy.cpp +Models/qualmodel.cpp +Models/tankmixmodel.cpp +Output/outputfile.cpp +Output/projectwriter.cpp +Output/reportfields.cpp +Output/reportwriter.cpp +Solvers/ggasolver.cpp +Solvers/hydsolver.cpp +Solvers/ltdsolver.cpp +Solvers/matrixsolver.cpp +Solvers/qualsolver.cpp +Solvers/sparspak.cpp +Solvers/sparspaksolver.cpp +Utilities/graph.cpp +Utilities/mempool.cpp +Utilities/segpool.cpp +Utilities/utilities.cpp +) + +SET (epanet_lib_headers +Core/constants.h +Core/datamanager.h +Core/diagnostics.h +Core/error.h +Core/hydbalance.h +Core/hydengine.h +Core/network.h +Core/options.h +Core/project.h +Core/qualbalance.h +Core/qualengine.h +Core/units.h +Elements/control.h +Elements/curve.h +Elements/demand.h +Elements/element.h +Elements/emitter.h +Elements/junction.h +Elements/link.h +Elements/node.h +Elements/pattern.h +Elements/pipe.h +Elements/pump.h +Elements/pumpcurve.h +Elements/qualsource.h +Elements/reservoir.h +Elements/tank.h +Elements/valve.h +Input/controlparser.h +Input/curveparser.h +Input/inputparser.h +Input/inputreader.h +Input/linkparser.h +Input/nodeparser.h +Input/optionparser.h +Input/patternparser.h +Models/demandmodel.h +Models/headlossmodel.h +Models/leakagemodel.h +Models/pumpenergy.h +Models/qualmodel.h +Models/tankmixmodel.h +Output/outputfile.h +Output/projectwriter.h +Output/reportfields.h +Output/reportwriter.h +Solvers/ggasolver.h +Solvers/hydsolver.h +Solvers/ltdsolver.h +Solvers/matrixsolver.h +Solvers/qualsolver.h +Solvers/sparspak.h +Solvers/sparspaksolver.h +Utilities/graph.h +Utilities/mempool.h +Utilities/segpool.h +Utilities/utilities.h +) + +source_group("Core" REGULAR_EXPRESSION "Core/.*") +source_group("Elements" REGULAR_EXPRESSION "Elements/.*") +source_group("Input" REGULAR_EXPRESSION "Input/.*") +source_group("Models" REGULAR_EXPRESSION "Models/.*") +source_group("Output" REGULAR_EXPRESSION "Output/.*") +source_group("Solvers" REGULAR_EXPRESSION "Solvers/.*") +source_group("Utilities" REGULAR_EXPRESSION "Utilities/.*") + +include_directories(. Core Elements Input Output Utilities Solvers) + +# static for ease of testing +add_library(epanet3 STATIC ${epanet_lib_sources} ${epanet_lib_headers}) + +add_executable(run-epanet3 CLI/main.cpp) +target_link_libraries(run-epanet3 LINK_PUBLIC epanet3) + +# put the library and executable in bin +set_target_properties( epanet3 run-epanet3 + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..834667e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,9 @@ + +# a cmake file for a test build +# For test +include_directories (${CMAKE_SOURCE_DIR}/src) + +## have to do this for each test +add_executable(test_pipe src/Elements/test_pipe.cpp) +target_link_libraries(test_pipe LINK_PUBLIC epanet3) +add_test( pipe test_pipe ) \ No newline at end of file From 01358a9d99f0d64f1e0c00fd6ce1b8231a99fbd7 Mon Sep 17 00:00:00 2001 From: Brad Eck Date: Fri, 28 Oct 2016 14:35:25 +0100 Subject: [PATCH 2/2] test pipe class --- src/Elements/element.h | 4 +++- test/src/Elements/test_pipe.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/src/Elements/test_pipe.cpp diff --git a/src/Elements/element.h b/src/Elements/element.h index 97adc9e..22bab62 100644 --- a/src/Elements/element.h +++ b/src/Elements/element.h @@ -28,10 +28,12 @@ class Element std::string name; //!< element's ID name int index; //!< index in array of elements + protected: + Element(const Element& e); private: // Elements can't be copied or tested for equality - Element(const Element& e); + //Element(const Element& e); Element& operator=(const Element& e); }; diff --git a/test/src/Elements/test_pipe.cpp b/test/src/Elements/test_pipe.cpp new file mode 100644 index 0000000..6d37b7c --- /dev/null +++ b/test/src/Elements/test_pipe.cpp @@ -0,0 +1,26 @@ +#include +#include +#include "Elements/pipe.h" + + + +/** + * An application for testing the pipe class. + * Should return 0 for passing, any other value + * fails. + */ +int main (void ) +{ + + std::string expected = "myPipe"; + Pipe p = Pipe( expected ); + + // see that the pipe has the correct name + std::cout << "Created a pipe named " << p.name << std::endl; + + std::string actual = p.name; + + int value = actual.compare(expected); + + return value; +}