Disable compiler checks


When running cmake it will try to find a suitable compiler and try to see if it can program a simple program with it.

  1. Can someone verify that if you specify a variable from the command line that this will not be passed to this test compilation and it will trash it?
  2. How can I disable these checks?

Can someone help please?


What kind of variable? Environment? Command line argument? To CMake itself? Do you have an example?

If you want CMake to compile C or C++ code, CMake needs to figure out what compiler it’s working with so that it can create the correct command lines to build your code. If you want to use a different compiler, you can set CC or CXX environment variables. There are also toolchain files you can use to specify more details for cross compilation.

Command line argument.

Basically I’m running this github repo https://github.com/ObKo/stm32-cmake and you can see what I am trying to do here
From the issue above I deduce that the command line argument is not being passed when doing the test compile.
And by running the cmake command with --trace I notice that toolchain file is included twice which is imo counter intuitive, even though I read somewhere that you should keep the toolchain fairly simple because it may be included multiple times.

I understand how to use a different compiler, but there are a few cases where you might want to pass an argument to the compiler even when doing a test build. From my limited experience it looks like this is impossible. When you specify a different compiler, let’s say arm-none-eabi-gcc, when testing the compiler it will run something simple such as arm-none-eabi-gcc test.c and it will definitely not include any command line arguments that may be needed.

Oh, that’s probably true. @brad.king Is there some way to pass additional CMAKE_FLAGS to the compiler detection try_compile internals? Or should these things be set directly in the toolchain file (as my gut is telling me is the sanctioned way)?

As I said above, I feel like this is supposed to be part of the toolchain file, but I am not super-well versed in them. Maybe it could do this via an include(OPTIONAL) to get the settings from a file somewhere?

Compiler flags that are always needed should either be in CMAKE_{C,CXX}_FLAGS (perhaps via CFLAGS and CXXFLAGS environment variables) or be added by code in a CMAKE_TOOLCHAIN_FILE. The toolchain file is always included in try_compile projects and so can add such flags consistently.