admin管理员组文章数量:1357312
I could of course be lazy and determine it by path alone. But say I want a more reliable approach, like:
if(IS_AVR)
add_compile_options(
--arduino-avr-specific-option
)
endif()
CMake does not support this natively, like it does with detecting windows/ios/linux. What I am doing currently is the inverse approach:
# If CMAKE_AVR_ROOT is set, I assume we compile for arduino/atmel and set the flags accordingly
if(CMAKE_AVR_ROOT)
set(CMAKE_SYSTEM_NAME Generic)
# another problem with this approach is you get .exe on windows, but not linux
# so this won't work on linux without an additional IF
set(CMAKE_C_COMPILER ${CMAKE_AVR_BIN}/avr-gcc.exe)
set(CMAKE_CXX_COMPILER ${CMAKE_AVR_BIN}/avr-g++.exe)
endif()
I would prefer if the CMake was set up to detect avr-gcc.exe
somehow from CMAKE_C_COMPILER
. Then, I'd set IS_AVR
and all my conditional flags/includes would be under if(IS_AVR)
. This would make the CMake work with other tools that set compiler automatically.
What is an elegant way of detecting AVR target of compilation by compiler alone?
I could of course be lazy and determine it by path alone. But say I want a more reliable approach, like:
if(IS_AVR)
add_compile_options(
--arduino-avr-specific-option
)
endif()
CMake does not support this natively, like it does with detecting windows/ios/linux. What I am doing currently is the inverse approach:
# If CMAKE_AVR_ROOT is set, I assume we compile for arduino/atmel and set the flags accordingly
if(CMAKE_AVR_ROOT)
set(CMAKE_SYSTEM_NAME Generic)
# another problem with this approach is you get .exe on windows, but not linux
# so this won't work on linux without an additional IF
set(CMAKE_C_COMPILER ${CMAKE_AVR_BIN}/avr-gcc.exe)
set(CMAKE_CXX_COMPILER ${CMAKE_AVR_BIN}/avr-g++.exe)
endif()
I would prefer if the CMake was set up to detect avr-gcc.exe
somehow from CMAKE_C_COMPILER
. Then, I'd set IS_AVR
and all my conditional flags/includes would be under if(IS_AVR)
. This would make the CMake work with other tools that set compiler automatically.
What is an elegant way of detecting AVR target of compilation by compiler alone?
Share Improve this question edited Mar 29 at 9:44 Tomáš Zato asked Mar 28 at 17:46 Tomáš ZatoTomáš Zato 53.5k63 gold badges310 silver badges827 bronze badges 3 |1 Answer
Reset to default 0You can use check_c_compiler_flag.
For example:
check_c_compiler_flag(-mmcu=atmega328p IS_AVR_COMPILER)
if(NOT IS_AVR_COMPILER)
message(FATAL_ERROR "Detected non avr gcc")
endif()
https://cmake./cmake/help/latest/module/CheckCCompilerFlag.html
本文标签: cHow to reliably determine that current CMake compiler is the avr compilerStack Overflow
版权声明:本文标题:c++ - How to reliably determine that current CMake compiler is the avr compiler? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744021172a2577234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
find_*
commands help? What aboutfind_program avr-gcc
? – Craig Estey Commented Mar 29 at 2:17env CMAKE_C_COMPILER=avr-gcc cmake ...
. Or, in the file:find_program(CMAKE_C_COMPILER NAMES gcc clang cc)
, you want to know ifCMAKE_C_COMPILER
containsavr-gcc
in some form? That would be a string operation?string(FIND ${CMAKE_C_COMPILER} avr-gcc IS_AVR_CC)
,string(LENGTH ${IS_AVR_CC} IS_AVR
(Or, using theREGEX
subcommand). – Craig Estey Commented Mar 30 at 0:13