find_program usage

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

find_program usage

vinay kumar Kotegowder
Hi Everyone,

This is simple code running on Windows machine:

if(WIN32)
  message(STATUS "On windows")
  find_program(_TOOL
              arm-none-eabi-gcc.exe
              PATHS "C:"
            )
endif()

message(STATUS "${_TOOL}")

Result after executing: cmake -P mycmake.cmake

-- On windows
-- _TOOL-NOTFOUND

Can anyone tell me what is wrong with the usage of "find_program"  ?

Vinay
Senior Engineer
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: find_program usage

CMake mailing list
On Tue, 2019-06-04 at 19:07 +0530, vinay kumar Kotegowder wrote:

> Hi Everyone,
>
> This is simple code running on Windows machine:
>
> if(WIN32)
>   message(STATUS "On windows")
>   find_program(_TOOL
>               arm-none-eabi-gcc.exe
>               PATHS "C:"
>             )
> endif()
>
> message(STATUS "${_TOOL}")
>
> Result after executing: cmake -P mycmake.cmake
>
> -- On windows
> -- _TOOL-NOTFOUND
>
> Can anyone tell me what is wrong with the usage of "find_program"  ?

find_program() is looking in C:, but not its subdirectories. So, unless
arm-none-eabi-gcc.exe is located directly in C:, CMake won't find it.

As a side note, GCC isn't typically found with find_program(). You most
likely want to write a cross-compiling toolchain file which contains
this location instead. See below for details:

https://cmake.org/cmake/help/v3.14/manual/cmake-toolchains.7.html

Kyle
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: find_program usage

vinay kumar Kotegowder
The original intent of the snippet is to find the required tool chain
(On windows : arm-none-eabi-gcc.exe or armclang.exe; On Linix :
arm-none-eabi-gcc or armclang) path which can later be used to build
the project.

I have been trying with find_program and find_path commands.
My understanding was that it would find the program from root(which is
C: in Windows and / in Linux) and all the sub directories underneath
it but I learnt from your reply that it is not the case.

Can this be done? I mean, should it be possible to find the program
without hard coding the path ?

- Vinay

On Tue, Jun 4, 2019 at 7:12 PM Kyle Edwards <[hidden email]> wrote:

>
> On Tue, 2019-06-04 at 19:07 +0530, vinay kumar Kotegowder wrote:
> > Hi Everyone,
> >
> > This is simple code running on Windows machine:
> >
> > if(WIN32)
> >   message(STATUS "On windows")
> >   find_program(_TOOL
> >               arm-none-eabi-gcc.exe
> >               PATHS "C:"
> >             )
> > endif()
> >
> > message(STATUS "${_TOOL}")
> >
> > Result after executing: cmake -P mycmake.cmake
> >
> > -- On windows
> > -- _TOOL-NOTFOUND
> >
> > Can anyone tell me what is wrong with the usage of "find_program"  ?
>
> find_program() is looking in C:, but not its subdirectories. So, unless
> arm-none-eabi-gcc.exe is located directly in C:, CMake won't find it.
>
> As a side note, GCC isn't typically found with find_program(). You most
> likely want to write a cross-compiling toolchain file which contains
> this location instead. See below for details:
>
> https://cmake.org/cmake/help/v3.14/manual/cmake-toolchains.7.html
>
> Kyle
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: find_program usage

CMake mailing list
On Tue, 2019-06-04 at 19:38 +0530, vinay kumar Kotegowder wrote:

> The original intent of the snippet is to find the required tool chain
> (On windows : arm-none-eabi-gcc.exe or armclang.exe; On Linix :
> arm-none-eabi-gcc or armclang) path which can later be used to build
> the project.
>
> I have been trying with find_program and find_path commands.
> My understanding was that it would find the program from root(which
> is
> C: in Windows and / in Linux) and all the sub directories underneath
> it but I learnt from your reply that it is not the case.
>
> Can this be done? I mean, should it be possible to find the program
> without hard coding the path ?

It is possible to pass hints and paths to find_program() telling it
additional places to look ("it *might* be in C:/MinGW/whatever/bin"),
but other than that, find_program() does not search recursively. See
the find_program() documentation for more details:

https://cmake.org/cmake/help/v3.14/command/find_program.html

Again, for GCC, I strongly recommend that you use a toolchain file,
rather than setting CMAKE_C_COMPILER from inside your project. CMake
does a bunch of checks with the compiler when you first call project(),
which end up no longer being valid if you change CMAKE_C_COMPILER. (I
suppose you could set CMAKE_C_COMPILER from in your project before
calling project(), but I do not recommend this method.) You *can* call
find_program() from inside your toolchain file if you don't want to
hard-code the paths.

Kyle
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake