[CMake] About variable Usage in cmake

Clark J. Wang dearvoid at gmail.com
Wed Jul 18 23:22:02 EDT 2007


On 7/19/07, cjacker <jzhuang at redflag-linux.com> wrote:
>
> I am writing a not too short Chinese tutorial about cmake.
> Up to now nine chapter had already been finished, include:


Interesting. Is RedFlag's project using CMake? :-)

prefix
> 1,about cmake
> 2,how to install cmake.
>
> 3,Hello World in cmake
> use helloworld as a demo to illustrate how to use cmake to manage and
> build a project.
> introduce PROJECT ADD_EXECUTABLE command and
> <projectname>_SOURCE_DIR,<projectname>_BINARY_DIR.
> also introduce in-source build and out-of-source build.
>
> 4,make Hello World better
> add more things to Helloworld, document, scripts, and illustrate the
> syntax of INSTALL and how to use it.
>
> 5,Manage shared library and static library
> introduce ADD_LIBRARY SET_TARGET_PROPERTIES command.
> also include how to build same name shared and static library and shared
> library versioning.
>
> 6,Use libraries in your project
> introduce INCLUDE_DIRECTORIES LINK_DIRECTORIES and TARGET_LINK_LIBRARIES
> command.
>
> 7,pre-defined cmake variables
> a lot of varibles in cmake, like CMAKE_BINARY_DIR and so on.
>
> 8,cmake command
> all commands in cmake.
>
> 9,how to use Find_ modules and write you own modules.
> also include CMAKE_MODULE_PATH varible.
>
>
>
>
> when I use cmake, the variable usage is confused me.
> for example, commonly if we want to use a variable, we should use ${},
> for example:
>
> MESSAGE(STATUS "the dir is: ${PROJECT_SOURCE_DIR}")
>
> SET(SRC_LIST main.c t1.c)
> ADD_EXECUTABLE(hello ${SRC_LIST})
>
> but when we use IF ELSEIF ENDIF command.
>
> we had to use it like
>
> FIND_PACKAGE(libX X11 /usr/lib/xorg)
> IF(libX) or IF(NOT libX)
>
> I can not use it like IF(${libX}) or IF(NOT ${libX}).


The `IF(var)' or `IF(NOT var)' command expects `var' to be the name of a
variable. This is stated in CMake's manual. So, for your situation
`IF(${libX})' is the same as `IF(/usr/lib/xorg)' and then CMake will check
the value of the variable named `/usr/lib/xorg'.

anybody can explain the rule that how to use variable in cmake?
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070719/63a8474d/attachment.html


More information about the CMake mailing list