[CMake] Per configuration ADD_CUSTOM_COMMAND

Rolf Eike Beer eike at sf-mail.de
Wed Nov 9 10:18:45 EST 2011


> Hi,
>
> I have different projects that generate a .lib and a .dll file, and I
> would
> like to copy these 2 files in a given directory as a post-build event. My
> main problem is that my debug libraries are post-fixed with _d, which
> require that I use the following code:
>
> SET(MY_PROJECT project)
> ADD_LIBRARY(${MY_PROJECT } SHARED ${HDRS} ${SOURCES} ... )
> [...]
> ADD_CUSTOM_COMMAND(TARGET ${MY_PROJECT } POST_BUILD COMMAND
> ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${MY_PROJECT }> ${EXTERNAL_DIR}
> VERBATIM)
> ADD_CUSTOM_COMMAND(TARGET ${MY_PROJECT } POST_BUILD COMMAND
> ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/debug/${MY_PROJECT }_d.lib
> ${EXTERNAL_DIR}/${MY_PROJECT }_d.lib VERBATIM)
> ADD_CUSTOM_COMMAND(TARGET ${MY_PROJECT } POST_BUILD COMMAND
> ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/release/${MY_PROJECT }.lib
> ${EXTERNAL_DIR}/${MY_PROJECT }.lib VERBATIM)
>
> The main problem is that the tool crash when I compile it the first time.
> For instance if I start to compile in Release the _d.lib file does not
> exist and it does not even process to copying the release .lib. Ok, it
> works if I compile it in the right order, but I would prefer to have a
> clean code for this.
>
> I have been looking at using
> INSTALL(TARGETS ${MY_PROJECT} DESTINATION ${EXTERNAL_DIR} COMPONENT
> Libraries)
> but it creates a separate install vcproj that runs after all my projects,
> and I need my libraries copied right after the compilation as other
> projects depend on these output. So this is not a solution for me.
>
> So I tryied to have a look at per configuration ADD_CUSTOM_COMMAND. I
>  found different discussion about this problem, but I don't manage to make
> it work:
> http://public.kitware.com/Bug/view.php?id=9974
> http://public.kitware.com/Bug/view.php?id=11209
>
> The first one provide a patch, but I don't manage to get it working with
> cmake. Is there a special way to include these "patches" to our
> configurations?

Use generator expressions to get the name of the generated files.

Eike


More information about the CMake mailing list