CMakeFile调试

bash 复制代码
cmake_minimum_required (VERSION 3.1)
set (EXE_NAME ch347-nor-prog)
project (${EXE_NAME} C CXX)
find_package(PkgConfig)
pkg_check_modules(libusb-1.0 REQUIRED IMPORTED_TARGET libusb-1.0)

include_directories(/usr/local/include)

add_executable(${EXE_NAME} ch347.c spi-op.cpp main.cpp misc.cpp spi_flash.cpp spi_ids.cpp stdafx.cpp)
set_property(TARGET ${EXE_NAME} PROPERTY C_STANDARD 99)

include(CMakePrintHelpers)
cmake_print_variables(libusb-1.0_INCLUDE_DIRS)
cmake_print_variables(libusb-1.0_LINK_LIBRARIES)

target_link_libraries(${EXE_NAME}  ${libusb-1.0_LINK_LIBRARIES})
#target_link_libraries(${EXE_NAME}  PkgConfig::libusb-1.0)

在编译项目时,常常需要打印环境变量,不同的版本间, 定义也不一致

bash 复制代码
include(CMakePrintHelpers)
cmake_print_variables(libusb-1.0_INCLUDE_DIRS)
cmake_print_variables(libusb-1.0_LINK_LIBRARIES)

引入工具可以节省许多时间

libusb1.0 not found

bash 复制代码
ss@SSdeiMac ch347-nor-prog % brew list libusb
/usr/local/Cellar/libusb/1.0.27/include/libusb-1.0/libusb.h
/usr/local/Cellar/libusb/1.0.27/lib/libusb-1.0.0.dylib
/usr/local/Cellar/libusb/1.0.27/lib/pkgconfig/libusb-1.0.pc
/usr/local/Cellar/libusb/1.0.27/lib/ (2 other files)
/usr/local/Cellar/libusb/1.0.27/sbom.spdx.json
/usr/local/Cellar/libusb/1.0.27/share/libusb/ (9 files)

依赖管理很方便

bash 复制代码
ss@SSdeiMac ch347-nor-prog % cmake .
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- libusb-1.0_INCLUDE_DIRS="/usr/local/Cellar/libusb/1.0.27/include/libusb-1.0"
-- libusb-1.0_LINK_LIBRARIES="/usr/local/Cellar/libusb/1.0.27/lib/libusb-1.0.dylib"
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/ss/Desktop/ch347-nor-prog
相关推荐
fufu03116 分钟前
vscode配置C/C++环境,用GDB调试简单程序分享
开发语言·c++
黑猫学长呀1 小时前
存储宝典第2篇:盲封TT wafer是什么意思?
linux·嵌入式硬件·项目·芯片·ufs·晶圆·产测
Strugglingler1 小时前
【Linux 用户态操作 UART】
linux·uart
代码熬夜敲Q1 小时前
ENSP 网络工程实验
linux·运维·服务器
水云桐程序员1 小时前
C++变量的概念及用法
开发语言·c++
csdn_life182 小时前
OpenClaw v2026.5.12+ 高级密钥管理:使用SecretRef实现真正的隐蔽存储
linux·openclaw
Terrence Shen2 小时前
Claude Code Harness 源码学习讲义
linux·学习·ubuntu
水饺编程2 小时前
第5章,[Win32 章节] :几种典型的颜色
c语言·c++·windows·visual studio
赵药师2 小时前
dpkg: warning: files list file for package ‘libselinux1:amd64‘ missing;
linux·运维·服务器
Larry_Yanan2 小时前
QML面试常见问题(一)QML中组件呈现方式的方法有哪些
开发语言·c++·qt·ui·面试