Skip to content

Commit

Permalink
Merge pull request #106 from ludos1978/ReworkingCmakeBuild
Browse files Browse the repository at this point in the history
Reworkingcmakebuild
  • Loading branch information
smasherprog authored Jul 31, 2021
2 parents f9fd1f4 + 2353f39 commit cb8d39e
Show file tree
Hide file tree
Showing 42 changed files with 889 additions and 156 deletions.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bld/
#NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
Expand Down Expand Up @@ -232,4 +232,13 @@ $RECYCLE.BIN/
*.msi
*.msm
*.msp
.vs/*
.vs/*
CMakeFiles
CMakeCache.txt
CTestTestfile.cmake
Makefile
cmake_install.cmake
cmake_uninstall.cmake
CMakeSettings.json
*.dll
*.sh
145 changes: 20 additions & 125 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,142 +1,35 @@
cmake_minimum_required(VERSION 3.8)
project(screen_capture_lite)
cmake_minimum_required(VERSION 3.20)
project(screen_capture_lite_build)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(BUILD_SHARED_LIBS "Build shared library" OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
option(BUILD_EXAMPLE "Build example" ON)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build shared libraries")
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
endif()

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
endif()

if(WIN32)
set(SCREEN_CAPTURE_PLATFORM_SRC
src/windows/GetWindows.cpp
src/windows/GetMonitors.cpp
src/windows/DXFrameProcessor.cpp
include/windows/DXFrameProcessor.h
src/windows/GDIFrameProcessor.cpp
include/windows/GDIFrameProcessor.h
src/windows/GDIMouseProcessor.cpp
include/windows/GDIMouseProcessor.h
src/windows/ThreadRunner.cpp
include/windows/GDIHelpers.h
)
set(SCREEN_CAPTURE_PLATFORM_INC
include/windows
)
add_definitions(-DNOMINMAX)
elseif(APPLE)

set(SCREEN_CAPTURE_PLATFORM_SRC
src/ios/GetWindows.cpp
src/ios/NSMouseCapture.m
include/ios/NSMouseCapture.h
src/ios/NSFrameProcessor.cpp
src/ios/NSFrameProcessor.mm
include/ios/NSFrameProcessorm.h
include/ios/NSFrameProcessor.h
src/ios/NSMouseProcessor.cpp
include/ios/NSMouseProcessor.h
src/ios/CGFrameProcessor.cpp
include/ios/CGFrameProcessor.h
src/ios/GetMonitors.cpp
src/ios/ThreadRunner.cpp
)
set(SCREEN_CAPTURE_PLATFORM_INC
include/ios
)
else()
set(SCREEN_CAPTURE_PLATFORM_SRC
include/linux/X11MouseProcessor.h
src/linux/X11MouseProcessor.cpp
include/linux/X11FrameProcessor.h
src/linux/X11FrameProcessor.cpp
src/linux/GetMonitors.cpp
src/linux/GetWindows.cpp
src/linux/ThreadRunner.cpp
)
find_package(X11 REQUIRED)
if(!X11_XTest_FOUND)
message(FATAL_ERROR "X11 extensions are required, but not found!")
endif()
if(!X11_Xfixes_LIB)
message(FATAL_ERROR "X11 fixes extension is required, but not found!")
endif()
set(SCREEN_CAPTURE_PLATFORM_INC
include/linux
${X11_INCLUDE_DIR}
)
endif()

add_subdirectory(src_cpp)
add_subdirectory(src_csharp)

include_directories(
include
${SCREEN_CAPTURE_PLATFORM_INC}
)
add_library(${PROJECT_NAME}
include/ScreenCapture.h
include/internal/SCCommon.h
include/internal/ThreadManager.h
src/ScreenCapture.cpp
src/SCCommon.cpp
src/ThreadManager.cpp
${SCREEN_CAPTURE_PLATFORM_SRC}
)
if(${BUILD_SHARED_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES DEFINE_SYMBOL SC_LITE_DLL)
if(WIN32)
target_link_libraries(${PROJECT_NAME} ${COMMON_LIBRARIES} Dwmapi)
install (FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)
elseif(APPLE)
find_package(Threads REQUIRED)
find_library(corefoundation_lib CoreFoundation REQUIRED)
find_library(cocoa_lib Cocoa REQUIRED)
find_library(coremedia_lib CoreMedia REQUIRED)
find_library(avfoundation_lib AVFoundation REQUIRED)
find_library(coregraphics_lib CoreGraphics REQUIRED)
find_library(corevideo_lib CoreVideo REQUIRED)

target_link_libraries(
${PROJECT_NAME}
${CMAKE_THREAD_LIBS_INIT}
${corefoundation_lib}
${cocoa_lib}
${coremedia_lib}
${avfoundation_lib}
${coregraphics_lib}
${corevideo_lib}
)
else()
find_package(X11 REQUIRED)
if(!X11_XTest_FOUND)
message(FATAL_ERROR "X11 extensions are required, but not found!")
endif()
if(!X11_Xfixes_LIB)
message(FATAL_ERROR "X11 fixes extension is required, but not found!")
endif()
find_package(Threads REQUIRED)
set(${PROJECT_NAME}_PLATFORM_LIBS
${X11_LIBRARIES}
${X11_Xfixes_LIB}
${X11_XTest_LIB}
${X11_Xinerama_LIB}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(${PROJECT_NAME} ${COMMON_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} dl)
endif()
endif()

install (TARGETS ${PROJECT_NAME}
install (TARGETS screen_capture_lite_static screen_capture_lite_shared
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install (FILES
include/ScreenCapture.h
DESTINATION include
Expand All @@ -155,5 +48,7 @@ endif()
enable_testing()

if (${BUILD_EXAMPLE})
add_subdirectory(Example)
add_subdirectory(Example_CPP)
add_subdirectory(Example_CSharp)
add_subdirectory(Example_Unity)
endif()
24 changes: 20 additions & 4 deletions Example/CMakeLists.txt → Example_CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(screen_capture_example)
project(screen_capture_example_cpp)

if(WIN32)
set(${PROJECT_NAME}_PLATFORM_LIBS Dwmapi)
Expand Down Expand Up @@ -39,9 +39,25 @@ else()
)
endif()

add_executable(${PROJECT_NAME}
include_directories(
../include
)

add_executable(${PROJECT_NAME}_static
lodepng.cpp
Screen_Capture_Example.cpp
)
target_link_libraries(${PROJECT_NAME}_static screen_capture_lite_static ${${PROJECT_NAME}_PLATFORM_LIBS})
add_test (NAME ${PROJECT_NAME}_static COMMAND ${PROJECT_NAME}_static)

add_executable(${PROJECT_NAME}_shared
lodepng.cpp
Screen_Capture_Example.cpp
)
target_link_libraries(${PROJECT_NAME} screen_capture_lite ${${PROJECT_NAME}_PLATFORM_LIBS})
add_test (NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

install (TARGETS ${PROJECT_NAME}_static ${PROJECT_NAME}_shared screen_capture_lite_shared
RUNTIME DESTINATION Examples
)

target_link_libraries(${PROJECT_NAME}_shared screen_capture_lite_shared ${${PROJECT_NAME}_PLATFORM_LIBS})
add_test (NAME ${PROJECT_NAME}_shared COMMAND ${PROJECT_NAME}_shared)
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void createframegrabber()
return mons;
})
->onFrameChanged([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Monitor &monitor) {
// std::cout << "Difference detected! " << img.Bounds << std::endl;
//std::cout << "Difference detected! " << img.Bounds << std::endl;
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions Example_CSharp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
project(screen_capture_lite_example_csharp)

set(OUTPUT ${PROJECT_NAME}.dll)
set(CSPROJ ${PROJECT_NAME}.csproj)

execute_process(COMMAND dotnet --version
RESULT_VARIABLE result
OUTPUT_QUIET
ERROR_QUIET)
if(result)
message(WARNING "CMake failed: dotnet executable not found but by this build. You must install dotnet to generate csharp bindings")
else()
message(STATUS "Found dotnet executable CSHARP bindings will be generated!")
add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:screen_capture_lite_shared> ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:screen_capture_lite_shared> ${CMAKE_BINARY_DIR}/Example_CSharp
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/${CSPROJ}
${CMAKE_BINARY_DIR}/Example_CSharp
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/Program.cs
${CMAKE_BINARY_DIR}/Example_CSharp
COMMAND dotnet build --configuration ${CMAKE_BUILD_TYPE} ${CMAKE_BINARY_DIR}/Example_CSharp/${CSPROJ} -o ${CMAKE_BINARY_DIR}
COMMENT "Building DOTNET Example ${CMAKE_BINARY_DIR}/${OUTPUT}"
)
add_custom_target(${PROJECT_NAME} ALL DEPENDS ${OUTPUT})
add_dependencies(${PROJECT_NAME} screen_capture_lite_csharp)

install (FILES ${CMAKE_BINARY_DIR}/${OUTPUT}
DESTINATION bin
)
install (FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb
DESTINATION bin
OPTIONAL
)

install (TARGETS screen_capture_lite_shared
RUNTIME DESTINATION Examples
)

endif()



105 changes: 105 additions & 0 deletions Example_CSharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;

namespace screen_capture_lite_example_csharp
{
public class Program
{
private static void WriteLine(ref SL.Screen_Capture.Monitor p)
{
Console.WriteLine($"Id = {p.Id} Index = {p.Index} Height = {p.Height} Width = {p.Width} OffsetX = {p.OffsetX} OffsetY= {p.OffsetY} Name= {p.Name}");
}
private static void WriteLine(ref SL.Screen_Capture.Image p)
{
Console.WriteLine($"BytesToNextRow = {p.BytesToNextRow} isContiguous = {p.isContiguous} Bounds.bottom = {p.Bounds.bottom} Bounds.left = {p.Bounds.left} Bounds.right = {p.Bounds.right} Bounds.top = {p.Bounds.top}");
}
static int onNewFramecounter = 0;
static DateTime onNewFramestart = DateTime.Now;
public static SL.Screen_Capture.CaptureConfiguration.ScreenCaptureManager createframegrabber()
{
onNewFramecounter = 0;
onNewFramestart = DateTime.Now;
return SL.Screen_Capture.CaptureConfiguration.CreateCaptureConfiguration(() =>
{
var mons = SL.Screen_Capture.GetMonitors();
Console.WriteLine("Library is requesting the list of monitors to capture!");
for (int i = 0; i < mons.Length; ++i)
{
WriteLine(ref mons[i]);
}
return mons;
}).onNewFrame((ref SL.Screen_Capture.Image img, ref SL.Screen_Capture.Monitor monitor) =>
{
//var newBitmap = new Bitmap(img.Bounds.right - img.Bounds.left, img.Bounds.bottom - img.Bounds.top, img.BytesToNextRow, System.Drawing.Imaging.PixelFormat.Format32bppRgb, img.Data);
//newBitmap.Save($"{onNewFramecounter++}onNewFrame.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
//WriteLine(ref img);
//WriteLine(ref monitor);
if ((DateTime.Now - onNewFramestart).TotalMilliseconds > 1000)
{
Console.WriteLine("onNewFrame fps" + onNewFramecounter);
onNewFramestart = DateTime.Now;
onNewFramecounter = 0;
}
Interlocked.Increment(ref onNewFramecounter);

}).onFrameChanged((ref SL.Screen_Capture.Image img, ref SL.Screen_Capture.Monitor monitor) =>
{
//var newBitmap = new Bitmap(img.Bounds.right - img.Bounds.left, img.Bounds.bottom - img.Bounds.top, img.BytesToNextRow, System.Drawing.Imaging.PixelFormat.Format32bppRgb, img.Data);
//newBitmap.Save($"{onNewFramecounter++}onFrameChanged.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
//WriteLine(ref img);
//WriteLine(ref monitor);
}).start_capturing();
}

public static void Main(string[] args)
{
Console.WriteLine("Starting Capture Demo/Test");
var goodmonitors = SL.Screen_Capture.GetMonitors();
for (int i = 0; i < goodmonitors.Length; ++i)
{
WriteLine(ref goodmonitors[i]);
Debug.Assert(SL.Screen_Capture.isMonitorInsideBounds(goodmonitors, goodmonitors[i]));
}

var badmonitors = SL.Screen_Capture.GetMonitors();
for (int i = 0; i < badmonitors.Length; ++i)
{
badmonitors[i].Height += 1;
WriteLine(ref badmonitors[i]);
Debug.Assert(!SL.Screen_Capture.isMonitorInsideBounds(goodmonitors, badmonitors[i]));
}
for (int i = 0; i < badmonitors.Length; ++i)
{
badmonitors[i].Width += 1;
WriteLine(ref badmonitors[i]);
Debug.Assert(!SL.Screen_Capture.isMonitorInsideBounds(goodmonitors, badmonitors[i]));
}

Console.WriteLine("Running display capturing for 10 seconds");
using (var framgrabber = createframegrabber())
{
System.Threading.Thread.Sleep(10 * 1000);
}

Console.WriteLine("Running display capturing for 1 seconds");
using (var framgrabber = createframegrabber())
{
System.Threading.Thread.Sleep(1 * 1000);
Console.WriteLine("Pausing for 10 seconds.");
framgrabber.pause();
var counti = 0;
while (counti++ < 10)
{
Debug.Assert(framgrabber.isPaused());
Console.Write(" . ");
System.Threading.Thread.Sleep(1 * 1000);
}
Console.WriteLine("Resuming . . . for 5 seconds");
framgrabber.resume();
System.Threading.Thread.Sleep(5 * 1000);
}
}
}
}
Loading

0 comments on commit cb8d39e

Please sign in to comment.