[CMake] output a string instead of a list

Peter Kümmel syntheticpp at gmx.net
Mon Jun 12 05:11:32 EDT 2006


Brandon J. Van Every wrote:
> Peter Kümmel wrote:
>> Peter Kümmel wrote:
>>  
>>> Brandon J. Van Every wrote:
>>>    
>>>> This is driving me nuts.  I have a list of compiler flags:
>>>>
>>>> GET_DIRECTORY_PROPERTY(EXCESSIVE_CPPFLAGS_LIST
>>>>  DIRECTORY ${Chicken_SOURCE_DIR}
>>>>  DEFINITIONS
>>>> )
>>>>
>>>> I want to turn this list into a string with NO SEMICOLONS.  I need to
>>>> shove this into a .scm file and semicolons won't be appreciated.  I
>>>> keep
>>>> trying all these different FOREACH and STRING functions, and nothing
>>>> works!  I always end up with semicolons.  What's the answer?  It's like
>>>> CMake is too smart about string handling, the double quotes " " always
>>>> have side effects.  It won't let me manipulate a plain old dumb string.
>>>>
>>>> This failed:
>>>> STRING(REPLACE ";" " " EXCESSIVE_CPPFLAGS "${EXCESSIVE_CPPFLAGS_LIST}")
>>>>
>>>> This failed:
>>>> MACRO(TO_STRING list string)
>>>>  SET(${string} "")
>>>>  FOREACH(elem ${${list}})
>>>>    SET(${string} "${${string}} ${elem}")
>>>>  ENDFOREACH(elem)
>>>> ENDMACRO(TO_STRING)
>>>>
>>>> Everything I try fails.  HEEEELLLLPPPP!!!!!
>>>>
>>>>
>>>> Cheers,
>>>> Brandon Van Every
>>>>       
>>> Have you tried "${Chicken_SOURCE_DIR}"?
>>>
>>> Peter
>>>     
>>
>> Sorry, I mean  GET_DIRECTORY_PROPERTY("EXCESSIVE_CPPFLAGS_LIST"
>>
>>   
> The 1st argument is the VAR I want to dump the results into.  That's not
> the problem.  Assume that EXCESSIVE_CPPFLAGS_LIST contains a whole bunch
> of junk separated with semicolons.  Getting rid of the semicolons is the
> problem.
> 
> I wrote a totally separate script and proved that
> STRING(REPLACE ";" " " EXCESSIVE_CPPFLAGS "${EXCESSIVE_CPPFLAGS_LIST}")
> is supposed to work.  Now, is it me or is it CMake...
> 
> 
> Cheers,
> Brandon Van Every

Yes, you are right. The problem is not the construction of
EXCESSIVE_CPPFLAGS_LIST but the passing.
So when you use EXCESSIVE_CPPFLAGS_LIST do you enclose the
complete parameter list in quotes?

I had recently a similar problem, until I found this solution:

SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Zi -wd4996 -wd4800")

The point was to enclose ALSO the ${CMAKE_CXX_FLAGS_DEBUG} into the two quotes.


Hope this is a better hint.
Peter







More information about the CMake mailing list