Installing additional files with CMake

后端 未结 2 569
感情败类
感情败类 2021-02-07 05:24

I am attempting to supply some \"source\" files with some executables. I was wondering if there was a way to copy these source files to the build directory (From the source dire

相关标签:
2条回答
  • 2021-02-07 06:06

    You can copy the file to your build tree using add_custom_command by adding something like the following:

    add_custom_command(TARGET MyExe POST_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy_if_different
                           ${CMAKE_CURRENT_SOURCE_DIR}/src/some_opencl_kernel.cl
                           $<TARGET_FILE_DIR:MyExe>
                       )
    

    This adds a post-build event to your target (I've called it MyExe) which copies the file src/some_opencl_kernel.cl to the same directory in your build tree as your executable.

    There are various other ways of copying a file into the build tree, but I like this one since it uses the "generator expression" $<TARGET_FILE_DIR:MyExe> to identify the location of the executable's directory in the build tree. This can vary depending on e.g. build-type or platform, so the generator expression is about the most reliable, cross-platform way of specifying this location I feel.

    As for installing, you can just use the install(FILES ...) command. Assuming for your executable you have something like:

    install(TARGETS MyExe RUNTIME DESTINATION bin)
    

    you can just add:

    install(FILES src/some_opencl_kernel.cl DESTINATION bin)
    

    which will install it to ${CMAKE_INSTALL_PREFIX}/bin/some_opencl_kernel.cl alongside the executable.

    0 讨论(0)
  • 2021-02-07 06:27

    If you want to copy a folder's tree with some type of files:

      # Copy all assets to resources file
      INSTALL(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${INSTALL_PATH}/assets
              FILES_MATCHING PATTERN "*.dae"  PATTERN "*.jpg")
    

    If you want to copy all files in folders, just remove the FILES_MATCHING patterns.

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