Hello,
I'm using CMake to build an application made up of four projects:
- a.dll, which has no dependency
- b.dll, which depends on a.dll
- c.exe, which depends on a.dll and b.dll
- d.exe, which depends on a.dll and b.dll
Each project (or target in CMake's terminology) lies in its own subdirectory, and has its own CMakeLists.txt file. In addition there's a top-level CMakeLists.txt file that binds them all (using add_subdirectory
).
In the CMakeLists.txt files of b.dll, c.exe and d.exe, I'm using target_link_libraries
to link these targets to the import libraries of a.dll and b.dll. That works properly. So far, so good.
Now, in Visual Studio, it appears that CMake doesn't set any "Project Dependencies" between the various projects of the solution: if I go to Project -> Project Dependencies..., I can see that indeed b.dll doesn't have a dependency to a.dll, c.exe doesn't have a dependency to neither a.dll nor b.dll, etc. The result is that the build order of the projects is essentially random, and in practice the solution simply fails to build (because, for instance, c.exe is built before a.dll, and thus the corresponding import library a.lib has not yet been generated).
I'm rather puzzled. I've been scouting the net for an answer very thoroughly, but without luck (which makes me think this is a non-issue for most CMake users, and I must be doing something wrong).
Note that I also tried to use the add_dependencies
command, but that had no effect.
I'm using CMake 2.8.1 and Visual Studio 2008 (9.0).
Thanks, Franz
Here are the CMakeLists.txt files, for reference:
top-level CMakeLists.txt:
add_subdirectory(a)
add_subdirectory(b)
add_subdirectory(c)
add_subdirectory(d)
a/CMakeLists.txt:
add_library(a SHARED a.cpp)
b/CMakeLists.txt:
add_library(b SHARED b.cpp)
target_link_libraries(b a)
# also tried to add add_dependencies(b a) here
c/CMakeLists.txt:
add_executable(c c.cpp)
target_link_libraries(c a b)
# also tried to add add_dependencies(c a b) here
d/CMakeLists.txt:
add_executable(d d.cpp)
target_link_libraries(d a b)
# also tried to add add_dependencies(d a b) here