让编译器找到的CMake创建的文件 [英] Getting the compiler to find a Cmake-created file

查看:163
本文介绍了让编译器找到的CMake创建的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C进行 configure_file 命令功能可用性检查所描述的本页。该网页建议使用命令是这样的:

I'm using the configure_file command in Cmake in a feature availability check as described on this page. That page suggests using the command like this:

configure_file(config.h.in config.h)

这将转化 $ {} CMAKE_CURRENT_SOURCE_DIR /config.h.in $ {} CMAKE_CURRENT_BINARY_DIR /config.h 。但是,当我编译我的程序,编译器只查找 $ {CMAKE_CURRENT_SOURCE_DIR} 的头文件(如的config.h ) ,而不是在 $ {CMAKE_CURRENT_BINARY_DIR} 。所以很自然,编译器没有找到的config.h 它被生成,生成失败。

which will translate ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in to ${CMAKE_CURRENT_BINARY_DIR}/config.h. But when I compile my program, the compiler only looks in ${CMAKE_CURRENT_SOURCE_DIR} for headers (e.g. config.h), not in ${CMAKE_CURRENT_BINARY_DIR}. So naturally, the compiler doesn't find config.h where it was generated, and the build fails.

什么是解决这个问题的标准方法?我应该改变的CMakeLists.txt 的config.h 在源代码目录被创建?或者我应该改变它到构建目录添加到包括路径? (真的,为什么我必须在所有使用手动处理?[半反问])

What's the standard way to resolve this issue? Should I change CMakeLists.txt so that config.h gets created in the source directory? Or should I change it to add the build directory to the include path? (And really, why do I have to manually deal with this at all? [semi-rhetorical question])

这个问题涉及了类似的问题,但两个选项都认为是可能的解决方案;我想知道,如果有一个标准的做法,或者如果这表明我失去了一些东西约CMake的是怎样来使用。

This question concerns a similar issue but both options are suggested as possible solutions; I want to know if there's a standard practice, or if this indicates that I'm missing something about how Cmake is meant to be used.

推荐答案

保持你的源代码树'原始'是正确的,不这样做是错误的,如果你想要做多种不同的构建,例如,如果你想能够通过rm'ing build目录(不足够的,如果您正在生成的东西给源代码目录)来清理构建。

Keeping your source tree 'pristine' is right, and not doing so is 'wrong' if you want to do multiple different builds for example, or if you want to be able to clean up a build by rm'ing the build dir (not sufficient if you're generating stuff to the source dir).

生成它在build目录,并添加包含路径。

Generate it in the build dir and add the include path.

设置变量

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)

使自动添加的每个源代码目录的相应build目录,并提出对于其他目标的行为传递的消费(这样不必添加栏的build目录例如明确)。

<一个href=\"http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#build-specification-and-usage-requirements\">http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#build-specification-and-usage-requirements

这篇关于让编译器找到的CMake创建的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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