Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:58:37+00:00 2026-06-17T15:58:37+00:00

I am using the following command to copy config files into the build directory

  • 0

I am using the following command to copy config files into the build directory after each compile.

# Gather list of all .xml and .conf files in "/config"
file(GLOB ConfigFiles ${CMAKE_SOURCE_DIR}/config/*.xml
                      ${CMAKE_SOURCE_DIR}/config/*.conf)

foreach(ConfigFile ${ConfigFiles})
  add_custom_command(TARGET MyTarget PRE_BUILD
                     COMMAND ${CMAKE_COMMAND} -E
                         copy ${ConfigFile} $<TARGET_FILE_DIR:MyTarget>)
endforeach()

This action is triggered every time I compile the project. Is it possible to create a target in CMakeLists.txt to copy files without needing to compile anything? Something like “make copy”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:58:37+00:00Added an answer on June 17, 2026 at 3:58 pm

    You should be able to add a new custom target called copy and make that the target of your custom commands:

    file(GLOB ConfigFiles ${CMAKE_SOURCE_DIR}/config/*.xml
                          ${CMAKE_SOURCE_DIR}/config/*.conf)
    
    add_custom_target(copy)
    foreach(ConfigFile ${ConfigFiles})
      add_custom_command(TARGET copy PRE_BUILD
                         COMMAND ${CMAKE_COMMAND} -E
                             copy ${ConfigFile} $<TARGET_FILE_DIR:MyTarget>)
    endforeach()
    

    Now the custom commands will only execute if you build copy.

    If you want to keep this copy target as a dependency of MyTarget so that you can either just copy the files or have them copied if you build MyTarget, you’ll need to break the cyclic dependency. (MyTarget depends on copy, but copy depends on MyTarget to get the location of the copy-to directory).

    To do this, you can resort to the old-fashioned way of getting a target’s output directory:

    add_custom_target(copy)
    get_target_property(MyTargetLocation MyTarget LOCATION)
    get_filename_component(MyTargetDir ${MyTargetLocation} PATH)
    foreach(ConfigFile ${ConfigFiles})
      add_custom_command(TARGET copy PRE_BUILD
                         COMMAND ${CMAKE_COMMAND} -E
                             copy ${ConfigFile} ${MyTargetDir})
    endforeach()
    add_dependencies(MyTarget copy)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following custom command to copy all the files within the
I'm using the following command to copy all lines of text in a document
Using the following rsync command will let you copy numerous remote files to your
I am using the following command to copy files from a network share to
I'm using the following command to set up the AWS launch config: as-create-launch-config test1autoscale
I compile my C++ program to LLVM IR using the following command. clang++ -O4
I am trying to compile my gcc code using the following make command .
I can copy the records from one server to another using the following command.
Im trying to compile some java files using the Runtime.getRuntime.exec(command) and im generating the
I am using following command for start the production server. nohup ruby script/server webrick

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.