[CMake] Generated file and parallel build.

Óscar Fuentes ofv at wanadoo.es
Mon Sep 22 10:42:24 EDT 2008


Hello, Brad.

Brad King <brad.king at kitware.com> writes:

> Óscar Fuentes wrote:
>> Several libraries depends on a generared header file. For enabling
>> parallel builds I need to state that dependency, and I do it with
>> set_source_files_properties. This happens inside a macro:
>> 
>> macro(add_llvm_library name)
>>   if( LLVM_SOURCE_COMMON_DEPENDS )
>>     set_source_files_properties( ${ARGN}
>>       PROPERTIES OBJECT_DEPENDS ${LLVM_SOURCE_COMMON_DEPENDS}
>>       )
>>   endif( LLVM_SOURCE_COMMON_DEPENDS )
>>   add_library( ${name} ${ARGN} )
>> ....
>> 
>> where LLVM_SOURCE_COMMON_DEPENDS contains the name of the custom target
>> that is used to trigger the custom command that generates the file:
>
> You're mixing up file-level dependencies with target-level dependencies.
>  The OBJECT_DEPENDS property only specifies file-level dependencies.  I
> see its documentation is lacking.  I'll commit improved documentation
> for it.  The add_dependencies command is used to create extra
> inter-target dependencies:
>
> macro(add_llvm_library name)
>   add_library(${name} ${ARGN})
>   add_dependencies(${name} ${LLVM_SOURCE_COMMON_DEPENDS})
>   ....
> endmacro()

This doesn't work. The generation of the header file must be completed
before compiling the library's source files, and add_dependencies is not
for this. If my understanding is right, add_dependencies means that the
targets listed on LLVM_SOURCE_COMMON_DEPENDS must be built before
invoking `ar', but doesn't mean that the compilation of the library's
source files must be delayed until the targets listed on
add_dependencies are completed.

> Just make sure the LLVM_SOURCE_COMMON_DEPENDS variable contains only
> target names and not files.
>
>> add_custom_command(OUTPUT ${path_to_intrinsics_gen}
>>   COMMAND tblgen -gen-intrinsic ... -o ${path_to_intrinsics_gen}
>>   DEPENDS tblgen
>>   COMMENT "Building intrinsics.gen...")
>> 
>> add_custom_target(intrinsics_gen ALL
>>   DEPENDS ${path_to_intrinsics_gen})
>> 
>> set(LLVM_SOURCE_COMMON_DEPENDS ${LLVM_SOURCE_COMMON_DEPENDS} intrinsics_gen )
>
> This is correct.

-- 
Oscar



More information about the CMake mailing list