Skip to content

Conversation

flaviut
Copy link
Contributor

@flaviut flaviut commented Nov 10, 2022

Add a -nostdlib specifically for the check to ensure that it builds successfully. The -nostdlib isn't needed normally, because linking against the pico SDK will add in definitions for the previously-missing function.

However, when CMake checks to see what features the compiler supports, it compiles a custom program with nothing but the implicit dependencies, like libc. Previously, this was worked around by disabling feature detection by setting CMAKE_C_COMPILER_FORCED=TRUE.

I think the best way to fix this is to unconditionally link all programs against pico_standard_link in the toolchain. However, this can't be done without precompiling the library (I think--my CMake-fu is quite weak). And we don't actually need an executable that can be installed for compiler feature detection.

I've tested this on Arch Linux with arm-none-eabi-gcc-12.2.0. I haven't tested on other systems, but this doesn't get super deep into platform-specific stuff.

Fixes #1096

Add a -nostdlib specifically for the check to ensure that it builds
successfully.

The -nostdlib isn't needed normally, because linking against the pico
SDK will add in definitions for the previously-missing function
@kilograham kilograham modified the milestones: 1.4.1, 1.5.0 Nov 23, 2022
@kilograham
Copy link
Contributor

moving to 1.5.0 as this requires quite a bit of testing on different platforms

@flaviut
Copy link
Contributor Author

flaviut commented Nov 25, 2022 via email

@kilograham
Copy link
Contributor

kilograham commented Nov 25, 2022

Yeah probably want to test on

  • macOS
  • Linux
  • Windows (regular and mingw-w64)
  • Pi
    with whatever versions of cmake come standard (and the latest on some platform)

I mean we do test the platforms b4 the release, but in this case, yes, testing this up front to make sure there aren't any weird issues would be helpful (as 1.4.1 is really just going to be a bug fix release)

@peterharperuk
Copy link
Contributor

peterharperuk commented Jan 24, 2023

I spent some time trying to test on Windows, and failing
Later: What I mean is - I couldn't get pico examples building in Windows so couldn't test this change.

@flaviut
Copy link
Contributor Author

flaviut commented Jan 25, 2023

Can you please post your full console output @peterharperuk ?

@peterharperuk
Copy link
Contributor

peterharperuk commented Jan 25, 2023

To be clear - I have some config problem that's unrelated to this change. I don't normally develop on Windows.

C:\Users\peter\source\pico-examples\build\hello_world\serial>nmake VERBOSE=1

Microsoft (R) Program Maintenance Utility Version 14.34.31937.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cd C:\Users\peter\source\pico-examples\build
        "C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\peter\source\pico-examples -BC:\Users\peter\source\pico-examples\build --check-build-system CMakeFiles\Makefile.cmake 0
        cd C:\Users\peter\source\pico-examples\build\hello_world\serial
        cd C:\Users\peter\source\pico-examples\build
        "C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\peter\source\pico-examples\build\CMakeFiles C:\Users\peter\source\pico-examples\build\hello_world\serial\\CMakeFiles\progress.marks
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\Makefile2 /nologo -                   hello_world\serial\all
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default.dir\build.make /nologo -L                  pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default.dir\depend
        "C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "NMake Makefiles" C:\Users\peter\source\pico-examples C:\Users\peter\source\pico-sdk\src\rp2_common\boot_stage2 C:\Users\peter\source\pico-examples\build C:\Users\peter\source\pico-examples\build\pico-sdk\src\rp2_common\boot_stage2 C:\Users\peter\source\pico-examples\build\pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default.dir\DependInfo.cmake --color=
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default.dir\build.make /nologo -L                  pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default.dir\build
Built target bs2_default
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default_padded_checksummed_asm.dir\build.make /nologo -L                  pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default_padded_checksummed_asm.dir\depend
        "C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "NMake Makefiles" C:\Users\peter\source\pico-examples C:\Users\peter\source\pico-sdk\src\rp2_common\boot_stage2 C:\Users\peter\source\pico-examples\build C:\Users\peter\source\pico-examples\build\pico-sdk\src\rp2_common\boot_stage2 C:\Users\peter\source\pico-examples\build\pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default_padded_checksummed_asm.dir\DependInfo.cmake --color=
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default_padded_checksummed_asm.dir\build.make /nologo -L                  pico-sdk\src\rp2_common\boot_stage2\CMakeFiles\bs2_default_padded_checksummed_asm.dir\build
        cd C:\Users\peter\source\pico-examples\build\pico-sdk\src\rp2_common\boot_stage2
        cd C:\Users\peter\source\pico-examples\build
Built target bs2_default_padded_checksummed_asm
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f blink\CMakeFiles\ELF2UF2Build.dir\build.make /nologo -L                  blink\CMakeFiles\ELF2UF2Build.dir\depend
        "C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "NMake Makefiles" C:\Users\peter\source\pico-examples C:\Users\peter\source\pico-examples\blink C:\Users\peter\source\pico-examples\build C:\Users\peter\source\pico-examples\build\blink C:\Users\peter\source\pico-examples\build\blink\CMakeFiles\ELF2UF2Build.dir\DependInfo.cmake --color=
        "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f blink\CMakeFiles\ELF2UF2Build.dir\build.make /nologo -L                  blink\CMakeFiles\ELF2UF2Build.dir\build
Performing configure step for 'ELF2UF2Build'
        cd C:\Users\peter\source\pico-examples\build\elf2uf2
        echo >nul && "C:\Program Files\CMake\bin\cmake.exe" "-GNMake Makefiles" C:/Users/peter/source/pico-sdk/tools/elf2uf2
Re-run cmake no build system arguments
-- The C compiler identification is MSVC 19.34.31937.0
-- The CXX compiler identification is MSVC 19.34.31937.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/peter/source/pico-examples/build/elf2uf2/CMakeFiles/CMakeScratch/TryCompile-oq2ctk

    Run Build Command(s):nmake -f Makefile /nologo cmTC_059ee\fast &&   "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_059ee.dir\build.make /nologo -L                  CMakeFiles\cmTC_059ee.dir\build
    Building C object CMakeFiles/cmTC_059ee.dir/testCCompiler.c.obj
        "C:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_059ee.dir\testCCompiler.c.obj.d --working-dir=C:\Users\peter\source\pico-examples\build\elf2uf2\CMakeFiles\CMakeScratch\TryCompile-oq2ctk --filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\cl.exe @C:\Users\peter\AppData\Local\Temp\nmE337.tmp
    testCCompiler.c
    Linking C executable cmTC_059ee.exe
        "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_059ee.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_059ee.dir\objects1 @C:\Users\peter\AppData\Local\Temp\nmE376.tmp
    Visual Studio Incremental Link with embedded manifests
    Create CMakeFiles\cmTC_059ee.dir/manifest.rc
    Create empty: CMakeFiles\cmTC_059ee.dir/embed.manifest
    RC Pass 1:
    rc /fo CMakeFiles\cmTC_059ee.dir/manifest.res CMakeFiles\cmTC_059ee.dir/manifest.rc
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_059ee.dir/manifest.res CMakeFiles\cmTC_059ee.dir/manifest.rc" failed (exit code 0) with the following output:
    The system cannot find the file specifiedNMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"' : return code '0x2'
    Stop.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/peter/source/pico-examples/build/elf2uf2/CMakeFiles/CMakeOutput.log".
See also "C:/Users/peter/source/pico-examples/build/elf2uf2/CMakeFiles/CMakeError.log".
NMAKE : fatal error U1077: 'echo' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\nmake.exe"' : return code '0x2'
Stop.

@flaviut
Copy link
Contributor Author

flaviut commented Jan 26, 2023

Ah that makes sense. I don't develop on windows either but it looks like it's trying to compile with a Microsoft toolchain against your native environment rather than a gcc targeting ARM.

No suggestions here on how to fix it, but I appreciate you taking a look when I haven't had a chance to

@flaviut
Copy link
Contributor Author

flaviut commented Jan 29, 2023

I've added some basic automated builds on Windows in #1209, see also #1208.

Not sure if that's something y'all want, but if it is, it could inspire more confidence in that this MR won't break anything.

@kilograham
Copy link
Contributor

I tested this on Windows with NMake / Ninja and it was happy too, so looks good to me

Thanks

@kilograham kilograham merged commit 74b6c1c into raspberrypi:develop Feb 5, 2023
@ilcardella
Copy link

I'm having an issue caused by this change, but I can't figure out exactly why: my project links to an interface library and it uses find_package to find the xxxTargets.cmake to load the library target. Now this seems to work until this commit is introduced in the pico SDK. With these changes the CMake configuration fails because it does not accept the xxxTargets.cmake file for the library, logging this error:

the following configuration files were considered but not accepted:

    /usr/local/share/<library_name>/cmake/<library_name>Config.cmake, version: 0.4.0 (64bit)

That (64bit) is suspicious but I am not sure why these changes would impact how libraries are found. Does anybody have a clue?

@flaviut flaviut deleted the cmake-feature-inference branch November 12, 2023 15:19
@ilcardella
Copy link

I'm having an issue caused by this change, but I can't figure out exactly why: my project links to an interface library and it uses find_package to find the xxxTargets.cmake to load the library target. Now this seems to work until this commit is introduced in the pico SDK. With these changes the CMake configuration fails because it does not accept the xxxTargets.cmake file for the library, logging this error:

the following configuration files were considered but not accepted:

    /usr/local/share/<library_name>/cmake/<library_name>Config.cmake, version: 0.4.0 (64bit)

That (64bit) is suspicious but I am not sure why these changes would impact how libraries are found. Does anybody have a clue?

It turns out that I just needed to move the find_package before the include(.../pico_sdk_init.cmake). Not sure why yet but it resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants