[CMake] Circular dependencies because of file names?
Michael Hertling
mhertling at online.de
Tue Nov 15 09:04:14 EST 2011
On 11/14/2011 09:31 PM, Jookia wrote:
> I have the following code:
>
> # ---------- DOXYGEN
>
> find_package(Doxygen)
>
> set(docsDir "${CMAKE_BINARY_DIR}/docs/")
>
> add_custom_command(OUTPUT ${docsDir}
> COMMAND ${CMAKE_COMMAND} "-E" "make_directory"
> ${docsDir} VERBATIM)
>
> add_custom_target("docs"
> COMMAND "${DOXYGEN_EXECUTABLE}"
> "${CMAKE_SOURCE_DIR}/../doxygen/doxyfile"
> WORKING_DIRECTORY ${docsDir}
> DEPENDS ${docsDir})
>
> set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
> "${docsDir}")
>
> Which causes a circular conflict. But when I change the docsDir to
> "${CMAKE_BINARY_DIR}/docs2/", I no longer get the error.
>
> Is there a way to fix this?
The "docs" custom command is integrated in the "docs" custom target's
Makefile with a relative path, so there are dependencies of the type
"docs" (custom target) on "docs" (custom command's output) which are
ignored by Make. Thus, the "docs" directory is not created, and the
custom target fails. In general, it's a bad idea to have targets
with the same name as files/directories they depend on.
In order to solve this issue, add another custom target, say, docdir
which depends on the custom command's output; this will decouple the
"docs" custom target from the custom command. Finally, establish the
dependency of "docs" on "docdir" by ADD_DEPENDENCIES():
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(DOCS NONE)
SET(CMAKE_VERBOSE_MAKEFILE ON)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_BINARY_DIR}/docs
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/docs)
ADD_CUSTOM_TARGET(docdir DEPENDS ${CMAKE_BINARY_DIR}/docs)
ADD_CUSTOM_TARGET(docs
COMMAND ${CMAKE_COMMAND} -E echo "custom target docs"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/docs)
ADD_DEPENDENCIES(docs docdir)
Regards,
Michael
More information about the CMake
mailing list