[CMake] About variable Usage in cmake

cjacker jzhuang at redflag-linux.com
Wed Jul 18 22:56:08 EDT 2007


I am writing a not too short Chinese tutorial about cmake.
Up to now nine chapter had already been finished, include:

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}).

anybody can explain the rule that how to use variable in cmake?


More information about the CMake mailing list