简体   繁体   中英

How to set CMAKE_TRY_COMPILE_TARGET_TYPE from outside CMake

tl;dr

Given a CMakeList.txt which I cannot edit, can I set CMAKE_TRY_COMPILE_TARGET_TYPE to be STATIC_LIBRARY while configuring that file?

Ideally I could do this via an environmental variable, but if that is not possible, passing in my value as a command line argument would be ok too.

Details

I am trying to build a Conan profile that will allow me to cross build using the GNU Arm Embedded Toolchain .

Conan provides a mechanism for specifying the compiler binary and compiler + linker flags I would like CMake to use, but I need to specify set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) in order for GNU Arm Embedded to pass CMake's compiler check.

In order to get my cross build toolchain to work, then, I am left with 2 options:

  1. Every single CMake file that I want to support cross build must check if we are building for an embedded device, and if so, run set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) . This is annoying because it forces all projects to have to think about being embedded.
  2. OR, Somehow pass CMAKE_TRY_COMPILE_TARGET_TYPE to CMake without editing the CMakeList.txt .

I would like to do 2.

You may be able to get the functionality you're looking for with the -D flag.

I would try something like this: cmake -D CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM