1
0

Compare commits

...

5 Commits

Author SHA1 Message Date
a6e575962e Excerise 1 - Step 2 2023-10-30 13:12:33 +01:00
e2564d1ea8 Excercise 3 - Step 1 2023-10-30 09:41:08 +01:00
40bab85440 Excercise 2 - Step 1
Signed-off-by: Nigel <nigelbarink@hotmail.com>
2023-10-30 09:18:36 +01:00
6230552729 Step 1 Excercise 1 Completed
Signed-off-by: Nigel <nigelbarink@hotmail.com>
2023-10-30 09:18:36 +01:00
7ea0f8d749 Updated README
Signed-off-by: Nigel <nigelbarink@hotmail.com>
2023-10-30 09:18:36 +01:00
10 changed files with 48 additions and 36 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*_build/

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# CMake Tutorial
### Reasoning
Cmake is too popular to ignore.
Many crossplatform projects written in C and C++ use cmake as their buildtool of choice.
As this is the case I feel I need to integrate and become more comfortable with CMake myself.
[cmake.org tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/A%20Basic%20Starting%20Point.html)
### What is in this repository
This directory contains source code examples for the CMake Tutorial.
Each step has its own subdirectory containing code that may be used as a
starting point. The tutorial examples are progressive so that each step
provides the complete solution for the previous step.

View File

@ -1,4 +0,0 @@
This directory contains source code examples for the CMake Tutorial.
Each step has its own subdirectory containing code that may be used as a
starting point. The tutorial examples are progressive so that each step
provides the complete solution for the previous step.

View File

@ -1,16 +1,11 @@
# TODO 1: Set the minimum required version of CMake to be 3.10
cmake_minimum_required(VERSION 3.10)
project(
Tutorial
VERSION 1.0
)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# TODO 2: Create a project named Tutorial
# TODO 7: Set the project version number as 1.0 in the above project command
# TODO 6: Set the variable CMAKE_CXX_STANDARD to 11
# and the variable CMAKE_CXX_STANDARD_REQUIRED to True
# TODO 8: Use configure_file to configure and copy TutorialConfig.h.in to
# TutorialConfig.h
# TODO 3: Add an executable called Tutorial to the project
# Hint: Be sure to specify the source file as tutorial.cxx
# TODO 9: Use target_include_directories to include ${PROJECT_BINARY_DIR}
configure_file(TutorialConfig.h.in TutorialConfig.h)
add_executable(Tutorial tutorial.cxx)
target_include_directories(Tutorial PUBLIC ${PROJECT_BINARY_DIR})

View File

@ -1,2 +1,4 @@
// the configured options and settings for Tutorial
// TODO 10: Define Tutorial_VERSION_MAJOR and Tutorial_VERSION_MINOR
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@

View File

@ -1,23 +1,21 @@
// A simple program that computes the square root of a number
#include <cmath>
#include <cstdlib> // TODO 5: Remove this line
#include <iostream>
#include <string>
// TODO 11: Include TutorialConfig.h
#include "TutorialConfig.h"
int main(int argc, char* argv[])
{
if (argc < 2) {
// TODO 12: Create a print statement using Tutorial_VERSION_MAJOR
// and Tutorial_VERSION_MINOR
std::cout << argv[0] << " V " << Tutorial_VERSION_MAJOR << "." << Tutorial_VERSION_MINOR << std::endl;
std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
// convert input to double
// TODO 4: Replace atof(argv[1]) with std::stod(argv[1])
const double inputValue = atof(argv[1]);
const double inputValue = std::stod(argv[1]);
// calculate square root
const double outputValue = sqrt(inputValue);

View File

@ -11,15 +11,17 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)
# TODO 2: Use add_subdirectory() to add MathFunctions to this project
add_subdirectory(MathFunctions)
# add the executable
add_executable(Tutorial tutorial.cxx)
# TODO 3: Use target_link_libraries to link the library to our executable
target_link_libraries(Tutorial PUBLIC MathFunctions)
# TODO 4: Add MathFunctions to Tutorial's target_include_directories()
# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder!
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/MathFunctions"
)
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h

View File

@ -1,8 +1,7 @@
# TODO 14: Remove mysqrt.cxx from the list of sources
# TODO 1: Add a library called MathFunctions with sources MathFunctions.cxx
# and mysqrt.cxx
# Hint: You will need the add_library command
add_library(MathFunctions MathFunctions.cxx mysqrt.cxx)
# TODO 7: Create a variable USE_MYMATH using option and set default to ON

View File

@ -3,7 +3,7 @@
#include <iostream>
#include <string>
// TODO 5: Include MathFunctions.h
#include "MathFunctions/MathFunctions.h"
#include "TutorialConfig.h"
int main(int argc, char* argv[])
@ -19,10 +19,8 @@ int main(int argc, char* argv[])
// convert input to double
const double inputValue = std::stod(argv[1]);
// TODO 6: Replace sqrt with mathfunctions::sqrt
// calculate square root
const double outputValue = sqrt(inputValue);
const double outputValue = mathfunctions::sqrt(inputValue);
std::cout << "The square root of " << inputValue << " is " << outputValue
<< std::endl;
return 0;