[CMake] cmake_*_compile_flags doubt

Brad King brad.king at kitware.com
Sat Jun 17 19:25:09 EDT 2006


Vikas Kumar wrote:
> 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.

Use SET_TARGET_PROPERTIES to set the COMPILE_FLAGS property.

-Brad


More information about the CMake mailing list