如何打印CMakeList /节目包括目录 [英] How to print/show included directories in CMakeList

查看:1311
本文介绍了如何打印CMakeList /节目包括目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立使用CMake的概念项目的一个微不足道的证明,而我很快厌倦了它 - 来,我觉得这可能是一个更好的主意,手工制作我自己该死的Makefile点

I am trying to build a trivial proof of concept project using CMake, and I am rapidly getting tired of it - to the point that I think it may have been a better idea to handcraft my own damn Makefile.

我有一个看起来像这样的目录结构:

I have a directory structure that looks something like this:

project:
    /extproj
    /src/file.cpp
    /include/file1.h

我的CMakeLists.txt文件包含以下部分,这是我,看了CMake的文档,而天真地认为,将指定包括项目目录:

My CMakeLists.txt file contains the following section, which I, having read the CMake documentation, rather naively believed, will be specifying the include directories for the project:

INCLUDE_DIRECTORIES (include/ 
                     extproj/sdk/math/linearalg/ 
                     extproj/sdk/math/nonlinearsolvers/ 
                    )  

我尝试使用下面的命令来构建它

I am trying to build it using the following command

命令$ {CMAKE_CXX_COMPILER} $ {CMAKE_CXX_FLAGS} $ {ALL_SOURCES}

其中, $ {ALL_SOURCES} 是包含所有的C ++文件,我需要编译一个列表变量。我已经验证了这个变量包含正确的文件。

Where ${ALL_SOURCES} is a list variable that contains all the C++ files I need to compile. I have verified that this variable contains the correct files.

我不能然而,我的生活,工作了正在传递什么在地球上的编译器为包括目录。

I can't however, for the life of me, work out what on earth is being passed to the compiler as the include directories.

我在网上搜索,因此使用 get_directory_properties的建议后。我想,当然CMake的立即未能产生Makefile文件,并抱怨:

I searched online, and so a post that recommended using get_directory_properties. I tried that and of course CMake immediately failed to generate the Makefile and complained:

未知的CMake命令get_directory_properties。

当我创建一个Makefile文件,并运行make就可以了,编译器立即barfs,并显示错误消息:

When I create a Makefile and run make on it, the compiler barfs immediately, with the error message:

/path/to/project/src/file1.cpp:1:10:致命错误:'file1.h'文件不
  找到

/path/to/project/src/file1.cpp:1:10: fatal error: 'file1.h' file not found

有什么办法,我可以找出正在使用的地球上的包含路径传递到我的编译器?

Is there ANY WAY, I can find out what on earth is being used as the include paths being passed to my compiler?

推荐答案

我相信编译源文件的正确方法是使用
add_executable(executableName $ {索马里红新月} 。然后加入目录使用 include_directories(...)获得通过编译器自动。

I believe the correct way to compile the source files is using add_executable(executableName ${SRCS}. Then the directories added using include_directories(...) get passed to the compiler automatically.

如果您使用的是自定义命令编译你需要改变你的CMakeLists.txt文件。

If you are using a custom command to compile you need to change your CMakeLists.txt file.

set(MY_INCLUDE_DIRS_FLAGS "-Iinclude/ -Iextproj/sdk/math/linearalg/ -Iextproj/sdk/mat/nonlinearsolvers/")

set(MY_COMPILE_COMMAND ${CMAKE_CXX_COMPILER} ${MY_INCLUDE_DIRS_FLAGS} ${CMAKE_CXX_FLAGS} ${ALL_SOURCES}

这篇关于如何打印CMakeList /节目包括目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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