CMAKE_XXX_OUTPUT_DIRECTORY vs. target properties XXX_OUTPUT_DIRECTORY

Hello,

my goal is to use the CMAKE_XXX_OUTPUT_DIRECTORY variables to set the default location for the built binaries and use the respective target property XXX_OUTPUT_DIRECTORY (e.g. LIBRARY_OUTPUT_DIRECTORY) for specific targets to place the respective files in a different location in the build folder. According to the documentation this should work as the values of the global variables are used to set the value of the target property of the targets when they are created so i would guess that changing the property values would reflect in the output path.
The problem is now that changing the target property has no effect on the output path. Things i already double-checked:

  • the value of the property is correctly set, verified using get_target_property()
  • the name of the target is correct as setting the XXX_OUTPUT_NAME works and is reflected in the filename
  • if the global variables are not set before, the property works and the output path is correct

what am i missing here?
thx!

to answer my own question: the problem was that also the CMAKE_LIBRARY_OUTPUT_DIRECTORY_<BUILD_TYPE> was set so the target property LIBRARY_OUTPUT_DIRECTORY_<BUILD_TYPE> had to be set to change to output dir of the target.

hi
I am doing same thing as you. could you tell me how to set the param? I am new, thanks.
is it: set_target_properties(${ENCODER_X86_ASM_LIB_NAME} PROPERTIES CMAKE_LIBRARY_OUTPUT_DIRECTORY_<> ${PATH}) ?

its

set_target_properties(<target> PROPERTIES LIBRARY_OUTPUT_DIRECTORY <path>)

or if you want to set it for all configuration types:

    if(DEFINED CMAKE_CONFIGURATION_TYPES)
      foreach(config ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER ${config} config)
        set_target_properties(<target> PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} <path>)
      endforeach()
    endif()

hi, sorry, I am wrong, I met another issue that: duplicated obj file generated, not lib.
my question is inside : Two same output obj generated by VS IDE and CMake command line cause LNK4006 - Code - CMake Discourse

could you take a look? Many thanks!