diff options
author | Nils Gladitz <nilsgladitz@gmail.com> | 2016-02-07 19:25:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-02-09 15:28:57 (GMT) |
commit | a12b0f1b193024b71583b9150aeead33d364d189 (patch) | |
tree | f94b0230c6bfdb8e72b1572877fcadcb0d6d2a72 | |
parent | a5a5a6857241c21d306661d723b749839f4c6e1a (diff) | |
download | CMake-a12b0f1b193024b71583b9150aeead33d364d189.zip CMake-a12b0f1b193024b71583b9150aeead33d364d189.tar.gz CMake-a12b0f1b193024b71583b9150aeead33d364d189.tar.bz2 |
CMake: Prevent WiX installations over existing NSIS installations
Use a custom action to look for Uninstall.exe in the user
selected installation prefix.
Its presence indicates a previous NSIS installation.
Inform the user and request manual resolution of the issue.
-rw-r--r-- | CMakeCPack.cmake | 11 | ||||
-rw-r--r-- | CMakeCPackOptions.cmake.in | 28 | ||||
-rw-r--r-- | Utilities/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Utilities/Release/WiX/CMakeLists.txt | 12 | ||||
-rw-r--r-- | Utilities/Release/WiX/CustomAction/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp | 45 | ||||
-rw-r--r-- | Utilities/Release/WiX/CustomAction/exports.def | 2 | ||||
-rw-r--r-- | Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs | 21 | ||||
-rw-r--r-- | Utilities/Release/WiX/custom_action_dll.wxs.in | 6 | ||||
-rw-r--r-- | Utilities/Release/WiX/install_dir.wxs | 13 |
10 files changed, 151 insertions, 4 deletions
diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake index a0aadcc..3203279 100644 --- a/CMakeCPack.cmake +++ b/CMakeCPack.cmake @@ -198,6 +198,17 @@ if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") set(CPACK_WIX_UPGRADE_GUID "8ffd1d72-b7f1-11e2-8ee5-00238bca4991") + if(MSVC AND NOT "$ENV{WIX}" STREQUAL "") + set(WIX_CUSTOM_ACTION_ENABLED TRUE) + if(CMAKE_CONFIGURATION_TYPES) + set(WIX_CUSTOM_ACTION_MULTI_CONFIG TRUE) + else() + set(WIX_CUSTOM_ACTION_MULTI_CONFIG FALSE) + endif() + else() + set(WIX_CUSTOM_ACTION_ENABLED FALSE) + endif() + # Set the options file that needs to be included inside CMakeCPackOptions.cmake set(QT_DIALOG_CPACK_OPTIONS_FILE ${CMake_BINARY_DIR}/Source/QtDialog/QtDialogCPack.cmake) configure_file("${CMake_SOURCE_DIR}/CMakeCPackOptions.cmake.in" diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in index 25af0c9..59ae224 100644 --- a/CMakeCPackOptions.cmake.in +++ b/CMakeCPackOptions.cmake.in @@ -246,6 +246,29 @@ if("${CPACK_GENERATOR}" STREQUAL "WIX") "@CMake_SOURCE_DIR@/Utilities/Release/WiX/cmake_extra_dialog.wxs" ) + set(_WIX_CUSTOM_ACTION_ENABLED "@WIX_CUSTOM_ACTION_ENABLED@") + if(_WIX_CUSTOM_ACTION_ENABLED) + list(APPEND CPACK_WIX_EXTRA_SOURCES + "@CMake_SOURCE_DIR@/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs" + ) + list(APPEND CPACK_WIX_CANDLE_EXTRA_FLAGS -dCHECK_NSIS=1) + + set(_WIX_CUSTOM_ACTION_MULTI_CONFIG "@WIX_CUSTOM_ACTION_MULTI_CONFIG@") + if(_WIX_CUSTOM_ACTION_MULTI_CONFIG) + if(CPACK_BUILD_CONFIG) + set(_WIX_CUSTOM_ACTION_CONFIG "${CPACK_BUILD_CONFIG}") + else() + set(_WIX_CUSTOM_ACTION_CONFIG "Release") + endif() + + list(APPEND CPACK_WIX_EXTRA_SOURCES + "@CMake_BINARY_DIR@/Utilities/Release/WiX/custom_action_dll-${_WIX_CUSTOM_ACTION_CONFIG}.wxs") + else() + list(APPEND CPACK_WIX_EXTRA_SOURCES + "@CMake_BINARY_DIR@/Utilities/Release/WiX/custom_action_dll.wxs") + endif() + endif() + set(CPACK_WIX_UI_REF "CMakeUI_InstallDir") set(CPACK_WIX_PATCH_FILE @@ -261,8 +284,7 @@ if("${CPACK_GENERATOR}" STREQUAL "WIX") if(BUILD_QtDialog) list(APPEND CPACK_WIX_PATCH_FILE "@CMake_SOURCE_DIR@/Utilities/Release/WiX/patch_desktop_shortcut.xml" - ) - - set(CPACK_WIX_CANDLE_EXTRA_FLAGS "-dBUILD_QtDialog=1") + ) + list(APPEND CPACK_WIX_CANDLE_EXTRA_FLAGS -dBUILD_QtDialog=1) endif() endif() 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> |