How to define multiple build targets

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to define multiple build targets

3,316 次查看
Peter19
Contributor II

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?

MCUXPRESSO-VSC 

0 项奖励
回复
13 回复数

3,228 次查看
Peter19
Contributor II

Hi @Harry_Zhang 

That would be fine, are you putting together an example for this?

/Peter

0 项奖励
回复

3,207 次查看
Harry_Zhang
NXP Employee
NXP Employee

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

0 项奖励
回复

3,171 次查看
Peter19
Contributor II
Hi @Harry_Zhang
We are not using Zephyr, can you guide me for the SDK?
0 项奖励
回复

3,121 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Peter19 

Here are the muticore example, i think you can refer to it.

mcuxsdk-examples/multicore_examples/hello_world at release/24.12.00-pvw2 · nxp-mcuxpresso/mcuxsdk-ex...

BR

Harry

0 项奖励
回复

3,110 次查看
Peter19
Contributor II
Hi @Harry_Zhang
This is two root CMakeFiles (project is defined in two different CMakeFiles). That was not what I search for. I assume my use case is not supported by NXP SDK.
0 项奖励
回复

3,048 次查看
Harry_Zhang
NXP Employee
NXP Employee

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

0 项奖励
回复

2,975 次查看
Peter19
Contributor II
Well this did not work since MCUX_SDK_PROJECT_NAME is expected to be a target by NXP_SDK (as initial post).
1) Here it is no target.
2) What I want is two targets.
Moving MCUX_SDK_PROJECT_NAME into app1 and app2 CMakeLists.txt does not do the trick either...
0 项奖励
回复

2,945 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Peter19 

I just made an simple example.

Directory Structure
project/
├── CMakeLists.txt
├── src/
│ ├── main_target1.c
│ └── main_target2.c

Harry_Zhang_0-1733975052239.png

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

0 项奖励
回复

2,256 次查看
Peter19
Contributor II

Hi

@Harry_Zhang 

Did you change according to my code I shared? Can you share the results? I want to reproduce.

BR /Peter

0 项奖励
回复

2,243 次查看
Harry_Zhang
NXP Employee
NXP Employee

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.

Harry_Zhang_0-1739869888961.png

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

 

0 项奖励
回复

2,894 次查看
Peter19
Contributor II
I think your comments are too general and does not address what I reported as the problem.
If you could just share something that prooves that multi-target build is possible.

In example below app2 won't build. But just commenting out app1 from toplevel CMakeList.txt will fix build of app2. So there seem to be some crosstalk through NXP-SDK that needs to be sorted out.
https://github.com/PeterFromSweden/nxp-multiproject
0 项奖励
回复

2,267 次查看
Harry_Zhang
NXP Employee
NXP Employee

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

Harry_Zhang_1-1739781708588.png

After compilation, there will be two executable programs, app1 and app2.

Harry_Zhang_2-1739781798990.png

BR

Harry

 

0 项奖励
回复

3,276 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Peter19 

Is this the architecture you need?

Project Structure
project-root/
├── CMakeLists.txt
├── app1/
│ ├── CMakeLists.txt
│ ├── main.c
├── app2/
│ ├── CMakeLists.txt
│ ├── main.c

BR

Harry

0 项奖励
回复