Since the stm32 vscode extension was updated to 2.0, we have been developing stm32 using vscode.
It wasn’t difficult to add a library that you created yourself through CMakeListes.txt.
The function I want is to bundle the added library into one folder.
I searched it, but it wasn’t the result of what I wanted.
I’d appreciate it if you could help me.
now:
#include <types.h>
#include <test.h>
i want:
#include <test/types.h>
#include <test/test.h>
directory structure
.
├── CMakeLists.txt
├── CMakePresets.json
├── Core
│ ├── Inc
│ │ ├── FreeRTOSConfig.h
│ │ ├── gpio.h
│ │ ├── main.h
│ │ └── usart.h
│ └── Src
│ ├── freertos.c
│ ├── gpio.c
│ ├── main.c
│ ├── syscalls.c
│ ├── sysmem.c
│ ├── system_stm32f4xx.c
│ └── usart.c
├── Middlewares
│ └── Test
│ ├── CMakeLists.txt
│ ├── Inc
│ │ ├── types.h
│ │ └── test.h
│ └── Src
├── STM32F429ZITx_FLASH.ld
├── stm32_test.ioc
├── cmake
│ └── gcc-arm-none-eabi.cmake
└── startup_stm32f429xx.s
./CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#
# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
# Define the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Set the project name
set(CMAKE_PROJECT_NAME stm32_test)
# Include toolchain file
include("cmake/gcc-arm-none-eabi.cmake")
# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Enable CMake support for ASM and C languages
enable_language(C ASM)
# Core project settings
project(${CMAKE_PROJECT_NAME})
message("Build type: " ${CMAKE_BUILD_TYPE})
# Create an executable object type
add_executable(${CMAKE_PROJECT_NAME})
# Add STM32CubeMX generated sources
add_subdirectory(cmake/stm32cubemx)
# Add UltraSonic library
add_subdirectory(Middlewares/UltraSonic)
# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined library search paths
)
# Link options
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
-u _printf_float # to print float values
)
# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
# Add user sources here
)
# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined include paths
)
# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined symbols
)
# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
stm32cubemx
test
# Add user defined libraries
)
./Middlewares/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
# Enable CMake support for ASM and C languages
enable_language(C ASM)
# Core project settings
project(
test
LANGUAGES CXX
VERSION 1.0.0
)
add_library(test INTERFACE)
# Add include paths
target_include_directories(test INTERFACE
Inc
# Add user defined include paths
)
message(STATUS "test")
New contributor
황인규 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.