cmake REFACTOR update findpcre2 module
diff --git a/CMakeModules/FindPCRE2.cmake b/CMakeModules/FindPCRE2.cmake
index 8f60daa..65d6dc6 100644
--- a/CMakeModules/FindPCRE2.cmake
+++ b/CMakeModules/FindPCRE2.cmake
@@ -4,27 +4,49 @@
 # PCRE2_INCLUDE_DIRS    - where to find pcre.h, etc.
 # PCRE2_LIBRARIES   - List of libraries when using pcre.
 # PCRE2_FOUND   - True if pcre found.
+include(FindPackageHandleStandardArgs)
 
-# Look for the header file.
-FIND_PATH(PCRE2_INCLUDE_DIR pcre2.h)
+if(PCRE2_LIBRARIES AND PCRE2_INCLUDE_DIRS)
+    # in cache already
+    set(PCRE2_FOUND TRUE)
+else()
+    find_path(PCRE2_INCLUDE_DIR
+        NAMES
+        pcre2.h
+        PATHS
+        /usr/include
+        /usr/local/include
+        /opt/local/include
+        /sw/include
+        ${CMAKE_INCLUDE_PATH}
+        ${CMAKE_INSTALL_PREFIX}/include)
 
-# Look for the library.
-FIND_LIBRARY(PCRE2_LIBRARY NAMES libpcre2.a pcre2-8)
+    # Look for the library.
+    find_library(PCRE2_LIBRARY
+        NAMES
+        libpcre2.a
+        pcre2-8
+        PATHS
+        /usr/lib
+        /usr/lib64
+        /usr/local/lib
+        /usr/local/lib64
+        /opt/local/lib
+        /sw/lib
+        ${CMAKE_LIBRARY_PATH}
+        ${CMAKE_INSTALL_PREFIX}/lib)
 
-# Check required version
-execute_process(COMMAND pcre2-config --version OUTPUT_VARIABLE PCRE2_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(PCRE2_LIBRARY)
+        # Check required version
+        execute_process(COMMAND pcre2-config --version OUTPUT_VARIABLE PCRE2_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+    endif()
 
-# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR VERSION_VAR PCRE2_VERSION)
+    set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
+    set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
+    mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
 
-# Copy the results to the output variables.
-IF(PCRE2_FOUND)
-    SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
-    SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
-ELSE(PCRE2_FOUND)
-    SET(PCRE_LIBRARIES)
-    SET(PCRE_INCLUDE_DIRS)
-ENDIF(PCRE2_FOUND)
-
-MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
\ No newline at end of file
+    # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
+    find_package_handle_standard_args(PCRE2 FOUND_VAR PCRE2_FOUND
+        REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR
+        VERSION_VAR PCRE2_VERSION)
+endif()