Tutorial Exercise 2 - Adding an Option Solutions
Should the solution for TODO 11 be
#ifndef USE_MYMATH # include <cmath> #endif
instead of just
#include <cmath> is unnecessary when
Should text just above TODO 12 read
First, from within MathFunctions/CMakeLists.txt create a library called SqrtLibrary that has sources mysqrt.cxx.
First, from within USE_MYMATH create a library called SqrtLibrary that has sources mysqrt.cxx.
The stated objective of TODO 12 and TODO 13 is to not compile mysqrt.cxx when USE_MYMATH=OFF.
The solutions displayed for TODO 12 and TODO 13 are not wrapped in if(USE_MYMATH) i.e. bare
add_library(SqrtLibrary STATIC mysqrt.cxx )
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
(the eagle-eyed can see from the indentation that these fragments were copied from a CMakeLists.txt where there was probably an enclosing if). But if we use these the given fragments as solutions without an enclosing ‘if’ then SqrtLibrary is always built and linked, even when USE_MYMATH=OFF.
I would presume the correct solution is:
if(USE_MYMATH) add_library(SqrtLibrary STATIC mysqrt.cxx ) target_link_libraries(MathFunctions PRIVATE SqrtLibrary) endif()
where I see the build does not make SqrtLibrary when USE_MYMATH=OFF.