2

I am building using cmake -DCMAKE_BUILD_TYPE=Debug ..

And I am using set(CMAKE_DEBUG_POSTFIX d) to add a d to the end of the filename.

This is working for static libraries and I expected it to work for executables as well. But, at least in my case, it is compiling all the static libraries using *d.a and the executable without d suffix.

Am I missing something?

1 Answer 1

2

You are not missing anything. As the documentation says (emphasis mine):

When a non-executable target is created its <CONFIG>_POSTFIX target property is initialized with the value of this variable if it is set.

See: https://cmake.org/cmake/help/latest/variable/CMAKE_CONFIG_POSTFIX.html

By the sounds of it, though, you could manually set the property on your executable target with set_target_properties:

set_target_properties(
  target1 ... targetN
  PROPERTIES
  DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}"
)

Note, however, that it doesn't apply to executables by default because that's rarely what you want. For libraries, it's fairly common to package and deploy debug and release configurations simultaneously. On Windows, for development, it is a requirement. On the other hand, one very rarely needs to deploy debug applications and hence one very rarely wants a postfix applied.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much! That explains it well. I just have a question. Do I need to write PROPERTIES? Or is it simply a dummy text for properties? And I personally like to have a different filename for debug version, so that I can easily see which one is the release version for publishing :)
@Z0q - yes you do need PROPERTIES. It separates the list of target names from the pairs of property-value arguments. See the documentation for set_target_properties, here: cmake.org/cmake/help/latest/command/set_target_properties.html
Alright, thank you! Should I add it after add_executable(), like target_compile_definitions()?
@Z0q - I think you mean set_target_properties? In either case, yes. Both those commands require the target(s) to have been declared already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.