I have a project that uses a third-party library and I’ve written unit tests and added them to my test suite via gtest_discover_tests, but in order to successfully build the test target in VS I need to add the path to the third-party DLL to the PATH environment variable before running the unit test executable.
I’ve tried to use ENVIRONMENT_MODIFICATION to append to the PATH environment variable, but it doesn’t seem to do anything. I’ve tried to add a script to the TEST_INCLUDE_FILES to append to the PATH environment variable, and that doesn’t seem to do anything either. I can see the commands that in the POST_BUILD event of the test target in my solution that invokes my unit test, but the target won’t successfully “build” in MSVS without some workaround. I have several workarounds, but they’re not ideal:
I could add the path to the third-party DLL to my system environment variables before running MSVS, but the idea is that I’m using CMake to find/specify the location of the third-party library so that my project is more “portable” to other members of my team. The way the third-party library is supplied or installed may differ for other those users. I’d prefer not to have to change my system environment just so that this test case can succeed.
I can manually edit the POST_BUILD event command line and append to the PATH environment variable right after the “setlocal” command and right before the call to “cmake … -P GoogleTestAddTests.cmake” line after the MSVS solution is generated by CMake. The solution builds fine this way, but it’s annoying that CMake both knows where that third-party DLL is located (since it had to link to it), but I’m unable to inject the PATH line programmatically to the generated commands.
I can write a shell script that appends the path to the DLL to the PATH environment variable and invoke MSBUILD on the solution and everything works fine, but this solution is less friendly to other users who prefer to interact with the solution using the MSVS IDE.
Is there a better way to accomplish this?