[CMake] CMake builds library/executable out of order

Schuchard, Matthew Matthew.Schuchard at gtri.gatech.edu
Wed Dec 7 09:37:50 EST 2011


I am having this strange issue with building a library and then linking it to an executable.

If I have the following in my CMakeList:

add_library(libfoo.a ${srcfiles})
add_executable(foo_exec.Fx foo_exec.F)
target_link_libraries(foo_exec.Fx libfoo.a)

I get an error returned of "no rule to make target libfoo.a needed by foo_exec.Fx."
I should mention I have library prefixes and suffixes turned off for both linking and building, meaning that the full filename of libraries are specified (hence the libfoo.a and not just foo).

But if I change my CMakeList to:

add_library(libfoo.a ${srcfiles})
#add_executable(foo_exec.Fx foo_exec.F)
#target_link_libraries(foo_exec.Fx libfoo.a)

It builds libfoo.a without any complaint.  When I uncomment the executable lines after building libfoo.a via the above, the library is linked to the executable with no complaints.
I might also mention since the Fortran compiler used is ABSoft and I am building on a 64-bit Redhat system, the linker I am using for Fortran executables is g++, but that may be irrelevant.

How do I specify that the library needs to be built before the executable which links to it, so that CMake does not return an error when it tries to build and link the executable before building its dependent library?
This almost seems like a bug in CMake.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111207/6030380e/attachment.htm>


More information about the CMake mailing list