Variables in cmake-scripts

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

Variables in cmake-scripts

mereandor
Hi!

I have a question regarding cmake-scripts:

I have this simple example:

----CMakeLists.txt----
cmake_minimum_required(VERSION 2.6)
SET(TEST CACHE STRING "test variable")
INSTALL(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/install.cmake)

----install.cmake----
EXECUTE_PROCESS(
  COMMAND "/bin/echo" "--test=${TESTVAR} --prefix=${CMAKE_INSTALL_PREFIX}"
  RESULT_VARIABLE AD_HDM_RV
)

Here is the input and output that I get:

$ cmake -DTESTVAR=something
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mereandor/test
$ make install
Install the project...
-- Install configuration: ""
--test= --prefix=/usr/local

Why is ${CMAKE_INSTALL_PREFIX} set and ${TESTVAR} not?

thanks in advance for any help

regards
_______________________________________________
Powered by www.kitware.com

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

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

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

Re: Variables in cmake-scripts

Michael Jackson
where is TESTVAR ever set?

_________________________________________________________
Mike Jackson                  [hidden email]
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

On Oct 2, 2009, at 10:20 AM, [hidden email] wrote:

> Hi!
>
> I have a question regarding cmake-scripts:
>
> I have this simple example:
>
> ----CMakeLists.txt----
> cmake_minimum_required(VERSION 2.6)
> SET(TEST CACHE STRING "test variable")
> INSTALL(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/install.cmake)
>
> ----install.cmake----
> EXECUTE_PROCESS(
>  COMMAND "/bin/echo" "--test=${TESTVAR} --prefix=$
> {CMAKE_INSTALL_PREFIX}"
>  RESULT_VARIABLE AD_HDM_RV
> )
>
> Here is the input and output that I get:
>
> $ cmake -DTESTVAR=something
> -- The C compiler identification is GNU
> -- The CXX compiler identification is GNU
> -- Check for working C compiler: /usr/bin/gcc
> -- Check for working C compiler: /usr/bin/gcc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: /usr/bin/c++
> -- Check for working CXX compiler: /usr/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/mereandor/test
> $ make install
> Install the project...
> -- Install configuration: ""
> --test= --prefix=/usr/local
>
> Why is ${CMAKE_INSTALL_PREFIX} set and ${TESTVAR} not?
>
> thanks in advance for any help
>
> regards
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
Powered by www.kitware.com

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

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

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

Re: Variables in cmake-scripts

James C. Sutherland
In reply to this post by mereandor

On Oct 2, 2009, at 8:20 AM, <[hidden email]>  
<[hidden email]> wrote:

>
> ----CMakeLists.txt----
> cmake_minimum_required(VERSION 2.6)
> SET(TEST CACHE STRING "test variable")
> INSTALL(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/install.cmake)
>
> ----install.cmake----
> EXECUTE_PROCESS(
>  COMMAND "/bin/echo" "--test=${TESTVAR} --prefix=$
> {CMAKE_INSTALL_PREFIX}"
>  RESULT_VARIABLE AD_HDM_RV
> )
>
>
> Why is ${CMAKE_INSTALL_PREFIX} set and ${TESTVAR} not?
>
> thanks in advance for any help

CMAKE_INSTALL_PREFIX is a variable that is set by CMake to a default  
value of /usr/local on linux/unix flavor systems.

TESTVAR is something you need to set.
_______________________________________________
Powered by www.kitware.com

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

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

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

Re: Variables in cmake-scripts

Bill Hoffman
James C. Sutherland wrote:

>
> On Oct 2, 2009, at 8:20 AM, <[hidden email]> <[hidden email]>
> wrote:
>>
>> ----CMakeLists.txt----
>> cmake_minimum_required(VERSION 2.6)
>> SET(TEST CACHE STRING "test variable")
>> INSTALL(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/install.cmake)
>>
>> ----install.cmake----
>> EXECUTE_PROCESS(
>>  COMMAND "/bin/echo" "--test=${TESTVAR} --prefix=${CMAKE_INSTALL_PREFIX}"
>>  RESULT_VARIABLE AD_HDM_RV
>> )
>>
>>
>> Why is ${CMAKE_INSTALL_PREFIX} set and ${TESTVAR} not?
>>
>> thanks in advance for any help
>
> CMAKE_INSTALL_PREFIX is a variable that is set by CMake to a default
> value of /usr/local on linux/unix flavor systems.
>
> TESTVAR is something you need to set.

The problem is htat the install.cmake script does not load the cache
from the main CMake run for the project, nor should it.  If you want to
pass variables to it, you would have to configure them into a custom
install script.

-Bill
_______________________________________________
Powered by www.kitware.com

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

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

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

Re: Variables in cmake-scripts

Michael Jackson
In reply to this post by Michael Jackson
Oops.. Nice Catch.

I am going to hazard a guess and say that "Make" is running a new  
cmake instance with the install.cmake as its target script to run.  
This script will have NOTHING to do with the CMakeLists.txt file and  
therefor will have no idea about variables that are defined in the  
original CMakeLists.txt file.

   If presented with this I would probably opt to use a configured  
file such as:

install.cmake.in-----
EXECUTE_PROCESS(
  COMMAND "/bin/echo" "--test=$@TESTVAR@ --prefix=$
{CMAKE_INSTALL_PREFIX}"
  RESULT_VARIABLE AD_HDM_RV
)

Then in CMakeLists.txt:

configure_file ( ${PROJECT_SOURCE_DIR}/install.cmake.in $
{PROJECT_BINARY_DIR}/install.cmake )
INSTALL(SCRIPT ${PROJECT_BINARY_DIR}/install.cmake)

$ cmake -DTESTVAR=something
.
.
.
.
$ make install

--
Mike Jackson <www.bluequartz.net>


On Oct 2, 2009, at 10:35 AM, [hidden email] wrote:

> Isn't "cmake -DTESTVAR=something" supposed to do that?
>
> Am Freitag 02 Oktober 2009 16:30:44 schrieben Sie:
>> where is TESTVAR ever set?
>>
>> _________________________________________________________
>> Mike Jackson                  [hidden email]
>>
>> On Oct 2, 2009, at 10:20 AM, [hidden email] wrote:
>>> Hi!
>>>
>>> I have a question regarding cmake-scripts:
>>>
>>> I have this simple example:
>>>
>>> ----CMakeLists.txt----
>>> cmake_minimum_required(VERSION 2.6)
>>> SET(TEST CACHE STRING "test variable")
>>> INSTALL(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/install.cmake)
>>>
>>> ----install.cmake----
>>> EXECUTE_PROCESS(
>>> COMMAND "/bin/echo" "--test=${TESTVAR} --prefix=$
>>> {CMAKE_INSTALL_PREFIX}"
>>> RESULT_VARIABLE AD_HDM_RV
>>> )
>>>
>>> Here is the input and output that I get:
>>>
>>> $ cmake -DTESTVAR=something
>>> -- The C compiler identification is GNU
>>> -- The CXX compiler identification is GNU
>>> -- Check for working C compiler: /usr/bin/gcc
>>> -- Check for working C compiler: /usr/bin/gcc -- works
>>> -- Detecting C compiler ABI info
>>> -- Detecting C compiler ABI info - done
>>> -- Check for working CXX compiler: /usr/bin/c++
>>> -- Check for working CXX compiler: /usr/bin/c++ -- works
>>> -- Detecting CXX compiler ABI info
>>> -- Detecting CXX compiler ABI info - done
>>> -- Configuring done
>>> -- Generating done
>>> -- Build files have been written to: /home/mereandor/test
>>> $ make install
>>> Install the project...
>>> -- Install configuration: ""
>>> --test= --prefix=/usr/local
>>>
>>> Why is ${CMAKE_INSTALL_PREFIX} set and ${TESTVAR} not?
>>>
>>> thanks in advance for any help
>>>
>>> regards

_______________________________________________
Powered by www.kitware.com

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

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

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