CMake add_custom_target(): Run custom command using 'Debug->Start Debugging'

后端 未结 1 1989
遥遥无期
遥遥无期 2021-01-24 08:30
add_custom_target(NSISTest_Preprocess SOURCES precompress.nsi)
add_custom_command(TARGET NSISTest_Preprocess POST_BUILD
  COMMAND \"${NSIS_PATH}\" \"...\\\\precompress.n         


        
1条回答
  •  醉话见心
    2021-01-24 09:08

    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

    
    
      
        ${_my_installer_path}
        WindowsLocalDebugger
      
    
    

    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

    • Setting the Visual Studio Debugger path using CMake

    0 讨论(0)
提交回复
热议问题