MantisBT - CMake
View Issue Details
0011671CMakeCMakepublic2011-01-09 15:182011-01-12 08:15
Andreas Pakulat 
Brad King 
normalminoralways
closedfixed 
Linux
CMake 2.8.3 
CMake 2.8.4CMake 2.8.4 
0011671: changing RUNTIME_OUTPUT_DIR after fetching LOCATION fails
Attached is a simple cmake project which is supposed to put the setup binary into the top-level build directory, but puts it into the bin/ directory as set via CMAKE_RUNTIME_OUTPUT_DIRECTORY. The reason for this is that the LOCATION property of the target is being read and this seems to cause cmake to not update it anymore later on.

Commenting out the get_property line will put the binary into the top-level build directory.

I think this should either be allowed, with the implication that one needs to re-fetch the LOCATION property. Or it should be yielding a warning to set this
property on a target where it has no effect and be documented in the cmake manual.
Run cmake + make on the attached project, the setup binary should be in the top-level directory and not in the bin/ directory.
No tags attached.
gz test_output_dir.tar.gz (438) 2011-01-09 15:18
https://public.kitware.com/Bug/file/3608/test_output_dir.tar.gz
Issue History
2011-01-09 15:18Andreas PakulatNew Issue
2011-01-09 15:18Andreas PakulatFile Added: test_output_dir.tar.gz
2011-01-10 10:45Brad KingAssigned To => Brad King
2011-01-10 10:45Brad KingStatusnew => assigned
2011-01-10 11:07Brad KingNote Added: 0024533
2011-01-10 11:07Brad KingStatusassigned => closed
2011-01-10 11:07Brad KingResolutionopen => fixed
2011-01-10 11:29Andreas PakulatNote Added: 0024534
2011-01-10 11:29Andreas PakulatStatusclosed => feedback
2011-01-10 11:29Andreas PakulatResolutionfixed => reopened
2011-01-10 12:16Brad KingNote Added: 0024535
2011-01-10 12:26Andreas PakulatNote Added: 0024536
2011-01-10 12:26Andreas PakulatStatusfeedback => assigned
2011-01-10 13:07Brad KingNote Added: 0024538
2011-01-10 13:09Brad KingNote Added: 0024539
2011-01-10 16:07Andreas PakulatNote Added: 0024558
2011-01-10 16:20Brad KingNote Added: 0024560
2011-01-10 16:20Brad KingStatusassigned => closed
2011-01-10 16:20Brad KingResolutionreopened => fixed
2011-01-12 08:15David ColeFixed in Version => CMake 2.8.4
2011-01-12 08:15David ColeTarget Version => CMake 2.8.4

Notes
(0024533)
Brad King   
2011-01-10 11:07   
The LOCATION property has not been recommended for use since CMake 2.4. Implementing a real fix to this will introduce quite a bit of overhead for every property on every target. Furthermore projects that set location-changing properties after reading LOCATION are probably buggy anyway.

I've committed additional documentation to make the situation clear:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7ffe6d77 [^]
(0024534)
Andreas Pakulat   
2011-01-10 11:29   
Can you clarify wether the same 'deprecation' applies LOCATION_<CONFIG>? And if it does, whats the suggested way of getting the absolute path of an executable target from cmake?
(0024535)
Brad King   
2011-01-10 12:16   
LOCATION_<CONFIG> is okay to use, but still has this undefined behavior. Documentation updated:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=57344977 [^]

The documentation of LOCATION explains that it is only for compatibility with 2.4. The documentation of LOCATION_<CONFIG> says nothing of the kind.

Since CMake 2.6 one can write

  add_custom_command(... COMMAND myexecutable ...)

and CMake will recognize the target name "myexecutable" and replace it in the command line with the real location at build time automatically. Since CMake 2.8, add_test has supported generator expressions to refer to target locations anywhere in test command lines:

  http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_test [^]

Starting in CMake 2.8.4, generator expressions will be supported in add_custom_command and add_custom_target too:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f0cdb600 [^]

so that locations can be referenced anywhere in custom command lines.

Now, why do you need the LOCATION?
(0024536)
Andreas Pakulat   
2011-01-10 12:26   
I don't need LOCATION. I need a way to provide a wrapper-executable the build-dir-relative filename of the real executable that it should start. I can't change the code at this point to simply search for the real executable using some basename, so I need to supply the path relative to the top-builddir. And LOCATION seems to be the easiest way to do that. I also don't care about generators like VS or XCode which may add special stuff into that path, I just need something that works for nmake+(gnu-)make.
(0024538)
Brad King   
2011-01-10 13:07   
Target properties like OUTPUT_NAME_<CONFIG> affect the file name so getting the location really only makes sense given a configuration. This is why LOCATION should no longer be used. CMake does not know what configuration to use when computing the full path to the file.

LOCATION_<CONFIG> should work for your case. For the generators you are using the CMAKE_BUILD_TYPE variable holds the configuration name. Something like this might work:

  if(CMAKE_CONFIGURATION_TYPES)
    message(FATAL_ERROR "This project does not support multi-config generators like ${CMAKE_GENERATOR}. Use a Makefile generator.")
  endif()
  ...
  add_executable(myexe ...)
  set_target_properties(myexe PROPERTIES ...)
  ...
  string(TOUPPER "${CMAKE_BUILD_TYPE}" CONFIG)
  get_property(myexe_location TARGET myexe PROPERTY LOCATION_${CONFIG})
(0024539)
Brad King   
2011-01-10 13:09   
Alternatively, if your project never sets properties to change the output name of the executable target, you should be able to just hard-code the name in your wrapper without querying the LOCATION* properties. Since your project's code is setting RUNTIME_OUTPUT_DIRECTORY to tell the executable where to go, just configure the same value into your wrapper code.
(0024558)
Andreas Pakulat   
2011-01-10 16:07   
Thanks for the suggestions. I'd need to get at the filename extension too to use the hardcoding-the-output directory way, not sure there's a cmake variable/property for that but I'll find that out. Feel free to close this ticket now.
(0024560)
Brad King   
2011-01-10 16:20   
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_EXECUTABLE_SUFFIX [^]