From 1d6db661796b2b764e845b7cf6b9f8399037c668 Mon Sep 17 00:00:00 2001 From: Jannik Alber Date: Tue, 25 Oct 2022 22:13:02 +0200 Subject: CPack: Add Inno Setup generator --- Tests/CMakeLists.txt | 24 ++++ Tests/CPackInnoSetupGenerator/CMakeLists.txt | 55 +++++++++ Tests/CPackInnoSetupGenerator/Code.pas | 4 + .../RunCPackVerifyResult.cmake | 136 +++++++++++++++++++++ Tests/CPackInnoSetupGenerator/main.c | 7 ++ Tests/CPackInnoSetupGenerator/my_bitmap.bmp | Bin 0 -> 9294 bytes Tests/CPackInnoSetupGenerator/my_file.txt | 1 + 7 files changed, 227 insertions(+) create mode 100644 Tests/CPackInnoSetupGenerator/CMakeLists.txt create mode 100644 Tests/CPackInnoSetupGenerator/Code.pas create mode 100644 Tests/CPackInnoSetupGenerator/RunCPackVerifyResult.cmake create mode 100644 Tests/CPackInnoSetupGenerator/main.c create mode 100644 Tests/CPackInnoSetupGenerator/my_bitmap.bmp create mode 100644 Tests/CPackInnoSetupGenerator/my_file.txt (limited to 'Tests') diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index e92d1c1c09..e3b5ec41d8 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -986,6 +986,30 @@ if(BUILD_TESTING) endif() endif() + # On Windows run the CPackInnoSetupGenerator test + if(WIN32 AND CMake_TEST_CPACK_INNOSETUP) + add_test(CPackInnoSetupGenerator ${CMAKE_CTEST_COMMAND} + -C \${CTEST_CONFIGURATION_TYPE} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/CPackInnoSetupGenerator" + "${CMake_BINARY_DIR}/Tests/CPackInnoSetupGenerator" + ${build_generator_args} + --build-project CPackInnoSetupGenerator + --build-options + --test-command ${CMAKE_CMAKE_COMMAND} + "-DCPackInnoSetupGenerator_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackInnoSetupGenerator" + "-Dconfig=\${CTEST_CONFIGURATION_TYPE}" + -P "${CMake_SOURCE_DIR}/Tests/CPackInnoSetupGenerator/RunCPackVerifyResult.cmake") + + set_property(TEST CPackInnoSetupGenerator PROPERTY + ATTACHED_FILES_ON_FAIL + "${CMake_BINARY_DIR}/Tests/CPackInnoSetupGenerator/_CPack_Packages/win32/INNOSETUP/ISCCOutput.log") + + set_property(TEST CPackInnoSetupGenerator PROPERTY + ATTACHED_FILES + "${CMake_BINARY_DIR}/Tests/CPackInnoSetupGenerator/_CPack_Packages/win32/INNOSETUP/ISScript.iss") + endif() + # On Windows run the CPackNSISGenerator test # if the nsis is available if(WIN32 AND NSIS_MAKENSIS_EXECUTABLE) diff --git a/Tests/CPackInnoSetupGenerator/CMakeLists.txt b/Tests/CPackInnoSetupGenerator/CMakeLists.txt new file mode 100644 index 0000000000..bca0ad6cd7 --- /dev/null +++ b/Tests/CPackInnoSetupGenerator/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 3.13) + +project(CPackInnoSetupGenerator VERSION 42.0 HOMEPAGE_URL "https://www.example.com") + +add_executable(hello main.c) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/empty) + +install(TARGETS hello DESTINATION / COMPONENT application) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/empty DESTINATION / COMPONENT extras) +install(FILES my_bitmap.bmp DESTINATION awesome COMPONENT extras) +install(FILES my_file.txt DESTINATION / COMPONENT hidden_component) +install(FILES my_file.txt DESTINATION / COMPONENT hidden_component2) + +set(CPACK_GENERATOR "INNOSETUP") + +set(CPACK_PACKAGE_NAME "Hello, World!") # Test constant escape (like {cm:...}, see code documentation) +set(CPACK_PACKAGE_VENDOR "Sheldon Cooper") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "hello_world") +set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "hello_world") +set(CPACK_PACKAGE_FILE_NAME "hello_world_setup") +set(CPACK_SYSTEM_NAME "win32") +set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/my_bitmap.bmp") +set(CPACK_VERBATIM_VARIABLES ON) +set(CPACK_PACKAGE_EXECUTABLES "hello" "Hello, World!") +set(CPACK_CREATE_DESKTOP_LINKS hello) + +set(CPACK_INNOSETUP_INSTALL_ROOT "{autopf}\\Sheldon Cooper") +set(CPACK_INNOSETUP_PROGRAM_MENU_FOLDER ".") +set(CPACK_INNOSETUP_IGNORE_LICENSE_PAGE ON) +set(CPACK_INNOSETUP_IGNORE_README_PAGE OFF) # Test if only readme page is shown +set(CPACK_INNOSETUP_SETUP_AppComments ON) # Test if CPACK_INNOSETUP_USE_CMAKE_BOOL_FORMAT works +set(CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS "extras/empty" + "Name: \"{userdocs}\\empty\"\; Check: ReturnTrue\; Components: accessories\\extras") +set(CPACK_INNOSETUP_MENU_LINKS "https://www.example.com" "Web" + "my_file.txt" "Text") +set(CPACK_INNOSETUP_RUN_EXECUTABLES hello) +set(CPACK_INNOSETUP_CREATE_UNINSTALL_LINK ON) +# Test if this macro is available in the code file below containing the check function +set(CPACK_INNOSETUP_DEFINE_PascalMacro "end;") +set(CPACK_INNOSETUP_CODE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Code.pas") +set(CPACK_INNOSETUP_EXECUTABLE "ISCC.exe") + +include(CPackComponent) + +cpack_add_install_type(basic DISPLAY_NAME "Basic installation") +cpack_add_install_type(full DISPLAY_NAME "\"Large\" installation") # Test double quote syntax +cpack_add_component_group(accessories DISPLAY_NAME "Accessories") + +cpack_add_component(application DISPLAY_NAME "Application" INSTALL_TYPES basic full REQUIRED) +cpack_add_component(extras DISPLAY_NAME "Additional components" INSTALL_TYPES full GROUP accessories) +cpack_add_component(hidden_component HIDDEN) +cpack_add_component(hidden_component2 HIDDEN DISABLED) +set(CPACK_INNOSETUP_extras_INSTALL_DIRECTORY "{userdocs}") + +include(CPack) diff --git a/Tests/CPackInnoSetupGenerator/Code.pas b/Tests/CPackInnoSetupGenerator/Code.pas new file mode 100644 index 0000000000..d96d82f2df --- /dev/null +++ b/Tests/CPackInnoSetupGenerator/Code.pas @@ -0,0 +1,4 @@ +function ReturnTrue(): Boolean; +begin + Result := true; +{#PascalMacro} diff --git a/Tests/CPackInnoSetupGenerator/RunCPackVerifyResult.cmake b/Tests/CPackInnoSetupGenerator/RunCPackVerifyResult.cmake new file mode 100644 index 0000000000..72a26ee754 --- /dev/null +++ b/Tests/CPackInnoSetupGenerator/RunCPackVerifyResult.cmake @@ -0,0 +1,136 @@ +message(STATUS "=============================================================") +message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") +message(STATUS "") + +if(NOT CPackInnoSetupGenerator_BINARY_DIR) + message(FATAL_ERROR "CPackInnoSetupGenerator_BINARY_DIR not set") +endif() + +message(STATUS "CMAKE_COMMAND: ${CMAKE_COMMAND}") +message(STATUS "CMAKE_CPACK_COMMAND: ${CMAKE_CPACK_COMMAND}") +message(STATUS "CPackInnoSetupGenerator_BINARY_DIR: ${CPackInnoSetupGenerator_BINARY_DIR}") + +if(config) + set(_C_config -C ${config}) +endif() + +execute_process(COMMAND "${CMAKE_CPACK_COMMAND}" + ${_C_config} + RESULT_VARIABLE CPack_result + OUTPUT_VARIABLE CPack_output + ERROR_VARIABLE CPack_output + WORKING_DIRECTORY "${CPackInnoSetupGenerator_BINARY_DIR}") + +if(CPack_result) + message(FATAL_ERROR "CPack execution went wrong!, Output: ${CPack_output}") +else () + message(STATUS "Output: ${CPack_output}") +endif() + +file(GLOB project_file "${CPackInnoSetupGenerator_BINARY_DIR}/_CPack_Packages/win32/INNOSETUP/ISScript.iss") +file(GLOB installer_file "${CPackInnoSetupGenerator_BINARY_DIR}/_CPack_Packages/win32/INNOSETUP/hello_world_setup.exe") + +message(STATUS "Project file: '${project_file}'") +message(STATUS "Installer file: '${installer_file}'") + +if(NOT project_file) + message(FATAL_ERROR "Project file does not exist") +endif() + +if(NOT installer_file) + message(FATAL_ERROR "Installer file does not exist") +endif() + +# Test if the correct registry key is set +file(STRINGS "${project_file}" results REGEX "^AppId=hello_world$") +if(results STREQUAL "") + message(FATAL_ERROR "CPACK_PACKAGE_INSTALL_REGISTRY_KEY doesn't match AppId") +endif() + +# Test if only readme page is shown +file(STRINGS "${project_file}" results REGEX "^LicenseFile=") +file(STRINGS "${project_file}" results2 REGEX "^InfoBeforeFile=") +if(NOT results STREQUAL "" OR results2 STREQUAL "") + message(FATAL_ERROR "Erroneous output with license and readme files") +endif() + +# Test if classic style is used by default +file(STRINGS "${project_file}" results REGEX "compiler:SetupClassicIcon\\.ico") +file(STRINGS "${project_file}" results2 REGEX "compiler:WizClassicImage\\.bmp") +if(results STREQUAL "" OR results2 STREQUAL "") + message(FATAL_ERROR "Images of classic style not used") +endif() + +# Test if the top-level start menu folder is used +file(STRINGS "${project_file}" results REGEX "{autoprograms}") +file(STRINGS "${project_file}" results2 REGEX "{group}") +if(results STREQUAL "" OR NOT results2 STREQUAL "") + message(FATAL_ERROR "Top-level start menu folder not used") +endif() + +# Test CPACK_INNOSETUP_USE_CMAKE_BOOL_FORMAT +file(STRINGS "${project_file}" results REGEX "^AppComments=yes$") +if(results STREQUAL "") + message(FATAL_ERROR "CPACK_INNOSETUP_USE_CMAKE_BOOL_FORMAT doesn't convert booleans") +endif() + +# Test the custom installation rule +file(STRINGS "${project_file}" results REGEX "^Name: \"{userdocs}\\\\empty\"; Check: ReturnTrue; Components: accessories\\\\extras$") +if(results STREQUAL "") + message(FATAL_ERROR "Custom installation rule not found or incomplete") +endif() + +# Test if an uninstall shortcut has been created +file(STRINGS "${project_file}" results REGEX "{uninstallexe}") +if(results STREQUAL "") + message(FATAL_ERROR "No uninstall shortcut created") +endif() + +# Test CPACK_INNOSETUP__INSTALL_DIRECTORY +file(STRINGS "${project_file}" results REGEX "{app}.*Components: accessories\\\\extras") +if(NOT results STREQUAL "") + message(FATAL_ERROR "Component not in custom install directory") +endif() + +# Test if component names are nested correctly +file(STRINGS "${project_file}" results REGEX "Components:.* extras") +if(NOT results STREQUAL "") + message(FATAL_ERROR "Component names must contain their parent groups according to the documentation") +endif() + +# Test if custom installation type exists +file(STRINGS "${project_file}" results REGEX "Flags: .*iscustom") +if(results STREQUAL "") + message(FATAL_ERROR "Custom installation type doesn't exist") +endif() + +# Test if hidden components are processed but not displayed +file(STRINGS "${project_file}" results REGEX "Source:.+hidden_component\\\\my_file\\.txt") +file(STRINGS "${project_file}" results2 REGEX "Name: \"hidden_component\"") +if(results STREQUAL "" OR NOT results2 STREQUAL "") + message(FATAL_ERROR "Hidden component displayed or one of its files ignored") +endif() + +# Test if disabled and hidden components are ignored at all +file(STRINGS "${project_file}" results REGEX "Source:.+hidden_component2\\\\my_file\\.txt") +if(NOT results STREQUAL "") + message(FATAL_ERROR "Disabled and hidden component not ignored") +endif() + +# Test if required components ignore their installation types +file(STRINGS "${project_file}" results REGEX "Types: (basic|full|custom|basic full|full basic|basic custom|full custom); Flags: fixed") +if(NOT results STREQUAL "") + message(FATAL_ERROR "Required components don't ignore their installation types") +endif() + +# Test constant escape (should contain Hello%2c World!) +file(STRINGS "${project_file}" results REGEX "Hello%2c World!") +if(results STREQUAL "") + message(FATAL_ERROR "The comma character isn't escaped to %2c") +endif() + +# Test double quote syntax +file(STRINGS "${project_file}" results REGEX "\"\"Large\"\"") +if(results STREQUAL "") + message(FATAL_ERROR "The quote character isn't escaped correctly") +endif() diff --git a/Tests/CPackInnoSetupGenerator/main.c b/Tests/CPackInnoSetupGenerator/main.c new file mode 100644 index 0000000000..413899c807 --- /dev/null +++ b/Tests/CPackInnoSetupGenerator/main.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + printf("Hello, World!\n"); + return 42; +} diff --git a/Tests/CPackInnoSetupGenerator/my_bitmap.bmp b/Tests/CPackInnoSetupGenerator/my_bitmap.bmp new file mode 100644 index 0000000000..d0e562fb37 Binary files /dev/null and b/Tests/CPackInnoSetupGenerator/my_bitmap.bmp differ diff --git a/Tests/CPackInnoSetupGenerator/my_file.txt b/Tests/CPackInnoSetupGenerator/my_file.txt new file mode 100644 index 0000000000..8ab686eafe --- /dev/null +++ b/Tests/CPackInnoSetupGenerator/my_file.txt @@ -0,0 +1 @@ +Hello, World! -- cgit v1.2.1