[CMake] set CTEST_ENVIRONMENT from within CMakeLists.txt?

Roland Bock rbock at eudoxos.de
Thu Sep 10 08:16:31 EDT 2009


Hi,

that's good news for the future.

In the meantime, I have created a workaround that does the trick for the 
tests in my current project (and until CMake2.8).

#-----------------------------
# M_ADD_LOCAL_TEST
#
# Parameters:
# name of the test
# command string (including all parameters)
# additional environment settings string (optional)
#-------------------------------
MACRO (M_ADD_LOCAL_TEST name command)
   ADD_TEST(${name}
          "bash"
          "-c"
          "foo=\"bar\" ${ARGN} ${CMAKE_CURRENT_BINARY_DIR}/${command}")
ENDMACRO ()
#-------------------------------

For instance

M_ADD_LOCAL_TEST(test1
    "myTestProgram"
    --verbose" "LD_LIBRARY_PATH=/usr/local/myProject/lib")

Thanks and regards,

Roland

David Cole wrote:
> CTEST_ENVIRONMENT cannot be used from within CMakeLists.txt -- it is a 
> "ctest -S script" only variable...
> 
> To do what you want, you will have to use CVS CMake, or wait until CMake 
> 2.8 and then use the ENVIRONMENT test property.
> 
> With CVS or the upcoming CMake 2.8, after calling ADD_TEST in your 
> CMakeLists.txt file, you can do:
>   set_property(TEST TestName PROPERTY
>     ENVIRONMENT "CMAKE_ENVIRONMENT_TEST_VAR=Happy Thanksgiving!"
>   )
> 
> 
> HTH,
> David
> 
> 
> On Wed, Sep 9, 2009 at 12:04 PM, Roland Bock <rbock at eudoxos.de 
> <mailto:rbock at eudoxos.de>> wrote:
> 
>     Hi,
> 
>     I would like to set some environment variables for ctest which are
>     set when I call
> 
>     make test
> 
>     but not when I call
> 
>     make foo
> 
> 
>     I have read that in a ctest script, I can do this by
> 
>     SET (CTEST_ENVIRONMENT "foo=bar")
> 
>     But the same line does not seem to have any effect when I put it in
>     my CMakeLists.txt file. Any ideas? Or is this a 2.6 feature (I am
>     still using cmake 2.4 on Ubuntu-8.04 64bit)?
> 
> 
>     Thanks and regards,
> 
>     Roland
> 
>     _______________________________________________
>     Powered by www.kitware.com <http://www.kitware.com>
> 
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
> 
>     Please keep messages on-topic and check the CMake FAQ at:
>     http://www.cmake.org/Wiki/CMake_FAQ
> 
>     Follow this link to subscribe/unsubscribe:
>     http://www.cmake.org/mailman/listinfo/cmake
> 
> 


More information about the CMake mailing list