kodi-game/kodi-game-scripting

Support libretro cores that use CMake

fetzerch opened this issue · 2 comments

Turns out that this is not as easy as it seemed initially.

The libretro cores that are based on CMake have a CMakeLists.txt in the root directory of their repository. They do build the shared library, but they don't install it and they also don't write a CMake config file that would allow us to find the library. It lacks these lines

For other cores we just provide our own CMakeLists.txt, but as HandleDepends.cmake simply overrides the file and therefore we cannot provide our own.

Modifying HandleDepends.cmake to keep both files would probably be difficult. CMake doesn't support a different filename (only CMakeLists.txt) and moving the original file into a subdirectory would break the paths it uses.

Another idea might be to not depend on the installed shared library, but to search it in the build directory. This line would have to be adapted. As we don't really know the build dir, we would have to calculate it based on where the Kodi game addon is built.

What we could do instead is to download the CMakeLists.txt with kodi-game-scripting, append the lines above that install the shared library and create the CMake config file and then generate a patch we commit into the depends directory. This would be picked up by HandleDepends.cmake during the build and it would modify the upstream CMakeLists.txt to our needs.

Currently there are just a handful of libretro cores that are affected, therefore this doesn't have a high priority.

A working patch for thepowdertoy would look like this:

From f21f88356f1f9418576d27f9d2f0e2e2633e8332 Mon Sep 17 00:00:00 2001
From: Christian Fetzer <fetzer.ch@gmail.com>
Date: Fri, 16 Nov 2018 19:45:08 +0100
Subject: [PATCH 1/1] patch: Kodi addon compatibility

---
 CMakeLists.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8bd3a5f..acbe0dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -105,3 +105,10 @@ target_include_directories(data INTERFACE ./data)
 
 include_directories(src)
 add_subdirectory(src)
+
+# install the generated shared library
+install(FILES "$<TARGET_FILE:thepowdertoy_libretro>"
+        DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
+
+# write the config.cmake script
+file(GENERATE OUTPUT ${CMAKE_INSTALL_PREFIX}/libretro-thepowdertoy-config.cmake CONTENT "set(THEPOWDERTOY_LIB ${CMAKE_INSTALL_PREFIX}/lib/$<TARGET_FILE_NAME:thepowdertoy_libretro>)")
+
-- 
2.17.1