使用无效参数调用的cmake

使用无效参数调用的cmake

本文介绍了使用无效参数调用的cmake target_include_directories的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是cmake的新手。我以前使用过makefile,但是由于QtCreator,我不得不使用cmake。我也在尝试学习glfw。我有以下cmake文件:-

I am preaty new to cmake . I was using makefiles before but due to QtCreator I am forced to use cmake. I am trying to learn glfw as well too. I have following cmake file:-

cmake_minimum_required(VERSION 3.10)

project(untitled)
find_package(glfw3 3.2 REQUIRED)
find_package(OpenGL REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")

target_include_directories(untitled ${OPENGL_INCLUDE_DIR})
target_link_libraries(untitled ${OPENGL_gl_LIBRARY})

我得到以下错误:-

CMakeLists.txt:8: error: target_include_directories called with invalid arguments

我不知道这是什么意思。请帮助我

I have no Idea what does it mean. Please help me

推荐答案

如果您查看CMake文档,将会发现它的用法与您编写的内容有所不同:

If you look at the CMake documentation, you'll see that its usage differ a bit from what you wrote:

target_include_directories(<target> [SYSTEM] [BEFORE]
<INTERFACE|PUBLIC|PRIVATE> [items1...] [<INTERFACE|PUBLIC|PRIVATE>
[items2...] ...])


您会注意到,您错过了非可选参数< INTERFACE | PUBLIC | PRIVATE>

You'll notice that you miss the non optional argument <INTERFACE|PUBLIC|PRIVATE>

您必须指定包含目录的可见性:

You must specify the visibility of the include directory:

target_include_directories(untitled PRIVATE ${OPENGL_INCLUDE_DIR})

如果可执行文件在公共头文件中使用OpenGL头,则将其指定为public,以便链接到它的其他目标也包括OpenGL头。

If your executable uses OpenGL headers in a public header file, specify it as public so other targets that link to it also includes OpenGL headers.

我建议您习惯阅读文档,因为它是编写CMake脚本的最佳工具。

I suggest you to get used to read the documentation, as it will be your best tool writing CMake scripts.

即使它是可选的,也可以针对 target_link_libraries 采取这种形式,强烈建议您这样做:

Even though it's optional, can also take this form for target_link_libraries, which I strongly suggest you do:

target_link_libraries(untitled PUBLIC ${OPENGL_gl_LIBRARY})

这篇关于使用无效参数调用的cmake target_include_directories的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 18:07