I am using CMake to generate Visual Studio project files. I want to run the test executable after setting the PATH environment variable so that it is able to load the requir
You can give any options globally with the new VS_USER_PROPS target property (version >= 3.8).
Here is a working example:
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(SetEnvPathTest)
file(WRITE main.cpp [=[
// http://en.cppreference.com/w/cpp/utility/program/getenv
#include
#include
int main()
{
if(const char* env_p = std::getenv("PATH"))
std::cout << "Your PATH is: " << env_p << '\n';
}
]=])
add_executable(${PROJECT_NAME} main.cpp)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.Cpp.user.props" [=[
PATH=C:\Test
PATH=C:\Test
]=])
set_target_properties(
${PROJECT_NAME}
PROPERTIES
VS_USER_PROPS "${PROJECT_NAME}.Cpp.user.props"
)