[CMake] setting PYTHONPATH for test

Nils Gladitz nilsgladitz at gmail.com
Sun Jul 30 05:28:34 EDT 2017


On 30.07.2017 03:22, Kris Thielemans wrote:
>
> Hi
>
> I’m trying to add to the PYTHONPATH for a test that uses Python. I do 
> that using set_test_properties. When using the makefile generator, I 
> need to add ${CMAKE_CURRENT_BINARY_DIR}. However, for Visual Studio I 
> also need to add for instance ${CMAKE_CURRENT_BINARY_DIR}/Release.
>
> My current CMakeLists.txt works only on Windows and when building 
> Release mode:
>
> add_test(${name} “${PYTHON_EXECUTABLE}" ${testfile} )
>
>        set_tests_properties ( ${name} PROPERTIES ENVIRONMENT
>
> "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/Release\;${CMAKE_CURRENT_BINARY_DIR}")
>
> I have 2 problems:
>
>   * How do I figure out which configuration is being used?
>     $<TARGET_FILE_DIR:target}> doesn’t seem to work inside
>     set_test_properties (it just gets passed verbatim)
>

Try using the NAME/COMMAND signature of add_test() e.g.
     add_test(NAME ${name} COMMAND “${PYTHON_EXECUTABLE}" ${testfile})

It should enable generator expression processing in test properties.

Nils
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170730/95ff2d19/attachment.html>


More information about the CMake mailing list