I am trying to compile two executables foo and bar with cmake generating "Unix makefiles" under cygwin. Both executables are built from a single cmake project, so I have only a single CmakeLists.txt file.
The dependency between foo and bar is generated by an object file named depend.o, which is generated by the linker when linking foo.
I am able to tell cmake, that bar has an external dependency to a generated object file. I am also able to tell cmake that bar depends on foo, to get proper build order, but still the build fails when parallel builds are enabled.
This is what I did:
add_executable(bar .....)
add_executable(foo .....)
....
#Tell the linker we have an additional external library.
set_property(bar APPEND PROPERTY LINK_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/depend.o")
#Tell cmake depend.o is a generated object file.
SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/depend.o" PROPERTIES EXTERNAL_OBJECT true GENERATED true)
#And finally create dependency between the foo and bar
add_dependencies(bar foo)
So the question is: what trick is needed to get parallel builds work or how to properly define the dependency between foo and bar?
Edit: My question is not a duplicate of CMake: reuse object files built for a lib into another lib target. That question is about how to use the same object file in multiple libraries which can be done with "object libraries". I am after solving a dependency problem between two executables.