[CMake] Per configuration ADD_CUSTOM_COMMAND

David Cole david.cole at kitware.com
Wed Nov 9 11:18:49 EST 2011


There are also generator expressions for TARGET_LINKER_FILE and
TARGET_SONAME_FILE -- have you tried those? I think when the target is
a .dll, the TARGET_LINKER_FILE expression yields the name of the
corresponding .lib file...


HTH,
David


On Wed, Nov 9, 2011 at 10:28 AM, Ludovic Hoyet <lhoyet at gmail.com> wrote:
> I just tried it (maybe I did something wrong) but it does not work:
> 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 $<TARGET_FILE:${MY_PROJECT }>.lib ${EXTERNAL_DIR} VERBATIM)
> The first line copy the dll, no pb with this it was already working. The
> second line try to copy project_d.dll.lib for Debug and project.dll.lib for
> Release
> How can I access the name of the output file without the extension?
> 2011/11/9 Rolf Eike Beer <eike at sf-mail.de>
>>
>> > 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
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
> --
> _______________________________________
>
> Ludovic Hoyet
> Research Fellow,
> Graphics Vision and Visualisation group,
> Trinity College Dublin
> http://www.scss.tcd.ie/~hoyetl/
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list