CMake: how to change compiler for individual target -


i have embedded project using cross compiler. introduce google test, compiled native gcc compiler. additionally build unit test targets ctc compiler.

briefly:
have 3 different targets , compile them 3 different compilers. how express in cmakelists.txt? tried set_target_properties;
seems impossible set cxx variable command!

i had same issue right now, other answer didn't me. i'm cross-compiling, , need utility programs compiled gcc, core code compiled avr-gcc.

basically, if have cmakelists.txt, , want targets in file compiled compiler, can set variables hand.

define these macros somewhere:

macro(use_host_compiler)   if (${current_compiler} strequal "native")     # save current native flags     set(native_c_flags ${cmake_c_flags} cache string "gcc flags native compiler." force)      # change compiler     set(cmake_system_name ${cmake_host_system_name})     set(cmake_system_processor ${cmake_host_system_processor})     set(cmake_c_compiler ${host_c_compiler})     set(cmake_c_flags ${host_c_flags})     set(current_compiler "host" cache string "which compiler using." force)   endif() endmacro()   macro(use_native_compiler)   if (cmake_crosscompiling , ${current_compiler} strequal "host")     # save current host flags     set(host_c_flags ${cmake_c_flags} cache string "gcc flags host compiler." force)      # change compiler     set(cmake_system_name ${native_system_name})     set(cmake_system_processor ${native_system_processor})     set(cmake_c_compiler ${native_c_compiler})     set(cmake_c_flags ${native_c_flags})     set(current_compiler "native" cache string "which compiler using." force)   endif() endmacro() 

at beginning of cmakelists.txt script (or in toolchain file), set following variables according need:

  • current_compiler
  • host_c_compiler
  • host_c_flags
  • native_system_name
  • native_c_compiler
  • native_c_flags

the idea cmake_c_compiler (and company) variable other, setting inside scope leave changed within scope.


example usage:

use_host_compiler() add_executable(foo foo.c) # compiled host (computer)'s compiler. use_native_compiler() add_executable(bar bar.c) # compiled native compiler (e.g. `avr-gcc`). 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -