Reputation:
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
Upvotes: 16
Views: 23757
Reputation: 1
if you use target_include_directories or target_link_libraries, the optional argument is required.
Upvotes: 0
Reputation: 41770
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})
Upvotes: 27