Hello,

I am trying to make cmake include file for libraries, so I can do for example:

add_executable(exea a.cpp)
include(../somelib/include.cmake)
use_somelib(exea)

exea will now have proper compile flags and target_link_libraries

(as you can see, I have used the approach with target_link_libraries as suggested in this email: http://www.cmake.org/pipermail/cmake/2008-April/020957.html)


The problem is writing use_somelib macro - cmake syntax is quite wordy. Remember that I have a large acyclic graph of dependencies and the same use_* macro may be called multiple times for the same target, also the same include file might be included multiple times. My painfully verbose solution, emulating C preprocessor techniques:

if(NOT somelib_include)
        set(somelib_include 1)

        ... some general stuff ...

        macro(use_somelib TGT)
                if(NOT use_somelib_${TGT})
                        set(use_somelib_${TGT} 1)

                        if(NOT lib_somelib)
                                set(lib_somelib 1)
                                add_library(somelib ...)
                        endif(NOT lib_somelib)

                        target_link_libraries(${TGT} somelib)
                        ... add some cflags to TGT ...

                endif(NOT use_somelib_${TGT})
        endmacro(use_somelib TGT)
endif(NOT somelib_include)


Any suggestions on how to improve these patterns:

if(NOT x)
        set(x 1)
        ...
endif(NOT x)

and

macro(y X)
        if(NOT y_${X})
                set(y_${X} 1)
                ...
        endif(NOT y_${X})
endmacro(y)


Thanks
Egon Kocjan
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to