[CMake] Howto to work with variables from central makefiles....

Thomas Lehmann t.lehmann at rtsgroup.net
Wed Nov 17 10:56:52 EST 2010


> > for an automatically forced include I have provided an
> >
> > option like this:
> >
> >
> >
> > set(WIN32_SPEC
> ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/global/win32_spec.h)
>
> May you could use an absolute reference using
>
> ${PROJECT_SOURCE_DIR}/libs/global/win32_spec.h
>
> if your project is name TOTO
> (from the PROJECT(TOTO CXX) statement)
> you use
>
> ${TOTO_SOURCE_DIR}/libs/global/win32_spec.h.

it depends on how I use cmake. I can use the root of all
sources or I use a subtree.
Let's say I have following setup.

/src/libs
/src/cmake
/src/apps

when I call "cmake /src" or "cmake /src/apps" is relating the
application to be build no difference but the variable CMAKE_SOURCE_DIR
will change. My central files are in /src/cmake.

I would like avoiding to redefine search paths and variables in each individual
makefile depending on its location in the source tree. One example:

<code>
# ensuring that packages are found
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
                      ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/make)

# most common definitions, macros, ... required by most projects
find_package(AllOptions)
</code>

I think that the problem is that cmake does not know where the real root
is. I have not found something except adjusting an environment variable
but this is something I would like to avoid when possible...

Thomas



>
> >
> > add_definitions(-FI ${WIN32_SPEC})
> >
> >
> > But when including this central file (find_package) the variable
> CMAKE_CURRENT_SOURCE_DIR
> > changes and then the path and filename of the header is wrong.
> >
> >
> >
> > How to proceed best?
> > Can I avoid that for those "set" statement the variable is not
> overwritten by those
> > files including this central makefile?
>
> You may use a CACHED variable
> set(WIN32_SPEC ${PROJECT_SOURCE_DIR}/libs/global/win32_spec.h CACHE
> FILEPATH "Central Include")
>
> the first calling this will set the value then other set will be
> ignored.
> If you want to override a CACHE var value you'll have to use FORCE set
> option.
>
>
>
> --
> Erk
> Membre de l'April - « promouvoir et défendre le logiciel libre » -
> http://www.april.org

Thomas Lehmann
Scrum Master

RTS Realtime Systems Software GmbH, Rembrandtstrasse 13, D-60596 Frankfurt am Main
T: +49.69.61009.0 / F: +49.69.61009.181

Sitz: Frankfurt am Main - HRB 84467 Amtsgericht Frankfurt am Main
Geschäftsführer: Steffen Gemuenden, Igor Sluga

www.rtsgroup.net

This email and any attachments are for the exclusive and confidential use of the intended recipient. If you are not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, please do not read, distribute or take action in reliance upon this message. If you have received this in error, please notify me immediately by return email and promptly delete this message and its attachments from your computer system.


More information about the CMake mailing list