List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:February 4 2011 1:42pm
Subject:RE: review of bug#42969
View as plain text  

> -----Original Message-----
> From: Joerg Bruehe [mailto:joerg.bruehe@stripped]
> Sent: Freitag, 4. Februar 2011 12:23
> To: Guilhem Bichot
> Cc: commits
> Subject: Re: review of bug#42969
> 
> Hello Guilhem,


> Probably, that is the result of "@ONLY":
> For most of cmake's variables, simply using them "${CMAKE_SYSTEM}" is
> not enough, you first need the "SET" line:
>    SET(CMAKE_SYSTEM "@CMAKE_SYSTEM@")

Joerg, Guilhem.

Maybe it makes things a bit cleared with my explanation, I'll try .. 

Apart from cmake main functionality to be used to build software, It can be used just as 
normal  portable scripting language.

The classic program in cmake scripting language  would look like 
hello.cmake : 
MESSAGE(STATUS "hello, world")

You can run it with 
cmake -P  hello.cmake


When cmake is in script mode as above, it does not have build-related  context, nothing
like
 CMAKE_BUILD_DIR , or CMAKE_C_COMPILER_ID . It does not do system introspection, it does
not 
have CMakeCache.txt to get variables from,  it cannot do ADD_EXECUTABLE or ADD_LIBRARY
(those 
commands are not scriptable), and it has  zero builtin variables

Often it is desirable to run cmake scripts (cmake -P) as part of make, in places where
people would 
otherwise use non-portable bourne shell scripts or non-portable batch files otherwise. it
is often required
to have build-related  variables (buld directory etc)  in those scripts. 

"Configure file during cmake and run during make" is standard trick to accomplish that. 

For example.

A script to be configured could look like 

hello.cmake.in  :
SET(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@")
MESSAGE(STATUS "hello,${CMAKE_C_COMPILER_ID}")


In build it would be used like this : 

CMakeLists.txt:
# Configure file during cmake
CONFIGURE_FILE(
   ${CMAKE_CURRENT_SOURCE_DIR}/hello.cmake.in 
   ${CMAKE_CURRENT_BINARY_DIR}/hello.cmake
  @ONLY)

# After configure content of hello.cmake is 
# SET(CMAKE_C_COMPILER_ID "MSVC")
# MESSAGE(STATUS "hello,${CMAKE_C_COMPILER_ID}")

# Run configured file during make
ADD_CUSTOM_TARGET (
  Foo
  COMMAND
  ${CMAKE_EXECUTABLE} -P ${CMAKE_CURRENT_BINARY_DIR}/hello.cmake
 # ^ this is cmake -P hello.cmake
)

Wlad
 
 

Thread
review of bug#42969Guilhem Bichot4 Feb
  • Re: review of bug#42969Joerg Bruehe4 Feb
    • RE: review of bug#42969Vladislav Vaintroub4 Feb
      • Re: review of bug#42969Guilhem Bichot4 Feb
        • RE: review of bug#42969Vladislav Vaintroub4 Feb
    • Re: review of bug#42969Guilhem Bichot4 Feb