Skip to content

Commit

Permalink
Handle warning when the dependency provider is set but not used (#551)
Browse files Browse the repository at this point in the history
* Add warning when dependency provider is never invoked
  • Loading branch information
jcar87 authored Aug 30, 2023
1 parent ea0882f commit 8adc284
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ endfunction()


macro(conan_provide_dependency method package_name)
set_property(GLOBAL PROPERTY CONAN_PROVIDE_DEPENDENCY_INVOKED TRUE)
get_property(CONAN_INSTALL_SUCCESS GLOBAL PROPERTY CONAN_INSTALL_SUCCESS)
if(NOT CONAN_INSTALL_SUCCESS)
find_program(CONAN_COMMAND "conan" REQUIRED)
Expand Down Expand Up @@ -352,4 +353,24 @@ endmacro()
cmake_language(
SET_DEPENDENCY_PROVIDER conan_provide_dependency
SUPPORTED_METHODS FIND_PACKAGE
)
)

macro(conan_provide_dependency_check)
set(_CONAN_PROVIDE_DEPENDENCY_INVOKED FALSE)
get_property(_CONAN_PROVIDE_DEPENDENCY_INVOKED GLOBAL PROPERTY CONAN_PROVIDE_DEPENDENCY_INVOKED)
if(NOT _CONAN_PROVIDE_DEPENDENCY_INVOKED)
message(WARNING "Conan is correctly configured as dependency provider, "
"but Conan has not been invoked. Please add at least one "
"call to `find_package()`.")
if(DEFINED CONAN_COMMAND)
# supress warning in case `CONAN_COMMAND` was specified but unused.
set(_CONAN_COMMAND ${CONAN_COMMAND})
unset(_CONAN_COMMAND)
endif()
endif()
unset(_CONAN_PROVIDE_DEPENDENCY_INVOKED)
endmacro()

# Add a deferred call at the end of processing the top-level directory
# to check if the dependency provider was invoked at all.
cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL conan_provide_dependency_check)

0 comments on commit 8adc284

Please sign in to comment.