[CMake] Three newbie questions: default build type, find_package-modules, default compiler flags

Alexander Neundorf a.neundorf-work at gmx.net
Sat Jan 16 14:25:05 EST 2010


On Saturday 16 January 2010, Michael Roth wrote:
> Hello,
>
> I'm a cmake newbie and have three questions:
>
> a.) What is the best way to set a default build type? Currently I
>     do something like this:
>
> 	if (NOT CMAKE_BUILD_TYPE)
> 		message(STATUS "No build type selected, default to Release")
> 		set(CMAKE_BUILD_TYPE "Release")
> 	endif()

Looks ok.

> b.) When writing find_package-modules, what are the standard variable
>     names? Plural or singular?
>
> 	FOOBAR_INCLUDE_DIR
> 	FOOBAR_LIBRARY
>
> 	or
>
> 	FOOBAR_INCLUDE_DIRS
> 	FOOBAR_LIBRARIES
>
>     Some docs and specific modules are inconsistent with one another.

See the readme.txt in the Modules/ directory.
The variables for the individual files should be singular (i.e. the variables 
in the find_xxx() commands), the variables which should be used should be 
plural (since e.g. you may need to link to several libraries when you want to 
use foo).

> c.) I have written:
>
> 	if (CMAKE_COMPILER_IS_GNUCC)
> 		message(STATUS "Gnu-Compiler detected, setting custom flags")
> 		set(CMAKE_C_FLAGS_DEBUG "-O2 -Wall -g")
> 		set(CMAKE_C_FLAGS_RELEASE "-O2 -Wall -fomit-frame-pointer -DNDEBUG")
> 		set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")
> 	endif()
>
>
>     But when I add flags to CMAKE_C_FLAGS they are prepended to the other
>     three variants. Is this intended? Why?

CMAKE_C_FLAGS is used for all buildtypes, the three variables above are used 
only for the specific buildtype.

Alex


More information about the CMake mailing list