[cmake-developers] find_program() not using PATH on Windows?

Robert Dailey rcdailey.lists at gmail.com
Thu Apr 6 16:43:49 EDT 2017


Even worse, they seem to acknowledge this problem and created "proxy"
macros for the use by the host OS (code at the bottom)

Is it just me or is this really nasty?


# macro to find packages on the host OS
macro( find_host_package )
 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
 if( CMAKE_HOST_WIN32 )
  SET( WIN32 1 )
  SET( UNIX )
 elseif( CMAKE_HOST_APPLE )
  SET( APPLE 1 )
  SET( UNIX )
 endif()
 find_package( ${ARGN} )
 SET( WIN32 )
 SET( APPLE )
 SET( UNIX 1 )
 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endmacro()


# macro to find programs on the host OS
macro( find_host_program )
 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
 if( CMAKE_HOST_WIN32 )
  SET( WIN32 1 )
  SET( UNIX )
 elseif( CMAKE_HOST_APPLE )
  SET( APPLE 1 )
  SET( UNIX )
 endif()
 find_program( ${ARGN} )
 SET( WIN32 )
 SET( APPLE )
 SET( UNIX 1 )
 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endmacro()

On Thu, Apr 6, 2017 at 3:41 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> Unsetting these at the bottom of the toolchain file fixes it:
>
> unset( CMAKE_FIND_ROOT_PATH )
> unset( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM )
> unset( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY )
> unset( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE )
>
> However I'm not sure if this is the right solution. They do for some
> reason specify PROGRAM to ONLY. Should these values propagate outside
> of the toolchain file?
>
> On Thu, Apr 6, 2017 at 3:38 PM, Brad King <brad.king at kitware.com> wrote:
>> On 04/06/2017 04:32 PM, Robert Dailey wrote:
>>> directories coming from PATH can be "rerooted" like this, it makes
>>> things very confusing... maybe there is a reason for it, but I'd never
>>> want this personally, and I find it concerning that a toolchain file
>>> can break this for the whole project.
>>
>> The toolchain file is using CMAKE_FIND_ROOT_PATH to prevent find
>> commands from searching outside of those directories.  That is
>> why everything is rerooted.
>>
>> Often one doesn't want this for programs, so the toolchain file
>> should set CMAKE_FIND_ROOT_PATH_MODE_PROGRAM to NEVER or BOTH.
>> If it has some reason for not doing that then one can always use
>> NO_CMAKE_FIND_ROOT_PATH in the individual find_program call.
>>
>> -Brad
>>


More information about the cmake-developers mailing list