Kodi Community Forum

Full Version: Building on Windows - CMake Error Could NOT find hdhomerun (missing: HDHOMERUN_LI ...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What's required to build this add-on on Windows, and then integrate it into a Kodi instance? I'd like to take a stab at fixing a few issues, but I haven't gotten it to build.

I have cloned the repo from https://github.com/kodi-pvr/pvr.hdhomerun.git and attempted to follow the instructions.
I have VS2015 Professional installed (14.0.25431.01 Update 3) and cmake 3.7.2.


In the output from the command-line build is the following text, then report of the error at the very end of the run.

Code:
Building Custom Rule D:/Kodi-Dev/xbmc/cmake/addons/CMakeLists.txt
  CMake does not need to re-run because D:\Kodi-Dev\pvr.hdhomerun\CMakeFiles\ge
  nerate.stamp is up-to-date.
  Creating directories for 'hdhomerun'
  Performing gitconfig step: Disabling autocrlf to enable patching for 'hdhomer
  un'
  fatal: pathspec '.' did not match any files
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targ
ets(171,5): error MSB6006: "cmd.exe" exited with code 128. [D:\Kodi-Dev\pvr.hdh
omerun\hdhomerun.vcxproj]

Using the "ALL_BUILD" target in the IDE shows some errors that may be meaningful:

Code:
8>  -- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
8>  -- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
8>  CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
8>    Could NOT find hdhomerun (missing: HDHOMERUN_LIBRARIES
8>    HDHOMERUN_INCLUDE_DIRS)
8>  Call Stack (most recent call first):
8>    C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
8>    Findhdhomerun.cmake:13 (find_package_handle_standard_args)
8>    CMakeLists.txt:13 (find_package)
8>
8>
8>  -- Configuring incomplete, errors occurred!
8>  See also "D:/Kodi-Dev/pvr.hdhomerun/build/pvr.hdhomerun-prefix/src/pvr.hdhomerun-build/CMakeFiles/CMakeOutput.log".

There aren't any errors in that log file.

Any clues as to what I have missed?
I had a thought that perhaps I should build Kodi first. Kodi built and runs just fine. However, I still get the same error when attempting to build the pvr.hdhomerun.
I think you might need the libhdhomerun sources, or at least the Windows binaries. I'm not sure if the Windows app includes the libraries, but on SD's website you can download the library sources under the Linux downloads; don't worry, it might say they're the Linux libraries, they build on Windows, too. Or, you can get more recent versions on SD's GitHub repo.
Yep, after looking at the pvr.hdhomerun sources, they're looking for hdhomerun.h which is the blanket include file for libhdhomerun. Grab the sources as I mentioned above. You may need to build them first.
Ok, that's helpful. I downloaded the sources, and they have a makefile for gcc. I need to use mingw to compile this with gcc?

What isn't helpful is that the mingw installed by the XBMC build did not include the compiler. I'm going to try to install gcc within this mingw instance. Is that a useful path, or am I going about it all wrong?
Well, installing the compiler in the XMBC MinGW tree didn't happen. The mingw-get.exe program is not installed, so I attempted to apply the (horrible enough) manual process shown at http://www.mingw.org/wiki/howto_install_...iler_suite

The second and third "Files to Get" are 404's. Then I see that the page is from 2008. Doh!

So I downloaded MinGW again and installed it at the preferred location C:\MinGW. I'm missing a bunch of headers, headers that are at <path to>\xbmc\project\BuildDependencies\msys64\mingw32\i686-w64-mingw32\include

I figured why not try a complete hack, and copy the contents of the XBMC MinGW include directory to C:\MinGW\include. And the compilation does get much further, and fails trying to read <net/if.h>. Of course the fix for the hack and for the if.h file is to find the proper MinGW packages to install...

This is the first time that I've tried to use MinGW for anything. I understand wanting to use it for GUI work like Kodi, as the APIs on Windows are really very different from Linux. But it's kicking my butt here.
Um, why do you need a Makefile of any sort. You can easily compile each source file (excepting the "config" one, which is the hdhomerun_config source file), and then just link them all into a shared library. Or modify the Makefile to point to your compiler. Or manually execute each part of the Makefile by yourself, substituting msvc for gcc. Or ...

There are many many ways to do this without mingw/gcc.
Thank you. I think you're absolutely correct.

The problem is that I assumed that the makefile should specify the proper files to compile for Windows, since it explicitly checks for Windows. Well, it does not.

There are two source files that are Windows-specific, and are named *_windows.c instead of *_posix.c. Invoking the MS compiler CL.EXE on each of them not named hdhomerun_config.c or *_posix.c does in fact work. And CL can link them, given the proper additional libraries needed (ws2_32.lib iphlpapi.lib Advapi32.lib User32.lib), and will then produce a DLL.

I write above, "I think" because I still have not attempted to load this DLL into any executable so I am not sure that I have what I need, but I'm definitely further along than before. I need to figure out how to tell cmake where they are (the hdhomerun header files and this DLL), but that's a completely different problem. I'm not a complete cmake novice, but I'm far from an expert.
In addition to the above, of course I needed to specify the 32-bit object format, and define the symbol LIBHDHOMERUN_DLLEXPORT which here adorns the API functions with __declspec(dllexport). That causes the linker to emit a .lib file in addition to the .dll. Here's the build script that I used:

Code:
pushd "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
call vcvarsall.bat amd64_x86
popd

set CFLAGS=/c /O2 /DLIBHDHOMERUN_DLLEXPORT

cl %CFLAGS% hdhomerun_channels.c
cl %CFLAGS% hdhomerun_channelscan.c
cl %CFLAGS% hdhomerun_control.c
cl %CFLAGS% hdhomerun_debug.c
cl %CFLAGS% hdhomerun_device.c
cl %CFLAGS% hdhomerun_device_selector.c
cl %CFLAGS% hdhomerun_discover.c
cl %CFLAGS% hdhomerun_os_windows.c
cl %CFLAGS% hdhomerun_pkt.c
cl %CFLAGS% hdhomerun_sock_windows.c
cl %CFLAGS% hdhomerun_video.c

:: Link command, uses all object files
cl /LD /olibhdhomerun.dll *.obj /link ws2_32.lib iphlpapi.lib Advapi32.lib User32.lib

The next problem was the Findhdhomerun.cmake, to find the headers and library. I added PATHS statements to point to where I put the hdhomerun source and DLL, which did find it. I am not sure how it's supposed to find them, as an environment variable doesn't seem to be used. Then cmake decided that I wanted to find a .DLL file instead of a .LIB file as you need for MSVC.

I included a "set" for Windows, as it does not find the settings. This works for both Windows and Linux. For Windows, the libhdhomerun directory should be beside the pvr.hdhomerun and xbmc directories, and it is found with a relative path.

Code:
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
  pkg_check_modules (HDHOMERUN hdhomerun)
endif()

if(NOT HDHOMERUN_FOUND)
  find_path(HDHOMERUN_INCLUDE_DIRS
            #NAMES hdhomerun.h
            PATHS ${CMAKE_CURRENT_LIST_DIR}/../
            PATH_SUFFIXES hdhomerun libhdhomerun
            NO_DEFAULT_PATH
            )

  find_library(HDHOMERUN_LIBRARIES
            #NAMES libhdhomerun.lib
            PATHS ${CMAKE_CURRENT_LIST_DIR}/../
            PATH_SUFFIXES hdhomerun libhdhomerun
            NO_DEFAULT_PATH
            )


  if ((NOT HDHOMERUN_INCLUDE_DIRS) AND WIN32)
    set(HDHOMERUN_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../libhdhomerun)
  endif()

  if ((NOT HDHOMERUN_LIBRARIES) AND WIN32)
    set(HDHOMERUN_LIBRARIES ${CMAKE_CURRENT_LIST_DIR}/../libhdhomerun/libhdhomerun.lib)
  endif()

  if (HDHOMERUN_INCLUDE_DIRS)
    MESSAGE(STATUS "Found HDHOMERUN_INCLUDE_DIRS at " ${HDHOMERUN_INCLUDE_DIRS})
  else()
    MESSAGE(FATAL_ERROR "Not found HDHOMERUN_INCLUDE_DIRS")
  endif()

  if (HDHOMERUN_LIBRARIES)
    MESSAGE(STATUS "Found HDHOMERUN_LIBRARIES    at " ${HDHOMERUN_LIBRARIES})
  else()
    MESSAGE(FATAL_ERROR "Not found HDHOMERUN_LIBRARIES")
  endif()

endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(hdhomerun DEFAULT_MSG HDHOMERUN_LIBRARIES HDHOMERUN_INCLUDE_DIRS)

mark_as_advanced(HDHOMERUN_INCLUDE_DIRS HDHOMERUN_LIBRARIES)

Edited to change the cmake file, for one that works on both Linux and Windows.
The last piece of getting the PVR to build on Windows is to fix the build instructions. There's a typo, a missing space.

From the instructions:

Code:
cmake -G "Visual Studio 14" -DADDONS_TO_BUILD=pvr.hdhomerun -DCMAKE_BUILD_TYPE=Debug-DADDON_SRC_PREFIX=%ROOT%

I didn't notice the missing space before, after the CMAKE_BULD_TYPE=Debug. Adding this lets cmake find the code. Prior to adding this, it was downloading the pvr.hdhomerun from git again, within the build tree. It's a complete mystery to me as to why this download happens, rather than emitting an error.
Unfortunately, even after the DLL is built and copied to the Kodi tree by the PVR build, it will not load. I will create a new thread.
There's a bit deep in the tree that needs fixing, then cmake will download the code and build it.

The depends/common/hdhomerun/hdhomerun.txt points to the code to download. Pointing it a valid ZIP file from github fixes the build, for both Windows and Linux, using the original Findhdhomerun.cmake file. The original had what looked like a SHA1, I put a tag name, neither was working.

https://github.com/MatthewLundberg/pvr.h...109a23664e