CMakeFile调试

时间:2025-02-05 21:22:48
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)

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

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

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

libusb1.0 not found

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)

依赖管理很方便 

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