[CMake] comparing program output / getting path to current build of executable.

Rupert Brooks rupe.brooks at gmail.com
Fri Jul 3 16:26:54 EDT 2009


Hi everyone,

I have a feeling this should be obvious, but i cant figure it out.
Probably im using the wrong keywords to search the mailing list.

What i want to do is add a test (using ADD_TEST, for ctest) that
verifies that my program outputs what it was supposed to output.
CTest, however, expects to use the return value of the program to
determine if the test passed or not.  So, i wrote a simple program to
compare the output of a program, and a text file.  If it matches, it
returns zero, if not, it returns 1.

I end up with an addtest line that would look like this

ADD_TEST(OutputTest  CompareOutput  "PROGRAM  arguments"
"TextFileOfExpectedOutput")

My problem is the PROGRAM part in the above.  I need the path to the
executable that is going to be tested.  In particular, i want to
support build systems like visual studio where theres a subdirectory
(Debug, Release, etc) depending on build type, and systems where there
is not such a subdirectory.  In fact, visual studio is probably the
troublesome one, i think that something like
${CMAKE_CURRENT_BUILD_DIR}/program_name would work on linux.  CTest
has this information internally - since it runs the correct binary
when it runs the test.  But i cant figure out a way to get this
information as an argument to the tested program.

Any suggestions would be appreciated - same goes if theres a better
way to solve the original problem.

Thanks
Rupert B

-- 
--------------------------------------------------------------
Rupert Brooks, Ph. D.

Attaché de recherches | Research Associate
Simulation des Matériaux Déformables | Simulation of Deformable Materials
Institut des matériaux industriels | Industrial Materials Institute
Conseil national de recherches Canada | National Research Council Canada
75, de Mortagne, Boucherville, Québec, Canada, J4B 6Y4
Gouvernement du Canada | Government of Canada


More information about the CMake mailing list