Warning, /graphics/krita/packaging/windows/installer/MakeInstallerNsis.cmake.in is written in an unsupported language. File is not indexed.

0001 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
0002 
0003 if(NOT IS_DIRECTORY "${KRITA_PACKAGE_ROOT}")
0004     message(FATAL_ERROR "KRITA_PACKAGE_ROOT not set")
0005 endif()
0006 
0007 if(NOT DEFINED OUTPUT_FILEPATH)
0008     set(OUTPUT_FILEPATH "${CMAKE_CURRENT_BINARY_DIR}/krita-setup-x64.exe")
0009 endif()
0010 
0011 if(NOT DEFINED DOWNLOAD_DIR)
0012     set(DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
0013 endif()
0014 
0015 
0016 # Download and find NSIS
0017 if(NOT DEFINED NO_DOWNLOAD_NSIS)
0018     set(DOWNLOAD_NSIS_VERSION "3.05")
0019     message(STATUS "Downloading NSIS...")
0020     if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/nsis-${DOWNLOAD_NSIS_VERSION}")
0021         file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/nsis-${DOWNLOAD_NSIS_VERSION}")
0022     endif()
0023     file(DOWNLOAD "https://files.kde.org/krita/build/dependencies/nsis-${DOWNLOAD_NSIS_VERSION}.zip"
0024         "${DOWNLOAD_DIR}/nsis-${DOWNLOAD_NSIS_VERSION}.zip"
0025         EXPECTED_HASH SHA1=d0cf5c1397d3ffb5cf6643fbff46457e05a48312
0026     )
0027     execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${DOWNLOAD_DIR}/nsis-${DOWNLOAD_NSIS_VERSION}.zip"
0028         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
0029         RESULT_VARIABLE result_extract
0030     )
0031     if(NOT result_extract EQUAL 0)
0032         message(FATAL_ERROR "Failed to extract NSIS")
0033     endif()
0034     if(NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/nsis-${DOWNLOAD_NSIS_VERSION}")
0035         message(FATAL_ERROR "Failed to find NSIS after extracting")
0036     endif()
0037     find_program(TOOL_MAKENSIS
0038         NAMES makensis.exe
0039         PATHS
0040             "${CMAKE_CURRENT_BINARY_DIR}/nsis-${DOWNLOAD_NSIS_VERSION}"
0041         NO_DEFAULT_PATH
0042     )
0043 else()
0044     find_program(TOOL_MAKENSIS
0045         NAMES makensis.exe
0046         HINTS
0047             "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS]"
0048             "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]"
0049             "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS\\Unicode]"
0050             "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode]"
0051     )
0052 endif()
0053 if(NOT TOOL_MAKENSIS)
0054     message(FATAL_ERROR "Failed to find makensis.exe")
0055 endif()
0056 execute_process(COMMAND "${TOOL_MAKENSIS}" "/version"
0057     OUTPUT_VARIABLE MAKENSIS_VERSION
0058 )
0059 # Check version is v3.*
0060 if(NOT MAKENSIS_VERSION MATCHES "^v3\\.")
0061     message(FATAL_ERROR "Expected NSIS version v3.*, got ${MAKENSIS_VERSION}")
0062 endif()
0063 message(STATUS "NSIS version ${MAKENSIS_VERSION}")
0064 
0065 
0066 # Check if package contains debug symbols
0067 file(TO_CMAKE_PATH "${KRITA_PACKAGE_ROOT}" KRITA_PACKAGE_ROOT_PATCHED)
0068 set(is_msvc @MSVC@)
0069 if (is_msvc)
0070     file(GLOB_RECURSE globForDebugFiles
0071         "${KRITA_PACKAGE_ROOT_PATCHED}/*.pdb"
0072     )
0073 else ()
0074     file(GLOB_RECURSE globForDebugFiles
0075         "${KRITA_PACKAGE_ROOT_PATCHED}/*.debug"
0076     )
0077 endif()
0078 if(globForDebugFiles)
0079     if(REMOVE_DEBUG)
0080         message(STATUS "Removing debug symbols")
0081                 foreach(debugFileItem ${globForDebugFiles})
0082                         get_filename_component(debugFileDir "${debugFileItem}" DIRECTORY)
0083                         get_filename_component(debugDirName "${debugFileDir}" NAME)
0084                         if(debugDirName STREQUAL ".debug")
0085                                 if(EXISTS "${debugFileDir}")
0086                                         message(STATUS "Deleting ${debugFileDir}")
0087                                         file(REMOVE_RECURSE "${debugFileDir}")
0088                                 endif()
0089                         else()
0090                                 message(STATUS "Deleting ${debugFileItem}")
0091                                 file(REMOVE "${debugFileItem}")
0092                         endif()
0093                 endforeach()
0094     else()
0095         message(FATAL_ERROR "${KRITA_PACKAGE_ROOT} seems to contain debug symbols. Set REMOVE_DEBUG to true if you want to remove them.")
0096     endif()
0097 endif()
0098 
0099 
0100 # Download installer script package
0101 message(STATUS "Downloading NSIS script package...")
0102 if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis")
0103     file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis")
0104 endif()
0105 # From https://github.com/alvinhochun/KritaShellExtension/releases/tag/v1.2.4d
0106 file(DOWNLOAD "https://files.kde.org/krita/build/dependencies/krita-nsis-v1.2.4d.zip"
0107     "${DOWNLOAD_DIR}/krita-nsis.zip"
0108     EXPECTED_HASH SHA256=163a7fa0a6b36fdaf2447042780965346f746ca5fed8237e51b2f08e53c4cd4f
0109 )
0110 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${DOWNLOAD_DIR}/krita-nsis.zip"
0111     WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
0112     RESULT_VARIABLE result_extract
0113 )
0114 if(NOT result_extract EQUAL 0)
0115     message(FATAL_ERROR "Failed to extract krita-nsis package")
0116 endif()
0117 if(NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis")
0118     message(FATAL_ERROR "Failed to find krita-nsis after extracting")
0119 endif()
0120 
0121 
0122 # We supply our own freshly-generated icons, so no need for the bundled ones.
0123 file(REMOVE
0124     "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis/krita.ico"
0125     "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis/kritafile.ico"
0126 )
0127 
0128 # Place Krita installer files in the right place
0129 file(COPY "${CMAKE_CURRENT_LIST_DIR}/installer/"
0130     DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis/"
0131     FILES_MATCHING PATTERN "*"
0132 )
0133 
0134 
0135 # Build installer
0136 message(STATUS "Building installer...")
0137 set(KRITA_VERSION_NUMBER "@KRITA_STABLE_VERSION_MAJOR@.@KRITA_STABLE_VERSION_MINOR@.@KRITA_VERSION_RELEASE@.@KRITA_VERSION_REVISION@")
0138 set(KRITA_VERSION_STRING "@KRITA_VERSION_STRING@")
0139 set(KRITA_GIT_SHA1_STRING "@KRITA_GIT_SHA1_STRING@")
0140 if(KRITA_GIT_SHA1_STRING)
0141     set(KRITA_VERSION_STRING "${KRITA_VERSION_STRING} (git ${KRITA_GIT_SHA1_STRING})")
0142 endif()
0143 execute_process(COMMAND "${TOOL_MAKENSIS}"
0144     "/DKRITA_INSTALLER_64"
0145     "/DKRITA_VERSION=${KRITA_VERSION_NUMBER}"
0146     "/DKRITA_VERSION_DISPLAY=${KRITA_VERSION_STRING}"
0147     "/DKRITA_INSTALLER_OUTPUT_DIR="
0148     "/DKRITA_INSTALLER_OUTPUT_NAME=${OUTPUT_FILEPATH}"
0149     "/DKRITA_PACKAGE_ROOT=${KRITA_PACKAGE_ROOT}"
0150     "/XSetCompressor /SOLID lzma"
0151     "/V3"
0152     "/INPUTCHARSET" "UTF8"
0153     "${CMAKE_CURRENT_BINARY_DIR}/krita-nsis/installer_krita.nsi"
0154     RESULT_VARIABLE result_makensis
0155 )
0156 if(NOT result_makensis EQUAL 0)
0157     message(FATAL_ERROR "Failed to build installer")
0158 endif()
0159 
0160 message(STATUS "Built installer")