From 4c59d385efa31ba47c575d35b02e82239efda5c5 Mon Sep 17 00:00:00 2001 From: rude Date: Wed, 25 Sep 2013 20:26:58 +0200 Subject: [PATCH] Add SDL2 to main CMakeLists.txt. Also expose SDL_LINK_DIR. This is required because the main target inherits some of SDL2 extra dependcies (DirectX) for some reason. --- CMakeLists.txt | 10 ++++++++++ libs/SDL2-2.0.0/CMakeLists.txt | 6 +++++- src/test.cpp | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3922e357..cef2dc64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ set(DEP_LIBOGG_VER "1.3.1") set(DEP_LIBVORBIS_VER "1.3.3") set(DEP_MPG123_VER "1.15.3") set(DEP_FREETYPE_VER "2.5.0.1") +set(DEP_SDL2_VER "2.0.0") set(SKIP_INSTALL_ALL TRUE) @@ -34,7 +35,9 @@ add_subdirectory("libs/libogg-${DEP_LIBOGG_VER}" ${CMAKE_BINARY_DIR}/libogg) add_subdirectory("libs/libvorbis-${DEP_LIBVORBIS_VER}" ${CMAKE_BINARY_DIR}/libvorbis) add_subdirectory("libs/mpg123-${DEP_MPG123_VER}" ${CMAKE_BINARY_DIR}/mpg123) add_subdirectory("libs/freetype-${DEP_FREETYPE_VER}" ${CMAKE_BINARY_DIR}/freetype) +add_subdirectory("libs/SDL2-${DEP_SDL2_VER}" ${CMAKE_BINARY_DIR}/SDL2) +link_directories(${SDL_LINK_DIR}) add_executable(ldeptest src/test.cpp) target_link_libraries(ldeptest zlibstatic @@ -47,9 +50,16 @@ target_link_libraries(ldeptest vorbisfile-static mpg123 freetype-static + SDL2 + SDL2main ) add_custom_command(TARGET ldeptest POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/$/$) + +add_custom_command(TARGET ldeptest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_CURRENT_BINARY_DIR}/$/$) diff --git a/libs/SDL2-2.0.0/CMakeLists.txt b/libs/SDL2-2.0.0/CMakeLists.txt index 925392eb..857790ba 100644 --- a/libs/SDL2-2.0.0/CMakeLists.txt +++ b/libs/SDL2-2.0.0/CMakeLists.txt @@ -756,7 +756,9 @@ elseif(WINDOWS) if(HAVE_D3D_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H) set(HAVE_DIRECTX TRUE) # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks - link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH}) + set(SDL_LINK_DIR $ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH}) + set(SDL_LINK_DIR ${SDL_LINK_DIR} PARENT_SCOPE) + link_directories(${SDL_LINK_DIR}) include_directories($ENV{DXSDK_DIR}\\Include) endif() set(CMAKE_REQUIRED_FLAGS) @@ -1159,6 +1161,7 @@ if(SDL_SHARED) endif(UNIX) set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS}) target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) + target_include_directories(SDL2 PUBLIC include) endif(SDL_SHARED) if(SDL_STATIC) @@ -1168,6 +1171,7 @@ if(SDL_STATIC) # libraries - do we need to consider this? set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS}) target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) + target_include_directories(SDL2-static PUBLIC include) endif(SDL_STATIC) ##### Installation targets ##### diff --git a/src/test.cpp b/src/test.cpp index f0b82119..bdb4434a 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -14,6 +14,7 @@ #include "mpg123.h" #include #include +#include extern "C" { # include "lua.h" @@ -30,7 +31,7 @@ std::string pad(std::string s, size_t size = 16) return s; } -int main(int argc, const char **argv) +int main(int argc, char **argv) { vfunc zlib = [](strs &c, strs &l) { @@ -117,6 +118,19 @@ int main(int argc, const char **argv) return "freetype"; }; + vfunc SDL2 = [](strs &c, strs &l) + { + SDL_version compiled; + SDL_version linked; + + SDL_VERSION(&compiled); + SDL_GetVersion(&linked); + + c << (int)compiled.major << "." << (int)compiled.minor << "." << (int)compiled.patch; + l << (int)linked.major << "." << (int)linked.minor << "." << (int)linked.patch; + return "SDL2"; + }; + std::vector funcs; funcs.push_back(zlib); funcs.push_back(physfs); @@ -128,6 +142,7 @@ int main(int argc, const char **argv) funcs.push_back(vorbisfile); funcs.push_back(mpg123); funcs.push_back(freetype); + funcs.push_back(SDL2); for (size_t i = 0; i < funcs.size(); ++i) {