Copy target file to another location in a post build step in CMake

前端 未结 3 882
攒了一身酷
攒了一身酷 2020-12-04 17:11

I have a dynamic library that gets a different name depending on configuration, specified in the CMake scripts by:

set_target_properties(${name} PROPERTIES O         


        
3条回答
  •  抹茶落季
    2020-12-04 17:31

    Rather than using the obsolete LOCATION property, prefer using generator expressions:

    add_custom_command(TARGET mylibrary POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy $ ${targetfile}
    )
    

    You could also just generate the exe in the target directory directly by setting the target property RUNTIME_OUTPUT_DIRECTORY instead of copying it. This has per-configuration options (e.g. RUNTIME_OUTPUT_DIRECTORY_DEBUG).

    set_target_properties(mylibrary PROPERTIES
                          RUNTIME_OUTPUT_DIRECTORY_DEBUG 
                          RUNTIME_OUTPUT_DIRECTORY_RELEASE 
    )
    

    For further details run:

    cmake --help-property "RUNTIME_OUTPUT_DIRECTORY"
    cmake --help-property "RUNTIME_OUTPUT_DIRECTORY_"
    

    Also, you should be able to use forward slashes throughout for path separators, even on Windows.

提交回复
热议问题