[CMake] Two questions...

Lars Pechan lars.pechan at parkerpechan.com
Thu Oct 14 17:44:27 EDT 2004


Hi there,
I'm in the process of trying to port quite a large legacy 
multi-platform makefile project to CMake. A couple of questions have 
popped up:

1) Quite far down in the tree is a directory which is built differently 
with regards to compiler switches, include paths and defines. CMakes 
recursive inheriting of those variables leave me with a set of options 
by the time I get to this tree that simply won't work. How can I reset 
these for a new subproject? Or should I do that dir as a separate 
project and then bring in the library that is produced there by means 
of some nifty dependency trick? Changing the original directory 
structure is not an option.

2) On MacOSX I get various link errors. Basically what I have is a 
number of subdirectories that each contain a part of the project. I 
build a (static most of the time) library in each such dir and the try 
and link them all together at the top level. Sadly, g++ produces link 
errors (undefined symbols) relating to files that are definitely in one 
of the static libs (and, of course linked in via 
TARGET_LINK_LIBRARIES(...)). In this particular case I can easily see 
that the errors are pertaining to two different statically linked libs 
from further down the tree.

However, interestingly, if I change the link line so that these two 
dirs are included as .a-files with absolute paths it links just fine. 
Eg

 From CMake:

g++ -Ltop/Sub1 -Ltop/sub2/ -Ltop/sub3 -ls1 -ls2 -ls3 ...

produces undefined symbols pertaining to libs2.a and libs3.a. If I then 
change the command line manually to:

g++ -Ltop/Sub1 top/sub2/libs1.a top/sub3/libs2.a -ls3 ...

it links just fine.

Any ideas of why this is? And also, more importantly, is there any way 
for me to express this style of linking in CMake? (I tried adding the 
.a files to the ADD_EXECUTABLE but that won't work. I also tried to 
tweak TARGET_LINK_LIBRARIES to no avail)

While I'm at it, sorry if this is too trivial for the list, but I would 
like to pre-populate CMakeCache.txt with appropriate CXX_FLAGS etc 
using the option to pre-initialize the cache with 'cmake -C'. I'm 
already populating some settings this way but I'm not sure how to set 
the compiler flags?

Thanks,

/Lars

Ah, cmake 2.0.3, MacOSX 10.3.5, apple-gcc 3.3



More information about the CMake mailing list