如何使用的CMake和Visual Studio运行测试设置PATH环境变量 [英] How to Set Path Environment Variable using CMake and Visual Studio to Run Test

查看:2769
本文介绍了如何使用的CMake和Visual Studio运行测试设置PATH环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的CMake生成Visual Studio项目文件。我想设置PATH环境变量,以便它能够加载所需的dll后运行测试可执行文件。我试着按照讨论的<一个href=\"http://www.mail-archive.com/cmake@cmake.org/msg21493.html\">http://www.mail-archive.com/cmake@cmake.org/msg21493.html但它不工作。

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 required dll. I tried as per the discussion at http://www.mail-archive.com/cmake@cmake.org/msg21493.html but it does not work.

你有没有使用的CMake与Visual Studio为此目的吗?请分享你的经验。

Have you used CMake with Visual Studio for this purpose? Please share your experiences.

另外,我觉得没有简单的方法来调试我的CMake的脚本,例如,看它分配到PATH变量什么价值。 CMake的设置与 CMAKE_VERBOSE_MAKEFILE 长篇大论于事无补。我将如何着手调试它自己?

Also, I find no easy way to debug my CMake script, for example to see what value it assigns to the PATH variable. Setting CMake verbose with CMAKE_VERBOSE_MAKEFILE does not help. How would I go about debugging it myself?

推荐答案

有关从CMake的Visual Studio中设置自定义项目设置,你可以使用XML文件作为可以从CMake的配置模板的<$ C $工作C>。用户文件。

在我的工作中,我们使用它来设置自定义调试参数。

For setting custom project setting in Visual Studio from CMake you can use a XML file as a template which can be configured from CMake to work as the .user file.
At my work we use this to set custom debug parameters.

检查包含在。用户文件的用户设置生成的的.vcproj 文件的目录。下面是一个例子的一个片段,我们使用 UserTemplate.vcproj 文件。

Check the directory containing the generated .vcproj files for the user settings in the .user files. Here is a snippet of an example UserTemplate.vcproj file we use.

<?xml version="1.0" encoding="Windows-1252"?>
  <VisualStudioUserFile
    ProjectType="Visual C++"
    Version="9.00"
    ShowAllFiles="false"
    >
    <Configurations>
    	<Configuration
    		Name="Debug|@USERFILE_PLATFORM@"
    		>
    		<DebugSettings
    			Command="@USERFILE_COMMAND_DEBUG@"
    			WorkingDirectory="@USERFILE_WORKING_DIRECTORY_DEBUG@"
    			CommandArguments="@USERFILE_COMMAND_ARGUMENTS_DEBUG@"
    			Attach="false"
    			DebuggerType="3"
    			Remote="1"
    			RemoteMachine="@USERFILE_REMOTE_MACHINE_DEBUG@"
                            <!-- More settings removed for snippet -->
    		/>
    	</Configuration>
            <!-- Rest of Configurations -->

这种方式可以从注入CMake的任何需要的变量到。用户文件。
在CMake的你可以设置此时,相应的CMake变量(和增加更多的模板文件,如果需要的话)。接下来,你可以做这样的事情配置文件。

This way you can inject any needed variables from CMake into the .user file. In CMake you can set the appropiate CMake variables (and add more in the template file if you need them). Next you can do something like this to configure the file.

# Find user and system name
SET(SYSTEM_NAME $ENV{USERDOMAIN} CACHE STRING SystemName)
SET(USER_NAME $ENV{USERNAME} CACHE STRING UserName)

# Configure the template file
SET(USER_FILE ${_projectName}.vcproj.${SYSTEM_NAME}.${USER_NAME}.user)
SET(OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${USER_FILE})
CONFIGURE_FILE(UserTemplate.user ${USER_FILE} @ONLY)

这篇关于如何使用的CMake和Visual Studio运行测试设置PATH环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆