From 108c7d3aaaa4e5bad279ad01c05a4a3abe8ef940 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 22 May 2019 14:59:19 +1000 Subject: [PATCH] [c-host] fixed project for cross compliation for Win on Linux Thanks @fatalis for your guidance on this --- VERSION | 2 +- c-host/README.md | 20 +++++++++++++++++++ c-host/platform/Windows/CMakeLists.txt | 2 +- .../platform/Windows/capture/CMakeLists.txt | 8 +++++--- .../Windows/capture/DXGI/CMakeLists.txt | 2 +- .../Windows/capture/DXGI/src/dxgi_extra.h | 4 ++++ .../Windows/capture/NVFBC/CMakeLists.txt | 5 +++-- c-host/toolchain-mingw64.cmake | 17 ++++++++++++++++ 8 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 c-host/toolchain-mingw64.cmake diff --git a/VERSION b/VERSION index f0912545..9d8c2ca4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -a12-207-g84b2917706+1 \ No newline at end of file +a12-208-g86f4256b5a+1 \ No newline at end of file diff --git a/c-host/README.md b/c-host/README.md index c1daf212..1256e269 100644 --- a/c-host/README.md +++ b/c-host/README.md @@ -36,6 +36,8 @@ Don't ask if you can't figure it out, this code is the very definition of experi Hint: +### For Windows on Windows + ``` mkdir build cd build @@ -43,6 +45,24 @@ cmake -G "MSYS Makefiles" .. make ``` +### For Linux on Linux + +``` +mkdir build +cd build +cmake .. +make +``` + +### For Windows cross compiling on Linux + +``` +mkdir build +cd build +cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw64.cmake .. +make +``` + ## Where is the log? It is in your user's temp directory: diff --git a/c-host/platform/Windows/CMakeLists.txt b/c-host/platform/Windows/CMakeLists.txt index 0629d675..a1ca4075 100644 --- a/c-host/platform/Windows/CMakeLists.txt +++ b/c-host/platform/Windows/CMakeLists.txt @@ -13,7 +13,7 @@ add_library(platform_Windows STATIC add_subdirectory("capture") -FIND_PROGRAM(WINDRES_EXECUTABLE NAMES "windres.exe" DOC "windres executable") +FIND_PROGRAM(WINDRES_EXECUTABLE NAMES "x86_64-w64-mingw32-windres" "windres.exe" DOC "windres executable") ADD_CUSTOM_COMMAND(TARGET platform_Windows POST_BUILD WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${WINDRES_EXECUTABLE} -i resource.rc -o "${PROJECT_BINARY_DIR}/resource.o" diff --git a/c-host/platform/Windows/capture/CMakeLists.txt b/c-host/platform/Windows/capture/CMakeLists.txt index 409e766e..9c09a638 100644 --- a/c-host/platform/Windows/capture/CMakeLists.txt +++ b/c-host/platform/Windows/capture/CMakeLists.txt @@ -7,10 +7,12 @@ option(USE_NVFBC "Enable NVFBC Support" OFF) option(USE_DXGI "Enable DXGI Support" ON) if(NOT DEFINED NVFBC_SDK) - set(NVFBC_SDK "C:\\Program Files (x86)\\NVIDIA Corporation\\NVIDIA Capture SDK") + set(NVFBC_SDK "C:/Program Files (x86)/NVIDIA Corporation/NVIDIA Capture SDK") endif() - -if(NOT EXISTS "${NVFBC_SDK}\\inc" OR NOT IS_DIRECTORY "${NVFBC_SDK}\\inc") + +file(TO_CMAKE_PATH "${NVFBC_SDK}" nvfbc_sdk) + +if(NOT EXISTS "${nvfbc_sdk}/inc" OR NOT IS_DIRECTORY "${nvfbc_sdk}/inc") message("Disabling NVFBC support, can't find the SDK headers") set(USE_NVFBC OFF) endif() diff --git a/c-host/platform/Windows/capture/DXGI/CMakeLists.txt b/c-host/platform/Windows/capture/DXGI/CMakeLists.txt index 8fc82c4d..11786819 100644 --- a/c-host/platform/Windows/capture/DXGI/CMakeLists.txt +++ b/c-host/platform/Windows/capture/DXGI/CMakeLists.txt @@ -7,7 +7,7 @@ add_library(capture_DXGI STATIC add_definitions("-DCOBJMACROS -DINITGUID") -FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "dlltool.exe" DOC "dlltool executable") +FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "x86_64-w64-mingw32-dlltool" "dlltool" "dlltool.exe" DOC "dlltool executable") ADD_CUSTOM_COMMAND(TARGET capture_DXGI POST_BUILD WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/dll" COMMAND ${DLLTOOL_EXECUTABLE} --def libd3d11.def --output-lib "${PROJECT_BINARY_DIR}/libd3d11.dll" diff --git a/c-host/platform/Windows/capture/DXGI/src/dxgi_extra.h b/c-host/platform/Windows/capture/DXGI/src/dxgi_extra.h index 37de9c74..6e0d8c83 100644 --- a/c-host/platform/Windows/capture/DXGI/src/dxgi_extra.h +++ b/c-host/platform/Windows/capture/DXGI/src/dxgi_extra.h @@ -26,8 +26,10 @@ HRESULT __stdcall CreateDXGIFactory1(REFIID riid, void **factory); #define D3D_FEATURE_LEVEL_12_0 0xc000 #define D3D_FEATURE_LEVEL_12_1 0xc100 +#ifndef __dxgicommon_h__ #define DXGI_ERROR_ACCESS_LOST _HRESULT_TYPEDEF_(0x887A0026L) #define DXGI_ERROR_WAIT_TIMEOUT _HRESULT_TYPEDEF_(0x887A0027L) +#endif enum DXGI_OUTDUPL_POINTER_SHAPE_TYPE { DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME = 1, @@ -188,6 +190,7 @@ typedef struct DXGI_MODE_DESC1 } DXGI_MODE_DESC1; +#ifndef __dxgicommon_h__ typedef enum DXGI_COLOR_SPACE_TYPE { DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 = 0, DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 = 1, @@ -216,6 +219,7 @@ typedef enum DXGI_COLOR_SPACE_TYPE { DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24, DXGI_COLOR_SPACE_CUSTOM = 0xFFFFFFFF } DXGI_COLOR_SPACE_TYPE; +#endif DEFINE_GUID(IID_IDXGIOutput1, 0x00cddea8, 0x939b, 0x4b83, 0xa3,0x40,0xa6,0x85,0x22,0x66,0x66,0xcc); diff --git a/c-host/platform/Windows/capture/NVFBC/CMakeLists.txt b/c-host/platform/Windows/capture/NVFBC/CMakeLists.txt index 7977ac60..601cc651 100644 --- a/c-host/platform/Windows/capture/NVFBC/CMakeLists.txt +++ b/c-host/platform/Windows/capture/NVFBC/CMakeLists.txt @@ -2,11 +2,12 @@ cmake_minimum_required(VERSION 3.0) project(capture_NVFBC LANGUAGES C CXX) add_library(capture_NVFBC STATIC - src/nvFBC.c + src/nvfbc.c src/wrapper.cpp ) -include_directories("${NVFBC_SDK}\\inc") +file(TO_CMAKE_PATH "${NVFBC_SDK}" nvfbc_sdk) +include_directories(file, "${nvfbc_sdk}/inc") target_include_directories(capture_NVFBC PRIVATE diff --git a/c-host/toolchain-mingw64.cmake b/c-host/toolchain-mingw64.cmake new file mode 100644 index 00000000..4256f44d --- /dev/null +++ b/c-host/toolchain-mingw64.cmake @@ -0,0 +1,17 @@ +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) +SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)