Skip to content

Commit 46bcb68

Browse files
committed
finish "step7":exercise 1
1 parent c4cccc2 commit 46bcb68

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎Step7/CMakePresets.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"description": "Preset to use with the tutorial",
88
"binaryDir": "${sourceDir}/build",
99
"cacheVariables": {
10+
"CMAKE_CXX_COMPILER":"g++-13",
11+
"CMAKE_EXPORT_COMPILE_COMMANDS":"ON",
12+
1013
"TUTORIAL_USE_STD_SQRT": "OFF",
1114
"TUTORIAL_ENABLE_IPO": "OFF"
1215
}

‎Step7/MathFunctions/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ target_sources(MathFunctions
1414
target_link_libraries(MathFunctions
1515
PRIVATE
1616
MathLogger
17+
GeneratedTable
1718

1819
PUBLIC
1920
OpAdd
@@ -52,3 +53,4 @@ endif()
5253
add_subdirectory(MathLogger)
5354
add_subdirectory(MathExtensions)
5455
# TODO9: Add the MakeTable subdirectory to the project
56+
add_subdirectory(MakeTable)
Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
# TODO1: Add a MakeTable executable
2-
2+
add_executable(MakeTable)
33
# TODO2: Add MakeTable.cxx to the MakeTable executable
4-
4+
target_sources(
5+
MakeTable
6+
PRIVATE
7+
MakeTable.cxx
8+
)
59
# TODO3: Add a custom command which invokes MakeTable to generate SqrtTable.h
6-
10+
add_custom_command(
11+
OUTPUT SqrtTable.h
12+
COMMAND MakeTable SqrtTable.h
13+
DEPENDS MakeTable
14+
VERBATIM
15+
)
716
# TODO4: Add a custom target which depends on SqrtTable.h
8-
17+
add_custom_target(GenerateSqrtTable DEPENDS SqrtTable.h)
918
# TODO5: Add an INTERFACE library to describe the SqrtTable header
10-
19+
add_library(GeneratedTable INTERFACE)
1120
# TODO6: Add the current binary directory (and optionally the SqrtTable.h FILE)
1221
# to a header file set of the interface library
22+
target_sources(GeneratedTable
23+
INTERFACE
24+
FILE_SET HEADERS
25+
BASE_DIRS
26+
${CMAKE_CURRENT_BINARY_DIR}
27+
FILES
28+
${CMAKE_CURRENT_BINARY_DIR}/SqrtTable.h
29+
)
1330

1431
# TODO7: Use add_dependencies to ensure the custom target always runs before
1532
# targets that depend on the interface library
33+
add_dependencies(GeneratedTable GenerateSqrtTable)

‎Step7/MathFunctions/MathFunctions.cxx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ double fallback_mysqrt(double x)
5656
}
5757

5858
// TODO10: Replace this hardcoded sqrtTable with #include <SqrtTable.h>
59-
double sqrtTable[] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3 };
59+
#include "SqrtTable.h"
60+
// double sqrtTable[] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3 };
6061

6162
double table_sqrt(double x)
6263
{

0 commit comments

Comments
 (0)