Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "Testing/helper"] | ||
path = Testing/helper | ||
url = git@github.coventry.ac.uk:ac0745/4003CEM-helper.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
a_function(); | ||
|
||
return 0; | ||
} | ||
|
||
void a function() | ||
{ | ||
cout << "This is a function 1" << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void a_function() | ||
{ | ||
cout << "This is a function 1" << endl; | ||
} | ||
|
||
int main() | ||
{ | ||
a_function(); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void print_two( int a, int b ) | ||
{ | ||
cout << a << "+" << b | ||
<< "=" << a+b << endl; | ||
} | ||
|
||
int main() | ||
{ | ||
print_two( 1, 2 ); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void print_two( int a, int b ) | ||
{ | ||
cout << a << "+" << b | ||
<< "=" << a+b << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "print_two.h" | ||
|
||
void print_two( int a, int b ) | ||
{ | ||
cout << a << "+" << b | ||
<< "=" << a+b << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef PRINT_TWO_H | ||
#define PRINT_TWO_H | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
void print_two( int a, int b ); | ||
|
||
#endif |