pico_add_extra_outputs( ) puts map file in wrong directory for add_subdirectory( ) projects #1753

Closed
opened 2024-07-03 12:22:31 -05:00 by smithps · 9 comments
smithps commented 2024-07-03 12:22:31 -05:00 (Migrated from github.com)

I am using Visual Studio with VisualGDB to make a complex project and my Cmakelists.txt was getting a bit out of hand. I then created a sub folder to split my project into pieces. I found that the .map file for my executable that was in the subfolder was found in the directory above where the other extra output files were.

I have recreated the issue by simply using the "Hello Serial" example, then adding another copy of "Hello Serial" called "Hello2 Serial".

The contents of my top level Cmakelists.txt is as so.

cmake_minimum_required(VERSION 3.12)
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)

project(Hello C CXX ASM)
pico_sdk_init()

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
add_executable(hello_serial
        hello_serial.c
        )

# pull in common dependencies
target_link_libraries(hello_serial pico_stdlib)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(hello_serial)

# add url via pico_set_program_url
# example_auto_set_url(hello_serial)

add_subdirectory(Hello2)

The subdirectory Hello2 contains an almost identical Cmakelists.txt with hello_serial replaced with Hello2_serial everywhere,... The outputs I get are as follows:

ProjectDir
   |
   |__ VisualGDB
              |
              |___ Debug
                         |
                         |___ hello_serial.bin
                         |___ hello_serial.dis
                         |___ hello_serial.elf
                         |___ hello_serial.elf.map
                         |___ hello_serial.hex
                         |___ hello_serial.uf2
                         |___ hello2_serial.elf.map         <--  Expected to be in folder "Hello2"
                         |___ Hello2
                                    |___ hello2_serial.bin
                                    |___ hello2_serial.dis
                                    |___ hello2_serial.elf
                                    |___ hello2_serial.hex
                                    |___ hello2_serial.uf2
                
     
I am using Visual Studio with VisualGDB to make a complex project and my Cmakelists.txt was getting a bit out of hand. I then created a sub folder to split my project into pieces. I found that the .map file for my executable that was in the subfolder was found in the directory above where the other extra output files were. I have recreated the issue by simply using the "Hello Serial" example, then adding another copy of "Hello Serial" called "Hello2 Serial". The contents of my top level Cmakelists.txt is as so. ``` cmake_minimum_required(VERSION 3.12) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) project(Hello C CXX ASM) pico_sdk_init() set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) add_executable(hello_serial hello_serial.c ) # pull in common dependencies target_link_libraries(hello_serial pico_stdlib) # create map/bin/hex/uf2 file etc. pico_add_extra_outputs(hello_serial) # add url via pico_set_program_url # example_auto_set_url(hello_serial) add_subdirectory(Hello2) ``` The subdirectory Hello2 contains an almost identical Cmakelists.txt with hello_serial replaced with Hello2_serial everywhere,... The outputs I get are as follows: ``` ProjectDir | |__ VisualGDB | |___ Debug | |___ hello_serial.bin |___ hello_serial.dis |___ hello_serial.elf |___ hello_serial.elf.map |___ hello_serial.hex |___ hello_serial.uf2 |___ hello2_serial.elf.map <-- Expected to be in folder "Hello2" |___ Hello2 |___ hello2_serial.bin |___ hello2_serial.dis |___ hello2_serial.elf |___ hello2_serial.hex |___ hello2_serial.uf2 ```
peterharperuk commented 2024-07-03 12:34:38 -05:00 (Migrated from github.com)

Does it do that when you build from the command line? It doesn't on Linux at least.

Does it do that when you build from the command line? It doesn't on Linux at least.
smithps commented 2024-07-03 14:22:37 -05:00 (Migrated from github.com)

There is the added complication that the build tools are "Sysprogs" specific versions of CMake and Ninja, running on a Windows 10 Machine, however when I build manually using the same tools in a Command prompt the map file still ended up in the wrong place. I wouldn't have thought that the Build tools would affect things, but maybe the difference is between Linux and Windows.

I can post any debug/output logs if required, but I thought the example I gave was straightforward enough - can you try building on a Windows platform?

There is the added complication that the build tools are "Sysprogs" specific versions of CMake and Ninja, running on a Windows 10 Machine, however when I build manually using the same tools in a Command prompt the map file still ended up in the wrong place. I wouldn't have thought that the Build tools would affect things, but maybe the difference is between Linux and Windows. I can post any debug/output logs if required, but I thought the example I gave was straightforward enough - can you try building on a Windows platform?
peterharperuk commented 2024-07-04 04:54:23 -05:00 (Migrated from github.com)

When I build on Windows using ninja I don't seem to get map files. Odd.
I tell a lie - they ALL go to the root of the build folder.
A quick look at the cmake and it doesn't look like pico_add_extra_outputs has anything to do with map files.

When I build on Windows using ninja I don't seem to get map files. Odd. I tell a lie - they ALL go to the root of the build folder. A quick look at the cmake and it doesn't look like pico_add_extra_outputs has anything to do with map files.
lurch commented 2024-07-04 05:37:23 -05:00 (Migrated from github.com)
The map files seem to be added at https://github.com/raspberrypi/pico-sdk/blob/develop/src/CMakeLists.txt#L59 ?
lurch commented 2024-07-04 05:42:59 -05:00 (Migrated from github.com)
Ahhh, looks like this might be related to https://github.com/raspberrypi/pico-sdk/pull/432#issuecomment-846449239 ?
smithps commented 2024-07-04 07:39:04 -05:00 (Migrated from github.com)

I am not by any stretch of the imagination familiar with Cmakelists, Cmake or Ninja but I did come to the same conclusion as @lurch that it's dealt with seperately from the other additional output files - and I also think it's related to Line 59 in the CMakelists.txt file

I just don't have the knowledge to be able to figure out what might be a potential fix, so for now I will live with the file being in the "wrong" place. Thanks for looking.

I am not by any stretch of the imagination familiar with Cmakelists, Cmake or Ninja but I did come to the same conclusion as @lurch that it's dealt with seperately from the other additional output files - and I also think it's related to Line 59 in the CMakelists.txt file I just don't have the knowledge to be able to figure out what might be a potential fix, so for now I will live with the file being in the "wrong" place. Thanks for looking.
will-v-pi commented 2025-07-22 05:35:02 -05:00 (Migrated from github.com)

This is due to the .map file being added by a linker script argument, so it is generated when compiling/linking, which on Ninja (and probably other generators too) is done from the root build directory before changing into the subdirectory for the POST_BUILD commands which generate the other output files. When using Makefiles, the compiling/linking is done from the subdirectory already, so the .map file appears in the correct place.

I think the simple fix would be a CMake script that checks for the .map file in the root build directory, and if present moves it into the subdirectory. I will have a look at doing that - note that this will have similar limitations around generator expressions as #2504

This is due to the `.map` file being added by a linker script argument, so it is generated when compiling/linking, which on Ninja (and probably other generators too) is done from the root `build` directory before changing into the subdirectory for the `POST_BUILD` commands which generate the other output files. When using Makefiles, the compiling/linking is done from the subdirectory already, so the `.map` file appears in the correct place. I think the simple fix would be a CMake script that checks for the `.map` file in the root `build` directory, and if present moves it into the subdirectory. I will have a look at doing that - note that this will have similar limitations around generator expressions as #2504
lurch commented 2025-07-23 07:14:05 -05:00 (Migrated from github.com)

@smithps Would you like to test the fix in #2584 please?

@smithps Would you like to test the fix in #2584 please?
lurch commented 2025-07-23 12:43:39 -05:00 (Migrated from github.com)

Fix has been merged into develop

Fix has been merged into `develop`
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#1753
No description provided.