[CMake] debug- and release options

Filipe Sousa filipe at ipb.pt
Mon Feb 6 17:27:52 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Brad King wrote:
> Filipe Sousa wrote:
> 
> There is no default, if the build type is not set then _neither_ will be 
> linked.  The reason there is no default is a bit complicated (I once 

Are you sure? I did this test with the fallowing CMakeLists.txt

PROJECT(default)
ADD_LIBRARY(debug_lib debug_lib.c)
ADD_LIBRARY(release_lib release_lib.c)
SET(LIBRARY debug debug_lib optimized release_lib)
ADD_EXECUTABLE(default main.c)
TARGET_LINK_LIBRARIES(default ${LIBRARY})

Now here is the results
fsousa at neptuno ~/tmp/default/build $ cmake -DCMAKE_BUILD_TYPE=release ..
fsousa at neptuno ~/tmp/default/build $ make VERBOSE=1
/usr/bin/gcc  -O3 -DNDEBUG   -o CMakeFiles/default.dir/main.o   -c
/home/fsousa/tmp/default/main.c
Linking C executable default
/usr/local/bin/cmake -E remove -f default
/usr/bin/gcc    -O3 -DNDEBUG  -fPIC "CMakeFiles/default.dir/main.o"   -o
default -rdynamic -L/home/fsousa/t


mp/default/build -lrelease_lib -Wl,-rpath,/home/fsousa/tmp/default/build

release_lib is used

fsousa at neptuno ~/tmp/default/build $ cmake -DCMAKE_BUILD_TYPE=debug ..
fsousa at neptuno ~/tmp/default/build $ make VERBOSE=1
/usr/bin/gcc  -g   -o CMakeFiles/default.dir/main.o   -c
/home/fsousa/tmp/default/main.c
Linking C executable default
/usr/local/bin/cmake -E remove -f default
/usr/bin/gcc    -g  -fPIC "CMakeFiles/default.dir/main.o"   -o default
- -rdynamic -L/home/fsousa/tmp/default/build -ldebug_lib
- -Wl,-rpath,/home/fsousa/tmp/default/build

debug_lib is used

fsousa at neptuno ~/tmp/default/build $ cmake -DCMAKE_BUILD_TYPE="" ..
/usr/bin/gcc   -o CMakeFiles/default.dir/main.o   -c
/home/fsousa/tmp/default/main.c
Linking C executable default
/usr/local/bin/cmake -E remove -f default
/usr/bin/gcc     -fPIC "CMakeFiles/default.dir/main.o"   -o default
- -rdynamic -L/home/fsousa/tmp/default/build -lrelease_lib
- -Wl,-rpath,/home/fsousa/tmp/default/build

if build type is not set release_lib is used

f/usr/bin/gcc   -o CMakeFiles/default.dir/main.o   -c
/home/fsousa/tmp/default/main.c
Linking C executable default
/usr/local/bin/cmake -E remove -f default
/usr/bin/gcc     -fPIC "CMakeFiles/default.dir/main.o"   -o default
- -rdynamic -L/home/fsousa/tmp/default/build -lrelease_lib
- -Wl,-rpath,/home/fsousa/tmp/default/build
sousa at neptuno ~/tmp/default/build $ cmake -DCMAKE_BUILD_TYPE=foo ..

again, release lib is used

> looked at making Release the default) and I don't have time to explain 

Oops! I meant the optimized library

> it now.  We have plans to address this problem but for now the "right" 
> way is:
> 
> IF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
>    SET(FOO_LIB optimized liby debug libz)
> ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
>    SET(FOO_LIB liby)
> ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
> target_link_libraries(testapp libx ${FOO_LIB})
> 
> Effectively one manually chooses the default on a per-library basis.
> 
> 
> SET(CMAKE_DEBUG_POSTFIX _debug)
> 
> -Brad
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 
> 


- --
Filipe Sousa
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD581obQdNYqwwwCwRAt/3AJ98fkM1JXV3aH9Yw58quDG5bAalygCfZBnf
XMeAFBEAQ48cWLhh+ln/uIU=
=wdKM
-----END PGP SIGNATURE-----


More information about the CMake mailing list