cmake target_include_directories called with invalid arguments
Asked Answered
D

2

16

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

Delicatessen answered 28/3, 2018 at 15:32 Comment(0)
R
27

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.

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})
Randell answered 28/3, 2018 at 15:40 Comment(0)
T
0

if you use target_include_directories or target_link_libraries, the optional argument is required.

Trim answered 20/4, 2023 at 17:13 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Tejeda

© 2022 - 2024 — McMap. All rights reserved.