Browse Source

CMake: Fix success message after finding dependency

Michael Ragazzon 11 months ago
parent
commit
dba410f34a
2 changed files with 23 additions and 6 deletions
  1. 1 3
      CMake/DependenciesForBackends.cmake
  2. 22 3
      CMake/Utilities.cmake

+ 1 - 3
CMake/DependenciesForBackends.cmake

@@ -69,9 +69,7 @@ if(RMLUI_BACKEND MATCHES "^(BackwardCompatible_)?GLFW")
 	find_package("glfw3" "3.3")
 
 	# Instead of relying on the <package_name>_FOUND variable, we check directly for the target
-	if(NOT TARGET glfw)
-		report_dependency_found_or_error("GLFW" "glfw3" glfw)
-	endif()
+	report_dependency_found_or_error("GLFW" "glfw3" glfw)
 endif()
 
 # SFML

+ 22 - 3
CMake/Utilities.cmake

@@ -37,6 +37,24 @@ function(report_dependency_not_found friendly_name package_name target_name)
 	)
 endfunction()
 
+#[[
+	Print a message for the dependency after being found.
+	Arguments:
+		- package_name: Name of the package to search for
+		- target_name: Name of the CMake target the project will link against
+		- success_message: Message to show when the target exists (optional)
+]]
+function(report_dependency_found package_name target_name)
+	set(message "")
+	if(DEFINED ${package_name}_VERSION AND NOT ${package_name}_VERSION STREQUAL "UNKNOWN")
+		set(message " v${${package_name}_VERSION}")
+	endif()
+	if(ARGC GREATER "2" AND ARGV2)
+		set(message "${message} - ${ARGV2}")
+	endif()
+	message(STATUS "Found ${target_name}${message}")
+endfunction()
+
 #[[
 	Verify that the target is found and print a message, otherwise stop execution.
 	Arguments:
@@ -49,10 +67,11 @@ function(report_dependency_found_or_error friendly_name package_name target_name
 	if(NOT TARGET ${target_name})
 		report_dependency_not_found(${friendly_name} ${package_name} ${target_name})
 	endif()
-	if(ARGC GREATER "2" AND ARGV2)
-		set(success_message " - ${ARGV2}")
+	set(success_message "")
+	if(ARGC GREATER "3" AND ARGV3)
+		set(success_message "${ARGV3}")
 	endif()
-	message(STATUS "Found ${target_name}${success_message}")
+	report_dependency_found(${package_name} ${target_name} ${success_message})
 endfunction()
 
 #[[