在cmake命令行上指定包含目录 [英] Specifying include directories on the cmake command line
问题描述
运行 cmake
时是否可以指定包含目录。例如
Is it possible to specify an include directory when running cmake
. For example
cmake . -INCLUDE=/foo/bar
头文件位于与我来源不同的目录中喜欢编译,我想补救一下,而不是修补由 cmake
生成的 Makefile
。
The header files are in a separate directory from the sources that I would like to compile, and I would like to remedy this without tinkering with the Makefile
generated by cmake
.
更新
项目确实有 CMakeLists.txt
。摘录:
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/ga)
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src/utils)
可以 $ {EO_SOURCE_DIR}
可以从命令行设置吗?
Can ${EO_SOURCE_DIR}
be set from the command line?
推荐答案
如果你的标题的路径相对于你的来源是固定的,那么你应该能够避免通过命令行传递这个信息。
If the path to your headers is fixed in relation to your sources, then you should be able to avoid having to pass this info via the command line.
说你的项目的目录结构是:
Say your project's directory structure is:
/CMakeLists.txt
/my_sources/main.cpp
/my_sources/foo.cpp
/my_includes/foo.hpp
在你的CMakeLists.txt中,你现在有类似的东西:
and in your CMakeLists.txt, you currently have something like:
add_executable(MyExe my_sources/main.cpp my_sources/foo.cpp)
然后将 / my_includes
文件夹添加到包含搜索路径列表中,您只需要添加以下内容ing:
then to add the /my_includes
folder to the the list of include search paths, you only need to add the following:
include_directories(my_includes)
有关 include_directories
的更多信息,请运行
cmake --help-command include_directories
回答有问题的更新:
是的,使用 -D
命令行选项执行
Yes, using the -D
command line option just do
cmake . -DEO_SOURCE_DIR:PATH=<Path to required dir>
变量 $ {EO_SOURCE_DIR}
被缓存因此,您只需要一次 -D
参数(除非所需的路径发生更改或删除了您的CMakeCache文件等)。
The variable ${EO_SOURCE_DIR}
gets cached as a result of this, so you only need this -D
argument once (unless the required path changes or you delete your CMakeCache file, etc.)
这篇关于在cmake命令行上指定包含目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!