[CMake] Add pre-existing object file to linker line?

Trevor Kellaway tkellaway at asl-electronics.co.uk
Sun May 27 12:41:35 EDT 2007


Bill,

> > ADD_EXECUTABLE(myapp mysrc1.c mysrc2. myexisiting.o)
> >
> > If I perform the above CMake complains it doesn't know how to build 
> > myexisiting.o.
> >
> What version of CMake are you using? The above should work.

Sorry, my fault, you are right it does work, I was stupidly not
specifying the full (or relative path to the file, brain fade thinking
it might be found in the link path but obviously not). Thanks.


Previously we discussed using "GET_TARGET_PROPERTY (_obj_list ${target}
OBJECT_FILES)" to determine the absolute object file path for a source
file. This works, but I'm in catch 22 situation, as I can only determine
a source file's object file once it has been added to a library or
executable, and by then it is too late for me to use this information to
add other source file (.lint) rules to the library. (Unless you can add
extra source file dependencies to a previous ADD_LIBRARY?)

Allow me to take a step back, what I'm trying to do is to get Lint to
run if a source file or its dependencies have changed. In my straight
makefile world I'd just add an extra command line to the .c.obj
inference rule. I can't see how I can do this in CMake, under Unix I
could use the shell "&&" to run two commands for the compile, but under
Windows this is a non-starter.

Currently I'm creating a phoney target "filename.lint" and making this
depend on the object file, but having to predict the object output
directory, which is very fragile, and breaks if a CMakeLists.txt
references a source file out of the tree (CMake works but produces a
huge path under the binary directory that can't be easily predicted).

What do you suggest? You're help would be gratefully appreciated.

 - TrevK




More information about the CMake mailing list