问题描述
我的项目的目录结构基本上如下:
My project's directory structure is basically as follows:
root/src
根/资产
根/库
我目前已设置CMake来编译源代码,编译库,然后通过从根目录调用make来链接它们.
I currently have CMake set up to compile the source, compile the library, and then link them, by calling make from the root directory.
然后我必须手动将可执行文件移动到原始资产目录中以使其运行,因为它是预期的运行位置(并且我们要在资产中的目录结构进行测试,使其与我们期望的位置接近完成后.)
I then have to manually move the executable into the original assets directory to get it to run, since that's where it expects to be (and we want to test with our directory structure in assets as close to what we expect it to be when it's done).
那么,有什么方法可以告诉CMake自动将编译后的二进制文件粘贴到该目录中,以及将资产复制过来吗?由于我们不进行源代码构建,因此将可执行文件重新粘贴到原始项目源文件的资产文件夹中似乎很奇怪.
So, is there any way to tell CMake to automatically stick the compiled binary in that directory, as well as copy the assets over? Since we're doing out of source builds, sticking the executable back into the original project source's assets folder seems odd.
简而言之,有两个问题:是否有办法使CMake复制资产和代码,是否有办法使CMake将生成的可执行文件复制到构建树中的特定位置?
In short, two questions: Is there any way to get CMake to copy assets as well as code, and is there any way to have it copy the generated executable to a specific location in the build tree?
任何帮助将不胜感激---谢谢!
Any help would be appreciated --- thank you!
推荐答案
下面是一个简单的示例,其中包含类似您的结构:
Here's a simple example with a structure like yours:
- root/src/main.cpp(仅源文件)
- root/assets(我要把可执行文件放到哪里)
这是cmake文件:
PROJECT(HelloCMake)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${HelloCMake_SOURCE_DIR}/assets)
add_executable (HelloCMake src/main.cpp)
当我使用Visual Studio对此进行构建时,我将输出放置在root/assets/debug中.我必须进行挖掘以弄清楚如何摆脱额外的配置文件夹(调试).并非完美,但希望能使您走上正确的轨道.
When I build against this using Visual Studio I get the output placed in root/assets/debug. I'd have to dig to figure out how to get rid of the extra configuration folder (debug). Not perfect, but hopefully that gets you on the right track.
编辑...甚至更好:
INSTALL(TARGETS HelloCMake DESTINATION ${HelloCMake_SOURCE_DIR}/assets)
这篇关于让CMake将生成的二进制文件放入具有资产的特定目录结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!