[CMake] Problem with circular dependencies

Tyler Roscoe tyler at cryptio.net
Thu May 28 14:54:05 EDT 2009


On Thu, May 28, 2009 at 08:56:04PM +0300, Dmytro Ovdiienko wrote:
> 1. We have two projects A and B.
> 2. Project A is stored to <root>/A
> 3. Project B is stored to <root>/B
> 4. Project A depends on B.
> 5. Project B depends on A. (please don't ask me why:) )
> 6. There is CMakeLists.txt in the <root>

If A and B really depend on each other, I don't know how you would ever
expect to build them, nor how you would expect CMake to handle this
case.

But from your Lists below it appears that they don't really depend on
one another, in a "target A must be built before target B" sense, but
simply that they use headers from each other's source directories?

> #####################################
> # Project A
> #####################################
> SET (PROJECT_NAME A )
> PROJECT (${PROJECT_NAME})
> 
> INCLUDE_DIRECTORIES(
>   ${B_SOURCE_DIR}
> )
> 
> FILE (GLOB ${PROJECT_NAME}_SOURCE_LIST
>     *.cpp
> )
> 
> ADD_LIBRARY (${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE_LIST})
> 
> #####################################
> # Project B
> #####################################
> SET (PROJECT_NAME B )
> PROJECT (${PROJECT_NAME})
> 
> INCLUDE_DIRECTORIES(
>   ${A_SOURCE_DIR}
> )
> 
> FILE (GLOB ${PROJECT_NAME}_SOURCE_LIST
>     *.cpp
> )
> 
> ADD_LIBRARY (${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE_LIST})
> 
> 
> And now we generate the project files and check Additional Includes
> Directories of the A project.
> 
> Expected it is equal to <root>/B.
> But in fact it is empty.

Is ${B_SOURCE_DIR} defined in the CMakeLists for project A?

> The other side of this problem is you have to write ADD_SUBDIRECTORY
> commands in specific order. IMHO it is inconvenient.

CMakeLists are essentially a scripting language, so of course order
matters. What would you propose instead?

tyler


More information about the CMake mailing list