Skip to content

Commit

Permalink
Fix SDL2 include dirs in CMake files (#169)
Browse files Browse the repository at this point in the history
Match those returned by pkg-config
  • Loading branch information
cxong committed Oct 24, 2015
1 parent 80d0faf commit a59269e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/cmake")

find_package(PkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer)
if(NOT ${SDL2_FOUND})
pkg_search_module(SDL2 sdl2)
pkg_search_module(SDL2_IMAGE SDL2_image)
pkg_search_module(SDL2_MIXER SDL2_mixer)
if(NOT "${SDL2_FOUND}")
message("looking for SDL2")
find_package(SDL2 REQUIRED)
endif()
if(NOT ${SDL2_IMAGE_FOUND})
if(NOT "${SDL2_IMAGE_FOUND}")
find_package(SDL2_image REQUIRED)
endif()
if(NOT ${SDL2_MIXER_FOUND})
if(NOT "${SDL2_MIXER_FOUND}")
find_package(SDL2_mixer REQUIRED)
endif()
link_directories(${SDL2_LIBRARY_DIRS} ${SDL2_IMAGE_LIBRARY_DIRS} ${SDL2_MIXER_LIBRARY_DIRS})
Expand Down
16 changes: 8 additions & 8 deletions build/cmake/FindSDL2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL
# SDL2_INCLUDE_DIR, where to find SDL.h
# SDL2_INCLUDE_DIRS, where to find SDL.h
# SDL2_VERSION_STRING, human-readable string containing the version of SDL2
#
# This module responds to the the flag:
Expand Down Expand Up @@ -38,7 +38,7 @@
# See the License for more information.
#=============================================================================

find_path(SDL2_INCLUDE_DIR SDL.h
find_path(SDL2_INCLUDE_DIRS SDL.h
HINTS
ENV SDLDIR
PATH_SUFFIXES include/SDL2 include
Expand All @@ -52,7 +52,7 @@ find_library(SDL2_LIBRARY_TEMP
)

if(NOT SDL2_BUILDING_LIBRARY)
if(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
if(NOT ${SDL2_INCLUDE_DIRS} MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDLmain for compatibility even though they don't
Expand Down Expand Up @@ -124,10 +124,10 @@ if(SDL2_LIBRARY_TEMP)
set(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
endif()

if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
if(SDL2_INCLUDE_DIRS AND EXISTS "${SDL2_INCLUDE_DIRS}/SDL_version.h")
file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}")
Expand All @@ -143,5 +143,5 @@ endif()
include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIRS
VERSION_VAR SDL2_VERSION_STRING)
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(. ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
include_directories(. ${SDL2_INCLUDE_DIRS})

add_subdirectory(cdogs)
add_subdirectory(cdogsed)
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
include_directories(${SDL2_INCLUDE_DIRS})
add_definitions(-DSTATIC)
set(CDOGS_SOURCES
actor_placement.c
Expand Down

0 comments on commit a59269e

Please sign in to comment.