256 character limit on CACHE INTERNAL entries

This is a comment rather than a question…

I had a problem today where I was trying to store a long list of libraries, which were being found in a recursive search through many layers of function calls but needed to be available in the global scope.

I decided it would a clever idea to store the list globally as a string using CACHE INTERNAL.

It wasn’t clever; after a certain number of libraries had been found, the rest were being ignored. It was a hard problem to debug, but eventually I realised that once the total length of the string exceeded 256 characters, nothing more could be added to it.

I wouldn’t mind so much but I can’t find this in the documentation anywhere.

I got my application working by replacing the intended cache variable with an ordinary list, and making sure that it was promoted using PARENT_SCOPE in each layer of the the recursion all the way up to the global scope. It does the job, but it’s a much less elegant solution than I’d hoped for.

That’s surprising to me. I’ve stored very long contents in ordinary CMake variables, and I’m not aware of any restriction specific to cache variables. Can you provide a minimal example which demonstrates the problem for you? If you can distill it down to the bare minimum needed to show the problem, that will make it more likely someone will investigate. I suspect the real problem you’re hitting is related to the different variable scopes involved (each function has its own variable scope).

I can’t reproduce this:

cmake_minimum_required(VERSION 3.12)
project(foo NONE)

set(value
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890
  12345678901234567890123456789012345678901234567890)
message("${long}")
set(long "${value}" CACHE INTERNAL "")
message("${value}")
message("${long}")
$ cmake .

12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/boeckb/misc/code/sb/cm-cache-int-limit
$ cmake .
12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890;12345678901234567890123456789012345678901234567890
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/boeckb/misc/code/sb/cm-cache-int-limit

In any case, I would recommend using a global property instead of a cache variable, especially if it only matters within a single configure run (and not across configures).