[CMake] Conditional dependency
Eric Noulard
eric.noulard at gmail.com
Tue Nov 6 04:36:01 EST 2007
2007/11/6, Salvatore Iovene <salvatore.iovene+cmake at googlemail.com>:
> On 11/6/07, Nicholas Yue <yue.nicholas at gmail.com> 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 <etc> )
>
> 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 <any otherunconditional source>)
# 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
More information about the CMake
mailing list