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 7986923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:59:36+00:00 2026-06-04T11:59:36+00:00

We use CMake for generating the Visual Studio files of our sources in our

  • 0

We use CMake for generating the Visual Studio files of our sources in our SVN. Now my tool requires some DLL files to be in the same folder as the executable. The DLL files are in a folder alongside the source.

How can I change my CMakeLists.txt such that the generated Visual Studio project will either have already the particular DLL files in the release/debug folders or will copy them upon compilation?

  • 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-04T11:59:37+00:00Added an answer on June 4, 2026 at 11:59 am

    I’d use add_custom_command to achieve this along with cmake -E copy_if_different.... For full info run

    cmake --help-command add_custom_command
    cmake -E
    

    So in your case, if you have the following directory structure:

    /CMakeLists.txt
    /src
    /libs/test.dll
    

    and your CMake target to which the command applies is MyTest, then you could add the following to your CMakeLists.txt:

    add_custom_command(TARGET MyTest POST_BUILD        # Adds a post-build event to MyTest
        COMMAND ${CMAKE_COMMAND} -E copy_if_different  # which executes "cmake - E copy_if_different..."
            "${PROJECT_SOURCE_DIR}/libs/test.dll"      # <--this is in-file
            $<TARGET_FILE_DIR:MyTest>)                 # <--this is out-file path
    

    If you just want the entire contents of the /libs/ directory copied, use cmake -E copy_directory:

    add_custom_command(TARGET MyTest POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_directory
            "${PROJECT_SOURCE_DIR}/libs"
            $<TARGET_FILE_DIR:MyTest>)
    

    If you need to copy different dlls depending upon the configuration (Release, Debug, eg) then you could have these in subdirectories named with the corresponding configuration: /libs/Release, and /libs/Debug. You then need to inject the configuration type into the path to the dll in the add_custom_command call, like this:

    add_custom_command(TARGET MyTest POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_directory
            "${PROJECT_SOURCE_DIR}/libs/$<CONFIGURATION>"
            $<TARGET_FILE_DIR:MyTest>)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use CMake to generate a Visual Studio 2010 project and solution file. Actually
I'm setting up my visual studio project to use CMake, but I got two
Use case: I've just entered insert mode, and typed some text. Now I want
I'd like to use CMake to run some tests for an xslt coding project.
I have two projects, both of which use CMake. Now I want to include
I'm trying to use CMake to build a program relying on blas, I'm detecting
I use a cmake generated makefile to compile a c++ file that depends on
Use case: user clicks the link on a webpage - boom! load of files
we develop a data processing tool to extract some scientific results out of a
I use CMake with GNU Make and would like to see all commands exactly

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.