Skip to content

Commit 1bbcf8c

Browse files
committed
refactor: opencv依赖改为vcpkg编译
1 parent 087fad8 commit 1bbcf8c

File tree

9 files changed

+99
-18
lines changed

9 files changed

+99
-18
lines changed

Diff for: .github/workflows/cmake.yml

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CMake
22

33
on:
44
push:
5-
branches: [ "master", "dev", "dev-*" ]
5+
branches: [ "master", "dev", "dev-*", "refactor-*" ]
66
pull_request:
77
branches: [ "master", "dev" ]
88

@@ -22,14 +22,24 @@ jobs:
2222
steps:
2323
- name: Add MSBuild to PATH
2424
uses: microsoft/[email protected]
25+
26+
- name: setup-vsdevenv
27+
uses: seanmiddleditch/gha-setup-vsdevenv@master
2528

2629
- uses: actions/checkout@v3
2730

28-
- name: Configure CMake
29-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
31+
- name: run-vcpkg
32+
uses: lukka/run-vcpkg@v11
33+
with:
34+
runVcpkgInstall: true
35+
36+
- name: run-cmake
37+
uses: lukka/run-cmake@v10
38+
with:
39+
configurePreset: Release
3040

31-
- name: Build
32-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
41+
- name: build
42+
run: cmake --build build --config ${{ env.BUILD_TYPE }}
3343

3444
- name: Test
3545
working-directory: ${{github.workspace}}/build

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/3rdparty/staticlib/*
77
/resource/old/
88
.vscode
9+
.vscode/settings.json

Diff for: CMakeLists.txt

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1414
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
1515
#=======================================================================================================================
1616
include(cmake/find_onnxruntime.cmake)
17-
include(cmake/find_opencv.cmake)
17+
# include(cmake/find_opencv.cmake)
1818
include(cmake/find_deps.cmake)
19-
set(opencv_dir "${CMAKE_SOURCE_DIR}/deps/opencv" CACHE STRING "opencv dir")
19+
# set(opencv_dir "${CMAKE_SOURCE_DIR}/deps/opencv" CACHE STRING "opencv dir")
2020
set(onnxruntime_dir "${CMAKE_SOURCE_DIR}/deps/onnxruntime" CACHE STRING "onnxruntime dir")
21-
if(NOT EXISTS ${opencv_dir})
22-
message(STATUS "opencv dir not found, auto download deps...")
23-
find_opencv(opencv_dir)
24-
endif()
21+
# if(NOT EXISTS ${opencv_dir})
22+
# message(STATUS "opencv dir not found, auto download deps...")
23+
# find_opencv(opencv_dir)
24+
# endif()
2525
if(NOT EXISTS ${onnxruntime_dir})
2626
message(STATUS "onnxruntime dir not found, auto download deps...")
2727
find_onnxruntime(onnxruntime_dir)
2828
endif()
29-
set(opencv_include_dir "${opencv_dir}/include")
29+
# set(opencv_include_dir "${opencv_dir}/include")
3030
set(onnxruntime_include_dir "${onnxruntime_dir}/include")
3131
#=======================================================================================================================
3232
include(cmake/parse_version.cmake)
@@ -61,8 +61,10 @@ if(NOT EXISTS ${model_rec_dict_file})
6161
set(model_rec_dict_file "not found")
6262
endif()
6363
#=======================================================================================================================
64-
find_static_library(opencv ${opencv_dir})
6564
find_static_library(onnxruntime ${onnxruntime_dir})
65+
# find_static_library(opencv ${opencv_dir})
66+
# find_package(ONNXRuntime REQUIRED)
67+
find_package(OpenCV CONFIG REQUIRED)
6668
#=======================================================================================================================
6769
add_subdirectory(source)
6870
if (BUILD_TEST)

Diff for: CMakePresets.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"version": 2,
3+
"configurePresets": [
4+
{
5+
"name": "vcpkg-base",
6+
"hidden": true,
7+
"generator": "Visual Studio 17 2022",
8+
"binaryDir": "${sourceDir}/build",
9+
"cacheVariables": {
10+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
11+
"VCPKG_TARGET_TRIPLET": "x64-windows-static"
12+
}
13+
},
14+
{
15+
"name": "Debug",
16+
"displayName": "Debug",
17+
"inherits": "vcpkg-base",
18+
"architecture": {
19+
"value": "x64",
20+
"strategy": "external"
21+
},
22+
"cacheVariables": {
23+
"CMAKE_BUILD_TYPE": "Debug"
24+
}
25+
},
26+
{
27+
"name": "Release",
28+
"displayName": "Release",
29+
"inherits": "vcpkg-base",
30+
"architecture": {
31+
"value": "x64",
32+
"strategy": "external"
33+
},
34+
"cacheVariables": {
35+
"CMAKE_BUILD_TYPE": "Release"
36+
}
37+
}
38+
],
39+
"buildPresets": [
40+
{
41+
"name": "Release",
42+
"description": "",
43+
"displayName": "",
44+
"configurePreset": "Release",
45+
"configuration": "Release"
46+
}
47+
]
48+
}

Diff for: resource/version.ver

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.8
1+
0.3.29

Diff for: resource/version_hash.hash

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2b03f72
1+
087fad8

Diff for: source/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ add_library(${BUILD_TARGET_NAME} SHARED)
22
add_library(${BUILD_TARGET_NAME}::ocr ALIAS ${BUILD_TARGET_NAME})
33

44
target_compile_options(${BUILD_TARGET_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
5-
set_target_properties(${BUILD_TARGET_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${WITH_DYNAMIC_DEPS}>:DLL>")
5+
set_target_properties(${BUILD_TARGET_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
66
target_compile_options(${BUILD_TARGET_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/MP>)
77

88
# rc文件
@@ -26,8 +26,9 @@ target_compile_definitions(${BUILD_TARGET_NAME} PRIVATE LIBOCR_NAME="${BUILD_TAR
2626

2727
target_sources(${BUILD_TARGET_NAME} PUBLIC ${include_dir}/libocr/libocr.h PRIVATE ${source_files})
2828

29-
target_include_directories(${BUILD_TARGET_NAME} PRIVATE ${opencv_INCLUDE_DIR} ${onnxruntime_INCLUDE_DIR})
30-
target_link_libraries(${BUILD_TARGET_NAME} PRIVATE ${opencv_LIBRARYS} ${onnxruntime_LIBRARYS})
29+
target_link_libraries(${BUILD_TARGET_NAME} PRIVATE opencv_core opencv_imgcodecs opencv_imgproc)
30+
target_include_directories(${BUILD_TARGET_NAME} PRIVATE ${onnxruntime_INCLUDE_DIR})
31+
target_link_libraries(${BUILD_TARGET_NAME} PRIVATE ${onnxruntime_LIBRARYS})
3132

3233
# 编译完成后,install到install目录
3334
install(TARGETS ${BUILD_TARGET_NAME})

Diff for: vcpkg-configuration.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "28c4ec8670e356d704827a349751c3454156d808",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "artifact",
10+
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11+
"name": "microsoft"
12+
}
13+
]
14+
}

Diff for: vcpkg.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": [
3+
"opencv"
4+
]
5+
}

0 commit comments

Comments
 (0)