Skip to content

Instantly share code, notes, and snippets.

@wldomiciano wldomiciano/FindSDL2.cmake
Last active Aug 30, 2018

Embed
What would you like to do?
Only a custom CMake find module for SDL 2 in development stage
set(SDL2_SEARCH_PATHS "$ENV{SDL2_HOME}/SDL2")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if(MINGW)
set(PATH_SUFFIXES "x86_64-w64-mingw32/bin" "x86_64-w64-mingw32/lib" "x86_64-w64-mingw32/include/SDL2")
elseif(WIN32)
set(PATH_SUFFIXES "lib/x64" "include")
endif()
else()
if(MINGW)
set(PATH_SUFFIXES "i686-w64-mingw32/bin" "i686-w64-mingw32/lib" "i686-w64-mingw32/include/SDL2")
elseif(WIN32)
set(PATH_SUFFIXES "lib/x86" "include")
endif()
endif()
find_path(SDL2_INCLUDE_DIR "SDL.h"
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS})
find_library(SDL2_LIBRARY "SDL2"
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS})
find_library(SDL2MAIN_LIBRARY "SDL2main"
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS})
function(MOVE_DLLS MY_PATH)
find_path(TEST_${MY_PATH} "${MY_PATH}.dll"
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS})
file(COPY ${TEST_${MY_PATH}}/ DESTINATION ${CMAKE_BINARY_DIR} FILES_MATCHING PATTERN "*.dll")
message("\n\nArquivo: ${MY_PATH}\nCaminho: ${TEST_${MY_PATH}}\nSearch: ${SDL2_SEARCH_PATHS}\n\n")
endfunction()
MOVE_DLLS("SDL2")
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
foreach(COMPONENT ${SDL2_FIND_COMPONENTS})
list(APPEND SDL2_SEARCH_PATHS "$ENV{SDL2_HOME}/SDL2_${COMPONENT}")
find_path(SDL2_${COMPONENT}_INCLUDE_DIR "SDL_${COMPONENT}.h"
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS})
find_library(SDL2_${COMPONENT}_LIBRARY "SDL2_${COMPONENT}"
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS})
MOVE_DLLS("SDL2_${COMPONENT}")
list(APPEND SDL2_INCLUDE_DIRS ${SDL2_${COMPONENT}_INCLUDE_DIR})
list(APPEND SDL2_EXTRA_LIBRARIES ${SDL2_${COMPONENT}_LIBRARY})
endforeach()
find_package(Threads)
set(SDL2_LIBRARIES ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${SDL2_EXTRA_LIBRARIES})
if(MINGW)
set(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
set(SDL2_LIBRARIES ${MINGW32_LIBRARY} ${SDL2_LIBRARIES})
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARIES SDL2_INCLUDE_DIRS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.