[CMake] POST_BUILD in a different directory

Andreas Pokorny andreas.pokorny at gmail.com
Mon Apr 28 11:39:24 EDT 2008


Hello,
I have the same requirement. I would like to attach copy commands to targets
built in different directories. I want to copy dlls/pdb/so -files into
other directories
that contain test cases which are supposed to use the libraries.

I have a "clean" solution that only works in NMake and gnumake. The macro
that creates the test cases, creates a new target and attaches all
copy commands
to that target, by specifying a dependencies two the original library,
the copy command
will be executed everytime the library changes.

ADD_CUSTOM_TARGET(Dummy ALL)

ADD_CUSTOM_COMMAND(TARGET Dummy
                        POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy
                        ${__COPY_SOURCE_PATH}/${LIBNAME}.dll
                        ${__COPY_DEST_PATH}
                        DEPENDS ${__COPY_SOURCE_PATH}/${LIBNAME}.dll
                        )

The dummy target exists within each cmake project that calls the
macro. But with
Visual Studio the project names must be unique. So only the first one
is loaded :(.

To solve that issue the "dirty" solution ensures that the dummy target
is created from
the project name, so the target and project file will be unique.

ADD_CUSTOM_TARGET(${PROJECT_NAME}_Dummy ALL)
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME}_Dummy
                        POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy
                        ${__COPY_SOURCE_PATH}/${LIBNAME}.dll
                        ${__COPY_DEST_PATH}
                        DEPENDS ${__COPY_SOURCE_PATH}/${LIBNAME}.dll
                        )



kind regards
Andreas

2008/4/24 Judicaël Bedouet <j.bedouet at infonie.fr>:
> Hello,
>
>  I would like to use the POST_BUILD option of the command
>  ADD_CUSTOM_COMMAND in a CMakeLists.txt, different from the
>  CMakeLists.txt which is used to
>  generate the target. I made this test.
>
>
>  In the top level source directory,
>
>  CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
>
>  PROJECT (test CXX)
>
>  ADD_SUBDIRECTORY (lib1)
>  ADD_SUBDIRECTORY (lib2)
>
>
>  In the directory lib1/,
>
>  ADD_LIBRARY (lib1 lib1.cpp)
>
>  ADD_CUSTOM_COMMAND (TARGET lib1 POST_BUILD
>   COMMAND echo
>   ARGS "Hello"
>   COMMENT "echo hello 1"
>  )
>
>
>  In the directory lib2/,
>
>  ADD_CUSTOM_COMMAND (TARGET lib1 POST_BUILD
>   COMMAND echo
>   ARGS "Hello"
>   COMMENT "echo hello 2"
>  )
>
>
>  The echo command in lib2/ is never executed.
>
>  This is a dummy example but in the case of my project, I would like to
>  generate a library in directory lib\ and documentation in directory
>  doc\. Documentation must be regenerated only when the library is
>  rebuilt.
>
>  Is there a way to make the option POST_BUILD works in another directory ?
>
>  I'm working under Linux with cmake 2.6-0 RC-8.
>
>  Thanks,
>
>  J. Bedouet
>  _______________________________________________
>  CMake mailing list
>  CMake at cmake.org
>  http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list