最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - How to select the "main" cmake file for VS Code Cmake tools? - Stack Overflow

programmeradmin2浏览0评论

I have a project that targets Arduino. As such, my "main" cmake is unusual and sets a lot of weird flags and special build targets to create a .hex file and upload it to the chip.

However, as the project is getting more complex, I really need unit tests. I want the unit tests to be the "main" CMake folder for VS Code. This is my folder structure:

  • myProject/display
    • display_controller/CMakeLists.txt - CMake for arduino compilation and upload
      • This code also depends on arduino libraries
    • display_shared/CMakeLists.txt - static library CMake with platform agnostic code
    • display_test/CMakeLists.txt - Newly added CMake with Boost test framework

At this point, VSCode seems to take display_controller as the main CMake. The tests CMake looks like this:

cmake_minimum_required(VERSION 3.11)
find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Project name
project("DisplayTest" VERSION 0.1 LANGUAGES CXX)

# Product filename

file(GLOB SRC_FILES "src/*.cpp") # Load all files in src folder



target_link_libraries(${PRODUCT_NAME} PRIVATE
    MCULib
    ConnectionsDisplaySerialize
    ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
    ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
)
target_include_directories(techsheet_lib_unit_tests PRIVATE ${Boost_INCLUDE_DIR})

add_subdirectory("../display_serialize" "${CMAKE_BINARY_DIR}/display_serialize")
add_subdirectory("../mcu_lib" "${CMAKE_BINARY_DIR}/mcu_lib")

# Create one target
add_executable(${PROJECT_NAME} ${SRC_FILES})

But in VSCode, if I want to pick a target for configure, it offers only targets from display_controller. When I click CMAKE - PROJECT STATUS - Build - Set Build Target, I get this list:

The test target is not even there. What I want is to intead use my display_test/CMakeLists.txt and only consider CMake files that this cmake imports.

发布评论

评论列表(0)

  1. 暂无评论