[CMake] Using Checksum to generate files

avner cohen avcoh at yahoo.com
Tue Aug 11 14:28:14 EDT 2009


Hi Eric,
Thanks again for your help.
1. (Let me clarify here, that the Diskspace issue was a simple example of the wider solution I am looking for).
2. (Apologies for the long post).
 
As I know feel I've been fighting with this for long enough, I'll try again from scratch.
 
All in all, my feeling is that I'm inventing the wheel here as what I need to do seems rather basic (or maybe not?)
So I'll try to detail this from the beginning, maybe a new suggestion will come:
 
1. I have a series of NON cpp files (IDL files) that requires automatic generation whenever an IDL is being changed.
I was able to create the script to generate the IDLs:
EXECUTE_PROCESS (COMMAND ${IDL_COMPILER} -I ${PROJECT_SOURCE_DIR}IDLs ${PROJECT_SOURCE_DIR}/IDLs/CORBAStructDefs.idl WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/IDLs RESULT_VARIABLE  retcode)
 
2. I need to execute the above command ONLY when the IDL is changed (otherwise full build is incorrectly triggered each time), so I took the approach of creating a checksum for the file, saving this in the cache and than comparing this every time to "identify" the change of this file:
GET_PROPERTY(SCOPE GLOBAL PROPERTY  CACHED_IDL_CHECKSUM)  #Get saved checksum from previous run.
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND}  -E md5sum ${IDL_FILE}
   OUTPUT_VARIABLE CalculatedCheckSum OUTPUT_STRIP_TRAILING_WHITESPACE) # generate new checksum
IF (NOT "${CACHED_IDL_CHECKSUM}"  STREQUAL  "${CalculatedCheckSum}") #Comapre checksums
   ....DO IDL Generation
    ... Update Checksum
ENDIF (NOT "${CACHED_IDL_CHECKSUM}"  STREQUAL  "${CalculatedCheckSum}")
 
 
So far so good.
But now, I need to take this a step further and add a custom rule so that I make sure that the above logic is execute on each and every build (i.e. reminder - the trigger to generate the IDL is IDL change and not CMakeLists.txt change).
It than that the "-P" comes into play, and I can try and do (where above logic is inside  IDL_COMPILE.cmake):
ADD_CUSTOM_TARGET(IDL_4 ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/IDL_COMPILE.cmake SOURCES "${PROJECT_SOURCE_DIR}/IDL_COMPILE.cmake")
ADD_DEPENDENCIES(${PROJECT_NAME} IDL_4)
 
I'm bumping into "solution killers" since, within the scope of "-P cmakescript" I need:
1. Use main CMAKE variables, i.e. PROJECT_NAME, CMAKE_COMMAND etc  (get's complicated as I need to use -D or CONFIGURE_FILE).
2. SET cache variables to update the checksum (Can't be done as per documentation).
3. Call Cmake Functions (Can't be done, I tried both functions in the -P file or from include() I have in my main script, both failed).
 
 
Any help on this will be much appreciated.
 
Regards,
        Avner Cohen.



----- Original Message ----
From: Eric Noulard <eric.noulard at gmail.com>
To: avner cohen <avcoh at yahoo.com>
Cc: cmake at cmake.org
Sent: Tuesday, August 11, 2009 11:23:02 AM
Subject: Re: [CMake] Checking Disk space with Cmake

2009/8/11 avner cohen <avcoh at yahoo.com>:
>
> Thank you very much Eric, this defiently helps.
> My problem now is that I want my "<your_check_disk_command>" to be a MACRO/FUNCTION if already written in my cmake scripts (rather than running a shell script) is that possible ?

Almost yes, in fact you cannot "call a macro" in add_custom_target,
however you may put whatever you want in a checkdisk.cmake CMake script file
and then call this script  using CMake -P, like in:

add_custom_target(CheckDisk ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/checkdisk.cmake
                  COMMENT "Check available disk space before build"
                  SOURCES checkdisk.cmake)

If you need to pass value to your checkdisk.cmake, then you may use -D
arguments to CMake
and/or configure_file(checkdisk.cmake.in checkdisk.cmake)  in order to
make the called
script contains configured values from your project.


-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org



      


More information about the CMake mailing list