From 28cb14289ae97f77ca802fda44256c090f714cd1 Mon Sep 17 00:00:00 2001
From: Bret Curtis <psi29a@gmail.com>
Date: Sun, 21 Feb 2021 01:03:36 +0100
Subject: [PATCH 1/4] initial attempt at FindRecastNavigation.cmake

---
 CI/install_debian_deps.sh        |   1 +
 CMakeLists.txt                   |   4 +
 cmake/FindRecastNavigation.cmake | 143 +++++++++++++++++++++++++++++++
 components/CMakeLists.txt        |   5 +-
 4 files changed, 151 insertions(+), 2 deletions(-)
 create mode 100644 cmake/FindRecastNavigation.cmake

diff --git a/CI/install_debian_deps.sh b/CI/install_debian_deps.sh
index 82d2ff6819..3e7ab7fca3 100755
--- a/CI/install_debian_deps.sh
+++ b/CI/install_debian_deps.sh
@@ -23,6 +23,7 @@ declare -rA GROUPED_DEPS=(
     libsdl2-dev libqt5opengl5-dev libopenal-dev libunshield-dev libtinyxml-dev
     libbullet-dev liblz4-dev libpng-dev libjpeg-dev
   "
+  # TODO: add librecastnavigation-dev when debian is ready
 
   # These dependencies can alternatively be built and linked statically.
   [openmw-deps-dynamic]="libmygui-dev libopenscenegraph-dev"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdac00d1e5..405f4e8740 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -130,6 +130,10 @@ option(MYGUI_STATIC "Link static build of Mygui into the binaries" ${_mygui_stat
 option(OPENMW_USE_SYSTEM_RECASTNAVIGATION "Use system provided recastnavigation library" OFF)
 if(OPENMW_USE_SYSTEM_RECASTNAVIGATION)
     set(_recastnavigation_static_default OFF)
+
+    find_package(RecastNavigation REQUIRED)
+    include_directories(SYSTEM ${RecastNavigation_INCLUDE_DIRS})
+
 else()
     set(_recastnavigation_static_default ON)
 endif()
diff --git a/cmake/FindRecastNavigation.cmake b/cmake/FindRecastNavigation.cmake
new file mode 100644
index 0000000000..ae85faaaaa
--- /dev/null
+++ b/cmake/FindRecastNavigation.cmake
@@ -0,0 +1,143 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindRecastNavigation
+-------
+
+Find the RecastNavigation include directory and library.
+
+Use this module by invoking find_package with the form::
+
+.. code-block:: cmake
+
+  find_package(RecastNavigation
+    [version]              # Minimum version e.g. 1.8.0
+    [REQUIRED]             # Fail with error if RECASTNAV is not found
+  )
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+.. variable:: RecastNavigation::Recast
+
+  Imported target for using the RECASTNAV library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+.. variable:: RECASTNAV_FOUND
+
+  Set to true if RECASTNAV library found, otherwise false or undefined.
+
+.. variable:: RECASTNAV_INCLUDE_DIRS
+
+  Paths to include directories listed in one variable for use by RECASTNAV client.
+
+.. variable:: RECASTNAV_LIBRARIES
+
+  Paths to libraries to linked against to use RECASTNAV.
+
+.. variable:: RECAST_VERSION
+
+  The version string of RECASTNAV found.
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+For users who wish to edit and control the module behavior, this module
+reads hints about search locations from the following variables::
+
+.. variable:: RECASTNAV_INCLUDE_DIR
+
+  Path to RECASTNAV include directory with ``Recast.h`` header.
+
+.. variable:: RECASTNAV_LIBRARY
+
+  Path to RECASTNAV library to be linked.
+
+NOTE: The variables above should not usually be used in CMakeLists.txt files!
+
+#]=======================================================================]
+
+### Find library ##############################################################
+
+if(NOT RECASTNAV_LIBRARY)
+    find_library(RECASTNAV_LIBRARY_RELEASE NAMES Recast)
+    find_library(RECASTNAV_LIBRARY_DEBUG NAMES Recastd)
+
+# TODO: figure out a way to get Recast, Detour and DebugUtils libs together
+#    find_library(RECAST_LIBRARY_RELEASE NAMES Recast)
+#    find_library(RECAST_LIBRARY_DEBUG NAMES Recastd)
+
+#    find_library(DETOUR_LIBRARY_RELEASE NAMES Detour)
+#    find_library(DETOUR_LIBRARY_DEBUG NAMES Detourd)
+
+#    SET(RECASTNAV_LIBRARY_RELEASE ${RECAST_LIBRARY_RELEASE} ${DETOUR_LIBRARY_RELEASE})
+#    SET(RECASTNAV_LIBRARY_DEBUG ${RECAST_LIBRARY_DEBUG} ${DETOUR_LIBRARY_DEBUG})
+
+    include(SelectLibraryConfigurations)
+    select_library_configurations(RECASTNAV)
+else()
+    file(TO_CMAKE_PATH "${RECASTNAV_LIBRARY}" RECASTNAV_LIBRARY)
+endif()
+
+### Find include directory ####################################################
+find_path(RECASTNAV_INCLUDE_DIR NAMES Recast.h PATH_SUFFIXES include RECASTNAV include/recastnavigation)
+
+if(RECASTNAV_INCLUDE_DIR AND EXISTS "${RECASTNAV_INCLUDE_DIR}/Recast.h")
+    file(STRINGS "${RECASTNAV_INCLUDE_DIR}/Recast.h" _Recast_h_contents
+            REGEX "#define RECAST_VERSION_[A-Z]+[ ]+[0-9]+")
+    string(REGEX REPLACE "#define RECAST_VERSION_MAJOR[ ]+([0-9]+).+" "\\1"
+            RECAST_VERSION_MAJOR "${_Recast_h_contents}")
+    string(REGEX REPLACE ".+#define RECAST_VERSION_MINOR[ ]+([0-9]+).+" "\\1"
+            RECAST_VERSION_MINOR "${_Recast_h_contents}")
+    string(REGEX REPLACE ".+#define RECAST_VERSION_RELEASE[ ]+([0-9]+).*" "\\1"
+            RECAST_VERSION_RELEASE "${_Recast_h_contents}")
+    set(RECAST_VERSION "${RECAST_VERSION_MAJOR}.${RECAST_VERSION_MINOR}.${RECAST_VERSION_RELEASE}")
+    unset(_Recast_h_contents)
+endif()
+
+#TODO: they don't include a version yet
+set(RECAST_VERSION "1.5.1")
+
+### Set result variables ######################################################
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(RecastNavigation DEFAULT_MSG
+        RECASTNAV_LIBRARY RECASTNAV_INCLUDE_DIR RECAST_VERSION)
+
+mark_as_advanced(RECASTNAV_INCLUDE_DIR RECASTNAV_LIBRARY)
+
+set(RECASTNAV_LIBRARIES ${RECASTNAV_LIBRARY})
+set(RECASTNAV_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
+
+### Import targets ############################################################
+if(RECASTNAV_FOUND)
+    if(NOT TARGET RecastNavigation::Recast)
+        add_library(RecastNavigation::Recast UNKNOWN IMPORTED)
+        set_target_properties(RecastNavigation::Recast PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+                INTERFACE_INCLUDE_DIRECTORIES "${RECASTNAV_INCLUDE_DIR}")
+
+        if(RECASTNAV_LIBRARY_RELEASE)
+            set_property(TARGET RecastNavigation::Recast APPEND PROPERTY
+                    IMPORTED_CONFIGURATIONS RELEASE)
+            set_target_properties(RecastNavigation::Recast PROPERTIES
+                    IMPORTED_LOCATION_RELEASE "${RECASTNAV_LIBRARY_RELEASE}")
+        endif()
+
+        if(RECASTNAV_LIBRARY_DEBUG)
+            set_property(TARGET RecastNavigation::Recast APPEND PROPERTY
+                    IMPORTED_CONFIGURATIONS DEBUG)
+            set_target_properties(RecastNavigation::Recast PROPERTIES
+                    IMPORTED_LOCATION_DEBUG "${RECASTNAV_LIBRARY_DEBUG}")
+        endif()
+
+        if(NOT RECASTNAV_LIBRARY_RELEASE AND NOT RECASTNAV_LIBRARY_DEBUG)
+            set_property(TARGET RecastNavigation::Recast APPEND PROPERTY
+                    IMPORTED_LOCATION "${RECASTNAV_LIBRARY}")
+        endif()
+    endif()
+endif()
diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt
index 2120afc1a4..349f1cd79f 100644
--- a/components/CMakeLists.txt
+++ b/components/CMakeLists.txt
@@ -241,8 +241,9 @@ target_link_libraries(components
     ${OPENGL_gl_LIBRARY}
     ${MyGUI_LIBRARIES}
     LZ4::LZ4
-    RecastNavigation::DebugUtils
-    RecastNavigation::Detour
+# TODO: uncomment these when ready
+#    RecastNavigation::DebugUtils
+#    RecastNavigation::Detour
     RecastNavigation::Recast
     )
 

From ed74834e01aa68c75d36857833dbf0f177fa7556 Mon Sep 17 00:00:00 2001
From: Bret Curtis <psi29a@gmail.com>
Date: Sun, 21 Feb 2021 21:19:11 +0100
Subject: [PATCH 2/4] put back the recast stuff

---
 components/CMakeLists.txt | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt
index 349f1cd79f..2120afc1a4 100644
--- a/components/CMakeLists.txt
+++ b/components/CMakeLists.txt
@@ -241,9 +241,8 @@ target_link_libraries(components
     ${OPENGL_gl_LIBRARY}
     ${MyGUI_LIBRARIES}
     LZ4::LZ4
-# TODO: uncomment these when ready
-#    RecastNavigation::DebugUtils
-#    RecastNavigation::Detour
+    RecastNavigation::DebugUtils
+    RecastNavigation::Detour
     RecastNavigation::Recast
     )
 

From c4064fca0c7335b20f87579b5a848910fac51db0 Mon Sep 17 00:00:00 2001
From: Bret Curtis <psi29a@gmail.com>
Date: Tue, 2 Mar 2021 23:11:06 +0100
Subject: [PATCH 3/4] include feedback and add DebugUtils and Detour

---
 CMakeLists.txt                   |  3 -
 cmake/FindRecastNavigation.cmake | 95 +++++++++++++++++++++++++++-----
 2 files changed, 80 insertions(+), 18 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 405f4e8740..055f981aa6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -130,10 +130,7 @@ option(MYGUI_STATIC "Link static build of Mygui into the binaries" ${_mygui_stat
 option(OPENMW_USE_SYSTEM_RECASTNAVIGATION "Use system provided recastnavigation library" OFF)
 if(OPENMW_USE_SYSTEM_RECASTNAVIGATION)
     set(_recastnavigation_static_default OFF)
-
     find_package(RecastNavigation REQUIRED)
-    include_directories(SYSTEM ${RecastNavigation_INCLUDE_DIRS})
-
 else()
     set(_recastnavigation_static_default ON)
 endif()
diff --git a/cmake/FindRecastNavigation.cmake b/cmake/FindRecastNavigation.cmake
index ae85faaaaa..b0ce629a97 100644
--- a/cmake/FindRecastNavigation.cmake
+++ b/cmake/FindRecastNavigation.cmake
@@ -62,30 +62,38 @@ NOTE: The variables above should not usually be used in CMakeLists.txt files!
 
 #]=======================================================================]
 
-### Find library ##############################################################
+### Find libraries ##############################################################
 
 if(NOT RECASTNAV_LIBRARY)
     find_library(RECASTNAV_LIBRARY_RELEASE NAMES Recast)
     find_library(RECASTNAV_LIBRARY_DEBUG NAMES Recastd)
-
-# TODO: figure out a way to get Recast, Detour and DebugUtils libs together
-#    find_library(RECAST_LIBRARY_RELEASE NAMES Recast)
-#    find_library(RECAST_LIBRARY_DEBUG NAMES Recastd)
-
-#    find_library(DETOUR_LIBRARY_RELEASE NAMES Detour)
-#    find_library(DETOUR_LIBRARY_DEBUG NAMES Detourd)
-
-#    SET(RECASTNAV_LIBRARY_RELEASE ${RECAST_LIBRARY_RELEASE} ${DETOUR_LIBRARY_RELEASE})
-#    SET(RECASTNAV_LIBRARY_DEBUG ${RECAST_LIBRARY_DEBUG} ${DETOUR_LIBRARY_DEBUG})
-
     include(SelectLibraryConfigurations)
     select_library_configurations(RECASTNAV)
 else()
     file(TO_CMAKE_PATH "${RECASTNAV_LIBRARY}" RECASTNAV_LIBRARY)
 endif()
 
+if(NOT DETOUR_LIBRARY)
+    find_library(DETOUR_LIBRARY_RELEASE NAMES Detour)
+    find_library(DETOUR_LIBRARY_DEBUG NAMES Detourd)
+    include(SelectLibraryConfigurations)
+    select_library_configurations(DETOUR)
+else()
+    file(TO_CMAKE_PATH "${DETOUR_LIBRARY}" DETOUR_LIBRARY)
+endif()
+
+if(NOT DEBUGUTILS_LIBRARY)
+    find_library(DEBUGUTILS_LIBRARY_RELEASE NAMES DebugUtils)
+    find_library(DEBUGUTILS_LIBRARY_DEBUG NAMES DebugUtilsd)
+    include(SelectLibraryConfigurations)
+    select_library_configurations(DEBUGUTILS)
+else()
+    file(TO_CMAKE_PATH "${DEBUGUTILS_LIBRARY}" DEBUGUTILS_LIBRARY)
+endif()
+
 ### Find include directory ####################################################
 find_path(RECASTNAV_INCLUDE_DIR NAMES Recast.h PATH_SUFFIXES include RECASTNAV include/recastnavigation)
+mark_as_advanced(RECASTNAV_INCLUDE_DIR RECASTNAV_LIBRARY)
 
 if(RECASTNAV_INCLUDE_DIR AND EXISTS "${RECASTNAV_INCLUDE_DIR}/Recast.h")
     file(STRINGS "${RECASTNAV_INCLUDE_DIR}/Recast.h" _Recast_h_contents
@@ -108,13 +116,17 @@ include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(RecastNavigation DEFAULT_MSG
         RECASTNAV_LIBRARY RECASTNAV_INCLUDE_DIR RECAST_VERSION)
 
-mark_as_advanced(RECASTNAV_INCLUDE_DIR RECASTNAV_LIBRARY)
-
 set(RECASTNAV_LIBRARIES ${RECASTNAV_LIBRARY})
 set(RECASTNAV_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
 
+set(DETOUR_LIBRARIES ${DETOUR_LIBRARY})
+set(DETOUR_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
+
+set(DEBUGUTILS_LIBRARIES ${DEBUGUTILS_LIBRARY})
+set(DEBUGUTILS_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
+
 ### Import targets ############################################################
-if(RECASTNAV_FOUND)
+if(RecastNavigation_FOUND)
     if(NOT TARGET RecastNavigation::Recast)
         add_library(RecastNavigation::Recast UNKNOWN IMPORTED)
         set_target_properties(RecastNavigation::Recast PROPERTIES
@@ -140,4 +152,57 @@ if(RECASTNAV_FOUND)
                     IMPORTED_LOCATION "${RECASTNAV_LIBRARY}")
         endif()
     endif()
+
+    if(NOT TARGET RecastNavigation::Detour)
+        add_library(RecastNavigation::Detour UNKNOWN IMPORTED)
+        set_target_properties(RecastNavigation::Detour PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+                INTERFACE_INCLUDE_DIRECTORIES "${DETOUR_INCLUDE_DIR}")
+
+        if(RECASTNAV_LIBRARY_RELEASE)
+            set_property(TARGET RecastNavigation::Detour APPEND PROPERTY
+                    IMPORTED_CONFIGURATIONS RELEASE)
+            set_target_properties(RecastNavigation::Detour PROPERTIES
+                    IMPORTED_LOCATION_RELEASE "${DETOUR_LIBRARY_RELEASE}")
+        endif()
+
+        if(RECASTNAV_LIBRARY_DEBUG)
+            set_property(TARGET RecastNavigation::Detour APPEND PROPERTY
+                    IMPORTED_CONFIGURATIONS DEBUG)
+            set_target_properties(RecastNavigation::Detour PROPERTIES
+                    IMPORTED_LOCATION_DEBUG "${DETOUR_LIBRARY_DEBUG}")
+        endif()
+
+        if(NOT RECASTNAV_LIBRARY_RELEASE AND NOT RECASTNAV_LIBRARY_DEBUG)
+            set_property(TARGET RecastNavigation::Detour APPEND PROPERTY
+                    IMPORTED_LOCATION "${DETOUR_LIBRARY}")
+        endif()
+    endif()
+
+    if(NOT TARGET RecastNavigation::DebugUtils)
+        add_library(RecastNavigation::DebugUtils UNKNOWN IMPORTED)
+        set_target_properties(RecastNavigation::DebugUtils PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+                INTERFACE_INCLUDE_DIRECTORIES "${DEBUGUTILS_INCLUDE_DIR}")
+
+        if(RECASTNAV_LIBRARY_RELEASE)
+            set_property(TARGET RecastNavigation::DebugUtils APPEND PROPERTY
+                    IMPORTED_CONFIGURATIONS RELEASE)
+            set_target_properties(RecastNavigation::DebugUtils PROPERTIES
+                    IMPORTED_LOCATION_RELEASE "${DEBUGUTILS_LIBRARY_RELEASE}")
+        endif()
+
+        if(RECASTNAV_LIBRARY_DEBUG)
+            set_property(TARGET RecastNavigation::DebugUtils APPEND PROPERTY
+                    IMPORTED_CONFIGURATIONS DEBUG)
+            set_target_properties(RecastNavigation::DebugUtils PROPERTIES
+                    IMPORTED_LOCATION_DEBUG "${DEBUGUTILS_LIBRARY_DEBUG}")
+        endif()
+
+        if(NOT RECASTNAV_LIBRARY_RELEASE AND NOT RECASTNAV_LIBRARY_DEBUG)
+            set_property(TARGET RecastNavigation::DebugUtils APPEND PROPERTY
+                    IMPORTED_LOCATION "${DEBUGUTILS_LIBRARY}")
+        endif()
+    endif()
+
 endif()

From 2bc5a44e15162ee6557d441310080d36bc6e1787 Mon Sep 17 00:00:00 2001
From: Bret Curtis <psi29a@gmail.com>
Date: Wed, 3 Mar 2021 11:38:28 +0100
Subject: [PATCH 4/4] Added copyright, refactored to be more clear and marked
 certain things as advanced.

---
 cmake/FindRecastNavigation.cmake | 85 +++++++++++++++++---------------
 1 file changed, 44 insertions(+), 41 deletions(-)

diff --git a/cmake/FindRecastNavigation.cmake b/cmake/FindRecastNavigation.cmake
index b0ce629a97..ee6122e5d6 100644
--- a/cmake/FindRecastNavigation.cmake
+++ b/cmake/FindRecastNavigation.cmake
@@ -1,6 +1,6 @@
 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
 # file Copyright.txt or https://cmake.org/licensing for details.
-
+# Copyright 2021 Bret Curtis for OpenMW
 #[=======================================================================[.rst:
 FindRecastNavigation
 -------
@@ -13,7 +13,7 @@ Use this module by invoking find_package with the form::
 
   find_package(RecastNavigation
     [version]              # Minimum version e.g. 1.8.0
-    [REQUIRED]             # Fail with error if RECASTNAV is not found
+    [REQUIRED]             # Fail with error if RECAST is not found
   )
 
 Imported targets
@@ -23,26 +23,26 @@ This module defines the following :prop_tgt:`IMPORTED` targets:
 
 .. variable:: RecastNavigation::Recast
 
-  Imported target for using the RECASTNAV library, if found.
+  Imported target for using the RECAST library, if found.
 
 Result variables
 ^^^^^^^^^^^^^^^^
 
-.. variable:: RECASTNAV_FOUND
+.. variable:: RECAST_FOUND
 
-  Set to true if RECASTNAV library found, otherwise false or undefined.
+  Set to true if RECAST library found, otherwise false or undefined.
 
-.. variable:: RECASTNAV_INCLUDE_DIRS
+.. variable:: RECAST_INCLUDE_DIRS
 
-  Paths to include directories listed in one variable for use by RECASTNAV client.
+  Paths to include directories listed in one variable for use by RECAST client.
 
-.. variable:: RECASTNAV_LIBRARIES
+.. variable:: RECAST_LIBRARIES
 
-  Paths to libraries to linked against to use RECASTNAV.
+  Paths to libraries to linked against to use RECAST.
 
 .. variable:: RECAST_VERSION
 
-  The version string of RECASTNAV found.
+  The version string of RECAST found.
 
 Cache variables
 ^^^^^^^^^^^^^^^
@@ -50,13 +50,13 @@ Cache variables
 For users who wish to edit and control the module behavior, this module
 reads hints about search locations from the following variables::
 
-.. variable:: RECASTNAV_INCLUDE_DIR
+.. variable:: RECAST_INCLUDE_DIR
 
-  Path to RECASTNAV include directory with ``Recast.h`` header.
+  Path to RECAST include directory with ``Recast.h`` header.
 
-.. variable:: RECASTNAV_LIBRARY
+.. variable:: RECAST_LIBRARY
 
-  Path to RECASTNAV library to be linked.
+  Path to RECAST library to be linked.
 
 NOTE: The variables above should not usually be used in CMakeLists.txt files!
 
@@ -64,13 +64,14 @@ NOTE: The variables above should not usually be used in CMakeLists.txt files!
 
 ### Find libraries ##############################################################
 
-if(NOT RECASTNAV_LIBRARY)
-    find_library(RECASTNAV_LIBRARY_RELEASE NAMES Recast)
-    find_library(RECASTNAV_LIBRARY_DEBUG NAMES Recastd)
+if(NOT RECAST_LIBRARY)
+    find_library(RECAST_LIBRARY_RELEASE NAMES Recast)
+    find_library(RECAST_LIBRARY_DEBUG NAMES Recastd)
     include(SelectLibraryConfigurations)
-    select_library_configurations(RECASTNAV)
+    select_library_configurations(RECAST)
+    mark_as_advanced(RECAST_LIBRARY_RELEASE RECAST_LIBRARY_DEBUG)
 else()
-    file(TO_CMAKE_PATH "${RECASTNAV_LIBRARY}" RECASTNAV_LIBRARY)
+    file(TO_CMAKE_PATH "${RECAST_LIBRARY}" RECAST_LIBRARY)
 endif()
 
 if(NOT DETOUR_LIBRARY)
@@ -78,6 +79,7 @@ if(NOT DETOUR_LIBRARY)
     find_library(DETOUR_LIBRARY_DEBUG NAMES Detourd)
     include(SelectLibraryConfigurations)
     select_library_configurations(DETOUR)
+    mark_as_advanced(DETOUR_LIBRARY_RELEASE DETOUR_LIBRARY_DEBUG)
 else()
     file(TO_CMAKE_PATH "${DETOUR_LIBRARY}" DETOUR_LIBRARY)
 endif()
@@ -87,16 +89,17 @@ if(NOT DEBUGUTILS_LIBRARY)
     find_library(DEBUGUTILS_LIBRARY_DEBUG NAMES DebugUtilsd)
     include(SelectLibraryConfigurations)
     select_library_configurations(DEBUGUTILS)
+    mark_as_advanced(DEBUGUTILS_LIBRARY_RELEASE DEBUGUTILS_LIBRARY_DEBUG)
 else()
     file(TO_CMAKE_PATH "${DEBUGUTILS_LIBRARY}" DEBUGUTILS_LIBRARY)
 endif()
 
 ### Find include directory ####################################################
-find_path(RECASTNAV_INCLUDE_DIR NAMES Recast.h PATH_SUFFIXES include RECASTNAV include/recastnavigation)
-mark_as_advanced(RECASTNAV_INCLUDE_DIR RECASTNAV_LIBRARY)
+find_path(RECAST_INCLUDE_DIR NAMES Recast.h PATH_SUFFIXES include RECAST include/recastnavigation)
+mark_as_advanced(RECAST_INCLUDE_DIR)
 
-if(RECASTNAV_INCLUDE_DIR AND EXISTS "${RECASTNAV_INCLUDE_DIR}/Recast.h")
-    file(STRINGS "${RECASTNAV_INCLUDE_DIR}/Recast.h" _Recast_h_contents
+if(RECAST_INCLUDE_DIR AND EXISTS "${RECAST_INCLUDE_DIR}/Recast.h")
+    file(STRINGS "${RECAST_INCLUDE_DIR}/Recast.h" _Recast_h_contents
             REGEX "#define RECAST_VERSION_[A-Z]+[ ]+[0-9]+")
     string(REGEX REPLACE "#define RECAST_VERSION_MAJOR[ ]+([0-9]+).+" "\\1"
             RECAST_VERSION_MAJOR "${_Recast_h_contents}")
@@ -114,16 +117,16 @@ set(RECAST_VERSION "1.5.1")
 ### Set result variables ######################################################
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(RecastNavigation DEFAULT_MSG
-        RECASTNAV_LIBRARY RECASTNAV_INCLUDE_DIR RECAST_VERSION)
+        RECAST_LIBRARY RECAST_INCLUDE_DIR RECAST_VERSION)
 
-set(RECASTNAV_LIBRARIES ${RECASTNAV_LIBRARY})
-set(RECASTNAV_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
+set(RECAST_LIBRARIES ${RECAST_LIBRARY})
+set(RECAST_INCLUDE_DIRS ${RECAST_INCLUDE_DIR})
 
 set(DETOUR_LIBRARIES ${DETOUR_LIBRARY})
-set(DETOUR_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
+set(DETOUR_INCLUDE_DIRS ${RECAST_INCLUDE_DIR})
 
 set(DEBUGUTILS_LIBRARIES ${DEBUGUTILS_LIBRARY})
-set(DEBUGUTILS_INCLUDE_DIRS ${RECASTNAV_INCLUDE_DIR})
+set(DEBUGUTILS_INCLUDE_DIRS ${RECAST_INCLUDE_DIR})
 
 ### Import targets ############################################################
 if(RecastNavigation_FOUND)
@@ -131,25 +134,25 @@ if(RecastNavigation_FOUND)
         add_library(RecastNavigation::Recast UNKNOWN IMPORTED)
         set_target_properties(RecastNavigation::Recast PROPERTIES
                 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
-                INTERFACE_INCLUDE_DIRECTORIES "${RECASTNAV_INCLUDE_DIR}")
+                INTERFACE_INCLUDE_DIRECTORIES "${RECAST_INCLUDE_DIR}")
 
-        if(RECASTNAV_LIBRARY_RELEASE)
+        if(RECAST_LIBRARY_RELEASE)
             set_property(TARGET RecastNavigation::Recast APPEND PROPERTY
                     IMPORTED_CONFIGURATIONS RELEASE)
             set_target_properties(RecastNavigation::Recast PROPERTIES
-                    IMPORTED_LOCATION_RELEASE "${RECASTNAV_LIBRARY_RELEASE}")
+                    IMPORTED_LOCATION_RELEASE "${RECAST_LIBRARY_RELEASE}")
         endif()
 
-        if(RECASTNAV_LIBRARY_DEBUG)
+        if(RECAST_LIBRARY_DEBUG)
             set_property(TARGET RecastNavigation::Recast APPEND PROPERTY
                     IMPORTED_CONFIGURATIONS DEBUG)
             set_target_properties(RecastNavigation::Recast PROPERTIES
-                    IMPORTED_LOCATION_DEBUG "${RECASTNAV_LIBRARY_DEBUG}")
+                    IMPORTED_LOCATION_DEBUG "${RECAST_LIBRARY_DEBUG}")
         endif()
 
-        if(NOT RECASTNAV_LIBRARY_RELEASE AND NOT RECASTNAV_LIBRARY_DEBUG)
+        if(NOT RECAST_LIBRARY_RELEASE AND NOT RECAST_LIBRARY_DEBUG)
             set_property(TARGET RecastNavigation::Recast APPEND PROPERTY
-                    IMPORTED_LOCATION "${RECASTNAV_LIBRARY}")
+                    IMPORTED_LOCATION "${RECAST_LIBRARY}")
         endif()
     endif()
 
@@ -159,21 +162,21 @@ if(RecastNavigation_FOUND)
                 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
                 INTERFACE_INCLUDE_DIRECTORIES "${DETOUR_INCLUDE_DIR}")
 
-        if(RECASTNAV_LIBRARY_RELEASE)
+        if(RECAST_LIBRARY_RELEASE)
             set_property(TARGET RecastNavigation::Detour APPEND PROPERTY
                     IMPORTED_CONFIGURATIONS RELEASE)
             set_target_properties(RecastNavigation::Detour PROPERTIES
                     IMPORTED_LOCATION_RELEASE "${DETOUR_LIBRARY_RELEASE}")
         endif()
 
-        if(RECASTNAV_LIBRARY_DEBUG)
+        if(RECAST_LIBRARY_DEBUG)
             set_property(TARGET RecastNavigation::Detour APPEND PROPERTY
                     IMPORTED_CONFIGURATIONS DEBUG)
             set_target_properties(RecastNavigation::Detour PROPERTIES
                     IMPORTED_LOCATION_DEBUG "${DETOUR_LIBRARY_DEBUG}")
         endif()
 
-        if(NOT RECASTNAV_LIBRARY_RELEASE AND NOT RECASTNAV_LIBRARY_DEBUG)
+        if(NOT RECAST_LIBRARY_RELEASE AND NOT RECAST_LIBRARY_DEBUG)
             set_property(TARGET RecastNavigation::Detour APPEND PROPERTY
                     IMPORTED_LOCATION "${DETOUR_LIBRARY}")
         endif()
@@ -185,21 +188,21 @@ if(RecastNavigation_FOUND)
                 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
                 INTERFACE_INCLUDE_DIRECTORIES "${DEBUGUTILS_INCLUDE_DIR}")
 
-        if(RECASTNAV_LIBRARY_RELEASE)
+        if(RECAST_LIBRARY_RELEASE)
             set_property(TARGET RecastNavigation::DebugUtils APPEND PROPERTY
                     IMPORTED_CONFIGURATIONS RELEASE)
             set_target_properties(RecastNavigation::DebugUtils PROPERTIES
                     IMPORTED_LOCATION_RELEASE "${DEBUGUTILS_LIBRARY_RELEASE}")
         endif()
 
-        if(RECASTNAV_LIBRARY_DEBUG)
+        if(RECAST_LIBRARY_DEBUG)
             set_property(TARGET RecastNavigation::DebugUtils APPEND PROPERTY
                     IMPORTED_CONFIGURATIONS DEBUG)
             set_target_properties(RecastNavigation::DebugUtils PROPERTIES
                     IMPORTED_LOCATION_DEBUG "${DEBUGUTILS_LIBRARY_DEBUG}")
         endif()
 
-        if(NOT RECASTNAV_LIBRARY_RELEASE AND NOT RECASTNAV_LIBRARY_DEBUG)
+        if(NOT RECAST_LIBRARY_RELEASE AND NOT RECAST_LIBRARY_DEBUG)
             set_property(TARGET RecastNavigation::DebugUtils APPEND PROPERTY
                     IMPORTED_LOCATION "${DEBUGUTILS_LIBRARY}")
         endif()