mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-22 13:33:40 +00:00
[c-host] restructure project to use cmake
This commit is contained in:
parent
ccd0fd8902
commit
a82b1a2e2f
2
c-host/.gitignore
vendored
Normal file
2
c-host/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build/
|
||||
*.swp
|
63
c-host/CMakeLists.txt
Normal file
63
c-host/CMakeLists.txt
Normal file
@ -0,0 +1,63 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(looking-glass-host C)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
include(FeatureSummary)
|
||||
|
||||
option(OPTIMIZE_FOR_NATIVE "Build with -march=native" ON)
|
||||
if(OPTIMIZE_FOR_NATIVE)
|
||||
CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
|
||||
if(COMPILER_SUPPORTS_MARCH_NATIVE)
|
||||
add_compile_options("-march=native")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
"-Wall"
|
||||
"-Werror"
|
||||
"-Wfatal-errors"
|
||||
"-ffast-math"
|
||||
"-fdata-sections"
|
||||
"-ffunction-sections"
|
||||
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb>"
|
||||
)
|
||||
set(CMAKE_EXE_LINKER FLAGS "-Wl,--gc-sections")
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
execute_process(
|
||||
COMMAND cat ../VERSION
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE BUILD_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
add_definitions(-D BUILD_VERSION='"${BUILD_VERSION}"')
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${CMAKE_BINARY_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/../common
|
||||
${PROJECT_SOURCE_DIR}/../vendor/kvm-guest-drivers-windows
|
||||
${PKGCONFIG_INCLUDE_DIRS}
|
||||
${GMP_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
#link_libraries(
|
||||
#)
|
||||
|
||||
set(SOURCES
|
||||
src/app.c
|
||||
)
|
||||
|
||||
add_subdirectory(platform)
|
||||
|
||||
add_executable(looking-glass-host ${SOURCES})
|
||||
target_link_libraries(looking-glass-host
|
||||
platform
|
||||
)
|
||||
|
||||
install(PROGRAMS ${CMAKE_BINARY_DIR}/looking-glass-host DESTINATION bin/ COMPONENT binary)
|
||||
|
||||
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
|
@ -1,52 +0,0 @@
|
||||
USE_DXGI ?= 1
|
||||
USE_XCB ?= 1
|
||||
|
||||
OUTPUT = looking-glass-host
|
||||
EXT =
|
||||
|
||||
CFLAGS = -std=gnu99 -Wall -Werror
|
||||
CFLAGS += -g -O3
|
||||
CFLAGS += -I.
|
||||
CFLAGS += -I../common
|
||||
|
||||
OBJS = app.o
|
||||
|
||||
# if windows
|
||||
ifdef OS
|
||||
CC = gcc.exe
|
||||
LDFLAGS = -L./windows/dll -mwindows
|
||||
LIBS += -lsetupapi
|
||||
OBJS += windows/platform.o
|
||||
OBJS += windows/windebug.o
|
||||
CFLAGS += -I../vendor/kvm-guest-drivers-windows
|
||||
EXT = .exe
|
||||
|
||||
ifeq ($(USE_DXGI), 1)
|
||||
CFLAGS += -DUSE_DXGI -DCOBJMACROS -DINITGUID
|
||||
LIBS += -ld3d11 -ldxgi
|
||||
DLLS += windows/dll/libd3d11.a
|
||||
OBJS += windows/capture/dxgi.o
|
||||
endif
|
||||
else
|
||||
CC = gcc
|
||||
OBJS += linux/platform.o
|
||||
LIBS += -lpthread
|
||||
|
||||
ifeq ($(USE_XCB), 1)
|
||||
CFLAGS += -DUSE_XCB
|
||||
LIBS += -lxcb -lxcb-shm -lXfixes
|
||||
OBJS += linux/capture/xcb.o
|
||||
endif
|
||||
endif
|
||||
|
||||
all: $(OBJS) $(DLLS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $(OUTPUT)$(EXT) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -v $(OBJS) $(DLLS) $(OUTPUT)$(EXT)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
%.a: %.def
|
||||
dlltool --def $< --output-lib $@
|
@ -25,10 +25,20 @@ Yes, but only when it is feature complete.
|
||||
|
||||
# Why doesn't this use CMake?
|
||||
|
||||
Because win-builds doesn't distribute it, so to make it easy for everyone to compile we do not require it.
|
||||
It does now...
|
||||
~~Because win-builds doesn't distribute it, so to make it easy for everyone to compile we do not require it.~~
|
||||
|
||||
# How do I build it?
|
||||
|
||||
Don't ask if you can't figure it out, this code is the very definition of experiemental and incomplete and should not be in use yet.
|
||||
|
||||
Hint:
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "MSYS Makefiles" ..
|
||||
make
|
||||
```
|
||||
|
||||
_-Geoff_
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
#if defined(USE_DXGI)
|
||||
struct CaptureInterface Capture_DXGI;
|
||||
#endif
|
||||
|
||||
#if defined(USE_XCB)
|
||||
struct CaptureInterface Capture_XCB;
|
||||
#endif
|
||||
|
||||
struct CaptureInterface * CaptureInterfaces[] =
|
||||
{
|
||||
#if defined(USE_DXGI)
|
||||
&Capture_DXGI,
|
||||
#endif
|
||||
#if defined(USE_XCB)
|
||||
&Capture_XCB,
|
||||
#endif
|
||||
NULL
|
||||
};
|
15
c-host/cmake/PostCapture.cmake
Normal file
15
c-host/cmake/PostCapture.cmake
Normal file
@ -0,0 +1,15 @@
|
||||
list(REMOVE_AT CAPTURE 0)
|
||||
list(REMOVE_AT CAPTURE_LINK 0)
|
||||
|
||||
list(LENGTH CAPTURE CAPTURE_COUNT)
|
||||
file(APPEND ${CAPTURE_H} "#define LG_CAPTURE_COUNT ${CAPTURE_COUNT}\n")
|
||||
|
||||
foreach(renderer ${CAPTURE})
|
||||
file(APPEND ${CAPTURE_C} "extern CaptureInterface Capture_${renderer};\n")
|
||||
endforeach()
|
||||
|
||||
file(APPEND ${CAPTURE_C} "\nconst CaptureInterface * CaptureInterfaces[] =\n{\n")
|
||||
foreach(renderer ${CAPTURE})
|
||||
file(APPEND ${CAPTURE_C} " &Capture_${renderer},\n")
|
||||
endforeach()
|
||||
file(APPEND ${CAPTURE_C} " NULL\n};")
|
16
c-host/cmake/PreCapture.cmake
Normal file
16
c-host/cmake/PreCapture.cmake
Normal file
@ -0,0 +1,16 @@
|
||||
set(CAPTURE_H "${CMAKE_BINARY_DIR}/include/dynamic/capture.h")
|
||||
set(CAPTURE_C "${CMAKE_BINARY_DIR}/src/capture.c")
|
||||
|
||||
file(WRITE ${CAPTURE_H} "#include \"interface/capture.h\"\n\n")
|
||||
file(APPEND ${CAPTURE_H} "extern CaptureInterface * CaptureInterfaces[];\n\n")
|
||||
|
||||
file(WRITE ${CAPTURE_C} "#include \"interface/capture.h\"\n\n")
|
||||
file(APPEND ${CAPTURE_C} "#include <stddef.h>\n\n")
|
||||
|
||||
set(CAPTURE "_")
|
||||
set(CAPTURE_LINK "_")
|
||||
function(add_capture name)
|
||||
set(CAPTURE "${CAPTURE};${name}" PARENT_SCOPE)
|
||||
set(CAPTURE_LINK "${CAPTURE_LINK};capture_${name}" PARENT_SCOPE)
|
||||
add_subdirectory(${name})
|
||||
endfunction()
|
13
c-host/platform/CMakeLists.txt
Normal file
13
c-host/platform/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(platform LANGUAGES C)
|
||||
|
||||
if (UNIX)
|
||||
set(PLATFORM "Linux")
|
||||
elseif(WIN32)
|
||||
set(PLATFORM "Windows")
|
||||
endif()
|
||||
|
||||
add_subdirectory(${PLATFORM})
|
||||
|
||||
add_library(platform INTERFACE)
|
||||
target_link_libraries(platform INTERFACE platform_${PLATFORM})
|
22
c-host/platform/Linux/CMakeLists.txt
Normal file
22
c-host/platform/Linux/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(platform_Linux LANGUAGES C)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_library(platform_Linux STATIC
|
||||
src/platform.c
|
||||
)
|
||||
|
||||
add_subdirectory("capture")
|
||||
|
||||
target_link_libraries(platform_Linux
|
||||
capture
|
||||
pthread
|
||||
)
|
||||
|
||||
target_include_directories(platform_Linux
|
||||
PRIVATE
|
||||
src
|
||||
)
|
11
c-host/platform/Linux/capture/CMakeLists.txt
Normal file
11
c-host/platform/Linux/capture/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(capture LANGUAGES C)
|
||||
|
||||
include("PreCapture")
|
||||
|
||||
add_capture("XCB")
|
||||
|
||||
include("PostCapture")
|
||||
|
||||
add_library(capture STATIC ${CAPTURE_C})
|
||||
target_link_libraries(capture ${CAPTURE_LINK})
|
17
c-host/platform/Linux/capture/XCB/CMakeLists.txt
Normal file
17
c-host/platform/Linux/capture/XCB/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(capture_XCB LANGUAGES C)
|
||||
|
||||
add_library(capture_XCB STATIC
|
||||
src/xcb.c
|
||||
)
|
||||
|
||||
target_link_libraries(capture_XCB
|
||||
xcb
|
||||
xcb-shm
|
||||
Xfixes
|
||||
)
|
||||
|
||||
target_include_directories(capture_XCB
|
||||
PRIVATE
|
||||
src
|
||||
)
|
23
c-host/platform/Windows/CMakeLists.txt
Normal file
23
c-host/platform/Windows/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(platform_Windows LANGUAGES C)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_library(platform_Windows STATIC
|
||||
src/platform.c
|
||||
src/windebug.c
|
||||
)
|
||||
|
||||
add_subdirectory("capture")
|
||||
|
||||
target_link_libraries(platform_Windows
|
||||
capture
|
||||
setupapi
|
||||
)
|
||||
|
||||
target_include_directories(platform_Windows
|
||||
PRIVATE
|
||||
src
|
||||
)
|
11
c-host/platform/Windows/capture/CMakeLists.txt
Normal file
11
c-host/platform/Windows/capture/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(capture LANGUAGES C)
|
||||
|
||||
include("PreCapture")
|
||||
|
||||
add_capture("DXGI")
|
||||
|
||||
include("PostCapture")
|
||||
|
||||
add_library(capture STATIC ${CAPTURE_C})
|
||||
target_link_libraries(capture ${CAPTURE_LINK})
|
25
c-host/platform/Windows/capture/DXGI/CMakeLists.txt
Normal file
25
c-host/platform/Windows/capture/DXGI/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(capture_DXGI LANGUAGES C)
|
||||
|
||||
add_library(capture_DXGI STATIC
|
||||
src/dxgi.c
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOBJMACROS -DINITGUID")
|
||||
|
||||
FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "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"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
target_link_libraries(capture_DXGI
|
||||
${PROJECT_BINARY_DIR}/libd3d11.dll
|
||||
dxgi
|
||||
)
|
||||
|
||||
target_include_directories(capture_DXGI
|
||||
PRIVATE
|
||||
src
|
||||
)
|
@ -17,8 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "capture/interface.h"
|
||||
#include "app.h"
|
||||
#include "interface/capture.h"
|
||||
#include "interface/platform.h"
|
||||
#include "debug.h"
|
||||
#include "windows/windebug.h"
|
||||
|
@ -20,9 +20,9 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "interface/platform.h"
|
||||
#include "debug.h"
|
||||
#include "windebug.h"
|
||||
#include "windows/windebug.h"
|
||||
#include "ivshmem/Public.h"
|
||||
|
||||
static HANDLE shmemHandle = INVALID_HANDLE_VALUE;
|
@ -17,7 +17,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "windebug.h"
|
||||
#include "windows/windebug.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void DebugWinError(const char * file, const unsigned int line, const char * function, const char * desc, HRESULT status)
|
@ -17,7 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "app.h"
|
||||
#include "interface/platform.h"
|
||||
#include "interface/capture.h"
|
||||
#include "dynamic/capture.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
@ -26,7 +28,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
#include "locking.h"
|
||||
#include "capture/interfaces.h"
|
||||
#include "KVMFR.h"
|
||||
|
||||
#define ALIGN_DN(x) ((uintptr_t)(x) & ~0x7F)
|
Loading…
Reference in New Issue
Block a user