1
add_custom_target(NSISTest_Preprocess SOURCES precompress.nsi)
add_custom_command(TARGET NSISTest_Preprocess POST_BUILD
  COMMAND "${NSIS_PATH}" "...\\precompress.nsi")

The output name of the installer is defined in the nsi script. Now I'd like to simply run the installer. How do I specify what is supposed to happen when I use 'Debug->Start Debugging' or 'Debug->Start Without Debugging' in Visual Studio 2010?

I tried the CreateLaunchers.cmake script, which generates .user files, but I think it only works with add_executable.

I also tried target properties ARCHIVE_OUTPUT_NAME, LIBRARY_OUTPUT_NAME, RUNTIME_OUTPUT_NAME, but none of them have any effect.

4
  • I think the answer would be that it doesn't matter for a custom target, if you execute it with the VS debugger or not. Can you please explain why you need to differentiate the two cases? Generally speaking the Debug settings are stored in VS .vcxproj.user files, which are normally not generated by CMake. This blog post by Jim Butler generally describes the process of generating your own debugger settings files with CMake. Commented Nov 2, 2015 at 12:25
  • @Florian No, I don't need to differentiate. Either would be fine. I just want to run the executable from within VS. Since I was able to specify how to build it in CMake I thought it would be nice to specify how to run it. Commented Nov 2, 2015 at 12:49
  • You could run the installer with e.g. add_custom_target(RunInstaller COMMAND ...) from within VS. You just need to use Build instead of Debug. Add set_target_properties(RunInstaller PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) to prevent it being called with other builds. Do I understand correctly that you don't have the installer's name/path, because it's defined inside the .nsi script? Getting the name from the script or output of the script is also possible. Can you please add an example of the script content/output (I admit I don't have NSIS)? Commented Nov 2, 2015 at 13:25
  • I added an answer for the .user settings part, because I think it explains the approach better if you see the actual code. Commented Nov 2, 2015 at 14:02

1 Answer 1

1

The .user settings approach also works for custom targets. You could just add - if the path is known - the installer's .exe as a command the debugger should call with 'Debug->Start Debugging'.

VS2010Test-Debug.vcxproj.user.in

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LocalDebuggerCommand>${_my_installer_path}</LocalDebuggerCommand>
    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
  </PropertyGroup>
</Project>

CMakeLists.txt

...
if (MSVC_VERSION GREATER 1599 AND
    NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/NSISTest_Preprocess.vcxproj.user")
    file(TO_NATIVE_PATH "[your installer's path goes here]" _my_installer_path)
    configure_file(
        "VS2010Test-Debug.vcxproj.user.in"
        "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/NSISTest_Preprocess.vcxproj.user"
    )
    file(
        COPY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/NSISTest_Preprocess.vcxproj.user"
        DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
        FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
    )
endif()

Background

  • I only copy/configure the file when it's not present, because VS does not handle outside changes to .user files very well
  • I have to make sure all file access rights are set properly, because your SCM may set a read-only flag (which is maintained by configure_file())

References

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. I will test it tomorrow.
@AndreasHaferburg Your're welcome. Just wanted to check if it worked and has solved your problem? Thanks.
the link in the references seems broken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.