Skip to content

FindPerl.cmake from git bash finds an incompatible perl

On Windows, there is typically no Perl distribution installed. One can install Cygwin Perl, Strawberry Perl, ActiveState Perl and probably others. Consider the following CMakeLists.txt file:

cmake_minimum_required(VERSION 3.12)
project(FindPerlTest LANGUAGES)
find_package(Perl REQUIRED)
message(STATUS "PERL_FOUND: ${PERL_FOUND}")
message(STATUS "PERL_EXECUTABLE: ${PERL_EXECUTABLE}")
message(STATUS "PERL_VERSION_STRING: ${PERL_VERSION_STRING}")

When executed from CMD or PowerShell, it properly locates Strawberry Perl (if using CMake 3.12 or newer). When executed from git-bash however, it finds an incompatible version at C:/Program Files/Git/usr/bin/perl.exe. This version is rather limited and lacks modules such as Pod::Usage. (The current Windows preview of Travis CI executes all commands from git bash, so this can potentially have increasingly more impact.)

As a project, we have some potential workarounds:

  • Set CMAKE_PROGRAM_PATH to C:/Strawberry/perl/bin.
  • Copy FindPerl.cmake and change PATHS to HINTS in find_path(PERL_EXECUTABLE NAMES perl PATHS ...) such that some educated guesses can yield a result before $ENV{PATH}.

However I believe that changing the search behavior could be beneficial for other consumers of Perl on Windows. What do you think about one of these:

  • Search for pod2man first and use its directory as hint for finding perl. Scratch this, git also includes this.
  • Change PATHS to HINTS.
  • (something else to the effect of ignoring git-bash Perl)
Edited by Peter Wu
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information