There is no magic way to do this with CMake.   However, if you don't mind
writing some functions/macros you can use a variant of the following
function to do what you want:

function(build_library NAME KIND SOURCES DEFINITIONS CFLAGS LFLAGS LIBS
IPATHS LPATHS)
    unset(MYCOMPILE_FLAGS)
    unset(MYLINK_FLAGS)

    set(MYCOMPILE_FLAGS "${CFLAGS}")
    set(MYLINK_FLAGS "${LFLAGS}")

    if(UNIX)
        foreach(IPATH ${IPATHS})
            set(MYCOMPILE_FLAGS "${MYCOMPILE_FLAGS} -I${IPATH}")
        endforeach(IPATH)

        foreach(LPATH ${LPATHS})
            set(MYLINK_FLAGS "${MYLINK_FLAGS} -L${LPATH}")
        endforeach(LPATH)
    elseif(WIN32)
        foreach(IPATH ${IPATHS})
            set(MYCOMPILE_FLAGS "${MYCOMPILE_FLAGS} /I${IPATH}")
        endforeach(IPATH)

        foreach(LPATH ${LPATHS})
            set(MYLINK_FLAGS "${MYLINK_FLAGS} /LIBPATH:\"${LPATH}\"")
        endforeach(LPATH)
    endif(UNIX)

    add_library(${NAME} ${KIND} ${SOURCES})

    target_link_libraries(${NAME} ${LIBS})

    set_target_properties(${NAME} PROPERTIES
        COMPILE_DEFINITIONS "${DEFINITIONS}"
        COMPILE_FLAGS "${MYCOMPILE_FLAGS}"
        LINK_FLAGS "${MYLINK_FLAGS}"
    )
endfunction(build_library)


This function build_library is designed to allow you to pass target specific
configurations where includes/etc are different for each target.  You assign
the includes/defintions/etc to variables and then pass the values as
follows:

build_library(foo STATIC
 "${FOO_SOURCES}"
 "${FOO_COMPILE_DEFINITIONS}"
 "${FOO_COMPILE_FLAGS}"
 "${FOO_LINK_FLAGS}"
 "${FOO_LIBS}"
 "${FOO_INCLUDE_DIRECTORIES}"
 "${FOO_LINK_DIRECTORIES}"
)

The sources, compile definitions, libraries, include directories and link
directories variables should all be lists of values while the compile flags
and the link flags should be strings of compiler/linker flags.  The second
argument of the function sets the kind of library, STATIC/SHARED/etc...

This function then 'hacks' the include directories into the compiler flags
and the link directories into the link flags with the appropriate command
line escape by platform (-I for Unix, /I for Windows, etc...).

Hope this helps,

Steve

On Wed, Nov 4, 2009 at 8:39 AM, Olivier Pierard
<olivier.pier...@cenaero.be>wrote:

> Hi,
>
> A quite basic question...
>
> In a given project, I build several libraries and an executable.  How
> can I get a different 'include_directories' for each library and not the
> same list for all of them (typically, I don't want to have access to the
> includes related to the last library when compiling the first one).
>
> Thank you,
>
> Olivier
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to