Peter Moran
Peter Moran

Reputation: 313

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, runset(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.

Upvotes: 2

Views: 3803

Answers (1)

Brandon Dyer
Brandon Dyer

Reputation: 1386

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

Upvotes: 3

Related Questions