[CMake] Any portable way in CMake build tree to find Source tree path?

Cory Quammen cquammen at cs.unc.edu
Fri Jan 25 18:55:24 EST 2013


Kent,

I have a CMake function that may be of interest to you (see attached file).

For your purposes, use it as follows:

GetCMakeCacheValue( "${ABC_BUILD_DIR}" ABC_SOURCE_DIR )

where the project against which you want to build is named "ABC".

The first argument must always be the build directory of a project
configured with CMake. The second (and an arbitrary number of
subsequent arguments) are variables whose values you want to retrieve
from the CMakeCache.txt file.

Assuming everything goes well, two new variables will be defined in
the scope in which you called GetCMakeCacheValue:

ABC_SOURCE_DIR
ABC_SOURCE_DIR_TYPE

If there is no entry for ABC_SOURCE_DIR, then the above variables will
take on the values

ABC_SOURCE_DIR-NOT_FOUND
ABC_SOURCE_DIR_TYPE-NOT_FOUND

I hope this is useful to you and others. It would be great if CMake
had similar functionality built in.

- Cory

On Fri, Jan 25, 2013 at 6:13 PM, Jean-Christophe Fillion-Robin
<jchris.fillionr at kitware.com> wrote:
> Hi Kent,
>
> On all the platform, the build tree contains a CMakeCache.txt that will
> systematically contain the following text:
>
>      FOO_SOURCE_DIR:STATIC=/path/to/foosource
>
> where FOO is the name of the project.
>
> You could simply check for the existence of "CMakeCache.txt", and extact the
> value using a regex.
>
> Hth
> Jc
>
>
>
>
> On Fri, Jan 25, 2013 at 5:41 PM, Kent Williams <nkwmailinglists at gmail.com>
> wrote:
>>
>> I'm trying to write a Find<package>.cmake file for a library that doesn't
>> generate a proper <package>Config.cmake file.
>>
>> The problem I'm trying to solve is how to build against a build tree
>> instead of an install tree.  On OS X and Windows (well, probably any
>> Makefile generator) CMake helpfully adds CMakeDirectoryInformation.cmake
>> files to the build tree, which makes it straightforward to recover the root
>> of the source tree.
>>
>> Come to find out, that doesn't work on Windows with Visual Studio build
>> system, and probably won't work with other build systems besides Makefile on
>> OS X and Linux.
>>
>> So the question is, given that I can't go in and fix the CMake build
>> system for this package, is there a portable way to find the source tree by
>> looking at the build tree?
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
>
> --
> +1 919 869 8849
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



-- 
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GetCMakeCacheValue.cmake
Type: application/octet-stream
Size: 2523 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130125/9c588e01/attachment.obj>


More information about the CMake mailing list