[cmake-developers] Proposed change to behavior of find_program

Thompson, KT kgt at lanl.gov
Fri Dec 19 18:25:34 EST 2014


Hmm.  It looks my original proposal breaks some backward compatibility.  Maybe this patch is better:

--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -1148,13 +1148,13 @@ bool SystemTools::FileExists(const kwsys_stl::string& filename)
     {
     return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES);
     }
-  return access(filename.c_str(), R_OK) == 0;
+  return access(filename.c_str(), R_OK) == 0 || access(filename.c_str(), X_OK) == 0;
#elif defined(_WIN32)
   return (GetFileAttributesW(
             SystemTools::ConvertToWindowsExtendedPath(filename).c_str())
           != INVALID_FILE_ATTRIBUTES);
#else
-  return access(filename.c_str(), R_OK) == 0;
+  return access(filename.c_str(), R_OK) == 0 || access(filename.c_str(), X_OK) == 0;
#endif
}


From: cmake-developers [mailto:cmake-developers-bounces at cmake.org] On Behalf Of Thompson, KT
Sent: Friday, December 19, 2014 3:46 PM
To: cmake-developers at cmake.org
Subject: [cmake-developers] Proposed change to behavior of find_program

CMake developers,

I am proposing a small change to SystemTools.cxx to address a problem I have on multiple systems.  I need find_program to return the path to an executable file that is not marked with the read permission bit, but is marked with the execute bit (e.g.: chmod 111 file).

On Linux systems, find_program unnecessarily requires that a file be readable.  I propose that the FileExists function be changed to test for execute permission instead of read permission:

--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -1148,13 +1148,13 @@ bool SystemTools::FileExists(const kwsys_stl::string& filename)
     {
     return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES);
     }
-  return access(filename.c_str(), R_OK) == 0;
+  return access(filename.c_str(), X_OK) == 0;
#elif defined(_WIN32)
   return (GetFileAttributesW(
             SystemTools::ConvertToWindowsExtendedPath(filename).c_str())
           != INVALID_FILE_ATTRIBUTES);
#else
-  return access(filename.c_str(), R_OK) == 0;
+  return access(filename.c_str(), X_OK) == 0;
#endif
}

Comments? Thoughts?

-kt
Kelly (KT) Thompson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141219/911c793e/attachment.html>


More information about the cmake-developers mailing list