string(JSON ... SET ...) and CACHE or PARENT_SCOPE variables - truncating due to newline
Collecting JSON data from subprojects using variables in differing scopes appears to not be possible...
Use Case:
myProject/CMakeLists.txt: SET(InfoInJSON "{}")
myProject/subProjectA/CMakeLists.txt: STRING(JSON InfoInJSON SET ...)
myProject/subProjectB/CMakeLists.txt: STRING(JSON InfoInJSON SET ...)
myProject/CMakeLists.txt: MESSAGE(STATUS "All the sub project info in JSON ${InfoInJSON}")
Problem:
-
Directory scope limits STRING() modifying myProject/InfoInJSON ... no PARENT_SCOPE or CACHE arguments for STRING()
-
cannot use...
myProject/subProjectA/CMakeLists.txt: STRING(JSON tmpVar SET "${InfoInJSON}" ...)
myProject/subProjectA/CMakeLists.txt: SET(InfoInJSON "${tmpVar}" PARENT_SCOPE)
because SET() truncates the newlines in ${tmpVar}
Workaround:
Currently writing ${InfoInJSON} to a file and then reading in each subproject then writing, etc...
Question:
Should bracket arguments [=[ allow variable expansion? perhaps with @@? ]=] which would then allow
SET(InfoInJSON [=[${tmpVar}]=] PARENT_SCOPE)
or should STRING() have PARENT_SCOPE/CACHE arguments...
I feel like I am missing something but clearly can't figure out what.
I posted here instead of forums since the forums have only 1 or 2 posts on STRING(JSON ... SET ...) - one of which is my own...
cheers