1

Currently, I programmatically generate a conanfile.txt using two functions I have written:

message(STATUS "Fetching Doxygen from Conan.")
add_project_dependencies(${PROJECT_NAME}_docs CONAN BUILD_DEPS REQUIRED doxygen/1.9.1)
link_project_dependencies(${PROJECT_NAME}_docs PRIVATE)

Together, they create ${CMAKE_BINARY_DIR}/deps_${PROJECT_NAME}_docs/conanfile.txt:


[requires]


[build_requires]
doxygen/1.9.1

[generators]
cmake_find_package

[options]


[imports]

And then they run conan install . in that directory and Doxygen is built successfully. As I use cmake_find_package generator, a Finddoxygen.cmake is created inside that directory as well. So far, so good. However, finding the package like this:

find_package(doxygen REQUIRED)

Doesn't provide the DOXYGEN_EXECUTABLE like it's supposed to (it is set to DOXYGEN_EXECUTABLE-NOTFOUND). Neither does it provide the doxygen_add_docs() for use. So according to FindDoxygen docs , and as the conan-generated Finddoxygen.cmake contains target definition for doxygen::doxygen I thought I should use the generator expressions (as per here):

add_custom_target(docs
    COMMAND $<TARGET_FILE:doxygen::doxygen> ${DOXYGEN_OUT}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating API documentation with Doxygen"
    VERBATIM)

But this generates the error: Target "doxygen::doxygen" is not an executable or library. Neither that or LOCATION target property work; I used this snippet to view target's properties:

doxygen::doxygen IMPORTED = TRUE
doxygen::doxygen IMPORTED_GLOBAL = FALSE
doxygen::doxygen INTERFACE_COMPILE_OPTIONS = ;
doxygen::doxygen INTERFACE_LINK_LIBRARIES = ;xapian::xapian;ZLIB::ZLIB;$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>;$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>;$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>
doxygen::doxygen NAME = doxygen::doxygen
doxygen::doxygen TYPE = INTERFACE_LIBRARY

And it doesn't provide any property containing the path to the doxygen binary that is generated at ~/.conan/data/doxygen/1.9.1/_/_/package/ff3ada3b39a52bebe18da7d8c32a4aead970f75c/bin/doxygen.

So how can I use it inside my CMake scripts? Am I missing something? Because looking at the example usage in this resolved issue, it seems that my approach is correct and it should have found the binary and set DOXYGEN_EXECUTABLE.

Evg
  • 25,259
  • 5
  • 41
  • 83
Saeid Akbari
  • 115
  • 8

1 Answers1

1

This can be achieved by using CONAN_BIN_DIRS_DOXYGEN/doxygen.

Also list of other useful variables: https://docs.conan.io/en/latest/reference/generators/cmake.html

ymochurad
  • 941
  • 7
  • 15
  • From what I understand, this explains how to access the executable from a CMake script conditionally to the fact we are sure that conan was used to install doxygen. How does this answer fit the case where we don't know if Doxygen was installed systen-wide, using conan, or brew? – WaterFox Nov 22 '22 at 22:16