Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building for Windows ARM64 #670

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
8 changes: 4 additions & 4 deletions include/ceccloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "cecc.h"

#include <stdio.h>
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
#include <windows.h>
#include <conio.h>
typedef HINSTANCE libcecc_lib_instance_t;
Expand Down Expand Up @@ -217,7 +217,7 @@ static int libcecc_resolve_all(void* lib, libcec_interface_t* iface)
static libcecc_lib_instance_t libcecc_load_library(const char* strLib)
{
libcecc_lib_instance_t lib;
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
lib = LoadLibrary(strLib ? strLib : "cec.dll");
if (lib == NULL)
printf("failed to load cec.dll\n");
Expand All @@ -235,7 +235,7 @@ static libcecc_lib_instance_t libcecc_load_library(const char* strLib)

static void libcecc_close_library(libcecc_lib_instance_t lib)
{
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
FreeLibrary(lib);
#else
dlclose(lib);
Expand All @@ -244,7 +244,7 @@ static void libcecc_close_library(libcecc_lib_instance_t lib)

static void* libcecc_resolve(void* lib, const char* name)
{
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
return GetProcAddress(lib, name);
#else
return dlsym(lib, name);
Expand Down
2 changes: 1 addition & 1 deletion include/cecloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* http://www.pulse-eight.net/
*/

#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
#include <windows.h>
#include <conio.h>

Expand Down
4 changes: 2 additions & 2 deletions include/cectypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
#include <stdint.h>
#include <string.h>

#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
#define CEC_CDECL __cdecl
#else
#define CEC_CDECL
#endif

#if !defined(DECLSPEC)
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
#include <windows.h>
#if defined DLL_EXPORT
#define DECLSPEC __declspec(dllexport)
Expand Down
2 changes: 1 addition & 1 deletion src/cec-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (NOT WIN32)
endif()
else()
add_definitions(-DTARGET_WINDOWS -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_WINSOCKAPI_)
if (${WIN64})
if ((${WIN64}) OR (${_M_ARM64}))
string(REPLACE "/arch:SSE2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
else()
add_definitions(-D_USE_32BIT_TIME_T)
Expand Down
2 changes: 1 addition & 1 deletion src/cecc-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (NOT WIN32)
endif()
else()
add_definitions(-DTARGET_WINDOWS -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_WINSOCKAPI_)
if (${WIN64})
if ((${WIN64}) OR (${_M_ARM64}))
string(REPLACE "/arch:SSE2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
else()
add_definitions(-D_USE_32BIT_TIME_T)
Expand Down
2 changes: 1 addition & 1 deletion src/libcec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ if (WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcec.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/libcec.rc)
add_definitions(-DDLL_EXPORT)
add_definitions(-DTARGET_WINDOWS -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_WINSOCKAPI_)
if (${WIN64})
if ((${WIN64}) OR (${_M_ARM64}))
string(REPLACE "/arch:SSE2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
else()
add_definitions(-D_USE_32BIT_TIME_T)
Expand Down
4 changes: 3 additions & 1 deletion src/libcec/LibCEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,10 @@ const char *CLibCEC::GetLibInfo(void)
#ifndef LIB_INFO
#ifdef _WIN32
#define FEATURES "'P8 USB' 'P8 USB detect'"
#ifdef _WIN64
#if defined(_WIN64)
#define HOST_TYPE "Windows (x64)"
#elseif defined(_M_ARM64)
#define HOST_TYPE "Windows (ARM64)"
#else
#define HOST_TYPE "Windows (x86)"
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/libcec/cmake/CheckPlatformSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ if(WIN32)
endif()
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM")
set(LIB_INFO "${LIB_INFO} (arm)")
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM64")
set(LIB_INFO "${LIB_INFO} (arm64)")
else()
message(FATAL_ERROR "Unknown architecture id: ${MSVC_C_ARCHITECTURE_ID}")
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/libcec/platform/adl/adl_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct AdapterInfo
int iPresent;
// @}

#if defined (_WIN32) || defined (_WIN64)
#if defined (_WIN32) || defined (_WIN64) || defined(_M_ARM64)
/// \WIN_STRUCT_MEM

/// Exist or not; 1 is exist and 0 is not present.
Expand All @@ -64,7 +64,7 @@ typedef struct AdapterInfo
/// It is generated from EnumDisplayDevices.
int iOSDisplayIndex;
// @}
#endif /* (_WIN32) || (_WIN64) */
#endif /* (_WIN32) || (_WIN64) || (_M_ARM64) */

#if defined (LINUX)
/// \LNX_STRUCT_MEM
Expand Down
24 changes: 12 additions & 12 deletions src/libcec/platform/windows/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;

// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
#if defined(_WIN64) || defined(_M_ARM64) // [
typedef signed __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
#else // _WIN64 || _M_ARM64 ][
typedef _W64 signed int intptr_t;
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
#endif // _WIN64 || _M_ARM64 ]

// 7.18.1.5 Greatest-width integer types
typedef int64_t intmax_t;
Expand Down Expand Up @@ -176,15 +176,15 @@ typedef uint64_t uintmax_t;
#define UINT_FAST64_MAX UINT64_MAX

// 7.18.2.4 Limits of integer types capable of holding object pointers
#ifdef _WIN64 // [
#if defined(_WIN64) || defined(_M_ARM64) // [
# define INTPTR_MIN INT64_MIN
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
#else // _WIN64 ][
#else // _WIN64 || _M_ARM64 ][
# define INTPTR_MIN INT32_MIN
# define INTPTR_MAX INT32_MAX
# define UINTPTR_MAX UINT32_MAX
#endif // _WIN64 ]
#endif // _WIN64 || _M_ARM64 ]

// 7.18.2.5 Limits of greatest-width integer types
#define INTMAX_MIN INT64_MIN
Expand All @@ -193,23 +193,23 @@ typedef uint64_t uintmax_t;

// 7.18.3 Limits of other integer types

#ifdef _WIN64 // [
#if defined(_WIN64) || defined(_M_ARM64) // [
# define PTRDIFF_MIN _I64_MIN
# define PTRDIFF_MAX _I64_MAX
#else // _WIN64 ][
#else // _WIN64 || _M_ARM64 ][
# define PTRDIFF_MIN _I32_MIN
# define PTRDIFF_MAX _I32_MAX
#endif // _WIN64 ]
#endif // _WIN64 || _M_ARM64 ]

#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX

#ifndef SIZE_MAX // [
# ifdef _WIN64 // [
# if defined(_WIN64) || defined(_M_ARM64) // [
# define SIZE_MAX _UI64_MAX
# else // _WIN64 ][
# else // _WIN64 || _M_ARM64 ][
# define SIZE_MAX _UI32_MAX
# endif // _WIN64 ]
# endif // _WIN64 || _M_ARM64 ]
#endif // SIZE_MAX ]

// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
Expand Down
2 changes: 1 addition & 1 deletion support
69 changes: 40 additions & 29 deletions windows/build-all.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ SET RUNTIMEARCH=amd64
IF "%PROCESSOR_ARCHITECTURE%"=="x86" IF "%PROCESSOR_ARCHITEW6432%"=="" (
SET RUNTIMEARCH=x86
)
IF "%PROCESSOR_ARCHITECTURE%"=="arm64" (
SET RUNTIMEARCH=arm64
)
IF "%1" == "" (
SET BUILDARCH=%RUNTIMEARCH%
) ELSE (
Expand Down Expand Up @@ -44,6 +47,11 @@ IF "%4" == "" (
SET DOTNETAPPS=0
)

rem Building .NET applications is not supported on ARM64
if "%BUILDARCH%" == "arm64" (
SET DOTNETAPPS=0
)

SET BUILDPATH=%MYDIR%..\build
SET EXITCODE=1

Expand All @@ -62,43 +70,46 @@ IF %errorlevel% neq 0 (
EXIT /b 1
)

rem Set up the toolchain
rem Set up the toolchain
CALL "%MYDIR%..\support\windows\config\toolchain.cmd" >nul
IF "%TOOLCHAIN_NAME%" == "" (
ECHO.*** Visual Studio toolchain could not be configured for %BUILDARCH% ***
ECHO.
ECHO.See docs\README.windows.md
EXIT /b 2
)

rem Building LibCecSharp isn't supported on ARM64
if not "%BUILDARCH%" == "arm64" (
rem Compile LibCecSharp and LibCecSharpCore
ECHO. * cleaning LibCecSharp and LibCecSharpCore for %BUILDARCH%
"%DevEnvDir%devenv.com" libcec.sln /Clean "%BUILDTYPE%|%BUILDARCHPROJECT%"
ECHO. * compiling LibCecSharp and LibCecSharpCore for %BUILDARCH%
"%DevEnvDir%devenv.com" libcec.sln /Build "%BUILDTYPE%|%BUILDARCHPROJECT%"

rem Create dir for referenced libs and check compilation results
RMDIR /s /q "%MYDIR%..\build\ref" >nul 2>&1
MKDIR "%MYDIR%..\build\ref" >nul
MKDIR "%MYDIR%..\build\ref\netcore" >nul

rem Check and copy LibCecSharp
IF EXIST "%MYDIR%..\build\%BUILDARCH%\LibCecSharp.dll" (
COPY "%MYDIR%..\build\%BUILDARCH%\LibCecSharp.*" "%MYDIR%..\build\ref" >nul
) ELSE (
ECHO. *** failed to build LibCecSharp for %BUILDARCH% ***
PAUSE
EXIT /b 1
)

rem Compile LibCecSharp and LibCecSharpCore
ECHO. * cleaning LibCecSharp and LibCecSharpCore for %BUILDARCH%
"%DevEnvDir%devenv.com" libcec.sln /Clean "%BUILDTYPE%|%BUILDARCHPROJECT%"
ECHO. * compiling LibCecSharp and LibCecSharpCore for %BUILDARCH%
"%DevEnvDir%devenv.com" libcec.sln /Build "%BUILDTYPE%|%BUILDARCHPROJECT%"

rem Create dir for referenced libs and check compilation results
RMDIR /s /q "%MYDIR%..\build\ref" >nul 2>&1
MKDIR "%MYDIR%..\build\ref" >nul
MKDIR "%MYDIR%..\build\ref\netcore" >nul

rem Check and copy LibCecSharp
IF EXIST "%MYDIR%..\build\%BUILDARCH%\LibCecSharp.dll" (
COPY "%MYDIR%..\build\%BUILDARCH%\LibCecSharp.*" "%MYDIR%..\build\ref" >nul
) ELSE (
ECHO. *** failed to build LibCecSharp for %BUILDARCH% ***
PAUSE
EXIT /b 1
)

rem Check and copy LibCecSharpCore
IF EXIST "%MYDIR%..\build\%BUILDARCH%\netcore\LibCecSharpCore.dll" (
COPY "%MYDIR%..\build\%BUILDARCH%\netcore\LibCecSharpCore.*" "%MYDIR%..\build\ref\netcore\." >nul
) ELSE (
ECHO. *** failed to build LibCecSharpCore for %BUILDARCH% ***
PAUSE
EXIT /b 1
)
rem Check and copy LibCecSharpCore
IF EXIST "%MYDIR%..\build\%BUILDARCH%\netcore\LibCecSharpCore.dll" (
COPY "%MYDIR%..\build\%BUILDARCH%\netcore\LibCecSharpCore.*" "%MYDIR%..\build\ref\netcore\." >nul
) ELSE (
ECHO. *** failed to build LibCecSharpCore for %BUILDARCH% ***
PAUSE
EXIT /b 1
)
)

IF %DOTNETAPPS% == 1 (
rem Compile cec-tray and CecSharpTester apps
Expand Down
2 changes: 1 addition & 1 deletion windows/build-lib.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ EXIT /b 0
ECHO.%~dp0 requires 5 parameters
ECHO. %~dp0 [architecture] [type] [vs version] [install path] [project type]
ECHO.
ECHO. architecture: amd64 x86
ECHO. architecture: amd64 x86 arm64
ECHO. build type: Release Debug
ECHO. vs version: Visual Studio version (2019)
ECHO. install path: installation path without quotes
Expand Down
3 changes: 2 additions & 1 deletion windows/visual-studio.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ rem delete old build folder
RMDIR /s /q "%MYDIR%..\build" >nul 2>&1

rem build/generate vs project files
FOR %%T IN (amd64 x86) DO (
FOR %%T IN (amd64 x86 arm64) DO (
CALL "%MYDIR%build-lib.cmd" %%T %BUILDTYPE% %VSVERSION% "%INSTALLPATH%" vs
IF %errorlevel% neq 0 EXIT /b %errorlevel%
)

ECHO Visual Studio solutions can be found in:
ECHO 32 bits: "%MYDIR%..\build\cmake\x86\libcec.sln"
ECHO 64 bits: "%MYDIR%..\build\cmake\amd64\libcec.sln"
ECHO arm64: "%MYDIR%..\build\cmake\arm64\libcec.sln"
ECHO.
ECHO These projects only compile in %BUILDTYPE% mode and have been generated for Visual Studio %VSVERSION%.