cmake target_include_directories called with invalid arguments

杀马特。学长 韩版系。学妹 提交于 2019-12-10 19:12:46

问题


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})

And I get following error:-

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

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


回答1:


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...] ...])

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})

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.

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



来源:https://stackoverflow.com/questions/49538580/cmake-target-include-directories-called-with-invalid-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!