I am quite new to CMake and want to achieve a very "common" task with it. Until now, I simply used Eclipse CDT with auto generated makefiles. Suppose I have two projects A and B. A builds a static library and B needs this library. Of course, when building B, I want to ensure that the static library built by A is up-to-date. Thus, a building of project B should trigger the building of A if any changes were made in the sources of A. This is the default behaviour of Eclipse when simply inserting A as a dependency of B.
So, what is the easiest way to achieve this with CMake? I have read some tutorials and similar questions, but none gave me a satisfying answer.
For example, there is the http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets tutorial which could be a solution. However, it seems quite complex for such an easy task. I have to "install" the targets of A, but I do not want to install anything, I just want B to depend on A. Next, I heard about ExternalProject_add but I don't know how to handle it either.
If you're building them from the same CMakeLists file, specifying the linkage using the target name will be enough:
add_library(LibraryA ${A_SOURCES}
target_link_libraries(LibraryA <any libraries that A depends on>)
add_executable(ProgramB)
target_link_libraries(ProgramB LibraryA <plus other libraries>)
If they're not in the same CMakeLists file, then either include the A build using ADD_SUBDIRECTORY(), (A is a child of B), or build them both from the same top-level file using an ADD_SUBDIRECTORY() for each one (A and B are siblings).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With