[CMake] ADD_TEST command path

Brad King brad.king at kitware.com
Tue May 10 09:07:56 EDT 2005


Sylvain Prat wrote:
> I'm trying to setup a (working hehe) test program with an ADD_TEST command but I do not have yet succeed to have 0 errors with the run_test target. The problem is related to the dynamically linked dll used by the program, for an out-source build with Visual C++. Here are my interrogations and suggestions :
> 
> 1. Why is the test program launched from the build_dir instead of the executable_dir ?

The working directory is the build tree directory corresponding to the 
source tree directory where the ADD_TEST command was invoked.

 > This behavior, which IMHO is not really intuitive, causes me a 
headache since I wanted to load some dynamically linked librairies 
(parts of the whole project) from the executable/library directory. I 
solved the problem right now (using argv[0]), but I think it should be 
documented at least.

On Windows the directory containing the executable should be searched 
for the needed DLLs automatically.  The working directory is a 
last-resort place to look.  Is your executable not next to its DLLs?

> 2. Does CTest use the PATH environment variable when launching the executable ? It seems not since my program is not able to load some dlls (not in the executable dir but in the system path) when run from the run_test target, but work when run from the command line ! What's the problem here ?

The PATH environment variable is used, but the behavior you are seeing 
is actually due to a Visual Studio "feature".  When VS launches 
processes to build its targets it does so in its own environment.  This 
environment contains a PATH that includes the VS compiler directories 
and such.  It also includes the system PATH that was in place WHEN VS 
WAS INSTALLED.  For some reason it does not update this PATH each time 
it runs.  This is why it works when you run ctest from the command line 
but not from the RUN_TESTS target.

-Brad


More information about the CMake mailing list