[CMake] Conditional dependency

Salvatore Iovene salvatore.iovene+cmake at googlemail.com
Tue Nov 6 03:49:03 EST 2007


On 11/6/07, Nicholas Yue <yue.nicholas at gmail.com> 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 <etc> )
>
>   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 <etc>)
>   ELSE (WIN32)
>   ADD_LIBRARY ( mylib STATIC a.cpp b.cpp c.cpp <etc>)
>   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 <etc> )

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


More information about the CMake mailing list