2

I've been trying to use CMake with a project I'm doing in SDL, but am running into some problems. My sdl folder for the libraries etc is located at C:\SDL\SDL-1.2.14. The error states:

Could NOT find SDL (missing:  SDL_LIBRARY SDL_INCLUDE_DIR)  Could NOT find SDLIMAGE (missing:  SDLIMAGE_LIBRARY SDLIMAGE_INCLUDE_DIR)  CMake Error at C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):   Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) Call Stack (most recent call first):   C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)   C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindSDL.cmake:172 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)   CMakeLists.txt:10 (Find_Package)

Here is my CMakeLists.txt file.

Project(SDLExample)
Include(FindSDL)
Include(FindSDL_image)

set(
    SOURCES 
    example.cpp
)

Find_Package(SDL REQUIRED)
Find_Package(SDL_image REQUIRED)

if(NOT SDL_FOUND)
    message( FATAL ERROR "SDL not found!")
endif(NOT SDL_FOUND)

link_libraries(
    ${SDL_LIBRARY}
    ${SDLIMAGE_LIBRARY}
    SDLmain
)

add_executable(
    Example
    WIN32
    MACOSX_BUNDLE
    {$SOURCES}
)

Any ideas?

Edit: I got it to work now by editing fields for the SDL paths in the Windows GUI. The problem is of course I can't find a way to 'backport' this back into the cmake file, so I'd have to re-edit them each time, the generated VS10 file loaded into visual studio, but none of the include paths etc for SDL were correctly loaded into the project, so it won't compile saying it does not know where SDL.h is.

genpfault
  • 51,148
  • 11
  • 85
  • 139
will
  • 1,397
  • 5
  • 23
  • 44
  • Check your CMakeCache.txt file in the build directory where you ran CMake from. There's probably an entry specifying `:PATH=` and one for SDL_image also. You need to add both these variables in an [`include_directories`](http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:include_directories) command. – Fraser May 24 '12 at 02:20
  • Could not find that, but I did add relative paths with include_directories and it worked, so thanks for the help!. Only problem now on windows is, I can compile the program, but the exe requires me to have the SDL dll's in the same directory as itself for it to be able to execute. Is there any way around this to either have the SDL's within the exe itself, or have cmake copy them to the correct directory? – will May 24 '12 at 12:35
  • Maybe [this answer](http://stackoverflow.com/questions/10671916/cmake-how-to-copy-dll-files-into-release-debug-folder/10672739#10672739) could help? – Fraser May 24 '12 at 12:56

1 Answers1

1

You dont need to include the Find<Lib> files. find_package( <Lib> ) finds and uses those files automatically.

If you are on Windows, I think you need to set the SDLDIR environment variable to the folder where the SDL /lib and /include folders are located.

grim
  • 143
  • 1
  • 7