217 lines
5.1 KiB
CMake
217 lines
5.1 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
project(touchsensor VERSION 2.0.0 LANGUAGES CXX)
|
|
|
|
option(BUILD_EXAMPLE "Build the cpstream demo executable" ON)
|
|
set(QT_VERSION Qt6 CACHE STRING "Qt major version to use")
|
|
|
|
set(CMAKE_CXX_STANDARD 23)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
add_compile_options(-Os -O3)
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH
|
|
"C:/msys64/mingw64/include"
|
|
)
|
|
|
|
find_package(${QT_VERSION} REQUIRED COMPONENTS Widgets Network PrintSupport)
|
|
find_package(Eigen3 REQUIRED)
|
|
|
|
qt_standard_project_setup()
|
|
|
|
file(
|
|
GLOB_RECURSE creeper_QT_SOURCES
|
|
CONFIGURE_DEPENDS
|
|
"creeper-qt/*.cc"
|
|
)
|
|
set(creeper_QT_HEADERS
|
|
creeper-qt/widget/sliders.hh
|
|
)
|
|
add_library(creeper-qt SHARED ${creeper_QT_SOURCES} ${creeper_QT_HEADERS})
|
|
target_include_directories(creeper-qt PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_link_libraries(creeper-qt
|
|
PUBLIC
|
|
${QT_VERSION}::Widgets
|
|
${QT_VERSION}::Network
|
|
Eigen3::Eigen
|
|
)
|
|
|
|
file(
|
|
GLOB_RECURSE QCUSTOMPLOT_SOURCES
|
|
CONFIGURE_DEPENDS
|
|
"qcustomplot/*.cpp"
|
|
"qcustomplot/*.h"
|
|
)
|
|
add_library(qcustomplot SHARED ${QCUSTOMPLOT_SOURCES})
|
|
target_include_directories(qcustomplot PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_link_libraries(qcustomplot
|
|
PUBLIC
|
|
${QT_VERSION}::Core
|
|
${QT_VERSION}::Gui
|
|
${QT_VERSION}::PrintSupport
|
|
)
|
|
|
|
file(
|
|
GLOB_RECURSE COMPONENT_SOURCES
|
|
CONFIGURE_DEPENDS
|
|
"components/*.cc"
|
|
)
|
|
file(
|
|
GLOB_RECURSE UTILITY_SOURCES
|
|
CONFIGURE_DEPENDS
|
|
"dlog/*.cc"
|
|
)
|
|
|
|
file(
|
|
GLOB_RECURSE BASE_SOURCES
|
|
CONFIGURE_DEPENDS
|
|
"base/*.cc"
|
|
)
|
|
|
|
set(FFMSEP_SOURCES
|
|
components/ffmsep/cpdecoder.cc
|
|
components/ffmsep/cpstream_core.cc
|
|
components/ffmsep/presist/presist.cc
|
|
components/ffmsep/tactile/tacdec.cc
|
|
)
|
|
set(FFMSEP_HEADERS
|
|
components/ffmsep/cpdecoder.hh
|
|
components/ffmsep/cpstream_core.hh
|
|
components/ffmsep/presist/presist.hh
|
|
components/ffmsep/tactile/tacdec.hh
|
|
)
|
|
set(FFMSEP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/ffmsep")
|
|
set(BASE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/base")
|
|
|
|
set(TOUCHSENSOR_HEADERS
|
|
component.hh
|
|
components/charts/heatmap.hh
|
|
components/charts/heatmap.impl.hh
|
|
components/charts/vector_field.hh
|
|
components/charts/line_chart.hh
|
|
dlog/dlog.hh
|
|
${FFMSEP_HEADERS}
|
|
components/setting.cc
|
|
)
|
|
|
|
qt6_add_resources(APP_RESOURCES resources.qrc)
|
|
|
|
# add_executable(${PROJECT_NAME} WIN32
|
|
# ${COMPONENT_SOURCES}
|
|
# ${UTILITY_SOURCES}
|
|
# ${TOUCHSENSOR_HEADERS}
|
|
# ${BASE_SOURCES}
|
|
# main.cc
|
|
# )
|
|
|
|
add_executable(${PROJECT_NAME}
|
|
${COMPONENT_SOURCES}
|
|
${UTILITY_SOURCES}
|
|
${TOUCHSENSOR_HEADERS}
|
|
${BASE_SOURCES}
|
|
main.cc
|
|
)
|
|
target_sources(${PROJECT_NAME} PRIVATE ${APP_RESOURCES})
|
|
target_include_directories(${PROJECT_NAME}
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
${FFMSEP_INCLUDE_DIR}
|
|
${BASE_INCLUDE_DIR}
|
|
)
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PRIVATE
|
|
${QT_VERSION}::Widgets
|
|
${QT_VERSION}::Network
|
|
creeper-qt
|
|
qcustomplot
|
|
serial
|
|
setupapi
|
|
spdlog
|
|
)
|
|
|
|
if(BUILD_EXAMPLE)
|
|
add_executable(cpstream_demo
|
|
examples/cpstream_demo.cc
|
|
${FFMSEP_SOURCES}
|
|
)
|
|
target_include_directories(cpstream_demo
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
${FFMSEP_INCLUDE_DIR}
|
|
)
|
|
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()
|