[CMake] TARGET property LOCATION

Andreas Mohr andi at lisas.de
Wed Nov 27 13:29:31 EST 2013


Hi,

On Tue, Nov 26, 2013 at 12:00:10PM -0500, cmake-request at cmake.org wrote:
> Date: Tue, 26 Nov 2013 12:13:16 +0100
> From: Marcel Loose <loose at astron.nl>
> Subject: [CMake] TARGET property LOCATION

> Hi all,
> 
> According to the CMake documentation, the TARGET property LOCATION for a
> non-imported target is provided for compatibility with CMake 2.4 and
> below. My question is: are there any plans to deprecate this property? I
> want to know, because AFAIK, the only way to determine the full path to
> a built target is to use this property.

Yeah, a very good question. Especially since for somewhat older
(I assume that these already were a bit newer than the LOCATION deprecation event though!)
CMake versions I have a need for the following conditional code
(or similar to it - not 100% sure whether LOCATION is the only way to handle it):


# CMake add_test() has a plain signature and additionally a NAME/COMMAND signature
# in newer versions.
# Since I somehow managed to completely miss this,
# I filed a CMake bug report (#12589).
# Let's thus use the newer signature whenever it's supported.
set(cmake_add_test_command_signature_supported_ false)
set(cmake_version_add_test_command_signature_not_supported_last "2.7.0") # FIXME which version?
set(cmake_version_add_test_supports_command_signature_check "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
if("${cmake_version_add_test_supports_command_signature_check}" VERSION_GREATER "${cmake_version_add_test_command_signature_not_supported_last}")
  set(cmake_add_test_command_signature_supported_ true)
endif("${cmake_version_add_test_supports_command_signature_check}" VERSION_GREATER "${cmake_version_add_test_command_signature_not_supported_last}")

if(cmake_add_test_command_signature_supported_)
  function(_ctest_add_test_sanitized _target)
    set(testname_ "${_target}")
    set(testexe_ "${_target}")
    add_test(NAME "${testname_}" COMMAND "${testexe_}")
  endfunction(_ctest_add_test_sanitized _target)
else(cmake_add_test_command_signature_supported_)
  function(_ctest_add_test_sanitized _target)
    set(testname_ "${_target}")
    # Work around incapable add_test(), by using a property which
    # is said to be ""deprecated""... (*** SIGH ***).
    get_property(test_location_ TARGET "${_target}" PROPERTY LOCATION)
    set(testexe_ "${test_location_}")
    add_test("${testname_}" "${testexe_}")
  endfunction(_ctest_add_test_sanitized _target)
endif(cmake_add_test_command_signature_supported_)


> Best regards,
> Marcel Loose.

Andreas Mohr


More information about the CMake mailing list