[CMake] Howto to work with variables from central makefiles....
Michael Hertling
mhertling at online.de
Wed Nov 17 19:05:08 EST 2010
On 11/17/2010 04:56 PM, Thomas Lehmann wrote:
>>> 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...
If you don't want to make /src the definite top-level directory of your
project(s) you must indeed provide a hint to /src/cmake since otherwise,
CMake cannot have an idea that there's additional stuff in this sibling,
e.g. "cmake -DCMAKE_CENTRAL_DIR=/src/cmake /src/apps". Alternatively,
you might always configure /src and use options to decide which
projects, i.e. subdirectories, are actually built, e.g.:
/src/CMakeLists.txt:
OPTION(BUILD_LIBS "Build libs" ON)
OPTION(BUILD_APPS "Build apps" ON)
IF(BUILD_LIBS)
ADD_SUBDIRECTORY(libs)
ENDIF()
IF(BUILD_APPS)
ADD_SUBDIRECTORY(apps)
ENDIF()
So, you can say "cmake /src" to build libraries and applications, or
"cmake -DBUILD_APPS=OFF /src" to build libraries only etc., and in
any case, you may refer safely to ${CMAKE_SOURCE_DIR}/cmake from
each of your projects' CMakeLists.txt.
Regards,
Michael
>>> 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