[CMake] cmake_*_compile_flags doubt

Vikas Kumar vikasnkumar at users.sourceforge.net
Sat Jun 17 14:44:03 EDT 2006


Hi
Is there a way that I can change compile flags based on the target I
am building. I have played around with all the cmake command options
given and I am kinda out of ideas. So it seems that the CmakeCache.txt
variables are my only hope. But I do not have enough knowledge nor do
I have the CMake book to help me. (apparently it is out of stock)
As an example of the case that I have, in one directory I have some
source files.
These source files need to be built and linked and archived into
static libraries.
But the catch here is that they all use #ifdef's. Since the code is
supposed to be high-performance oriented, we cannot afford to use
runtime if-then-else checks. Hence compile time checks are done. All
the code is in C.
Now there are only 2 constants that are used in the code, lets call
them DEF_CON_1 and DEF_CON_2.
Let the source files be src1.c and src2.c . Both these source files
use the above constants and compile different functions based on the
constants and are supposed to create two different target static
libraries, libfoo1. a and libfoo2.a .
Now all of this is done under one Project.
I want to do
PROJ(Test)
ADD_LIBRARY(foo1 "STATIC" src1.c src2.c)
ADD_LIBRARY(foo2 "STATIC" src1.c src2.c)

using ADD_DEFINITIONS() sets the defines for all the targets. using
SET_SOURCE_FILES_PROPERTIES() sets the COMPILE_FLAGS for the sources
for whatever targets they are used to build.
SET_TARGET_PROPERTIES() does not work for static libraries, otherwise
I could have used target_EXPORTS instead.

Now is there a way that I can set CMAKE_C_COMPILE_FLAGS type variables
for the same sources pertaining to different targets.

And yes CONFIGURE_FILE() also does not work in this case because the
same sources are used for different targets and they are all present
in the same directory. Or maybe it does work and I am not using it
right.
I even tried placing the above in  the MACRO() functionality, but even
that did not do it.

Any help from the Cmake geniuses here will be appreciated ! :)
I have looked in the previous mailing lists and although some people
have had the same problems, they were able to work it out using some
hack for their configuration of the source tree.
But it does not work for me.
What am I doing wrong or what can I do to bypass this problem ?


Regards,
Vikas


More information about the CMake mailing list