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