mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
ENH: Add new Tutorial steps. Diff between Step5 and Step6 shows how to add a cpack driven installer to your project. Diff between Step6 and Step7 shows how to add ctest dashboard scripting capability.
This commit is contained in:
26
Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
Normal file
26
Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
# first we add the executable that generates the table
|
||||
add_executable(MakeTable MakeTable.cxx)
|
||||
|
||||
get_target_property(MakeTableLocation MakeTable LOCATION)
|
||||
|
||||
# add the command to generate the source code
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
|
||||
DEPENDS MakeTable
|
||||
COMMAND ${MakeTableLocation}
|
||||
ARGS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
|
||||
)
|
||||
|
||||
set_source_files_properties (
|
||||
mysqrt.cxx PROPERTIES
|
||||
OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
|
||||
)
|
||||
|
||||
# add the binary tree directory to the search path for include files
|
||||
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
|
||||
|
||||
# add the main library
|
||||
add_library(MathFunctions mysqrt.cxx)
|
||||
|
||||
install_targets (/bin MathFunctions)
|
||||
install_files (/include FILES MathFunctions.h)
|
||||
35
Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
Normal file
35
Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
Normal file
@@ -0,0 +1,35 @@
|
||||
// A simple program that builds a sqrt table
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
double result;
|
||||
|
||||
// make sure we have enough arguments
|
||||
if (argc < 2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// open the output file
|
||||
FILE *fout = fopen(argv[1],"w");
|
||||
if (!fout)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// crate a source file with a table of square roots
|
||||
fprintf(fout,"double sqrtTable[] = {\n");
|
||||
for (i = 0; i < 10; ++i)
|
||||
{
|
||||
result = sqrt(static_cast<double>(i));
|
||||
fprintf(fout,"%g,\n",result);
|
||||
}
|
||||
|
||||
// close the table with a zero
|
||||
fprintf(fout,"0};\n");
|
||||
fclose(fout);
|
||||
return 0;
|
||||
}
|
||||
1
Tests/Tutorial/Step7/MathFunctions/MathFunctions.h
Normal file
1
Tests/Tutorial/Step7/MathFunctions/MathFunctions.h
Normal file
@@ -0,0 +1 @@
|
||||
double mysqrt(double x);
|
||||
44
Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
Normal file
44
Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include "MathFunctions.h"
|
||||
#include "TutorialConfig.h"
|
||||
|
||||
// include the generated table
|
||||
#include "Table.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// a hack square root calculation using simple operations
|
||||
double mysqrt(double x)
|
||||
{
|
||||
if (x <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double result;
|
||||
|
||||
// if we have both log and exp then use them
|
||||
double delta;
|
||||
|
||||
// use the table to help find an initial value
|
||||
result = x;
|
||||
if (x >= 1 && x < 10)
|
||||
{
|
||||
result = sqrtTable[static_cast<int>(x)];
|
||||
}
|
||||
|
||||
// do ten iterations
|
||||
int i;
|
||||
for (i = 0; i < 10; ++i)
|
||||
{
|
||||
if (result <= 0)
|
||||
{
|
||||
result = 0.1;
|
||||
}
|
||||
delta = x - (result*result);
|
||||
result = result + 0.5*delta/result;
|
||||
fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user