[CMake] How to "install" then "test"?

Eric Noulard eric.noulard at gmail.com
Thu Dec 29 14:47:25 EST 2011


2011/12/29 Denis Scherbakov <denis_scherbakov at yahoo.com>:
> Dear All!
>
> Maybe someone can help me: I have a project, we compile binaries and then
> using various INSTALL directives finish the job by copying files where they
> belong: to "bin", "man", "libexec", etc. The point is, we need to run executables after they got installed into this tree, because otherwise
> they won't find all auxiliary files during runtime.

What do you mean by "auxiliary files" ?

If auxiliary files are shared libs they should be found just fine for
the executable in the build tree
(see http://www.vtk.org/Wiki/CMake_RPATH_handling)

Moreover add_test accepts "$<...>".  generator expressions
which may helps you to specify complete path to files produced by your build.

> So I am really missing the point here: how to install files (to a temporary
> directory, for example) and then run various tests? Maybe someone has ideas...

In any case,
if you want to install to a temp dir you can use a custom command/target
which use DESTDIR, like in

make DESTDIR=/tmp install
(I suppose you use Makefile generator in this case)

You can suppose that the user/developer should (explicitely) call some
custom target
add_custom_target(TempInstall ${CMAKE_BUILD_TOOL}
DESTDIR=${CMAKE_BINARY_DIR}/tempInstall
                             COMMENT "Install to temporary location
for testing purpose")

that will install the needed file in a temps location and then use a
"test driver" programs or scripts
which may be informed of the temp install dir
add_test(NAME mytest1
              COMMAND testDriver --tmp-install-dir
"${CMAKE_BINARY_DIR}/tempInstall" --test=test1)

add_test(NAME mytest2
              COMMAND testDriver --tmp-install-dir
"${CMAKE_BINARY_DIR}/tempInstall" --test=test2)

testDriver may itself be built/created by your build process.

with this you have to do:

make TempInstall
make test

in order to run the test properly.

It would be nice to have a way to make "test" depends on "TempInstall"
but I do not know
a way to do that: http://public.kitware.com/Bug/view.php?id=8438

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list