JohnRocha
Enthusiast
Enthusiast

How do I update a CMake file and InstallBuilder not replace CMake variables?

I have a CMake file such as:

------
....
option(ENABLE_FOO "some random string" OFF)
....

if(ENABLE_FOO)
    set(FOO_STATUS "enabled")
else()
    set(FOO_STATUS "disabled"
endif()

message(STATUS "Foo is ${FOO_STATUS}")

--------

 

I am trying to use InstallBuilder logic to change the ENABLE_FOO option from OFF to ON.

I originally tried this with the <substitute> command but that command doesn't support regular expression grouping.

I learned that I would have to use <setInstallerVariableFromRegEx>, where I could read the file into a variable, use <setInstallerVariableFromRegEx> to change the value from OFF to ON, and then write the variable back out to the file. Where the regular expression replacement is

 

<pattern>(option\(ENABLE_32_BIT_BUILD\s+".*?")\s+OFF</pattern>
<substitution>\1 ON</substitution>

 

However when I do this the existing CMake variables ${FOO_STATUS} are changed to ***unknown variable FOO_STATUS***.

I know I could do an exact search and replace but then that locks the format of the option line to exactly that value.

How do I get this to work? Is there some sub function that disables nested variable expansion? I read documentation and see there is stuff like .dos, .unix, .password, .escape_backslashes, etc. that cause the variables to interpret their data differently. Is there anything like that to prevent expansion of nested variables?

Labels (4)
0 Kudos
3 Replies
michieldhont_
Hot Shot
Hot Shot

Hi @JohnRocha,

To use groups in the substitute actions you can You can use `<enableBackreferences>`. For example:

<substitute enableBackreferences="1">
  <files>path/to/your.app/Contents/MacOS/installbuilder.sh</files>
  <substitutionList>
    <substitution>
      <pattern>(.*dirname.*\$executable.*)</pattern>
      <value>exec \1</value>
    </substitution>
  </substitutionList>
</substitute>

Regards,

Michiel

JohnRocha
Enthusiast
Enthusiast

This is great @michieldhont_ ! Thank you.

I don't see this mentioned in the online documentation at:

https://clients.bitrock.com/installbuilder/docs/installbuilder-userguide.html

Is there another location I should be reading from?

Tags (1)
0 Kudos
michieldhont_
Hot Shot
Hot Shot

Hi @JohnRocha,

We will work on adding it to the documentation.

Regards,

Michiel

0 Kudos