Discussion:
[CMake] CPack WIX examples
jmerkow
2014-09-23 14:34:18 UTC
Permalink
Hello

I am working on creating an msi installer using cpack with the WIX installer
(converting from old system). Im having some trouble finding some good
resources to do this.
My project needs to set a number of registry entries. We have a few
components, and licenses that are installed along with our software. I also
don't completely understand the example for CPACK_WIX_PATCH_FILE in the
documentation for adding components, etc.
I thought it would be helpful to see some of this in action and I was hoping
someone could point me to an example or two of a project that uses CPack WIX
generators to get me going. I searched github and around the CMake website,
and couldn't find any projects that use WIX.

-Jameson



--
View this message in context: http://cmake.3232098.n2.nabble.com/CPack-WIX-examples-tp7588561.html
Sent from the CMake mailing list archive at Nabble.com.
Nils Gladitz
2014-09-23 14:40:39 UTC
Permalink
Post by jmerkow
Hello
I am working on creating an msi installer using cpack with the WIX installer
(converting from old system). Im having some trouble finding some good
resources to do this.
My project needs to set a number of registry entries. We have a few
components, and licenses that are installed along with our software. I also
don't completely understand the example for CPACK_WIX_PATCH_FILE in the
documentation for adding components, etc.
I thought it would be helpful to see some of this in action and I was hoping
someone could point me to an example or two of a project that uses CPack WIX
generators to get me going. I searched github and around the CMake website,
and couldn't find any projects that use WIX.
I've got some tiny example projects (actually manual test cases):
https://github.com/ngladitz/cmake-wix-testsuite

Each sub directory should contain a self contained project usually
exercising one specific feature of the WIX generator.

Nils
jmerkow
2014-09-24 00:40:33 UTC
Permalink
Thanks a lot for your help! Those examples are excellent.

I have a follow up questions for creating the installer, though. We have a
number of registry entries that need to be created for the software to run
in 'release mode'. In our current system we add registry entries into the
wxs, but I don't see a way to do that with cmake/cpack easily.
We add a few lines, such as:
<Registry Id='regid7' Root='HKLM' Key='Software\proj\proj 2.0'
Name='HomeDir' Action='write' Type='string' Value='[INSTALLDIR]Home' />
We use these registry entries as anchors for the locations for software
assets.

It seems the best way to do this would be to override the template with a
number of configurable entries?
So I could add something like (there's about 15 of em):
<Registry Id='regid7' Root='HKLM' Key='Software\@proj_name@\@proj_name@
@proj_FULL_VERSION@' Name='HomeDir' Action='write' Type='string'
Value='[INSTALL_ROOT]@home_path@' />

I wanted to check to see if there was a way to handle this directly from
CMake.

-Jameson



--
View this message in context: http://cmake.3232098.n2.nabble.com/CPack-WIX-examples-tp7588561p7588576.html
Sent from the CMake mailing list archive at Nabble.com.
Nils Gladitz
2014-09-24 07:17:33 UTC
Permalink
Post by jmerkow
It seems the best way to do this would be to override the template with a
number of configurable entries?
@proj_FULL_VERSION@' Name='HomeDir' Action='write' Type='string'
I wanted to check to see if there was a way to handle this directly from
CMake.
The <Registry> elements will require a <Component> parent and that
component needs to be referenced by an existing feature.
I've used CPACK_WIX_PATCH_FILE (e.g. the fragment_injection example) to
insert similar content into existing components.
The patch file could also be configured by configure_file().

If you need this to be an independent <Component> I suppose you could
use your own template,
add the <Component> (and its <Registry> childen) to the <Product>
element and add a reference
to it from within the existing <FeatureRef Id="ProductFeature"/> element.

Nils
jmerkow
2014-09-24 19:26:05 UTC
Permalink
Ok I'm going the fragment injection route, but having some issues.

So I found the component id for the target that these registry values will
be needed by in files.wxs:
<Component Id="CMP_ID_1" Guid="*">
<File Id="FILE_ID_1" Source="C:/blah/blah/Bin/myapp.exe" KeyPath="yes"/>
</Component>
In this case its 'CMP_ID_1', using the first cmp id seemed like a safe bet
in general to have it referenced by a feature.

So a configurable patch.xml.in looks something like:
<CPackWiXPatch>
<CPackWiXFragment Id="CMP_ID_1">
<Registry Id='regid1' Root='HKLM'
Key='Software\myproj\@myproj_VERSION@
@***@.@myproj_MINOR_VERSION@' Name='InstallDir'
Action='write' Type='string' Value='[INSTALL_ROOT]' />
<Registry Id='regid2' ... />
...
</CPackWiXFragment>
</CPackWiXPatch>

There are just a few in there to test the process.

In CMake, i configure and add it the file to CPACK_WIX_PATCH_FILE:
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/windows/registry-patch.xml.in
"${TEMP_DIR}/registry-patch.xml" @ONLY)
set(CPACK_WIX_PATCH_FILE "${TEMP_DIR}/registry-patch.xml")

Then I generate the msi using cpack. However the resulting msi doesn't set
any registry entries, I also don't see any of the entries anywhere in the
resulting xml.
I did notice that in the documentations [1] and in your example your
component id is more complex..
It looks to be something like (and I'm abusing cmake generator expressions
for brevity)
Id='***@cmake_component@***@TARGET_FILE_DIR:***@.@TARGET_FILE_DIR:tgt@'. I
tried an Id of this nature as well (i.e. <CPackWiXFragment
Id="CMP_CP_CoreExecutables.Bin.myapp.exe">) but this also did not work.
Am I obtaining the id wrong? The documentation is a little confusing
compared to whats being generated. so I'm not sure exactly sure if I have
the proper id. Is there a way to get the Id from the in cmake to configure
the file directly? Maybe there is another issue entirely?

-Jameson
[1]
http://www.cmake.org/cmake/help/v3.0/module/CPackWIX.html?highlight=cpack_wix_patch
[2]
https://github.com/ngladitz/cmake-wix-testsuite/tree/master/fragment_injection



--
View this message in context: http://cmake.3232098.n2.nabble.com/CPack-WIX-examples-tp7588561p7588591.html
Sent from the CMake mailing list archive at Nabble.com.
Nils Gladitz
2014-09-24 20:07:40 UTC
Permalink
Post by jmerkow
Am I obtaining the id wrong? The documentation is a little confusing
compared to whats being generated. so I'm not sure exactly sure if I have
the proper id. Is there a way to get the Id from the in cmake to configure
the file directly? Maybe there is another issue entirely?
After running CPack with the WIX generator you will have a
"_CPack_Packages\<arch>\WIX" directory.
Within are all the WIX sources and everything else used to build the
installer.

In "files.wxs" you can find all the component definitions and their IDs.
Here you can also find your patch fragments (if they are being
successfully applied).

Using a non existent ID in a patch file should generate an error at
CPack time.

If you are currently successfully generating an installer with an
invalid ID that might indicate that the patch file isn't being used at all.
Is it possible that you are using an older CMake release or that you are
setting CPACK_WIX_PATCH_FILE after or outside the context of your
include(CPack)?

CPack only sees the options that make it to CPackConfig.cmake which is
generated by include(CPack).

Nils
jmerkow
2014-09-24 21:20:16 UTC
Permalink
Ok, I've double checked everything and I'm not sure whats going on.

I was looking in files.wxs (in _CPack_Packages/win64/WIX) for the component
ID, and i've tried a few different ones. I also dropped the config file
step and used your example patch.xml:
<CPackWiXPatch>
<CPackWiXFragment Id="CMP_ID_1">
<Environment Id="MyEnvironment" Action="set" Name="FOOBAR" Value="FooBar"/>
</CPackWiXFragment>
</CPackWiXPatch>

Still nothing added when I search file.wxs for FOOBAR or anything else that
should be added with the fragment injection. I am still curious as to why
the component id's look so different between your tests and whats being
generated in my file.wxs.

That seems to leave the older version question....
Is this feature new with 3+? I am using CMake 2.8.12.2

-Jameson



--
View this message in context: http://cmake.3232098.n2.nabble.com/CPack-WIX-examples-tp7588561p7588594.html
Sent from the CMake mailing list archive at Nabble.com.
jmerkow
2014-09-24 21:25:35 UTC
Permalink
I forgot to mention that I double checked that this particular code was being
executed. I started changing the name (and adding a time stamp) to the msi
in the same section of code to double check. Here is it is (its at send of
my code for cpack):

...
if(WIN32)
if(MSVC)
set(CPACK_GENERATOR "WIX")
set(CPACK_WIX_PRODUCT_GUID "---")
set(CPACK_WIX_UPGRADE_GUID "---")
SET(CPACK_PACKAGE_FILE_NAME
"myproj-${myproj_FULL_VERSION}-Win-x64_${TIMESTAMP}_NewTest")
set(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/patch.xml")
endif()
endif()

include(CPack)



--
View this message in context: http://cmake.3232098.n2.nabble.com/CPack-WIX-examples-tp7588561p7588595.html
Sent from the CMake mailing list archive at Nabble.com.
Nils Gladitz
2014-09-24 21:39:36 UTC
Permalink
Post by jmerkow
Ok, I've double checked everything and I'm not sure whats going on.
I was looking in files.wxs (in _CPack_Packages/win64/WIX) for the component
ID, and i've tried a few different ones. I also dropped the config file
<CPackWiXPatch>
<CPackWiXFragment Id="CMP_ID_1">
<Environment Id="MyEnvironment" Action="set" Name="FOOBAR" Value="FooBar"/>
</CPackWiXFragment>
</CPackWiXPatch>
Still nothing added when I search file.wxs for FOOBAR or anything else that
should be added with the fragment injection. I am still curious as to why
the component id's look so different between your tests and whats being
generated in my file.wxs.
That seems to leave the older version question....
Is this feature new with 3+? I am using CMake 2.8.12.2
Yes, 2.8.12 does not have CPACK_WIX_PATCH_FILE yet:
http://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:CPackWIX

You would need 3.0:
www.cmake.org/cmake/help/v3.0/module/CPackWIX.html

The WIX generator is still relatively new and hasn't had as much time as
the other generators to settle yet.
I am still in progress of adding features as requests come in which
means that many of the more recent additions will require a more current
CMake version.

Nils
jmerkow
2014-09-25 15:34:05 UTC
Permalink
Thanks a lot this worked! Are there any plans to add the functionality for
adding registry entries into the WIX xml directly? Looking at the source
code, it looks like it would be somewhat painless. If no one is already
working on this, I'll work on contributing the code myself, in the near
future.

-Jameson



--
View this message in context: http://cmake.3232098.n2.nabble.com/CPack-WIX-examples-tp7588561p7588600.html
Sent from the CMake mailing list archive at Nabble.com.
Nils Gladitz
2014-09-25 15:49:37 UTC
Permalink
Post by jmerkow
Thanks a lot this worked! Are there any plans to add the functionality for
adding registry entries into the WIX xml directly? Looking at the source
code, it looks like it would be somewhat painless. If no one is already
working on this, I'll work on contributing the code myself, in the near
future.
I was planning on extending the patch mechanism for the Product element
following up on a request that was part of a different issue:
http://public.kitware.com/Bug/view.php?id=15165#c36863

Which I think would also match this use case?
Unless you were thinking about adding these somewhere else or in an
entirely different way?

Nils

Loading...