[CMake] ADD_CUSTOM_COMMAND Application dependency

Angeliki Chrysochou angeliki.chrysochou at gmail.com
Wed Nov 19 08:10:07 EST 2014


Hi Lars,

What if you provide the working directory to ADD_CUSTOM_COMMAND like this:

    add_custom_command(
    OUTPUT <output>
    COMMAND command_to_be_executed <arg_1> <arg_2>
    DEPENDS ${lib1} ${lib2}
    WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
    VERBATIM)

Would it work?

Otherwise a trick (more like a hack) like the following might be useful:

    add_custom_command(
    OUTPUT <output>
    COMMAND PATH=$ENV{PATH}:<more_paths> ENVIRONMENT_VAR=<some_other_value>
&& command_to_be_executed <arg_1> <arg_2>
    DEPENDS <dependency_1> <dependency_2>
    WORKING_DIRECTORY <working_dir>
    VERBATIM)

This sets the PATH temporarily during the execution of the command, where
you could possibly add the paths to the libraries you need. You can set
more environment variables as well.

Cheers!
Angeliki


On Wed, Nov 19, 2014 at 11:14 AM, Lars <laasunde at hotmail.com> wrote:

>   The below example build "App" and copies it to EXECUTABLE_OUTPUT_PATH.
> ADD_EXECUTABLE(App ${source})
> TARGET_LINK_LIBRARIES(App ${lib1} ${lib2})
> INSTALL(TARGETS App ..)
>
> The top level CMakeLists.txt has install directives for lib1 and lib2
> INSTALL(FILES ${lib1}/bin/lib1.dll DESTINATION ...)
> INSTALL(FILES ${lib2}/bin/lib2.dll DESTINATION ...)
> Later in the build process we would like to use "App"
> ADD_CUSTOM_COMMAND(OUTPUT "${src} COMMAND App ...)
>
> The ADD_CUSTOM_COMMAND command currently fails because lib1 and lib2 are
> not present in EXECUTABLE_OUTPUT_PATH.
>
> The following solutions work but are not desirable approaches:
>  - Copying the necessary files to EXECUTABLE_OUTPUT_PATH via
> ADD_CUSTOM_COMMAND. This would be repeating top level install directives at
> target level.
>  - Update "path" environment variable to include paths to lib1 and lib2
> libraries.
> What other options are available using CMake? Does ADD_CUSTOM_COMMAND have
> a way to update path environment prior to executing a command?
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141119/bac520f1/attachment.html>


More information about the CMake mailing list