Reputation: 30028
I have this line in my CMakeLists.txt:
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
The problem is that WORKING_DIRECTORY
does not seem to be set correctly.
message("Futurama ${PROJECT_SOURCE_DIR}")
It shows that PROJECT_SOURCE_DIR
is what I expect, but when I run my generated VS projects, the work folder is $(ProjectDir)
, and that is wrong since I do the build in a separate folder.
Is it possible that setting of WORKING_DIRECTORY
is broken for the Visual Studio generator?
If not, how can I print the status of WORKING_DIRECTORY
after add_test
?
Upvotes: 3
Views: 6092
Reputation: 18243
There are a few ways you may verify that the WORKING_DIRECTORY
is set properly.
Programmatically (as commented):
get_test_property(${PROJECT_NAME} WORKING_DIRECTORY test_dir)
message("My test's working directory: ${test_dir}")
Inspection:
Navigate to the CTestTestfile.cmake
file in your build folder, and open it in a text editor. You can see in the commands here that the WORKING_DIRECTORY
property is being properly set.
However, the $(ProjectDir)
listed for Working Directory of the RUN_TESTS
Visual Studio project is pointing to a folder in your build directory; this is a Debugging property and isn't actually used when running the CTest tests. This is used when Visual Studio is debugging an executable. Because the RUN_TESTS
project cannot actually be debugged (the CTest tests are actually run as a post-build event), this Working Directory property doesn't apply to your situation.
Upvotes: 1