修改CMake添加install和deploy文件
This commit is contained in:
@@ -98,7 +98,7 @@ set(TOUCHSENSOR_HEADERS
|
||||
|
||||
qt6_add_resources(APP_RESOURCES resources.qrc)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
add_executable(${PROJECT_NAME} WIN32
|
||||
${COMPONENT_SOURCES}
|
||||
${UTILITY_SOURCES}
|
||||
${TOUCHSENSOR_HEADERS}
|
||||
@@ -136,3 +136,71 @@ if(BUILD_EXAMPLE)
|
||||
target_link_libraries(cpstream_demo PRIVATE serial)
|
||||
target_link_libraries(cpstream_demo PRIVATE setupapi)
|
||||
endif()
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/deploy" CACHE PATH "" FORCE)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS
|
||||
touchsensor
|
||||
creeper-qt
|
||||
qcustomplot
|
||||
RUNTIME DESTINATION .
|
||||
LIBRARY DESTINATION .
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
|
||||
if(BUILD_EXAMPLE)
|
||||
install(TARGETS cpstream_demo
|
||||
RUNTIME DESTINATION .
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# 利用 QtCore 目标找到 Qt bin 目录
|
||||
get_target_property(_qt_core_location ${QT_VERSION}::Core LOCATION)
|
||||
get_filename_component(_qt_bin_dir "${_qt_core_location}" DIRECTORY)
|
||||
|
||||
find_program(WINDEPLOYQT_EXECUTABLE
|
||||
NAMES windeployqt windeployqt.exe
|
||||
HINTS "${_qt_bin_dir}"
|
||||
)
|
||||
|
||||
if(WINDEPLOYQT_EXECUTABLE)
|
||||
message(STATUS "Found windeployqt: ${WINDEPLOYQT_EXECUTABLE}")
|
||||
|
||||
# 安装完之后,对 deploy/touchsensor.exe 跑 windeployqt
|
||||
install(CODE
|
||||
"execute_process(
|
||||
COMMAND \"${WINDEPLOYQT_EXECUTABLE}\"
|
||||
--dir \"${CMAKE_INSTALL_PREFIX}\"
|
||||
--no-translations
|
||||
\"${CMAKE_INSTALL_PREFIX}/touchsensor.exe\"
|
||||
RESULT_VARIABLE _windeployqt_result
|
||||
)
|
||||
if(NOT _windeployqt_result EQUAL 0)
|
||||
message(FATAL_ERROR \"windeployqt failed with exit code: \${_windeployqt_result}\")
|
||||
endif()"
|
||||
)
|
||||
else()
|
||||
message(WARNING "windeployqt not found, Qt 相关 dll 需要你手动处理")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
get_filename_component(MINGW_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY)
|
||||
|
||||
set(MINGW_RUNTIME_DLLS
|
||||
libstdc++-6.dll
|
||||
libgcc_s_seh-1.dll
|
||||
libwinpthread-1.dll
|
||||
)
|
||||
|
||||
foreach(dll ${MINGW_RUNTIME_DLLS})
|
||||
if(EXISTS "${MINGW_BIN_DIR}/${dll}")
|
||||
message(STATUS "Will install MinGW runtime DLL: ${dll}")
|
||||
install(FILES "${MINGW_BIN_DIR}/${dll}" DESTINATION .)
|
||||
else()
|
||||
message(WARNING "MinGW runtime DLL not found: ${MINGW_BIN_DIR}/${dll}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user