Usage of CMAKE_IMPORT_FILE_VERSION

Hi everyone! First time here, so sorry if I’m posting this in the wrong section.

I’m trying to implement generation of CMake exports in Meson, a build system that you may or may not know about. My goal is to be able to generate files that could be used without issues by the CMake ecosystem, but I also want to avoid having to implement something too difficult to maintain and reason about. I’ll limit this features to exports of shared and static libraries.

One thing I noticed in all nameTargets.cmake file is the definition of a CMAKE_IMPORT_FILE_VERSION variable, but it seems to be unused in the codebase and it is also undocumented. What it is used for? Can I avoid setting it in the files generated by Meson? Could this cause compatibility issues?

Thanks :slight_smile:

I would just set it to 1 to ensure that any relevant commands work as intended. It seems like it is some mechanism akin to cmake_minimum_required, but probably predates that mechanism.

Cc: @brad.king

It was added preemptively when install(EXPORT) was first developed in case we needed to make some major changes to the way the files work. So far we haven’t needed to use it.

Ok, I’ll add it in the files generated by Meson too, just in case. Or should I set it to something else? The files generated by the two build systems will differ in some way (for example, I don’t want to support anything older than CMake 3.11, so I can for example use target_link_options instead of set_target_properties), but should behave the same way.

Just set it to 1; if there is a 2 (or whatever), there will probably be other things that would need to be done differently. So for now, 1 is “act as you’ve always acted”.

Well, target_link_options is new in 3.13, so 3.11 isn’t sufficient for that.

Ok, thanks!

Yeah, sorry, I meant 3.13.

Thanks again guys : )