Skip to content

Commit ca34d5c

Browse files
fix: can not load pcanbasic close #72
1 parent 1caf377 commit ca34d5c

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ x_output_env(xTools)
307307
x_deploy_qt(xTools)
308308
x_deploy_resources(xTools)
309309
x_generate_translations(xTools)
310+
x_auto_deploy_pcan_base(xTools)
310311
target_link_libraries(xTools PRIVATE ${X_LIBS})
311312
get_target_property(X_LIBS_LINKED_LIBS xTools LINK_LIBRARIES)
312313
message(STATUS "[xTools] xTools linked libs: ${X_LIBS_LINKED_LIBS}")

cmake/x_qt_serialbus.cmake

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,69 @@ else()
5757
add_compile_definitions(X_ENABLE_X_CANBUS=0)
5858
remove_all_x_canbus_files()
5959
endif()
60+
61+
# --------------------------------------------------------------------------------------------------
62+
# PCAN-Base
63+
if(NOT WIN32)
64+
return()
65+
endif()
66+
67+
# https://github.com/x-tools-author/x-tools-dependencies/releases/download/dependencies/PCAN-Basic-V5.1.0.1194.zip
68+
set(PCAN_BASE_URL_BASE "https://github.com/x-tools-author/x-tools-dependencies/releases")
69+
set(PCAN_BASE_URL_BASE "${PCAN_BASE_URL_BASE}/download/dependencies")
70+
set(PCAN_BASE_VERSION "5.1.0.1194")
71+
set(PCAN_BASE_NAME "PCAN-Basic-V${PCAN_BASE_VERSION}")
72+
set(PCAN_BASE_URL "${PCAN_BASE_URL_BASE}/${PCAN_BASE_NAME}.zip")
73+
74+
function(x_auto_deploy_pcan_base target)
75+
if(NOT WIN32)
76+
return()
77+
endif()
78+
79+
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # x64
80+
set(PCAN_BASE_DLL "${X_3RD_DIR}/${PCAN_BASE_NAME}/x64/PCANBasic.dll")
81+
else() # x86
82+
set(PCAN_BASE_DLL "${X_3RD_DIR}/${PCAN_BASE_NAME}/x86/PCANBasic.dll")
83+
endif()
84+
85+
add_custom_command(
86+
TARGET ${target}
87+
POST_BUILD
88+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PCAN_BASE_DLL}" $<TARGET_FILE_DIR:${target}>)
89+
endfunction()
90+
91+
# --------------------------------------------------------------------------------------------------
92+
# Download the PCAN-Base repository if it does not exist
93+
if(NOT EXISTS "${X_3RD_DIR}/${PCAN_BASE_NAME}.zip")
94+
message(STATUS "Downloading ${PCAN_BASE_NAME} from ${PCAN_BASE_URL}")
95+
file(
96+
DOWNLOAD "${PCAN_BASE_URL}" "${X_3RD_DIR}/${PCAN_BASE_NAME}.zip"
97+
SHOW_PROGRESS
98+
STATUS DOWNLOAD_STATUS)
99+
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
100+
if(NOT DOWNLOAD_RESULT EQUAL 0)
101+
message(WARNING "Failed to download ${PCAN_BASE_NAME} from ${PCAN_BASE_URL}")
102+
message(WARNING "PeakCAN plugin will be disabled.")
103+
# Remove pcan-base files
104+
file(REMOVE "${X_3RD_DIR}/${PCAN_BASE_NAME}.zip")
105+
return()
106+
endif()
107+
endif()
108+
109+
# --------------------------------------------------------------------------------------------------
110+
# Unzip the PCAN-Base repository if it does not exist
111+
if(NOT EXISTS "${X_3RD_DIR}/${PCAN_BASE_NAME}/ReadMe.txt")
112+
message(STATUS "Unzipping ${PCAN_BASE_NAME}...")
113+
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${X_3RD_DIR}/${PCAN_BASE_NAME}")
114+
execute_process(
115+
COMMAND ${CMAKE_COMMAND} -E tar xzf "${X_3RD_DIR}/${PCAN_BASE_NAME}.zip"
116+
WORKING_DIRECTORY "${X_3RD_DIR}/${PCAN_BASE_NAME}"
117+
RESULT_VARIABLE UNZIP_RESULT)
118+
if(NOT UNZIP_RESULT EQUAL 0)
119+
message(WARNING "Failed to unzip ${PCAN_BASE_NAME}")
120+
message(WARNING "PeakCAN plugin will be disabled.")
121+
# Remove pcan-base files
122+
file(REMOVE "${X_3RD_DIR}/${PCAN_BASE_NAME}.zip")
123+
return()
124+
endif()
125+
endif()

0 commit comments

Comments
 (0)