Skip to content

Commit e893e95

Browse files
Add new executable using header-only library
1 parent 1fb1017 commit e893e95

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(LibTemplateCMake)
22
add_subdirectory(LibHeaderOnlyTemplateCMake)
33
add_subdirectory(ExeExample)
4+
add_subdirectory(ExeExampleHeaderOnly)

src/ExeExample/main.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
#include "LibTemplateCMake/LibTemplateCMake.h"
1+
#include <LibTemplateCMake/LibTemplateCMake.h>
22

33
#include <cstdlib>
44
#include <cmath>
55
#include <iostream>
66

77
int main()
88
{
9-
std::cout << "Example executable" << std::endl;
9+
std::cout << "Executable example using the library!" << std::endl;
10+
1011
LibTemplateCMake::summationClass sumClass;
1112
LibTemplateCMake::differenceClass diffClass;
1213

1314
double tol = 1e-10;
1415
double op1 = 15.0;
1516
double op2 = 10.0;
1617

17-
if( fabs(sumClass.doSomething(op1,op2)-(op1+op2)) > tol )
18+
if( fabs(sumClass.doSomething(op1, op2) - (op1 + op2)) > tol )
1819
{
1920
std::cerr << "[ERR] sumClass.doSomething(" << op1 << "," << op2
20-
<< ") is equal to " << sumClass.doSomething(op1,op2)
21-
<< " instead of the expected " << op1+op2 << std::endl;
21+
<< ") is equal to " << sumClass.doSomething(op1, op2)
22+
<< " instead of the expected " << op1 + op2 << std::endl;
2223
return EXIT_FAILURE;
2324
}
2425

25-
if( fabs(diffClass.doSomething(op1,op2)-(op1-op2)) > tol )
26+
if( fabs(diffClass.doSomething(op1, op2) - (op1 - op2)) > tol )
2627
{
2728
std::cerr << "[ERR] sumClass.doSomething(" << op1 << "," << op2
28-
<< ") is equal to " << diffClass.doSomething(op1,op2)
29-
<< " instead of the expected " << op1-op2 << std::endl;
29+
<< ") is equal to " << diffClass.doSomething(op1, op2)
30+
<< " instead of the expected " << op1 - op2 << std::endl;
3031
return EXIT_FAILURE;
3132
}
3233

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(EXE_TARGET_NAME ExeExampleHeaderOnly)
2+
3+
set(${EXE_TARGET_NAME}_SRC
4+
main.cpp
5+
)
6+
7+
add_executable(${EXE_TARGET_NAME} ${${EXE_TARGET_NAME}_SRC})
8+
9+
target_link_libraries(${EXE_TARGET_NAME} LibTemplateCMake::LibTemplateCMakeHeaderOnly)
10+
11+
install(TARGETS ${EXE_TARGET_NAME} DESTINATION bin)

src/ExeExampleHeaderOnly/main.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <LibHeaderOnlyTemplateCMake/LibHeaderOnlyTemplateCMake.h>
2+
3+
#include <cstdlib>
4+
#include <cmath>
5+
#include <iostream>
6+
7+
int main()
8+
{
9+
std::cout << "Executable example using the header-only library!" << std::endl;
10+
11+
double tol = 1e-10;
12+
double op1 = 15.0;
13+
double op2 = 10.0;
14+
15+
if( fabs(LibTemplateCMake::sum(op1, op2) - (op1 + op2)) > tol )
16+
{
17+
std::cerr << "[ERR] sumClass.doSomething(" << op1 << "," << op2
18+
<< ") is equal to " << LibTemplateCMake::sum(op1, op2)
19+
<< " instead of the expected " << op1 + op2 << std::endl;
20+
return EXIT_FAILURE;
21+
}
22+
23+
if( fabs(LibTemplateCMake::sub(op1, op2) - (op1 - op2)) > tol )
24+
{
25+
std::cerr << "[ERR] sumClass.doSomething(" << op1 << "," << op2
26+
<< ") is equal to " << LibTemplateCMake::sub(op1, op2)
27+
<< " instead of the expected " << op1 - op2 << std::endl;
28+
return EXIT_FAILURE;
29+
}
30+
31+
return EXIT_SUCCESS;
32+
}

0 commit comments

Comments
 (0)