View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0016056CMakeCMakepublic2016-04-08 13:182016-06-10 14:21
Reporterjohnnyzz 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product VersionCMake 3.5.1 
Target VersionFixed in Version 
Summary0016056: file(GENERATE) not processing variables from INPUT file
DescriptionThere is a bug when generating a file with:

file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/output1.txt"
      INPUT ${CMAKE_SOURCE_DIR}/input.txt
)

file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/output2.txt"
      CONTENT "SOURCE DIR = '${CMAKE_SOURCE_DIR}'"
)

- Using "INPUT filename", variables are not processed, but "CONTENT text" with the same content works properly
Steps To Reproduce1) cmake .
2) cat output1.txt
3) cat output2.txt

-> The variable in output1.txt is not replaced by its value
TagsNo tags attached.
Attached Filestxt file icon CMakeLists.txt [^] (270 bytes) 2016-04-08 13:18 [Show Content]
txt file icon input.txt [^] (35 bytes) 2016-04-08 13:19 [Show Content]

 Relationships

  Notes
(0040830)
Brad King (manager)
2016-04-08 13:27

file(GENERATE) does not document that it expands variables. It doesn't expand them in either case. In fact it is not well-defined to do so because the generation does not occur until after configuration is complete when the variable definitions may no longer be available.

The difference you're seeing is the CMake language processing that expands variables in the argument to CONTENT before the file(GENERATE) command even sees it.
(0040831)
Brad King (manager)
2016-04-08 13:30

> CMake language processing that expands variables in the argument to CONTENT

One can see this by using a bracket argument instead:

    file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/output2.txt"
         CONTENT [[SOURCE DIR = '${CMAKE_SOURCE_DIR}']]
    )

Bracket-enclosed arguments have no substitutions done by the language processing.

You could consider using configure_file first to replace variables and then use its output as the INPUT to file(GENERATE).
(0040832)
johnnyzz (reporter)
2016-04-08 14:01

Well, I see it now, thanks, my intention was to store the input template separately.
The configure_file looks what I'm looking for.
Anyway, documentation states that it can expand "generator expressions", so I thought it can/could do the same with variables
(0041198)
Kitware Robot (administrator)
2016-06-10 14:21

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2016-04-08 13:18 johnnyzz New Issue
2016-04-08 13:18 johnnyzz File Added: CMakeLists.txt
2016-04-08 13:19 johnnyzz File Added: input.txt
2016-04-08 13:27 Brad King Note Added: 0040830
2016-04-08 13:27 Brad King Status new => resolved
2016-04-08 13:27 Brad King Resolution open => no change required
2016-04-08 13:30 Brad King Note Added: 0040831
2016-04-08 14:01 johnnyzz Note Added: 0040832
2016-06-10 14:21 Kitware Robot Note Added: 0041198
2016-06-10 14:21 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team