conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.26k stars 980 forks source link

[question] How to pass Compiler and Linker flags to Conan CMake Generator #10588

Closed Ju1He1 closed 1 day ago

Ju1He1 commented 2 years ago

I'm trying to cross build on windows for an embedded target (arm-none-eabi). To achieve this, I'm using a cross compiling profile. Each embedded target has it's own specific compiler and linker flags

My cross compiling profile looks like this


target_host=arm-none-eabi
standalone_toolchain=C:/.../toolchains/Windows/gcc-10.2.1/
cc_compiler=gcc
cxx_compiler=g++

[settings]
os=Arduino
os.board=ANY
arch=armv7
compiler=gcc
compiler.version=10
compiler.libcxx=libstdc++11
build_type=Debug

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$standalone_toolchain/$target_host
PATH=[$standalone_toolchain/bin]
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
LD=$target_host-ld
STRIP=$target_host-strip
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
CFLAGS="-I $standalone_toolchain/$target_host/include -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nosys.specs -v"
CXXFLAGS="-I $standalone_toolchain/$target_host/include -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nosys.specs -v"
LDFLAGS="-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -v"

the workflow is the recommended workflow from https://github.com/conan-io/cmake-conan. it's basically a

conan_cmake_configure() +
conan_cmake_install(PROFILE MY_PROFILE)

The workflow is not the issue, I can see that the embedded compiler (in my case gcc 10) is properly recognised. Include paths etc. are set properly. However I'm suspecting that my provided compiler and/or linker flags are ommitted. I would have expected a little more output from the conan build especially after adding a -v to the compiler and linker flags


[CMake] tinyxml/2.6.2: Configuring sources in C:\Users\xxx\.conan\data\tinyxml\2.6.2\_\_\source
1> [CMake] 
1> [CMake] tinyxml/2.6.2: Copying sources to build folder
1> [CMake] tinyxml/2.6.2: Building your package in C:\Users\xxx\.conan\data\tinyxml\2.6.2\_\_\build\11b38960141478715841df824e568735e33d702c
1> [CMake] tinyxml/2.6.2: Generator cmake created conanbuildinfo.cmake
1> [CMake] tinyxml/2.6.2: Aggregating env generators
1> [CMake] tinyxml/2.6.2: Calling build()
1> [CMake] -- The C compiler identification is GNU 10.2.1
1> [CMake] -- The CXX compiler identification is GNU 10.2.1
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/xxx/toolchains/Windows/gcc-10.2.1/bin/arm-none-eabi-gcc.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/xxx/toolchains/Windows/gcc-10.2.1/bin/arm-none-eabi-g++.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Conan: called by CMake conan helper
1> [CMake] -- Conan: called inside local cache
1> [CMake] -- Conan: Adjusting output directories
1> [CMake] -- Conan: Using cmake global configuration
1> [CMake] -- Conan: Adjusting default RPATHs Conan policies
1> [CMake] -- Conan: Adjusting language standard
1> [CMake] -- Conan: Adjusting fPIC flag (OFF)
1> [CMake] -- Conan: Compiler GCC>=5, checking major version 10
1> [CMake] -- Conan: Checking correct version: 10
1> [CMake] -- Conan: C++ stdlib: libstdc++11
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] CMake Warning:
1> [CMake]   Manually-specified variables were not used by the project:
1> [CMake] 
1> [CMake]     CMAKE_EXPORT_NO_PACKAGE_REGISTRY
1> [CMake]     CMAKE_INSTALL_BINDIR
1> [CMake]     CMAKE_INSTALL_DATAROOTDIR
1> [CMake]     CMAKE_INSTALL_INCLUDEDIR
1> [CMake]     CMAKE_INSTALL_LIBDIR
1> [CMake]     CMAKE_INSTALL_LIBEXECDIR
1> [CMake]     CMAKE_INSTALL_OLDINCLUDEDIR
1> [CMake]     CMAKE_INSTALL_SBINDIR
1> [CMake] 
1> [CMake] 
1> [CMake] -- Build files have been written to: C:/Users/xxx/.conan/data/tinyxml/2.6.2/_/_/build/11b38960141478715841df824e568735e33d702c/build_subfolder
1> [CMake] [1/5] Building CXX object CMakeFiles/tinyxml.dir/source_subfolder/tinystr.cpp.obj
1> [CMake] [2/5] Building CXX object CMakeFiles/tinyxml.dir/source_subfolder/tinyxmlerror.cpp.obj
1> [CMake] [3/5] Building CXX object CMakeFiles/tinyxml.dir/source_subfolder/tinyxmlparser.cpp.obj
1> [CMake] [4/5] Building CXX object CMakeFiles/tinyxml.dir/source_subfolder/tinyxml.cpp.obj
1> [CMake] [5/5] Linking CXX static library lib\libtinyxml.a
1> [CMake] tinyxml/2.6.2: Package '11b38960141478715841df824e568735e33d702c' built
1> [CMake] tinyxml/2.6.2: Build folder C:\Users\xxx\.conan\data\tinyxml\2.6.2\_\_\build\11b38960141478715841df824e568735e33d702c
1> [CMake] tinyxml/2.6.2: Generated conaninfo.txt
1> [CMake] tinyxml/2.6.2: Generated conanbuildinfo.txt
1> [CMake] tinyxml/2.6.2: Generating the package
1> [CMake] tinyxml/2.6.2: Package folder C:\Users\xxx\.conan\data\tinyxml\2.6.2\_\_\package\11b38960141478715841df824e568735e33d702c
1> [CMake] tinyxml/2.6.2: Calling package()
1> [CMake] [0/1] Install the project...
1> [CMake] -- Install configuration: "Debug"
1> [CMake] -- Installing: C:/Users/xxx/.conan/data/tinyxml/2.6.2/_/_/package/11b38960141478715841df824e568735e33d702c/lib/libtinyxml.a
1> [CMake] -- Installing: C:/Users/xxx/.conan/data/tinyxml/2.6.2/_/_/package/11b38960141478715841df824e568735e33d702c/include/tinystr.h
1> [CMake] -- Installing: C:/Users/xxx/.conan/data/tinyxml/2.6.2/_/_/package/11b38960141478715841df824e568735e33d702c/include/tinyxml.h
1> [CMake] tinyxml/2.6.2 package(): Packaged 2 '.h' files: tinystr.h, tinyxml.h
1> [CMake] tinyxml/2.6.2 package(): Packaged 1 '.a' file: libtinyxml.a
1> [CMake] tinyxml/2.6.2 package(): Packaged 1 file: LICENSE
1> [CMake] tinyxml/2.6.2: Package '11b38960141478715841df824e568735e33d702c' created
1> [CMake] tinyxml/2.6.2: Created package revision cd6b06191d5c48b88402bf81c1a3e015
1> [CMake] conanfile.txt: Generator cmake_find_package created Findspdlog.cmake
1> [CMake] conanfile.txt: Generator cmake_find_package created FindTinyXML.cmake
1> [CMake] conanfile.txt: Generator cmake_find_package created Findmagic_enum.cmake
1> [CMake] conanfile.txt: Generator cmake_find_package created Findetl.cmake
1> [CMake] conanfile.txt: Generator cmake_find_package created Findfmt.cmake
1> [CMake] conanfile.txt: Generator qmake created conanbuildinfo.pri
1> [CMake] conanfile.txt: Generator txt created conanbuildinfo.txt
1> [CMake] conanfile.txt: Aggregating env generators
1> [CMake] conanfile.txt: Generated conaninfo.txt
1> [CMake] conanfile.txt: Generated graphinfo

Now compiling my project works fine however the linking fails error : bin\foo.elf uses VFP register arguments, C:/Users/xxx/.conan/data/tinyxml/2.6.2/_/_/package/11b38960141478715841df824e568735e33d702c/lib/libtinyxml.a(tinyxml.cpp.obj) does not

=>In my case, I'd like to use the Hardware FPU of my embedded controller. However it looks like conan ignores my Compiler and/or linker flags.

=>how can i pass specify compiler or linker flags to conan?

Thx for your help :)

Ju1He1 commented 2 years ago

is it possible to print the actual compiler and liker flags used by conan?

memsharded commented 1 day ago

Sorry this was not responded back then @Ju1He1, sometimes the team is too busy and some tickets fall through the cracks.

This seems now outdated, with a new cmake-conan integration, and also new CMakeDeps and other generators. I am closing this as outdated, please create new tickets if necessary, thanks for your feedback.