[CMake] Get configuration-dependant LOCATION property

Mateusz Loskot mateusz at loskot.net
Mon Oct 4 16:36:39 EDT 2010


On 04/10/10 12:01, Michael Wild wrote:
> 
> On 4. Oct, 2010, at 10:51 , Mateusz Loskot wrote:
> 
>> On 04/10/10 05:40, Michael Wild wrote:
>>> 
>>> On 3. Oct, 2010, at 23:53 , Mateusz Loskot wrote:
>>> 
>>>> On 03/10/10 22:27, J Decker wrote:
>>>>> On Sun, Oct 3, 2010 at 10:28 AM, Mateusz 
>>>>> Loskot<mateusz at loskot.net>  wrote:
>>>>>> Hi,
>>>>>> 
>>>>>> I understand what the manual [1] says about LOCATION
>>>>>> property that it is more or less deprecated. Is that
>>>>>> right?
>>>>>> 
>>>>>> I'm building software (shared libraries and executables)
>>>>>> on both, Linux and Windows (using VS 2005, 2008, 2010) and
>>>>>> I'm trying to find out what would be portable way to get
>>>>>> target output location. It is location of output directory
>>>>>> where toolset genreates .so or .dll files.
>>>>>> 
>>>>>> I tried LOCATION property but it is empty (on Windows at 
>>>>>> least)
>>>>>> 
>>>>>> get_target_property(MY_TARGET_LOCATION ${MY_TARGET}
>>>>>> LOCATION)
>>>>> 
>>>>> get_target_property(MY_TARGET_LOCATION ${MY_TARGET} 
>>>>> LOCATION_${CMAKE_BUILD_TYPE)) ?
>>>> 
>>>> It does not help.
>>>> 
>>>> As I mentioned in my original post, ${CMAKE_BUILD_TYPE} is
>>>> empty when you generate Visual Studio projects.
>>> 
>>> 
>>> I didn't look into the specifics of your problem, but would it be
>>> a solution to configure _all_ locations into a CMake script
>>> which performs your required action at build/test time?
>> 
>> I haven't mention that. I try to keep default CMake build tree 
>> layout. Regardless how simple changes it would require, IMHO, 
>> messing with *_OUTPUT properties overrides portability provided by
>> CMake out of the box and would require manual handling.
>> 
>> I define target for CMake and CMake knows where to output files. 
>> Now, simply, I would like to ask "Dear CMake, tell me please where
>> do you send my binaries".
>> 
>> Can I do it? How?
>> 
>>> You could pass the configuration type as a -D parameter.
>> 
>> I could pass CMAKE_BUILD_TYPE, but this would be available once 
>> when configuration is performed. Then, form Visual Studio IDE user
>> can change configuration which CMake settings will not be aware
>> of.
> 
> I think you didn't understand my answer. What I proposed was to wrap
> the operation you want to perform in a script. This way you can
> configure all possible output locations into it and then select the
> correct one at build time via an argument.

Michael,

Yes, I think I misunderstood it and I still can't understand how script
would help.

myproject/

myproject/lib1/lib1.cpp

myproject/lib1/CMakeLists.txt
  - builds lib1.dll

myproject/test1/test1.cpp

myproject/test1/CMakeLists.txt
  - builds and runs test for lib1.dll, so needs to know where to find
intermediate output of lib1/CMakeLists.txt target that builds lib1.dll,
so ENV[PATH] can be updated to allow .dll lookup, without running
install targets.

I don't want any scripts external to CMake, because in a script I would
need to handle all platforms once again - CMake is supposed to handle
multiplatform issue, isn't it?

It's frustrating, but I can't really understand it. If CMake knows where
tell compiler/linker to output binaries, why user can not query
this location from inside CMakeLists.txt file?

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org


More information about the CMake mailing list