From c8705299525302d6623349402fb010b77ea1e240 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 18 Dec 2018 09:53:25 +0000 Subject: [PATCH] Basic setup --- .gitignore | 18 +++++++++++++ .gitmodules | 3 +++ CMakeLists.txt | 25 ++++++++++++++++++ Lecture/CMakeLists.txt | 20 +++++++++++++++ Lecture/lec_CMakeLists.txt | 20 +++++++++++++++ Lecture/lec_doubly_dependant.cpp | 25 ++++++++++++++++++ Lecture/lec_doubly_dependant_fixed.cpp | 27 ++++++++++++++++++++ Lecture/lec_error.cpp | 14 +++++++++++ Lecture/lec_error_fixed.cpp | 15 +++++++++++ Lecture/lec_example.cpp | 15 +++++++++++ Lecture/lec_print_two.h | 8 ++++++ Testing/CMakeLists.txt | 35 ++++++++++++++++++++++++++ Testing/helper | 1 + print_two.cpp | 7 ++++++ print_two.h | 9 +++++++ 15 files changed, 242 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 Lecture/CMakeLists.txt create mode 100644 Lecture/lec_CMakeLists.txt create mode 100644 Lecture/lec_doubly_dependant.cpp create mode 100644 Lecture/lec_doubly_dependant_fixed.cpp create mode 100644 Lecture/lec_error.cpp create mode 100644 Lecture/lec_error_fixed.cpp create mode 100644 Lecture/lec_example.cpp create mode 100644 Lecture/lec_print_two.h create mode 100644 Testing/CMakeLists.txt create mode 160000 Testing/helper create mode 100644 print_two.cpp create mode 100644 print_two.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..507900b --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +bin/ +build/ +.vscode/ +CMakeFiles/ +Temporary/ +__pycache__/ + +solution_* +Solutions/*.cpp +Solutions/*.h +password + +CMakeCache.txt +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6ee2b02 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Testing/helper"] + path = Testing/helper + url = git@github.coventry.ac.uk:ac0745/4003CEM-helper.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3c476ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.0) +set(CMAKE_CXX_STANDARD 14) + +project(cmake_example CXX) + +# location of source code files +include_directories(${CMAKE_SOURCE_DIR}) + +# tell cmake where to put the executables that it creates +file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin ) + +# where to put the object files it creates +file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) +SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) + +add_library( print_two print_two.cpp ) + +add_executable( main main.cpp ) +target_link_libraries( main print_two ) + +# add tests +enable_testing() +add_subdirectory(Testing) +add_subdirectory(Lecture) diff --git a/Lecture/CMakeLists.txt b/Lecture/CMakeLists.txt new file mode 100644 index 0000000..2ac3f5d --- /dev/null +++ b/Lecture/CMakeLists.txt @@ -0,0 +1,20 @@ +# tell cmake where to put the executables that it creates +# also creates the directory if needed +file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin ) + +# compile the lecture examples +file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/lec_*.cpp") +foreach(filename ${files}) + # if lec file is "lec_thingy.cpp" then created test will be called "bin/lec_thingy" + get_filename_component(EXEC ${filename} NAME_WE) + + # skip over the lec_error example as it won't compile + if("${EXEC}" MATCHES "^(lec_error|lec_doubly_dependant)$") + continue() + endif() + + # create the executable + add_executable(${EXEC} ${filename} ${HEADERS}) +endforeach() + diff --git a/Lecture/lec_CMakeLists.txt b/Lecture/lec_CMakeLists.txt new file mode 100644 index 0000000..5dcc506 --- /dev/null +++ b/Lecture/lec_CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.0) +set(CMAKE_CXX_STANDARD 14) + +project(print_two CXX) + +# config directories +include_directories(${CMAKE_SOURCE_DIR}) + +# tell cmake where to put the executables that it creates +# also creates the directory if needed +file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin ) + +file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) + +add_library(print_two SHARED print_two.cpp) + +add_executable( main main.cpp ) +target_link_libraries( main print_two ) diff --git a/Lecture/lec_doubly_dependant.cpp b/Lecture/lec_doubly_dependant.cpp new file mode 100644 index 0000000..ddfd727 --- /dev/null +++ b/Lecture/lec_doubly_dependant.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +void function1( int counter ) +{ + if( counter == 0 ) return; + + cout << "This is a function 1" << endl; + function2( counter-1 ); +} + +void function2( int counter ) +{ + if( counter == 0 ) return; + + cout << "This is a function 2" << endl; + function1( counter-1 ); +} + +int main() +{ + function1(5); + + return 0; +} \ No newline at end of file diff --git a/Lecture/lec_doubly_dependant_fixed.cpp b/Lecture/lec_doubly_dependant_fixed.cpp new file mode 100644 index 0000000..55cfb75 --- /dev/null +++ b/Lecture/lec_doubly_dependant_fixed.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +void function2( int ); // function prototype + +void function1( int counter ) +{ + if( counter == 0 ) return; + + cout << "This is a function 1" << endl; + function2( counter-1 ); +} + +void function2( int counter ) +{ + if( counter == 0 ) return; + + cout << "This is a function 2" << endl; + function1( counter-1 ); +} + +int main() +{ + function1(5); + + return 0; +} \ No newline at end of file diff --git a/Lecture/lec_error.cpp b/Lecture/lec_error.cpp new file mode 100644 index 0000000..1b874bb --- /dev/null +++ b/Lecture/lec_error.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; + +int main() +{ + a_function(); + + return 0; +} + +void a function() +{ + cout << "This is a function 1" << endl; +} \ No newline at end of file diff --git a/Lecture/lec_error_fixed.cpp b/Lecture/lec_error_fixed.cpp new file mode 100644 index 0000000..0f2782d --- /dev/null +++ b/Lecture/lec_error_fixed.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +void a_function() +{ + cout << "This is a function 1" << endl; +} + +int main() +{ + a_function(); + + return 0; +} + diff --git a/Lecture/lec_example.cpp b/Lecture/lec_example.cpp new file mode 100644 index 0000000..f232162 --- /dev/null +++ b/Lecture/lec_example.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +void print_two( int a, int b ) +{ + cout << a << "+" << b + << "=" << a+b << endl; +} + +int main() +{ + print_two( 1, 2 ); + + return 0; +} \ No newline at end of file diff --git a/Lecture/lec_print_two.h b/Lecture/lec_print_two.h new file mode 100644 index 0000000..0050187 --- /dev/null +++ b/Lecture/lec_print_two.h @@ -0,0 +1,8 @@ +#include +using namespace std; + +void print_two( int a, int b ) +{ + cout << a << "+" << b + << "=" << a+b << endl; +} diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt new file mode 100644 index 0000000..aaf1990 --- /dev/null +++ b/Testing/CMakeLists.txt @@ -0,0 +1,35 @@ +# tell cmake where to put the executables that it creates +# also creates the directory if needed +file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin ) + +# tell cmake where to find the catch2 library +set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch) +add_library(Catch INTERFACE) +target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) + +# tell cmake where to find the captureio library +set(CAPIO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/captureio) +add_library(Capio INTERFACE) +target_include_directories(Capio INTERFACE ${CAPIO_INCLUDE_DIR}) + +# create the tests +# test files start with "test_" and end in ".cpp" +# create a seperate executable for each test file +enable_testing() +file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp") +foreach(filename ${files}) + # if test file is "test_thingy.cpp" then created test will be called "test_thingy" + get_filename_component(THIS_TEST ${filename} NAME_WE) + set(TEST_RUNNER ${THIS_TEST}) + + # create the executable, include the catch2 library + add_executable(${TEST_RUNNER} ${filename} ${HEADERS}) + target_link_libraries(${TEST_RUNNER} Catch) + target_link_libraries(${TEST_RUNNER} Capio) + + # say that this executable is a test so that ctest will run it + add_test(NAME ${THIS_TEST} + COMMAND ${TEST_RUNNER} ) +endforeach() + diff --git a/Testing/helper b/Testing/helper new file mode 160000 index 0000000..5641313 --- /dev/null +++ b/Testing/helper @@ -0,0 +1 @@ +Subproject commit 56413130eb31eb1e37461143a1152a9eae0b4810 diff --git a/print_two.cpp b/print_two.cpp new file mode 100644 index 0000000..0ff670b --- /dev/null +++ b/print_two.cpp @@ -0,0 +1,7 @@ +#include "print_two.h" + +void print_two( int a, int b ) +{ + cout << a << "+" << b + << "=" << a+b << endl; +} diff --git a/print_two.h b/print_two.h new file mode 100644 index 0000000..355b33b --- /dev/null +++ b/print_two.h @@ -0,0 +1,9 @@ +#ifndef PRINT_TWO_H +#define PRINT_TWO_H + +#include +using namespace std; + +void print_two( int a, int b ); + +#endif