feat: 切换cmake
将qmake切换成cmake,以符合标准,为单元测试框架做准备 Log: qmake切换成cmake Change-Id: If8f73140b02478849d1794ddc592e17321766788
This commit is contained in:
parent
9d915b7a59
commit
805c18edb3
131
CMakeLists.txt
131
CMakeLists.txt
|
@ -1,5 +1,6 @@
|
|||
#定义需要的cmake版本
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
set(CMD_NAME deepin-ocr)
|
||||
project(deepin-ocr)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
@ -7,83 +8,89 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
|
||||
#先查找到这些qt相关的模块以供链接使用
|
||||
set(QtModule Core Gui Widgets DBus)
|
||||
option(DOTEST "option for test" OFF)
|
||||
add_definitions(-DENABLE_ACCESSIBILITY=1)
|
||||
if(DOTEST)
|
||||
set(QtModule Core Gui Widgets DBus LinguistTools Test)
|
||||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64")
|
||||
set(CMAKE_CXX_FLAGS "-g -fprofile-arcs -ftest-coverage")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer -g -fprofile-arcs -ftest-coverage -lgcov")
|
||||
endif()
|
||||
else()
|
||||
set(QtModule Core Gui Widgets DBus LinguistTools)
|
||||
# 加速编译优化参数
|
||||
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi -z noexecstack")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi -z noexecstack")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-pie")
|
||||
else()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-pie")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
include_directories(${PROJECT_BINARY_DIR})
|
||||
include_directories(${PROJECT_SOURCE_DIR})
|
||||
|
||||
find_package(Qt5 REQUIRED ${QtModule})
|
||||
|
||||
#文件夹包含
|
||||
include_directories(src)
|
||||
aux_source_directory(./src allSource)
|
||||
include_directories(./src/service)
|
||||
include_directories(./src/tessocrutils)
|
||||
include_directories(./src/view)
|
||||
|
||||
aux_source_directory(src allSource)
|
||||
aux_source_directory(src/service allSource)
|
||||
aux_source_directory(src/tessocrutils allSource)
|
||||
aux_source_directory(src/view allSource)
|
||||
|
||||
FILE (GLOB allHeaders
|
||||
./src/mainwindow.h
|
||||
)
|
||||
|
||||
FILE (GLOB allSource
|
||||
./src/mainwindow.cpp
|
||||
set(AllQRC
|
||||
./resource.qrc
|
||||
)
|
||||
|
||||
# 翻译
|
||||
file(GLOB TargetTsFiles LIST_DIRECTORIES false ./translations/${CMD_NAME}*.ts)
|
||||
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)
|
||||
|
||||
|
||||
|
||||
#file(GLOB TS LIST_DIRECTORIES false ./translations/${PROJECT_NAME}*.ts)
|
||||
#set_source_files_properties(${TS}
|
||||
#PROPERTIES OUTPUT_LOCATION ${PROJECT_SOURCE_DIR}/translations)
|
||||
|
||||
#qt5_create_translation(QM ${allSource} ${TS})
|
||||
#set(TS_FILES
|
||||
# ./translations/deepin-ocr_zh_CN.ts
|
||||
## ./translations/deepin-ocr_zh_TW.ts
|
||||
# ./translations/deepin-ocr.ts)
|
||||
#find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} LinguistTools REQUIRED)
|
||||
#qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES} OPTIONS)
|
||||
#qt5_add_translation(qmFiles ${TargetTsFiles})
|
||||
#set_source_files_properties(${qmfiles} PROPERTIES OUTPUT_LOCATION "translations")
|
||||
if (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug"))
|
||||
qt5_create_translation(LangSrcs ${allSource} ${TargetTsFiles}
|
||||
OPTIONS )
|
||||
endif()
|
||||
qt5_add_translation(${TargetTsFiles})
|
||||
set_source_files_properties(${qmfiles} PROPERTIES OUTPUT_LOCATION "translations")
|
||||
|
||||
set(LINK_DIR lib)
|
||||
link_directories(${LINK_DIR})
|
||||
|
||||
add_executable(${PROJECT_NAME} ${allSource} ${AllQRC} ${LangSrcs} )
|
||||
|
||||
add_executable(${PROJECT_NAME} ${allSource} ${allHeaders} "./src/main.cpp")
|
||||
add_compile_definitions(LITE_DIV)
|
||||
|
||||
#------------------添加第三方库begins--------------------------#
|
||||
#使用第三方库需要用到的一个包
|
||||
#检查第三方库,然后取名3rd_lib
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(DtkCore REQUIRED)
|
||||
find_package(DtkWidget REQUIRED)
|
||||
find_package(DtkGui REQUIRED)
|
||||
|
||||
#添加第三方库的所有文件夹路径到工程中来(注意 *_INCLUDE_DIRS)
|
||||
pkg_check_modules(3rd_lib REQUIRED
|
||||
dtkwidget dtkgui
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${3rd_lib_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${3rd_lib_INCLUDE_DIRS} ${DtkWidget_INCLUDE_DIRS})
|
||||
if(DOTEST)
|
||||
target_include_directories(${PROJECT_NAME_TEST} PUBLIC ${3rd_lib_INCLUDE_DIRS} ${DtkWidget_INCLUDE_DIRS})
|
||||
target_include_directories(${PROJECT_NAME_TEST} PUBLIC ${3rd_lib_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${DtkWidget_LIBRARIES}
|
||||
${Qt5Widgets_LIBRARIES}
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} ${3rd_lib_LIBRARIES} lept tesseract)
|
||||
if(DOTEST)
|
||||
target_link_libraries(${PROJECT_NAME_TEST} ${3rd_lib_LIBRARIES} lept tesseract)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
find_package(Qt5LinguistTools REQUIRED)
|
||||
#find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} LinguistTools REQUIRED)
|
||||
file(GLOB TargetTsFiles LIST_DIRECTORIES false ./translations/deepin-ocr.ts)
|
||||
#set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)
|
||||
qt5_create_translation(LangSrcs ${allSource} "ss.ts")
|
||||
qt5_add_translation(${TargetTsFiles})
|
||||
#set_source_files_properties(${qmfiles} PROPERTIES OUTPUT_LOCATION "translations")
|
||||
|
||||
#------------------添加第三方库end--------------------------#
|
||||
qt5_use_modules(${PROJECT_NAME} ${QtModule})
|
||||
if(DOTEST)
|
||||
qt5_use_modules(${PROJECT_NAME_TEST} ${QtModule})
|
||||
endif()
|
||||
|
||||
#将工程与这些模块链接起来
|
||||
qt5_use_modules(${PROJECT_NAME} ${QtModule})
|
||||
|
@ -96,6 +103,7 @@ endif()
|
|||
# ------------------------------- install report script -------------------------------
|
||||
set(PREFIX /usr)
|
||||
set(TranslationDir ${PREFIX}/share/${PROJECT_NAME}/translations/)
|
||||
set(AppIconDir ${PREFIX}/share/icons/hicolor/scalable/apps)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
|
@ -106,3 +114,14 @@ install(TARGETS ${PROJECT_NAME}
|
|||
|
||||
#install
|
||||
install(FILES ${LangSrcs} DESTINATION ${TranslationDir})
|
||||
install(FILES ./assets/appicon_dark.svg DESTINATION ${AppIconDir})
|
||||
|
||||
install(FILES ./com.deepin.Ocr.service DESTINATION ${PREFIX}/share/dbus-1/services)
|
||||
|
||||
install(FILES ./assets/tesslangs/chi_sim.traineddata
|
||||
./assets/tesslangs/chi_tra.traineddata
|
||||
./assets/tesslangs/eng.traineddata
|
||||
./assets/tesslangs/chi_sim_vert.traineddata
|
||||
./assets/tesslangs/chi_tra_vert.traineddata
|
||||
DESTINATION ${PREFIX}/share/deepin-ocr/tesslangs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user