[CMake] Specify dependency on externally generated shared library

Scott Gray sgray at inventa.com
Wed May 6 15:53:10 EDT 2009


Hello,

I've been working for a while to integrate the C/C++ 
internationalization library ICU with our cmake build process and I've 
made some pretty good progress, but I'm currently kind of stuck.

During part of the ICU bundling process, it takes language resource 
files (*.res files) and a program called "pkgdata" packages these .res 
files into a shared library containing your translations.  In this way, 
there are no external resources (other than the DLL itself) your program 
needs run localized.

My problem is that I need to both generate the DLL and declare it as an 
imported library so that other programs can depend upon it.  I think I'm 
very close with the following:

#
# Compute name of the library pkgdata will produce containing our
# internationalization data
#
set (libname      
"${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}mylib_intl${CMAKE_SHARED_LIBRARY_SUFFIX}")

#
# This command will produce the ${libname} library by packaging up the
# resource files contained in ${icu_res_files} using the pkgdata program
#
add_custom_command(
    OUTPUT "${libname}"
    COMMAND pkgdata
            --libname "${libname}"
            --mode dll
            --destdir "${LIBRARY_OUTPUT_PATH}"
            ${icu_res_files}
    DEPENDS ${icu_res_files})

#
# Make the "mylib_intl" library available for use by other programs by 
pointing
# at the library produced by pkgadd
#
add_library(mylib_intl SHARED IMPORTED)
set_property(TARGET mylib_intl PROPERTY IMPORTED_LOCATION "${libname}")

...

#
# Create myprog and link in the internationalization library
#
add_program(myprog myprog.c)
target_link_libraries(myprog mylib_intl)


So, now, the problem is when I go to compile 'myprog', I get the 
following error:

make[2]: *** No rule to make target 
`src/util/build/dist/lib/libmylib_intl.so', needed by `src/util/test/myprog'

As I said, I'm close...all I need now is how to specify that 
"mylib_intl" is dependent upon producing the file ${libname} and I 
believe everything will work. So I'm assuming it is a matter of setting 
a property on the "liblib_intl" target but I'm struggling to figure out 
which one.

Thanks,
-scott



More information about the CMake mailing list