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

  • Home
  • SEARCH
  • 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 7749257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:59:54+00:00 2026-06-01T10:59:54+00:00

I have a dynamic library that gets a different name depending on configuration, specified

  • 0

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

set_target_properties(${name} PROPERTIES OUTPUT_NAME ${outputName}64)
set_target_properties(${name} PROPERTIES DEBUG_OUTPUT_NAME ${outputName}64_d)

The end result is that I get a different name on release and debug builds. I would like to copy the resulting library to a different directory as a post-build step, but the gift(?) of CMake-Fu did not smile upon yours truly.

I have tried doing this:

GET_TARGET_PROPERTY(origfile mylibrary LOCATION)
STRING(REGEX REPLACE "/" "\\\\" origfile ${origfile})

set(targetfile my_target_path\\${CMAKE_CFG_INTDIR}\\)
STRING(REGEX REPLACE "/" "\\\\" targetfile ${targetfile})

add_custom_command(TARGET mylibrary POST_BUILD
    COMMAND copy ${origfile} ${targetfile}
)

This works fine for release builds, but for debug the source does not include the _d that I would have expected.
How do I get the output path for the target so that I can copy the file?

Note: As can be seen from the above snippet, this is currently for Windows/Visual Studio, but I would like this to work on OS X / Xcode / make as well.

Note: I need the library to be placed in an extra directory that serves as the output directory for several other projects that depend on this library, so that these projects are able to load the library at runtime. An alternative solution that would be acceptable would be to be able to create a custom target that does the copying, so that the other projects can depend on this project, which in turn depends on the library.

  • 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-01T10:59:56+00:00Added an answer on June 1, 2026 at 10:59 am

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

    add_custom_command(TARGET mylibrary POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mylibrary> ${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 <debug path>
                          RUNTIME_OUTPUT_DIRECTORY_RELEASE <release path>
    )
    

    For further details run:

    cmake --help-property "RUNTIME_OUTPUT_DIRECTORY"
    cmake --help-property "RUNTIME_OUTPUT_DIRECTORY_<CONFIG>"
    

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a process A that loads a dynamic library L. Q:
I'm trying to create a C++ dynamic library that won't have a class. I'd
I have a dynamic library (plugin) that uses another dynamic library (dependency). I use
I have a Cocoa-based universal dynamic library that also includes more static libraries, from
I have a library that build UI using Javascript, and because of the dynamic
I have created a static and dynamic library that I want to distribute. How
HI I have a dynamic link library writting in Delphi 2006 that has forms.pas
I have a dynamic linked library written in C# 3.0. This library has a
I have some divs that have dynamic heights controlled by a 'click' function as
I have some divs that have dynamic heights controlled by a 'click' function as

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.