Find perl using the CMake's standard FindPerl module.

This gives a standard PERL_EXECUTABLE configuration knob which is useful for
specifying a perl to use without having it in PATH.

Change-Id: I4b196b77e0b4666081a3f291fee3654c47925844
Reviewed-on: https://boringssl-review.googlesource.com/3570
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/BUILDING b/BUILDING
index 8b7d36d..67f8a33 100644
--- a/BUILDING
+++ b/BUILDING
@@ -3,7 +3,8 @@
   * CMake[1] 2.8.8 or later is required.
 
   * Perl 5.6.1 or later is required. On Windows, Strawberry Perl and MSYS Perl
-    have both been reported to work.
+    have both been reported to work. If not found by CMake, it may be configured
+    explicitly by setting PERL_EXECUTABLE.
 
   * On Windows you currently must use Ninja[2] to build; on other platforms,
     it is not required, but recommended, because it makes builds faster.
@@ -11,7 +12,8 @@
   * If you need to build Ninja from source, then a recent version of
     Python[3] is required (Python 2.7.5 works).
 
-  * On Windows only, Yasm[4] is required.
+  * On Windows only, Yasm[4] is required. If not found by CMake, it may be
+    configured explicitly by setting CMAKE_ASM_NASM_COMPILER.
 
   * A C compiler is required. On Windows, MSVC 12 (Visual Studio 2013) or later
     with Platform SDK 8.1 or later are supported. Recent versions of GCC and
@@ -70,7 +72,4 @@
 
 [4] http://yasm.tortall.net/
 
-    Either ensure yasm.exe is in %PATH% or configure CMAKE_ASM_NASM_COMPILER
-    appropriately.
-
 [5] https://golang.org/dl/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c0bdc73..0a74166 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,8 @@
 
 project (BoringSSL)
 
+find_package(Perl REQUIRED)
+
 if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -ggdb -fvisibility=hidden")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ggdb -std=c++0x -fvisibility=hidden")
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt
index 972d57d..bbd4f20 100644
--- a/crypto/CMakeLists.txt
+++ b/crypto/CMakeLists.txt
@@ -37,7 +37,7 @@
 function(perlasm dest src)
   add_custom_command(
     OUTPUT ${dest}
-    COMMAND perl ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
+    COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
     DEPENDS
     ${src}
     ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl