CMake post-build-event: copy compiled libraries

后端 未结 1 1951
迷失自我
迷失自我 2021-01-21 03:26

The binary directory structure of my project is currently like this (Windows):

bin/mainProject/{Debug,Release}
bin/library1/{Debug,Release}
bin/library2/{Debug,R         


        
相关标签:
1条回答
  • 2021-01-21 04:10

    You can make this more generic by using generator expressions:

    add_custom_command(
        TARGET library1 
        POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy
            $<TARGET_FILE:library1>
            $<TARGET_FILE_DIR:mainProject>/$<TARGET_FILE_NAME:library1>
    )
    

    Alternative

    You could - if every dependency is build within your CMake project - also just give a common output path for all executables and DLLs with something like:

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Out")
    

    Note: The absolute path is required here because it would otherwise be relative to each targets default output path. And note that the configuration's sub-directory is appended by CMake automatically.

    References

    • How to copy DLL files into the same folder as the executable using CMake?
    0 讨论(0)
提交回复
热议问题