[CMake] dependency, custom command/target and parallel build.

Dhadi S adjustmadi at hotmail.com
Wed Apr 8 16:50:21 EDT 2009


Hi,
I'm new to cmake. Here is the version i'm using on a linux box. 

cmake version 2.6-patch 3

In my main directory i've the fllowing in my cmakelists.txt file.

assume my main directory to be  /home/srini

SET (XDR_FILES_HOME /home/thirdparty/xdr ) 
SET (XDR_FILES 
    ${XDR_FILES_HOME}/xdrPrt.h  
    ${XDR_FILES_HOME}/xdrPrtBuf.c
    ${XDR_FILES_HOME}/xdrPrt.c 
 )


add_subdirectory (lib0 ) 
add_subdirectory (lib1) 


Notice that the xdr files are not in my project heirarchy. 
The source files in both lib0 and lib1 depend on xdrPrt.h file generated at run time. 



In   lib0/cmakelists.txt file i've 


 ADD_CUSTOM_COMMAND(

   OUTPUT ${XDR_FILES}

   COMMAND  my_xdr_gen.exe

   WORKING_DIRECTORY ${XDR_FILES_HOME}

   )

ADD_CUSTOM_TARGET(lib0_xdr ALL DEPENDS ${XDR_FILES} )
add_library (LIB0_LIB SHARED ${XDR_FILES} lib0_src.c ) 


and in lib1/cmakelists.txt file,  i almost repeat the same.
ADD_CUSTOM_COMMAND(


   OUTPUT ${XDR_FILES}


   COMMAND  my_xdr_gen.exe


   WORKING_DIRECTORY ${XDR_FILES_HOME}


   )



ADD_CUSTOM_TARGET(lib1_xdr ALL DEPENDS ${XDR_FILES} )

add_library (LIB1_LIB SHARED ${XDR_FILES} lib1_src.c ) 


The
above works for me (i can't seem to move the common code to main
cmakelists.txt file) when i do gmake in the build dir. In
my_xdr_gen.exe i added print statement to make sure it was called. 
However when i do  gmake -j4  i see 2 print statements from it.  As if
both lib0 and lib1 called custom command at the same time. 

Here are my questions, since i'm newbie and i'm sure what i'm doing is not correct.

How can i not duplicate code in lib0/cmakelists.txt and lib1/cmakelists.txt 
I want to call my custom command just once and i want the lib0 and lib1 comilation to wait for the generation of my XDR_FILES. 
And i should be able to do parallel build also.

Many thanks,
Srini


_________________________________________________________________
Windows Live™: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_allup_1a_explore_042009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090408/2945c36e/attachment.htm>


More information about the CMake mailing list