Does CMake offer a method to set the working directory for a given build system to use when running/debugging the project?

后端 未结 3 1702
既然无缘
既然无缘 2020-12-05 13:18

I have a project with the following structure:

project_name/CMakeLists.txt
project_name/src
project_name/resources
...
project_name-build/configuration_name/         


        
相关标签:
3条回答
  • 2020-12-05 13:54

    Here is an easier solution. Paste this at the end of your cmake:

    file( WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.vcxproj.user" 
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>     \
        <Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">
        <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">
            <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
            <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
        </PropertyGroup>
        <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">
            <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
            <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
        </PropertyGroup>
        </Project>")
    

    It overwrites the default vcxproj.user file for the current project and specifies $(OutDir) for the Working Directory as desired for debugging. Make sure that $PROJECT_NAME is your project name.

    0 讨论(0)
  • 2020-12-05 14:03

    Since CMake 3.8, there is the VS_DEBUGGER_WORKING_DIRECTORY target property, which allows you to set the debugger working directory for a target in Visual Studio.

    Usage example:

    set_property(TARGET MyTarget PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
    
    0 讨论(0)
  • 2020-12-05 14:03

    As drescherjm pointed out (in his comment on the question) CMake doesn't provide a method to directly set a working directory. However, CMake does provide indirect methods of doing so.

    The path I think I'll take is to use the configure_file command to fill in a template .user file.

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