[CMake] Problem with custom command

Robert Dailey rcdailey.lists at gmail.com
Tue Mar 12 16:58:57 EDT 2013


I'm adding a custom command to a target created via add_library().
here is the function I call to create the custom command:


function( define_data target_name output_subdir )
    set( data_files ${ARGN} )
    set( output_dir ${CMAKE_BINARY_DIR}/output/data/${output_subdir} )
    set( copycmd ${CMAKE_COMMAND} -E copy )

    foreach( d ${data_files} )
        #get_filename_component( file ${d} NAME )
        #set( output_file ${output_dir}/${d} )
        #set( source_file ${CMAKE_CURRENT_SOURCE_DIR}/${d} )
        set( output_file ${output_dir}/${d} )
        set( source_file ${d} )

        list( APPEND output_files ${output_file} )
        list( APPEND copy_commands
            COMMAND ${copycmd} ${source_file} ${output_file}
        )
    endforeach()

    source_group( data FILES ${data_files} )

    add_custom_command(
        COMMENT "Copying data for target ${target_name}"
        OUTPUT ${output_files}
        DEPENDS ${data_files}
        ${copy_commands}
    )

    #add_dependencies( ${target_name} ${data_target} )
endfunction()

I call this function FIRST, then afterwards I call add_library() and I
include the data file(s) passed in as a source file to be included in
the target. When I build that target in VS2008 I do not see any files
copied to my output/data directory (which does not yet exist on my
hard drive). Any idea what I'm doing wrong?

How are relative/absolute paths handled here? I'm passing in relative
paths (just the filename for current source directory) into DEPENDS.


More information about the CMake mailing list