[CMake] acyclic builds 2.
Egon Kocjan
egon at krul.ath.cx
Wed Apr 9 05:45:52 EDT 2008
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
More information about the CMake
mailing list