Jelajahi Sumber

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.
rude 12 tahun lalu
induk
melakukan
4c59d385ef
3 mengubah file dengan 31 tambahan dan 2 penghapusan
  1. 10 0
      CMakeLists.txt
  2. 5 1
      libs/SDL2-2.0.0/CMakeLists.txt
  3. 16 1
      src/test.cpp

+ 10 - 0
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
 	$<TARGET_FILE:mpg123>
 	${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/$<TARGET_FILE_NAME:mpg123>)
+
+add_custom_command(TARGET ldeptest POST_BUILD
+	COMMAND ${CMAKE_COMMAND} -E copy
+	$<TARGET_FILE:SDL2>
+	${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/$<TARGET_FILE_NAME:SDL2>)

+ 5 - 1
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 #####

+ 16 - 1
src/test.cpp

@@ -14,6 +14,7 @@
 #include "mpg123.h"
 #include <freetype/config/ftconfig.h>
 #include <freetype/freetype.h>
+#include <SDL.h>
 
 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<vfunc> 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)
 	{