When using cmake it is common to define multiple build targets.
For NXP SDK it seems like ${MCUX_SDK_PROJECT_NAME} is used and limits to one target only.
Do you have any example that builds two targets in one project?
Hi @Peter19
I think you can refer to Zephyr's NXP multi-core code structure.
zephyr/boards/nxp/mimxrt1180_evk at main · zephyrproject-rtos/zephyr · GitHub
BR
Harry
Hi @Peter19
If you want to have one root CMakeFiles.
You can try to this.
project-root/
├── CMakeLists.txt
├── app1/
│ ├── CMakeLists.txt
│ ├── main.c
├── app2/
│ ├── CMakeLists.txt
│ ├── main.c
Root CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(MultiTargetExample)
# Include NXP MCUXpresso SDK
set(MCUX_SDK_PROJECT_NAME ${PROJECT_NAME})
include($ENV{MCUX_SDK_PATH}/tools/cmake/sdk.cmake)
# Add subdirectories for each application
add_subdirectory(app1)
add_subdirectory(app2)
app1/CMakeLists.txt
# Define the first application
set(TARGET_NAME app1)
add_executable(${TARGET_NAME} main.c)
# Link the NXP SDK components (adjust as necessary for your dependencies)
target_link_libraries(${TARGET_NAME} PRIVATE
${MCUX_SDK_PROJECT_NAME}.board
${MCUX_SDK_PROJECT_NAME}.drivers
${MCUX_SDK_PROJECT_NAME}.utilities
)
# Specify any additional compile definitions or flags for app1
target_compile_definitions(${TARGET_NAME} PRIVATE APP1_BUILD)
app2/CMakeLists.txt
# Define the second application
set(TARGET_NAME app2)
add_executable(${TARGET_NAME} main.c)
# Link the NXP SDK components (adjust as necessary for your dependencies)
target_link_libraries(${TARGET_NAME} PRIVATE
${MCUX_SDK_PROJECT_NAME}.board
${MCUX_SDK_PROJECT_NAME}.drivers
${MCUX_SDK_PROJECT_NAME}.utilities
)
# Specify any additional compile definitions or flags for app2
target_compile_definitions(${TARGET_NAME} PRIVATE APP2_BUILD)
BR
Harry
Hi @Peter19
I just made an simple example.
Directory Structure
project/
├── CMakeLists.txt
├── src/
│ ├── main_target1.c
│ └── main_target2.c
The cmake code is as follows.
cmake_minimum_required(VERSION 3.0)
project(MultiTargetExample)
# Set common compiler flags and settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
include_directories(${PROJECT_SOURCE_DIR}/include)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/driver DRIVER_LIST)
# Create the first target (target1)
add_executable(target1 ${DRIVER_LIST})
# Add source files for target1
target_sources(target1 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/main_target1.c
)
# Set linker script and other settings for target1
#target_link_options(target1 PRIVATE "-T${MCUX_SDK_PATH}/boards/<board_name>/linker.ld")
#add_executable(app main ${DRIVER_LIST})
# Create the second target (target2)
add_executable(target2 ${DRIVER_LIST})
# Add source files for target2
target_sources(target2 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/main_target2.c
)
# Set linker script and other settings for target2
#target_link_options(target2 PRIVATE "-T${MCUX_SDK_PATH}/boards/<board_name>/linker.ld")
Does this meet your needs?
BR
Harry
Hi @Peter19
I didn't refer to your code, but the architecture is the same.
I refer to the mcxn947 SDK hello world demo.
The picture is the results.
The build folder is the generated folder.
May I ask if this meets your needs?
Due to our company's policy, I am unable to share my code.
If this meets your needs, i will send this code to the local fae.
BR
Harry
Hi @Peter19
Hi @Peter19
Based on your needs, I have redesigned this project. The project is based on the Hello world in SDK.
This project contains all the files of the Hello World project.
project-root/
├── CMakeLists.txt
├── app1/
│ ├── CMakeLists.txt
│ ├── main.c
├── app2/
│ ├── CMakeLists.txt
│ ├── main.c
After compilation, there will be two executable programs, app1 and app2.
BR
Harry