Checking Variables in a tool-chain file

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

Checking Variables in a tool-chain file

Torsten Robitzki
Hi,
I have a tool-chain file, which requires a variable to be set to the path to the compiler on the local machine:

  set(CMAKE_C_COMPILER ${ARM_GCC_TOOL_PATH}/bin/arm-none-eabi-gcc)
  set(CMAKE_CXX_COMPILER ${ARM_GCC_TOOL_PATH}/bin/arm-none-eabi-g++)

Now I want to give the user an error message, in case that this variable is not set. The „usual“ check for the existence of the variable doesn’t work, because the tool-chain file is included in different context, without access to the cache.

Any idea?

regards,
Torsten


--

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

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Checking Variables in a tool-chain file

Sergei Nikulov
чт, 31 янв. 2019 г. в 10:29, Torsten Robitzki <[hidden email]>:

>
> Hi,
> I have a tool-chain file, which requires a variable to be set to the path to the compiler on the local machine:
>
>   set(CMAKE_C_COMPILER ${ARM_GCC_TOOL_PATH}/bin/arm-none-eabi-gcc)
>   set(CMAKE_CXX_COMPILER ${ARM_GCC_TOOL_PATH}/bin/arm-none-eabi-g++)
>
> Now I want to give the user an error message, in case that this variable is not set. The „usual“ check for the existence of the variable doesn’t work, because the tool-chain file is included in different context, without access to the cache.
>
> Any idea?

Just guessing maybe better use $ENV{ARM_GCC_TOOL_PATH} ?
https://cmake.org/cmake/help/latest/variable/ENV.html?highlight=env


--
Best Regards,
Sergei Nikulov
--

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: Checking Variables in a tool-chain file

Torsten Robitzki
Hi Sergei,

> Am 31.01.2019 um 08:42 schrieb Sergei Nikulov <[hidden email]>:
>
> Just guessing maybe better use $ENV{ARM_GCC_TOOL_PATH} ?
> https://cmake.org/cmake/help/latest/variable/ENV.html?highlight=env

Well, but this would mean, I had to configure CMake not only with Cache variables:

cmake -DARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..

But also with environment variables:
ARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update cmake -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..

Thanks for the pointer, I will think about it.

kind regards,
Torsten

--

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

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Checking Variables in a tool-chain file

Shoaib Meenai
We have a somewhat similar problem with LLVM's toolchain file for cross-compiling to Windows, and we solve it there by saving and restoring cache variables from the environment inside the toolchain file itself. See https://reviews.llvm.org/diffusion/L/browse/llvm/trunk/cmake/platforms/WinMsvc.cmake;352783$88-102?as=source&blame=off and the subsequent calls to init_user_prop.

On 1/31/19, 12:19 AM, "CMake on behalf of [hidden email]" <[hidden email] on behalf of [hidden email]> wrote:

    Hi Sergei,
   
    > Am 31.01.2019 um 08:42 schrieb Sergei Nikulov <[hidden email]>:
    >
    > Just guessing maybe better use $ENV{ARM_GCC_TOOL_PATH} ?
    > https://cmake.org/cmake/help/latest/variable/ENV.html?highlight=env
   
    Well, but this would mean, I had to configure CMake not only with Cache variables:
   
    cmake -DARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..
   
    But also with environment variables:
    ARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update cmake -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..
   
    Thanks for the pointer, I will think about it.
   
    kind regards,
    Torsten
   

--

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: Checking Variables in a tool-chain file

Craig Scott-3
This is precisely the scenario that the CMAKE_TRY_COMPILE_PLATFORM_VARIABLES variable is meant for. It allows a toolchain file to specify additional variables that should be passed along to try_compile().


On Fri, Feb 1, 2019 at 6:36 AM Shoaib Meenai <[hidden email]> wrote:
We have a somewhat similar problem with LLVM's toolchain file for cross-compiling to Windows, and we solve it there by saving and restoring cache variables from the environment inside the toolchain file itself. See https://reviews.llvm.org/diffusion/L/browse/llvm/trunk/cmake/platforms/WinMsvc.cmake;352783$88-102?as=source&blame=off and the subsequent calls to init_user_prop.

On 1/31/19, 12:19 AM, "CMake on behalf of [hidden email]" <[hidden email] on behalf of [hidden email]> wrote:

    Hi Sergei,

    > Am 31.01.2019 um 08:42 schrieb Sergei Nikulov <[hidden email]>:
    >
    > Just guessing maybe better use $ENV{ARM_GCC_TOOL_PATH} ?
    > https://cmake.org/cmake/help/latest/variable/ENV.html?highlight=env

    Well, but this would mean, I had to configure CMake not only with Cache variables:

    cmake -DARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..

    But also with environment variables:
    ARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update cmake -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..

    Thanks for the pointer, I will think about it.

    kind regards,
    Torsten
 
--
Craig Scott
Melbourne, Australia

Get the hand-book for every CMake user: Professional CMake: A Practical Guide

--

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: Checking Variables in a tool-chain file

Shoaib Meenai

That’s perfect! It looks like it was introduced in CMake 3.6, whereas LLVM targets a minimum of 3.4.3 right now, but I’ll make a note of it for the next CMake upgrade. Thanks!

 

From: CMake <[hidden email]> on behalf of Craig Scott <[hidden email]>
Date: Thursday, January 31, 2019 at 12:10 PM
To: "[hidden email]" <[hidden email]>
Cc: CMake MailingList <[hidden email]>
Subject: Re: [CMake] Checking Variables in a tool-chain file

 

This is precisely the scenario that the CMAKE_TRY_COMPILE_PLATFORM_VARIABLES variable is meant for. It allows a toolchain file to specify additional variables that should be passed along to try_compile().

 

 

On Fri, Feb 1, 2019 at 6:36 AM Shoaib Meenai <[hidden email]> wrote:

We have a somewhat similar problem with LLVM's toolchain file for cross-compiling to Windows, and we solve it there by saving and restoring cache variables from the environment inside the toolchain file itself. See https://reviews.llvm.org/diffusion/L/browse/llvm/trunk/cmake/platforms/WinMsvc.cmake;352783$88-102?as=source&blame=off and the subsequent calls to init_user_prop.

On 1/31/19, 12:19 AM, "CMake on behalf of [hidden email]" <[hidden email] on behalf of [hidden email]> wrote:

    Hi Sergei,

    > Am 31.01.2019 um 08:42 schrieb Sergei Nikulov <[hidden email]>:
    >
    > Just guessing maybe better use $ENV{ARM_GCC_TOOL_PATH} ?
    > https://cmake.org/cmake/help/latest/variable/ENV.html?highlight=env

    Well, but this would mean, I had to configure CMake not only with Cache variables:

    cmake -DARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..

    But also with environment variables:
    ARM_GCC_TOOL_PATH=/usr/local/gcc-arm-none-eabi-7-2018-q2-update cmake -DBINDING=nrf52 -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi.cmake -DNRF5_SDK_ROOT=~/CMSIS/nRF5_SDK_14-2/ ..

    Thanks for the pointer, I will think about it.

    kind regards,
    Torsten

 

--

Craig Scott

Melbourne, Australia

 

Get the hand-book for every CMake user: Professional CMake: A Practical Guide


--

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: Checking Variables in a tool-chain file

Torsten Robitzki
In reply to this post by Craig Scott-3

> Am 31.01.2019 um 21:10 schrieb Craig Scott <[hidden email]>:
>
> This is precisely the scenario that the CMAKE_TRY_COMPILE_PLATFORM_VARIABLES variable is meant for. It allows a toolchain file to specify additional variables that should be passed along to try_compile().

Works like a charm. Thanks a lot!

Torsten


--

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

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Checking Variables in a tool-chain file

frodak17
Be aware that CMAKE_TRY_COMPILE_PLATFORM_VARIABLES only works with the try_compile() command source file signature. Unfortunately it doesn't work with try_compile() whole projects signature.  The section on Other Behavior Settings mostly only applies to the source file signature.

On Fri, Feb 1, 2019 at 2:02 AM <[hidden email]> wrote:

> Am 31.01.2019 um 21:10 schrieb Craig Scott <[hidden email]>:
>
> This is precisely the scenario that the CMAKE_TRY_COMPILE_PLATFORM_VARIABLES variable is meant for. It allows a toolchain file to specify additional variables that should be passed along to try_compile().

Works like a charm. Thanks a lot!

Torsten

--

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

--

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: Checking Variables in a tool-chain file

Torsten Robitzki
Hi,

> Am 01.02.2019 um 17:17 schrieb frodak17 <[hidden email]>:
>
> Be aware that CMAKE_TRY_COMPILE_PLATFORM_VARIABLES only works with the try_compile() command source file signature. Unfortunately it doesn't work with try_compile() whole projects signature.  The section on Other Behavior Settings mostly only applies to the source file signature.

can you give me some details on the consequences? I’ve inserted following test into my tool-chain file (https://github.com/TorstenRobitzki/bluetoe/pull/39/commits/6067e808486c8421e6f3bf3a5dd9c14ab8aa6474):


        set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARM_GCC_TOOL_PATH)

        if (NOT DEFINED ARM_GCC_TOOL_PATH)
            message(FATAL_ERROR "To configure the arm-none-eabi-gcc correctly, please set ARM_GCC_TOOL_PATH to the path that contains the bin directory of your GCC installation.")
        elseif(NOT EXISTS ${tools}/bin)
            message(FATAL_ERROR "To configure the arm-none-eabi-gcc correctly, please set ARM_GCC_TOOL_PATH to the path that contains the bin directory of your GCC installation.")
        endif()

Will this fail eventually?

kind regards,

Torsten


--

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

signature.asc (849 bytes) Download Attachment