File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11cmake_minimum_required (VERSION 3.23 )
22
33project (Tutorial)
4-
4+ # set(CMAKE_CXX_COMPILER g++-13)
55option (TUTORIAL_BUILD_UTILITIES "Build the Tutorial executable" ON )
66
77# TODO1: Add a default-OFF option named TUTORIAL_USE_STD_SQRT, with a doc
88# string of "Use std::sqrt"
9+ option (TUTORIAL_USE_STD_SQRT "Use std::sqrt" OFF )
910
1011if (TUTORIAL_BUILD_UTILITIES)
1112 add_subdirectory (Tutorial )
Original file line number Diff line number Diff line change 77 "description" : " Preset to use with the tutorial" ,
88 "binaryDir" : " ${sourceDir}/build" ,
99 "cacheVariables" : {
10- "TODO7" : " Remove the CMAKE_CXX_STANDARD (and this TODO)" ,
11- "CMAKE_CXX_STANDARD" : " 20" ,
12- "TODO8" : " Set TUTORIAL_USE_STD_SQRT to ON"
10+ "CMAKE_CXX_COMPILER" :" g++-13" ,
11+ "CMAKE_EXPORT_COMPILE_COMMANDS" :" ON" ,
12+
13+ "TUTORIAL_USE_STD_SQRT" : " ON"
1314 }
1415 }
1516 ]
Original file line number Diff line number Diff line change @@ -2,15 +2,22 @@ add_library(MathFunctions)
22
33target_sources (MathFunctions
44 PRIVATE
5- MathFunctions.cxx
5+ MathFunctions.cxx
66
77 PUBLIC
8- FILE_SET HEADERS
9- FILES
10- MathFunctions.h
8+ FILE_SET HEADERS
9+ FILES
10+ MathFunctions.h
1111)
1212
1313# TODO2: Add a compile feature for C++20 support to MathFunctions
14+ target_compile_features (MathFunctions PRIVATE cxx_std_20 )
1415
1516# TODO3: Add a conditional which checks TUTORIAL_USE_STD_SQRT and if
1617# ON, set a compile definition on MathFunctions of the same name
18+ if (TUTORIAL_USE_STD_SQRT)
19+ target_compile_definitions (MathFunctions
20+ PRIVATE
21+ TUTORIAL_USE_STD_SQRT
22+ )
23+ endif ()
Original file line number Diff line number Diff line change 11// TODO5: Include <cmath>
2+ #include < cmath>
23
34#include < format>
45#include < iostream>
@@ -32,7 +33,10 @@ double sqrt(double x)
3233{
3334 // TODO6: Check if TUTORIAL_USE_STD_SQRT is defined, if so use std::sqrt
3435 // instead of mysqrt
35-
36+ #ifdef TUTORIAL_USE_STD_SQRT
37+ return std::sqrt (x);
38+ #else
3639 return mysqrt (x);
40+ #endif
3741}
3842}
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ target_link_libraries(Tutorial
1313)
1414
1515# TODO4: Add a compile feature for C++20 support to Tutorial
16+ target_compile_features (Tutorial PRIVATE cxx_std_20 )
1617
1718
1819if (
You can’t perform that action at this time.
0 commit comments