[CMake] ADD_CUSTOM_COMMAND Application dependency

Angeliki Chrysochou angeliki.chrysochou at gmail.com
Wed Nov 19 13:21:54 EST 2014


Hi Lars,

I see...Why don't you set the working directory then to lib1 and lib2, and
use the full path to App to call App? Not sure it will work, but maybe.

Cheers!
Angeliki


On Wed, Nov 19, 2014 at 7:19 PM, Lars <laasunde at hotmail.com> wrote:

> Hi Angeliki,
>
> Thank you for the suggestions.
>
> I suspect your first example wont work because lib1 and lib2 are not in
> executable_output_path. So when the add_custom_command executes "App" it
> wont be able to resolve the dependencies to lib1 and lib2. If I only had
> one dependency I could possibly set the working_directory to the path of
> lib1 and use the absolute path of the "App" for the command. That would
> probably work but not with multiple dependencies.
>
> Your second example might do the job but wont be accepted as a solution in
> our company.
>
> regards, Lars
>
> ------------------------------
> Date: Wed, 19 Nov 2014 14:10:07 +0100
> Subject: Re: [CMake] ADD_CUSTOM_COMMAND Application dependency
> From: angeliki.chrysochou at gmail.com
> To: laasunde at hotmail.com
> CC: cmake at cmake.org
>
>
> 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/fc3ae924/attachment-0001.html>


More information about the CMake mailing list