My project has a custom target that prepares some files that are later used in a test. The command of the custom target uses a tool that requires some shared libraries to be on the path. I don’t want to force my users to add it to the system path so I looked for a way to add it just for the custom target. My system is Visual Studio 2019 on Windows.
According to the first answer in this SO post the variable CMAKE_MSVCIDE_RUN_PATH is the tool for this. It should add a line set PATH=<path/to/add>;%PATH%
to the custom build step in VS. However it doesn’t seem to work for me–the line is not present. I could add the line manually but since there are many such custom targets, this would be a hassle and would clutter up the code because I’d need to add if (MSVC)
clauses.
I prepared a minimal example. It’d be easier to add it as an attachment but since I’m new user that’s not possible so I paste the code below.
CMakeLists.txt
:
project(msvcide_run_path_example LANGUAGES NONE)
cmake_minimum_required(VERSION 3.20)
enable_testing()
cmake_path(CONVERT "${CMAKE_SOURCE_DIR}/test_prep" TO_NATIVE_PATH_LIST test_prep_path)
set(CMAKE_MSVCIDE_RUN_PATH ${test_prep_path}) # this doesn't work
add_custom_target (test_prep
#COMMAND set "PATH=${test_prep_path};%PATH%" # uncomment this to make it work
COMMAND "test_prep.bat")
add_test(
NAME "my_test"
COMMAND "FC.exe" "test_file1.txt" "test_file2.txt"
)
The tool to prepare the files (test_prep.bat
) is located in subdirectory test_prep
which needs to be added to the path. The contents of the batch file is as follows:
echo test > test_file1.txt
echo test > test_file2.txt