Reputation: 23
I am CMake newbie and trying to use it within a project of mine in order to learn it
The project is a small game engine that use different external libraries such as GLFW, GLUT and SDL2. Some of them such as GL are in my os include directory and some of them such as SDL are inside my source tree (/vendors/SDL2).
I am trying to build the SDL2 library which is a few header files and link it to my project.
After some research I found out that the INTERFACE keyword should be used, this is how I am trying to do it :
add_library(SDL2 INTERFACE)
target_include_directories(SDL2 INTERFACE vendors/SDL2)
And at the end of my CMakeLists :
target_link_libraries(engine INTERFACE SDL2)
But the problem that I have is that I have also other libraries that I build the traditional way (without using the interface keyword) :
find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
set(LIBS_DIR ${OPENGL_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
set(LIBS ${OPENGL_LIBRARIES} ${GLFW_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARIES} SDL2 STB_IMAGE)
target_include_directories(
engine PUBLIC
${LIBS_DIR}
)
target_link_libraries(engine ${LIBS})
Doing that I end up with the following error which I interpret as saying that only a target_link_libraries per project should be used.
The plain signature for target_link_libraries has already been used with the target "engine". All uses of target_link_libraries with a target must be either all-keyword or all-plain.
My question is : how can I link two types of libraries to my project ?
And is my way of building the SDL2 library correct ? I've seen other methods online but this one seemed the simplest one to me
Thanks a lot !
I have also tried to add the SDL2 library to my LIBS value :
set(LIBS ${OPENGL_LIBRARIES} ${GLFW_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARIES} SDL2 STB_IMAGE)
and link it the normal way without using the keyword INTERFACE but I get undefined reference linker errors. In fact the methods that my engine use from the SDL2 libraries seem to be undefined so I guess that the library ha not been lined properly.
Upvotes: 0
Views: 314