如何改变可执行文件的输出目录为Win32 builds,在CMake? [英] How to change the executable output directory for Win32 builds, in CMake?
问题描述
我的问题是这样的:
我使用Visual Studio 2010开发一个小解析器。
我使用CMake作为构建配置工具。
但是我发现默认的可执行构建行为,不方便。
我想要的是,我的最终程序位于:
E:/ parsec / bin / exe-name>。< build-type> .exe
,而不是
E:/ parsec / bin /< build-type> /< exe-name>。exe
解决方案p>有几个选项:
- 在建立后复制可执行文件
- 自定义输出目录
一个成功的构建你可以复制可执行文件(见初学者的答案),但也许更适合使用安装目标:
使用install 命令指定目标(可执行文件,库,标题等),这些目标将被复制到< a href =http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable%3aCMAKE_INSTALL_PREFIX> CMAKE_INSTALL_PREFIX 目录。您可以在cmake的命令行(或在cmake GUI中)中指定CMAKE_INSTALL_PREFIX。
自定义可执行文件的输出目录
警告:不建议直接在cmakelists.txt中设置绝对路径。
使用< a href =http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command%3aset_target_properties> set_target_properties 自定义RUNTIME_OUTPUT_DIRECTORY
set_target_properties(yourexe PROPERTIES RUNTIME_OUTPUT_DIRECTORY E:/ parsec / bin /)
href =http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable%3aCMAKE_RUNTIME_OUTPUT_DIRECTORY> CMAKE_RUNTIME_OUTPUT_DIRECTORY 允许您为所有目标指定在cmake项目中。请小心,在您构建DLL时,您也可以修改 CMAKE_LIBRARY_OUTPUT_DIRECTORY 。
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / lib)
其他信息:看看这些问题:
My problem is as such : I'm developing a small parser using Visual Studio 2010. I use CMake as a build configuration tool.
But I find the default executable building behaviour, inconvenient. What I want is, have my final program be located in :
E:/parsec/bin/<exe-name>.<build-type>.exe
rather than
E:/parsec/bin/<build-type>/<exe-name>.exe
How would you do that using CMake ?
解决方案There are several options:
- Copy the executable after building
- Customizing the output-directory for your executable(s)
Copy the executable after building
After a succesful build you can copy the executable (see Beginners answer), but perhaps it is nicer to use an install target:
Use the install command to specify targets (executables, libraries, headers, etc.) which will be copied to the CMAKE_INSTALL_PREFIX directory. You can specify the CMAKE_INSTALL_PREFIX on the commandline of cmake (or in the cmake GUI).
Customizing the output-directory for your executable(s)
Warning: It is not advised to set absolute paths directly in your cmakelists.txt.
Use set_target_properties to customize the RUNTIME_OUTPUT_DIRECTORY
set_target_properties( yourexe PROPERTIES RUNTIME_OUTPUT_DIRECTORY E:/parsec/bin/ )
As an alternative, modifying the CMAKE_RUNTIME_OUTPUT_DIRECTORY allows you to specify this for all targets in the cmake project. Take care that you modify the CMAKE_LIBRARY_OUTPUT_DIRECTORY as well when you build dlls.
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
Additional info: Take a look at these questions:
这篇关于如何改变可执行文件的输出目录为Win32 builds,在CMake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!