fa4e8d
From 473c6f22b469015ad54a1245f7bf9c9096f66591 Mon Sep 17 00:00:00 2001
fa4e8d
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
fa4e8d
Date: Mon, 20 Nov 2017 14:04:25 +0100
fa4e8d
Subject: [PATCH 2/4] Unbundle WiiUse
2791c2
fa4e8d
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2791c2
---
Igor Gnatenko 0460b4
 CMakeLists.txt         |  8 ++--
2791c2
 cmake/FindWiiUse.cmake | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++
Igor Gnatenko 0460b4
 2 files changed, 102 insertions(+), 5 deletions(-)
2791c2
 create mode 100644 cmake/FindWiiUse.cmake
2791c2
2791c2
diff --git a/CMakeLists.txt b/CMakeLists.txt
fa4e8d
index e29cb1336..fc1dcf787 100644
2791c2
--- a/CMakeLists.txt
2791c2
+++ b/CMakeLists.txt
fa4e8d
@@ -185,10 +185,8 @@ include_directories("${PROJECT_SOURCE_DIR}/lib/irrlicht/include")
2791c2
 # (at least on VS) irrlicht will find wiiuse io.h file because
2791c2
 # of the added include directory.
2791c2
 if(USE_WIIUSE)
2791c2
-    if(WIIUSE_BUILD)
2791c2
-        add_subdirectory("${PROJECT_SOURCE_DIR}/lib/wiiuse")
2791c2
-    endif()
Igor Gnatenko 0460b4
-    include_directories("${PROJECT_SOURCE_DIR}/lib/wiiuse")
2791c2
+    find_package(WiiUse REQUIRED)
2791c2
+    include_directories(${WIIUSE_INCLUDE_DIR})
2791c2
 endif()
2791c2
 
Igor Gnatenko 0460b4
 # Set include paths
fa4e8d
@@ -474,7 +472,7 @@ if(USE_WIIUSE)
fa4e8d
             target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/wiiuse.lib)
2791c2
         endif()
2791c2
     else()
2791c2
-        target_link_libraries(supertuxkart wiiuse bluetooth)
2791c2
+        target_link_libraries(supertuxkart ${WIIUSE_LIBRARIES})
2791c2
     endif()
2791c2
     add_definitions(-DENABLE_WIIUSE)
2791c2
 
2791c2
diff --git a/cmake/FindWiiUse.cmake b/cmake/FindWiiUse.cmake
2791c2
new file mode 100644
fa4e8d
index 000000000..2657cbb60
2791c2
--- /dev/null
2791c2
+++ b/cmake/FindWiiUse.cmake
2791c2
@@ -0,0 +1,99 @@
2791c2
+# - try to find WiiUse library
2791c2
+#
2791c2
+# Cache Variables: (probably not for direct use in your scripts)
2791c2
+#  WIIUSE_INCLUDE_DIR
2791c2
+#  WIIUSE_LIBRARY
2791c2
+#
2791c2
+# Non-cache variables you might use in your CMakeLists.txt:
2791c2
+#  WIIUSE_FOUND
2791c2
+#  WIIUSE_INCLUDE_DIRS
2791c2
+#  WIIUSE_LIBRARIES
2791c2
+#  WIIUSE_RUNTIME_LIBRARIES - aka the dll for installing
2791c2
+#  WIIUSE_RUNTIME_LIBRARY_DIRS
2791c2
+#
2791c2
+# Requires these CMake modules:
2791c2
+#  FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
2791c2
+#
2791c2
+# Original Author:
2791c2
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
2791c2
+# http://academic.cleardefinition.com
2791c2
+# Iowa State University HCI Graduate Program/VRAC
2791c2
+#
2791c2
+# Copyright Iowa State University 2009-2010.
2791c2
+# Distributed under the Boost Software License, Version 1.0.
2791c2
+# (See accompanying file LICENSE_1_0.txt or copy at
2791c2
+# http://www.boost.org/LICENSE_1_0.txt)
2791c2
+
2791c2
+set(WIIUSE_ROOT_DIR
2791c2
+	"${WIIUSE_ROOT_DIR}"
2791c2
+	CACHE
2791c2
+	PATH
2791c2
+	"Directory to search for WiiUse")
2791c2
+
2791c2
+if(CMAKE_SIZEOF_VOID_P MATCHES "8")
2791c2
+	set(_LIBSUFFIXES /lib64 /lib)
2791c2
+else()
2791c2
+	set(_LIBSUFFIXES /lib)
2791c2
+endif()
2791c2
+
2791c2
+find_library(WIIUSE_LIBRARY
2791c2
+	NAMES
2791c2
+	wiiuse
2791c2
+	PATHS
2791c2
+	"${WIIUSE_ROOT_DIR}"
2791c2
+	PATH_SUFFIXES
2791c2
+	"${_LIBSUFFIXES}")
2791c2
+
2791c2
+get_filename_component(_libdir "${WIIUSE_LIBRARY}" PATH)
2791c2
+
2791c2
+find_path(WIIUSE_INCLUDE_DIR
2791c2
+	NAMES
2791c2
+	wiiuse.h
2791c2
+	HINTS
2791c2
+	"${_libdir}"
2791c2
+	"${_libdir}/.."
2791c2
+	PATHS
2791c2
+	"${WIIUSE_ROOT_DIR}"
2791c2
+	PATH_SUFFIXES
2791c2
+	include/)
2791c2
+
2791c2
+set(_deps_check)
2791c2
+if(WIN32)
2791c2
+	find_file(WIIUSE_RUNTIME_LIBRARY
2791c2
+		NAMES
2791c2
+		wiiuse.dll
2791c2
+		HINTS
2791c2
+		"${_libdir}"
2791c2
+		"${_libdir}/.."
2791c2
+		PATH_SUFFIXES
2791c2
+		bin)
2791c2
+
2791c2
+	set(WIIUSE_RUNTIME_LIBRARIES "${WIIUSE_RUNTIME_LIBRARY}")
2791c2
+	get_filename_component(WIIUSE_RUNTIME_LIBRARY_DIRS
2791c2
+		"${WIIUSE_RUNTIME_LIBRARY}"
2791c2
+		PATH)
2791c2
+	list(APPEND _deps_check WIIUSE_RUNTIME_LIBRARY)
2791c2
+else()
2791c2
+	set(WIIUSE_RUNTIME_LIBRARY "${WIIUSE_LIBRARY}")
2791c2
+	set(WIIUSE_RUNTIME_LIBRARIES "${WIIUSE_RUNTIME_LIBRARY}")
2791c2
+	get_filename_component(WIIUSE_RUNTIME_LIBRARY_DIRS
2791c2
+		"${WIIUSE_LIBRARY}"
2791c2
+		PATH)
2791c2
+endif()
2791c2
+
2791c2
+include(FindPackageHandleStandardArgs)
2791c2
+find_package_handle_standard_args(WiiUse
2791c2
+	DEFAULT_MSG
2791c2
+	WIIUSE_LIBRARY
2791c2
+	WIIUSE_INCLUDE_DIR
2791c2
+	${_deps_check})
2791c2
+
2791c2
+if(WIIUSE_FOUND)
2791c2
+	set(WIIUSE_LIBRARIES "${WIIUSE_LIBRARY}")
2791c2
+	set(WIIUSE_INCLUDE_DIRS "${WIIUSE_INCLUDE_DIR}")
2791c2
+	mark_as_advanced(WIIUSE_ROOT_DIR)
2791c2
+endif()
2791c2
+
2791c2
+mark_as_advanced(WIIUSE_INCLUDE_DIR
2791c2
+	WIIUSE_LIBRARY
2791c2
+	WIIUSE_RUNTIME_LIBRARY)