[CMake] Suggestions about my usage of CMake

groton at gmx.net groton at gmx.net
Sun May 28 09:05:39 EDT 2006


Hello,

I would like to have suggestions/feedback about my usage of CMake for 
MSVC2005. I have little project with an executable and a dynamic library.
I would like to generate either the debug and the release version of the 
dlls and exes files. So my CMakeLists.txt files looks like:

 CMakeLists.txt  for the library:
#########################################################
PROJECT (LIBRARY)
SET (PRJ_SRCS lib.cpp lib.h)
ADD_DEFINITIONS (-DLIBRARY_EXPORTS)
INCLUDE_DIRECTORIES (..)
ADD_LIBRARY(LIBRARY ${PRJ_SRCS})
SET_TARGET_PROPERTIES(LIBRARY PROPERTIES DEBUG_POSTFIX d)
#ADD -DDEBUG TO THE DEBUG TARGET. THIS DOES NOT WORK! HOW TO ADD -DDEBUG 
ONLY TO THE DEBUG
#TARGET AND NOT TO ANY TARGET? I TRYED TO USE "COMPILE_FLAGS_DEBUG" WITH 
NO LUCK.
 SET_TARGET_PROPERTIES (LIBRARY PROPERTIES COMPILE_FLAGS "-DDEBUG")
#######################################

CMakeLists.txt for the executable:
##############################################
PROJECT(exe)
SET (PRJ_SRCS exe.cpp )
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR}/../LIBRARY/ )
LINK_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR}/../LIBRARY/)
ADD_EXECUTABLE (exe WIN32 ${PRJ_SRCS})
TARGET_LINK_LIBRARIES(exe debug kgld optimized kgl)
ADD_DEFINITIONS (-D_CRT_SECURE_NO_DEPRECATE)
######################################

My main concerns are about:
1) How to set -DDEBUG only for the DEBUG target?  SET_TARGET_PROPERTIES 
(LIBRARY PROPERTIES COMPILE_FLAGS "-DDEBUG") set it for all targets, 
just as ADD_DEFINITIONS() does.

2) Is the usage of TARGET_LINK_LIBRARIES (exe debug xxx optimized xxx) 
any good? Or there is a better alternative?

Any other improvement is wellcome. Thanks in advance.

Greetings,
Luca


More information about the CMake mailing list