[CMake] help with learning add_library

luxInteg lux-integ at btconnect.com
Sat Nov 6 17:55:21 EDT 2010


On Saturday 06 November 2010 17:30:10 Michael Hertling wrote:
> On 11/06/2010 05:26 PM, luxInteg wrote:
> > Greetings,
> > 
> > I am learning cmake.
> > 
> > I have a question on  using add_library.  in my  project(learnCMAKE). 
> > The latter has:-
> > 
> > ---a) 2  source files   file1.c  file2.c
> > ---b) the envar {CFLAGS}  set
> > ---c)  need to generate  libLearnCMAKE.so and libLearnCMAKE.a
> 
> ADD_LIBRARY(LearnCMAKE-shared SHARED file1.c file2.c)
> ADD_LIBRARY(LearnCMAKE-static STATIC file1.c file2.c)
> SET_TARGET_PROPERTIES(LearnCMAKE-shared LearnCMAKE-static
>     PROPERTIES OUTPUT_NAME LearnCMAKE)
> 
> > ---d) need  to add preprocessor agruments -DXXX to CFLAGS  in the
> > compilation of  the source files  before liberies are archived  like
> > so:-
> > 
> > gcc ${CFLAGS} -DDINT /path/to/file1.c
> > gcc ${CFLAGS} -DDINT /path/to/file2.c
> > 
> > gcc ${CFLAGS} -DDLONG /path/to/file1.c
> > gcc ${CFLAGS} -DDLONG /path/to/file2.c
> 
> SET_TARGET_PROPERTIES(LearnCMAKE-shared LearnCMAKE-static
>     PROPERTIES COMPILE_DEFINITIONS DINT)
> 
> or
> 
> SET_SOURCE_FILES_PROPERTIES(/path/to/file1.c /path/to/file2.c
>     PROPERTIES COMPILE_DEFINITIONS DINT)
> 
> or
> 
> SET_DIRECTORY_PROPERTIES(
>     PROPERTIES COMPILE_DEFINITIONS DINT)
> 
> or
> 
> ADD_DEFINITIONS(-DDINT)
> 
> or
> 
> SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDINT")
> 


thanks  a lot.   I had the most success with  this:-
 SET_SOURCE_FILES_PROPERTIES(/path/to/file1.c /path/to/file2.c
    PROPERTIES COMPILE_DEFINITIONS DINT)


HOWEVER  I need to pass   the files through the compiler twice once with _DINT 
and other with -DDOUBLE before  the  object files are archived..

I tried this:

SET_SOURCE_FILES_PROPERTIES(/path/to/file1.c /path/to/file2.c
    PROPERTIES COMPILE_DEFINITIONS DINT)
SET_SOURCE_FILES_PROPERTIES(/path/to/file1.c /path/to/file2.c
    PROPERTIES COMPILE_DEFINITIONS DDOUBLE)

but only the last one was  done.    I am wondering if the DINT and DDOUBLE 
could be incorporated in a foreach loop?

advice would be appreciated.

sincerely
luxINTEG




More information about the CMake mailing list