[cmake-commits] david.cole committed CMakeLists.txt NONE 1.1
MakeTable.cxx NONE 1.1 MathFunctions.h NONE 1.1 mysqrt.cxx NONE 1.1
cmake-commits at cmake.org
cmake-commits at cmake.org
Thu Nov 8 10:38:28 EST 2007
Update of /cvsroot/CMake/CMake/Tests/Tutorial/Step6/MathFunctions
In directory public:/mounts/ram/cvs-serv25735/Tutorial/Step6/MathFunctions
Added Files:
CMakeLists.txt MakeTable.cxx MathFunctions.h mysqrt.cxx
Log Message:
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.
--- NEW FILE: MathFunctions.h ---
double mysqrt(double x);
--- NEW FILE: mysqrt.cxx ---
#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;
}
--- NEW FILE: CMakeLists.txt ---
# 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)
--- NEW FILE: MakeTable.cxx ---
// 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;
}
More information about the Cmake-commits
mailing list