vpetrigo / arm-cmake-toolchains

CMake toolchain configurations for ARM
BSD 3-Clause "New" or "Revised" License
269 stars 52 forks source link

Provide support for searching CRT files during Clang builds #12

Closed vpetrigo closed 4 years ago

vpetrigo commented 5 years ago

Right now examples CMakeLists.txt files contain something like this for properly build projects with Clang:

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
    list(APPEND efm32_test_obj ${ARM_TOOLCHAIN_DIR}/../arm-none-eabi/lib/thumb/v7-m/nofp/crt0.o)
    list(APPEND efm32_test_obj ${ARM_TOOLCHAIN_DIR}/../lib/gcc/arm-none-eabi/8.2.1/thumb/v7-m/nofp/crti.o)
endif()

To avoid that, provide a script that will look for CRT files in a toolchain sysroot.

vpetrigo commented 5 years ago

Potentially gcc -print-search-dirs should suit all needs, e.g.:

> toolchains/gcc-arm-none-eabi/bin/arm-none-eabi-gcc -march=armv7-m -print-search-dirs
install: /home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/
programs: =/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/
libraries: =/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/arm-none-eabi/8.2.1/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/arm-none-eabi/8.2.1/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/arm-none-eabi/8.2.1/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/thumb/v7-m/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/
> toolchains/gcc-arm-none-eabi/bin/arm-none-eabi-gcc -march=armv7 -print-search-dirs
install: /home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/
programs: =/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/
libraries: =/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/arm-none-eabi/8.2.1/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/arm-none-eabi/8.2.1/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/arm-none-eabi/8.2.1/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/thumb/v7/nofp/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/lib/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/arm-none-eabi/8.2.1/:/home/vpetrigo/toolchains/gcc-arm-none-eabi/bin/../arm-none-eabi/usr/lib/

So, should just parse all that stuff and provide to Clang.