Re: [CMake] Conditional dependency

2007-11-06 Thread Salvatore Iovene
On 11/6/07, Nicholas Yue <[EMAIL PROTECTED]> wrote:
> Hi,
>
>   I have a project which is build a library fine with CMake (has
> around 100 source file).
>
>   ADD_LIBRARY ( mylib STATIC a.cpp b.cpp c.cpp  )
>
>   The content in b.cpp is relevant to only some platform platform.
>
>   How do I tell CMake that file b.cpp is only to be include as depends
> of library "mylib" only if a platform string match.
>
>   I can achieve the desired effect with
>
>   IF (WIN32)
>   ADD_LIBRARY ( mylib STATIC a.cpp c.cpp )
>   ELSE (WIN32)
>   ADD_LIBRARY ( mylib STATIC a.cpp b.cpp c.cpp )
>   ENDIF (WIN32)
>
>   As there are hundreds of file, I want to avoid duplicating and add
> to maintainence.

Try this:

IF(NOT WIN32)
 SET(b_SOUCE b.cpp)
ENDIF(NOT WIN32)

ADD_LIBRARY ( myLib STATIC a.cpp ${b_SOURCE} c.cpp  )

If you're not on WIN32, then the variable ${b_SOURCE} will be empty.


-- 
Salvatore Iovene
http://www.iovene.com/
Key Fingerprint: 5647 944D D5AD 2E87 00B4  7D54 2864 359D FF20 16D8
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Conditional dependency

2007-11-06 Thread Eric Noulard
2007/11/6, Salvatore Iovene <[EMAIL PROTECTED]>:
> On 11/6/07, Nicholas Yue <[EMAIL PROTECTED]> wrote:
> >
> >   As there are hundreds of file, I want to avoid duplicating and add
> > to maintainence.
>
> Try this:
>
> IF(NOT WIN32)
>  SET(b_SOUCE b.cpp)
> ENDIF(NOT WIN32)
>
> ADD_LIBRARY ( myLib STATIC a.cpp ${b_SOURCE} c.cpp  )
>
> If you're not on WIN32, then the variable ${b_SOURCE} will be empty.

In the same spirit I usually define a var which contains the list
of file to be included in a library and augment var content
conditionally.

The general pattern is the following:

# put unconditional sources in
SET(MYLIB_SRC c.cpp g.cpp )

# then ADD the conditional ones
IF(WIN32)
   SET(MYLIB_SRC ${MYLIB_SRC} win32-a.cpp)
ENDIF(WIN32)

IF(LIBXML2_FOUND)
  SET(MYLIB_SRC ${MYLIB_SRC}  xml2-a.cpp)
ENDIF()

[... etc ...]

# now define the lib
ADD_LIBRARY(myLib STATIC ${MYLIB_SRC})


-- 
Erk
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Conditional dependency

2007-11-06 Thread Hendrik Sattler

Zitat von Eric Noulard <[EMAIL PROTECTED]>:


2007/11/6, Salvatore Iovene <[EMAIL PROTECTED]>:

On 11/6/07, Nicholas Yue <[EMAIL PROTECTED]> wrote:
>
>   As there are hundreds of file, I want to avoid duplicating and add
> to maintainence.

Try this:

IF(NOT WIN32)
 SET(b_SOUCE b.cpp)
ENDIF(NOT WIN32)

ADD_LIBRARY ( myLib STATIC a.cpp ${b_SOURCE} c.cpp  )

If you're not on WIN32, then the variable ${b_SOURCE} will be empty.


In the same spirit I usually define a var which contains the list
of file to be included in a library and augment var content
conditionally.

The general pattern is the following:

# put unconditional sources in
SET(MYLIB_SRC c.cpp g.cpp )

# then ADD the conditional ones
IF(WIN32)
   SET(MYLIB_SRC ${MYLIB_SRC} win32-a.cpp)
ENDIF(WIN32)

IF(LIBXML2_FOUND)
  SET(MYLIB_SRC ${MYLIB_SRC}  xml2-a.cpp)
ENDIF()


Additionally, I suggest using the LIST macro instead, the above  
actually reinvents LIST(APPEND ).


HS




___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Conditional dependency

2007-11-06 Thread Alan W. Irwin

On 2007-11-06 12:44+0100 Hendrik Sattler wrote:


Zitat von Eric Noulard <[EMAIL PROTECTED]>:

The general pattern is the following:

# put unconditional sources in
SET(MYLIB_SRC c.cpp g.cpp )

# then ADD the conditional ones
IF(WIN32)
   SET(MYLIB_SRC ${MYLIB_SRC} win32-a.cpp)
ENDIF(WIN32)

IF(LIBXML2_FOUND)
  SET(MYLIB_SRC ${MYLIB_SRC}  xml2-a.cpp)
ENDIF()


Additionally, I suggest using the LIST macro instead, the above actually 
reinvents LIST(APPEND ).


I would like to clean up the PLplot build system style which has a lot of
the former style instead of LIST(APPEND...).

However, before I do that work, does anybody know whether LIST(APPEND...)
was available for cmake-2.4.5 (the minimum version of cmake for the
PLplot build)?

To Bill Hoffman: at one time you were keen on committing the results of
cmake --help-full for each version of cmake to cvs so that differences (such
as when LIST(APPEND) was introduced) would spring out when browsing cvs
using the view-cvs GUI diff.  Did you ever implement that step in your
release process?  If so, where do you keep the results of cmake --help-full
in cvs?

Alan
__
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__

Linux-powered Science
__
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Conditional dependency

2007-11-06 Thread Bill Hoffman

Alan W. Irwin wrote:


However, before I do that work, does anybody know whether LIST(APPEND...)
was available for cmake-2.4.5 (the minimum version of cmake for the
PLplot build)?

To Bill Hoffman: at one time you were keen on committing the results of
cmake --help-full for each version of cmake to cvs so that differences 
(such

as when LIST(APPEND) was introduced) would spring out when browsing cvs
using the view-cvs GUI diff.  Did you ever implement that step in your
release process?  If so, where do you keep the results of cmake --help-full
in cvs?


Alex, actually did it, and you can find it here:

http://www.cmake.org/Wiki/CMake_Released_Versions

Looks like it is there.

-Bill
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake