0

So I have a number of CMake files - and I am trying to refactor many common things across multiple projects.

One example is we turn on features due to the compiler version (GCC)

I am having problems with: CMAKE_C_COMPILER_VERSION.

If I run cmake with --trace - I see the following:

/data/project/proj/build/thing.Debug/CMakeFiles/3.22.1/CMakeCCompiler.cmake(4):  set(CMAKE_C_COMPILER_VERSION 9.2.1 )

So - CMake knows the compiler version.

But - later in my CMake scripts I try to reference that variable and do this as a diagnostic:

  message("CMAKE_C_COMPILER_VERSION: ${CMAKE_C_COMPILER_VERSION}")

And On the console output, it is blank:

CMAKE_C_COMPILER_VERSION:

And If I try to reference the variable, it turns into blank. Why is this? Why does one part of CMake - find/understand and set a variable Only so that other parts cannot use the variable.

3
  • There are several ways for a variable to lost a value. E.g. after returning from a scope where the variable is defined: cmake.org/cmake/help/latest/manual/…. Or after calling unset for the variable. For get a specific answer you need to show your code (in form of minimal reproducible example). Commented Feb 25 at 6:25
  • Yea, that's not so simple - I am dealing with about 1100 C files, and the Cmake code is refactored into a number of 'modules' - with functions. Commented Feb 25 at 16:42
  • Please provide a minimal working example, otherwise the question is difficult to answer. You have to keep in mind that scoping is an important topic, see cmake.org/cmake/help/latest/command/set.html Commented Feb 27 at 10:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.