summaryrefslogtreecommitdiffstats
path: root/Utilities
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-02-10 13:49:33 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-02-10 13:49:33 (GMT)
commit6bd277d2c15201962c2774d71f326a6918f56231 (patch)
tree1809da70b56e0164430cf082e2dcf755e9523d36 /Utilities
parent7540deb185a40ddfbac759f8027df74c2a8569c3 (diff)
parenta12b0f1b193024b71583b9150aeead33d364d189 (diff)
downloadCMake-6bd277d2c15201962c2774d71f326a6918f56231.zip
CMake-6bd277d2c15201962c2774d71f326a6918f56231.tar.gz
CMake-6bd277d2c15201962c2774d71f326a6918f56231.tar.bz2
Merge topic 'wix-prevent-nsis-overwrite'
a12b0f1b CMake: Prevent WiX installations over existing NSIS installations
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/CMakeLists.txt4
-rw-r--r--Utilities/Release/WiX/CMakeLists.txt12
-rw-r--r--Utilities/Release/WiX/CustomAction/CMakeLists.txt13
-rw-r--r--Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp45
-rw-r--r--Utilities/Release/WiX/CustomAction/exports.def2
-rw-r--r--Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs21
-rw-r--r--Utilities/Release/WiX/custom_action_dll.wxs.in6
-rw-r--r--Utilities/Release/WiX/install_dir.wxs13
8 files changed, 115 insertions, 1 deletions
diff --git a/Utilities/CMakeLists.txt b/Utilities/CMakeLists.txt
index 8b3e325..cf6bb72 100644
--- a/Utilities/CMakeLists.txt
+++ b/Utilities/CMakeLists.txt
@@ -33,3 +33,7 @@ else()
# Normal documentation build.
add_subdirectory(Sphinx)
endif()
+
+if(WIX_CUSTOM_ACTION_ENABLED)
+ add_subdirectory(Release/WiX)
+endif()
diff --git a/Utilities/Release/WiX/CMakeLists.txt b/Utilities/Release/WiX/CMakeLists.txt
new file mode 100644
index 0000000..cc0dbe1
--- /dev/null
+++ b/Utilities/Release/WiX/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_subdirectory(CustomAction)
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(CUSTOM_ACTION_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/custom_action_dll-$<CONFIG>.wxs")
+else()
+ set(CUSTOM_ACTION_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/custom_action_dll.wxs")
+endif()
+
+file(GENERATE
+ OUTPUT "${CUSTOM_ACTION_OUTPUT}"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/custom_action_dll.wxs.in"
+ )
diff --git a/Utilities/Release/WiX/CustomAction/CMakeLists.txt b/Utilities/Release/WiX/CustomAction/CMakeLists.txt
new file mode 100644
index 0000000..7efd01e
--- /dev/null
+++ b/Utilities/Release/WiX/CustomAction/CMakeLists.txt
@@ -0,0 +1,13 @@
+foreach(CONFIG DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
+ string(REPLACE "/MD" "/MT"
+ "CMAKE_CXX_FLAGS_${CONFIG}"
+ "${CMAKE_CXX_FLAGS_${CONFIG}}"
+ )
+endforeach()
+
+add_library(CMakeWiXCustomActions MODULE
+ detect_nsis_overwrite.cpp
+ exports.def
+)
+
+target_link_libraries(CMakeWiXCustomActions PRIVATE msi)
diff --git a/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp b/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp
new file mode 100644
index 0000000..dad1ae5
--- /dev/null
+++ b/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp
@@ -0,0 +1,45 @@
+#include <windows.h>
+#include <msi.h>
+#include <msiquery.h>
+
+#include <string>
+#include <vector>
+
+std::wstring get_property(MSIHANDLE msi_handle, std::wstring const& name)
+{
+ DWORD size = 0;
+
+ UINT status = MsiGetPropertyW(msi_handle, name.c_str(), L"", &size);
+
+ if(status == ERROR_MORE_DATA)
+ {
+ std::vector<wchar_t> buffer(size + 1);
+ MsiGetPropertyW(msi_handle, name.c_str(), &buffer[0], &size);
+ return std::wstring(&buffer[0]);
+ }
+ else
+ {
+ return std::wstring();
+ }
+}
+
+void set_property(MSIHANDLE msi_handle,
+ std::wstring const& name, std::wstring const& value)
+{
+ MsiSetPropertyW(msi_handle, name.c_str(), value.c_str());
+}
+
+extern "C" UINT __stdcall DetectNsisOverwrite(MSIHANDLE msi_handle)
+{
+ std::wstring install_root = get_property(msi_handle, L"INSTALL_ROOT");
+
+ std::wstring uninstall_exe = install_root + L"\\uninstall.exe";
+
+ bool uninstall_exe_exists =
+ GetFileAttributesW(uninstall_exe.c_str()) != INVALID_FILE_ATTRIBUTES;
+
+ set_property(msi_handle, L"CMAKE_NSIS_OVERWRITE_DETECTED",
+ uninstall_exe_exists ? L"1" : L"0");
+
+ return ERROR_SUCCESS;
+}
diff --git a/Utilities/Release/WiX/CustomAction/exports.def b/Utilities/Release/WiX/CustomAction/exports.def
new file mode 100644
index 0000000..0e448b2
--- /dev/null
+++ b/Utilities/Release/WiX/CustomAction/exports.def
@@ -0,0 +1,2 @@
+EXPORTS
+ DetectNsisOverwrite=DetectNsisOverwrite
diff --git a/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs b/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs
new file mode 100644
index 0000000..8fe60f2
--- /dev/null
+++ b/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs
@@ -0,0 +1,21 @@
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+ <Fragment>
+ <UI>
+ <Dialog Id="CMakeNsisOverwriteDialog" Width="310" Height="120" Title="NSIS Installation Conflict">
+ <Control Id="OK" Type="PushButton" X="122" Y="90" Width="56" Height="17" Default="yes" Cancel="yes" Text="!(loc.WixUIOK)">
+ <Publish Event="EndDialog" Value="Return">1</Publish>
+ </Control>
+ <Control Id="Text" Type="Text" X="48" Y="22" Width="260" Height="60">
+ <Text>
+ Uninstall.exe was detected in your chosen installation prefix.
+ This indicates a conflicting NSIS based installation of CMake.
+
+ Please uninstall your old CMake installation or choose a different
+ installation directory.
+ </Text>
+ </Control>
+ <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="!(loc.InvalidDirDlgIconTooltip)" FixedSize="yes" IconSize="32" Text="!(loc.InvalidDirDlgIcon)" />
+ </Dialog>
+ </UI>
+ </Fragment>
+</Wix>
diff --git a/Utilities/Release/WiX/custom_action_dll.wxs.in b/Utilities/Release/WiX/custom_action_dll.wxs.in
new file mode 100644
index 0000000..021e63c
--- /dev/null
+++ b/Utilities/Release/WiX/custom_action_dll.wxs.in
@@ -0,0 +1,6 @@
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+ <Fragment>
+ <Binary Id="CMakeCustomActionsDll"
+ SourceFile="$<TARGET_FILE:CMakeWiXCustomActions>"/>
+ </Fragment>
+</Wix>
diff --git a/Utilities/Release/WiX/install_dir.wxs b/Utilities/Release/WiX/install_dir.wxs
index 883efba..49b74e3 100644
--- a/Utilities/Release/WiX/install_dir.wxs
+++ b/Utilities/Release/WiX/install_dir.wxs
@@ -9,6 +9,9 @@
<Property Id="WixUI_Mode" Value="InstallDir" />
<DialogRef Id="CMakeExtraDialog" />
+ <?ifdef CHECK_NSIS ?>
+ <DialogRef Id="CMakeNsisOverwriteDialog" />
+ <?endif ?>
<DialogRef Id="BrowseDlg" />
<DialogRef Id="DiskCostDlg" />
@@ -36,7 +39,11 @@
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
- <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
+ <?ifdef CHECK_NSIS ?>
+ <Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="CMakeDetectNsisOverwrite" Order="4">1</Publish>
+ <Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="CMakeNsisOverwriteDialog" Order="5">CMAKE_NSIS_OVERWRITE_DETECTED="1"</Publish>
+ <?endif ?>
+ <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="6"><![CDATA[(WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1") AND CMAKE_NSIS_OVERWRITE_DETECTED<>1]]></Publish>
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
@@ -57,5 +64,9 @@
</UI>
<UIRef Id="WixUI_Common" />
+
+ <?ifdef CHECK_NSIS ?>
+ <CustomAction Id="CMakeDetectNsisOverwrite" BinaryKey="CMakeCustomActionsDll" DllEntry="DetectNsisOverwrite"/>
+ <?endif ?>
</Fragment>
</Wix>