Ask Your Question
0

How to add SDL2 library in cmake

asked 2017-01-30 11:56:09 -0600

Cayero gravatar image

updated 2017-01-30 11:56:34 -0600

Hi I would like to add SDL2 library with headers to cmake. How can do that?? I'm new in ROS. I've tried something like this

include_directories(
include ${SDL2_INCLUDE_DIRS}
include ${catkin_INCLUDE_DIRS}
)

Could anyone help me? I would be very grateful

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-08-11 08:05:15 -0600

lucasw gravatar image

updated 2018-08-11 08:32:08 -0600

I have an example here: https://github.com/lucasw/sdl2_ros/bl... There is very little ros in it other than using cmake within catkin and ros params and info messages.

The two problems I encountered (only trying the mixer library) were that newer versions of CMake don't like spaces at the end of lists of libraries and that SDL2_mixer doesn't have a cmake file to find it, though SDL2 itself does:

find_package(SDL2 REQUIRED)
# https://stackoverflow.com/questions/45730098/cmake-leading-or-trailing-whitespace-policy-cmp0004
string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES)
# No FindSDL2_mixer.cmake in Ubuntu 16.04?
# find_package(SDL2_mixer REQUIRED)
# Use pkg-config instead
find_package(PkgConfig)
# Using an underscore like SDL2_mixer doesn't work
pkg_check_modules(SDL2mixer REQUIRED SDL2_mixer)

include_directories(
  ${SDL2_INCLUDE_DIRS}
  ${SDL2mixer_INCLUDE_DIRS}
  ${catkin_INCLUDE_DIRS}
)

add_executable(sdl2_mixer src/sdl2_mixer.cpp)

target_link_libraries(sdl2_mixer
  ${SDL2_LIBRARIES}
  ${SDL2mixer_LIBRARIES}
  ${catkin_LIBRARIES}
)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-01-30 11:56:09 -0600

Seen: 540 times

Last updated: Aug 11 '18