dependency in custom command?

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

dependency in custom command?

King, Steven R
Hello List,
I'm new to cmake and liking it a lot.  I'm using cmake 2.6.3 on Linux.

I'm building a dynamically loadable module and an executable to test it.  Each lives in a different directory.  My test program needs to know the location of the dll when calling dlopen().   To solve this, I created a custom command to copy the dll to the binary directory of the test program.   This works, but I have an annoying dependency problem.  Specifically, if the dll gets rebuilt, the copy command does not execute.  The copy command only executes if the test program gets rebuilt.  I do not understand how to make this copy depend on the dll being rebuilt.  I want all test programs to "pull" the rebuilt dll as needed.  I do not want the CMakeLists.txt for the dll to have any knowledge of the test programs.

In CMakeLists.txt for the test program:


add_executable            (
                          test_my_module
                          test_main.cpp
                          )

add_dependencies          (
                          test_my_module
                          my_module # not needed?
                          )

# Loadable modules are never listed at link time.
target_link_libraries     (
                          test_my_module
                          dl
                          )

# Put the location of the .so library we need in the SO_LOCATION variable.
# We then use this location in the copy command below.
get_target_property       (
                          SO_LOCATION
                          my_module        # .so library target
                          LOCATION
                          )

# Create a custom build step to copy the dynamically loaded .so file
# into the this directory so our test executable can find it.
add_custom_command        (
                          TARGET test_my_module
                          POST_BUILD
                          DEPENDS my_module  # no effect?
                          COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}
                          COMMENT "CUSTOM COMMAND: Copy my_module to build directory"
                          )


What should I do make the copy happen if the dll is rebuilt?

Thanks for any advice,
-steve
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Tyler Roscoe
On Fri, Aug 28, 2009 at 11:28:53AM -0700, King, Steven R wrote:

> I'm building a dynamically loadable module and an executable to test
> it.  Each lives in a different directory.  My test program needs to
> know the location of the dll when calling dlopen().   To solve this, I
> created a custom command to copy the dll to the binary directory of
> the test program.   This works, but I have an annoying dependency
> problem.  Specifically, if the dll gets rebuilt, the copy command does
> not execute.  The copy command only executes if the test program gets
> rebuilt.  I do not understand how to make this copy depend on the dll
> being rebuilt.  I want all test programs to "pull" the rebuilt dll as
> needed.  I do not want the CMakeLists.txt for the dll to have any
> knowledge of the test programs.

Wrap your custom_command with a custom_target. See the CMake FAQ for
some recipes.

Then just do:

add_dependencies (test_my_module custom_target_that_copies_my_module)

> In CMakeLists.txt for the test program:
> add_dependencies          (
>                           test_my_module
>                           my_module # not needed?
>                           )

You do want this stanza.

> # Put the location of the .so library we need in the SO_LOCATION variable.
> # We then use this location in the copy command below.
> get_target_property       (
>                           SO_LOCATION
>                           my_module        # .so library target
>                           LOCATION
>                           )

You don't need to do this. Since "my_module" is a CMake target, you can
just use "my_module" instead of ${SO_LOCATION} in the custom_command
below and CMake will figure out where the .so is on the disk

> # Create a custom build step to copy the dynamically loaded .so file
> # into the this directory so our test executable can find it.
> add_custom_command        (
>                           TARGET test_my_module
>                           POST_BUILD
>                           DEPENDS my_module  # no effect?
>                           COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}
>                           COMMENT "CUSTOM COMMAND: Copy my_module to build directory"
>                           )

You may want to use -E copy_if_different there instead.

tyler
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Michael Wild
In reply to this post by King, Steven R
You don't have to do the copying yourself. Just tell CMake in which  
directory it should create the module by either setting the  
LIBRARY_OUTPUT_DIRECTORY target property or the  
CMAKE_LIBRARY_OUTPUT_DIRECTORY variable.

AFAIK the LOCATION property is only present for compatibility with  
CMake 2.4, and shouldn't be used in new code.

HTH

Michael


On 28. Aug, 2009, at 20:28, King, Steven R wrote:

> Hello List,
> I'm new to cmake and liking it a lot.  I'm using cmake 2.6.3 on Linux.
>
> I'm building a dynamically loadable module and an executable to test  
> it.  Each lives in a different directory.  My test program needs to  
> know the location of the dll when calling dlopen().   To solve this,  
> I created a custom command to copy the dll to the binary directory  
> of the test program.   This works, but I have an annoying dependency  
> problem.  Specifically, if the dll gets rebuilt, the copy command  
> does not execute.  The copy command only executes if the test  
> program gets rebuilt.  I do not understand how to make this copy  
> depend on the dll being rebuilt.  I want all test programs to "pull"  
> the rebuilt dll as needed.  I do not want the CMakeLists.txt for the  
> dll to have any knowledge of the test programs.
>
> In CMakeLists.txt for the test program:
>
>
> add_executable            (
>                          test_my_module
>                          test_main.cpp
>                          )
>
> add_dependencies          (
>                          test_my_module
>                          my_module # not needed?
>                          )
>
> # Loadable modules are never listed at link time.
> target_link_libraries     (
>                          test_my_module
>                          dl
>                          )
>
> # Put the location of the .so library we need in the SO_LOCATION  
> variable.
> # We then use this location in the copy command below.
> get_target_property       (
>                          SO_LOCATION
>                          my_module        # .so library target
>                          LOCATION
>                          )
>
> # Create a custom build step to copy the dynamically loaded .so file
> # into the this directory so our test executable can find it.
> add_custom_command        (
>                          TARGET test_my_module
>                          POST_BUILD
>                          DEPENDS my_module  # no effect?
>                          COMMAND ${CMAKE_COMMAND} -E copy $
> {SO_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}
>                          COMMENT "CUSTOM COMMAND: Copy my_module to  
> build directory"
>                          )
>
>
> What should I do make the copy happen if the dll is rebuilt?
>
> Thanks for any advice,
> -steve
> _______________________________________________
> 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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

King, Steven R
In reply to this post by Tyler Roscoe
> You don't need to do this. Since "my_module" is a CMake target, you can
> just use "my_module" instead of ${SO_LOCATION} in the custom_command
> below and CMake will figure out where the .so is on the disk>

Hi Tyler  -- Substituting my_module did not work.  The copy fails.  Is this a cmake bug?

Thanks for the other pointers.
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

King, Steven R
In reply to this post by Michael Wild
> You don't have to do the copying yourself. Just tell CMake in which
> directory it should create the module by either setting the
> LIBRARY_OUTPUT_DIRECTORY target property or the
> CMAKE_LIBRARY_OUTPUT_DIRECTORY variable.
>
> AFAIK the LOCATION property is only present for compatibility with
> CMake 2.4, and shouldn't be used in new code.

Hi Mike -- I don't know from which directory my module test will run when using ctest.  So, my test program does not have an easy way to know the relative path to LIBRARY_OUTPUT_DIRECTORY when making the dlopen() call.  Allowing my test program to assume the dll is in its local directory seemed to be the easiest solution.
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

King, Steven R
In reply to this post by Tyler Roscoe
> Wrap your custom_command with a custom_target. See the CMake FAQ for
> some recipes.


OK, my CMakeLists.txt is growing rapidly.  :^(
All I've managed to do is cause the module to be copied every time.
Again, my goal is to copy the dll to the directory of the corresponding test program
if the dll has been rebuilt.

Any pointers are very much appreciated.  There must be some newb problems here.
My new approach with the add_custom_target:


add_dependencies          (
                          test_my_module
                          my_module
                          test_my_module_copy
                          )

target_link_libraries     (
                          test_my_module
                          dl
                          )

get_target_property       (
                          SO_LOCATION
                          my_module        # .so library target
                          LOCATION
                          )

get_target_property       (
                          SO_NAME
                          my_module        # .so library target
                          OUTPUT_NAME
                          )
                         
# Create a custom build step to copy the dynamically loaded .so file
# into the this directory so our test executable can find it.
add_custom_command        (
                          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SO_NAME}
                          COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}
                          DEPENDS my_module
                          COMMENT "CUSTOM COMMAND: Copy ${SO_NAME} to build directory"
                          )

add_custom_target         (
                          test_my_module_copy
                          DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SO_NAME}
                          DEPENDS my_module
                          )

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Clinton Stimpson
In reply to this post by King, Steven R
>> You don't have to do the copying yourself. Just tell CMake in which
>> directory it should create the module by either setting the
>> LIBRARY_OUTPUT_DIRECTORY target property or the
>> CMAKE_LIBRARY_OUTPUT_DIRECTORY variable.
>>
>> AFAIK the LOCATION property is only present for compatibility with
>> CMake 2.4, and shouldn't be used in new code.

> Hi Mike -- I don't know from which directory my module test will run when
> using ctest.  So, my test program does not have an easy way to know the
> relative path to LIBRARY_OUTPUT_DIRECTORY when making the dlopen() call.
> Allowing my test program to assume the dll is in its local directory
> seemed to be the easiest solution.

Can't you put all executables and shared libraries in one directory, so they are all local to each other?
In the top level CMakeLists.txt file just add
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

The executables you specify in ADD_TEST() will have a working directory that is ${CMAKE_CURRENT_BINARY_DIR}

Clint
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Tyler Roscoe
In reply to this post by King, Steven R
On Fri, Aug 28, 2009 at 05:19:19PM -0700, King, Steven R wrote:
> OK, my CMakeLists.txt is growing rapidly.  :^(

Welcome to the clube :).

> All I've managed to do is cause the module to be copied every time.

Use -E copy_if_different.

Also, give some serious thought to the other replies in this thread.
Custom copy rules can quickly grow to become a pain, whereas the One
Results Directory To Rule Them All strategy is simple and quick.

tyler
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

King, Steven R
In reply to this post by Clinton Stimpson
> Can't you put all executables and shared libraries in one directory, so they
> are all local to each other?
> In the top level CMakeLists.txt file just add
> SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
> SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
>
> The executables you specify in ADD_TEST() will have a working directory that
> is ${CMAKE_CURRENT_BINARY_DIR}

Thanks Clint and Tyler and others for your patient help.  The consolidated binary directory didn't work.

I now put all my binaries and libraries in ${CMAKE_BINARY_DIR}/bin as Clint suggested.  This caused ctest to fail for lack of knowing where the test binary went.  I made this adjustment:

add_test    (
            test_my_module
            ${CMAKE_BINARY_DIR}/bin/test_my_module
            )

which allowed ctest to find the executable.  However, the executable still can't find the dll, since ctest runs the test from ${CMAKE_CURRENT_BINARY_DIR} which is apparently not equal to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}.  As we've just belabored, putting the dll in ${CMAKE_CURRENT_BINARY_DIR} is neither easy nor well advised.

OK, now I'm actually getting worried.  Any other ideas, please?

Again my goal is to simply bring a dll and it's test program together so they run happily ever after.

Thanks,
-steve

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Michael Wild

On 31. Aug, 2009, at 7:08, King, Steven R wrote:

>> Can't you put all executables and shared libraries in one  
>> directory, so they
>> are all local to each other?
>> In the top level CMakeLists.txt file just add
>> SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
>> SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
>>
>> The executables you specify in ADD_TEST() will have a working  
>> directory that
>> is ${CMAKE_CURRENT_BINARY_DIR}
>
> Thanks Clint and Tyler and others for your patient help.  The  
> consolidated binary directory didn't work.
>
> I now put all my binaries and libraries in ${CMAKE_BINARY_DIR}/bin  
> as Clint suggested.  This caused ctest to fail for lack of knowing  
> where the test binary went.  I made this adjustment:
>
> add_test    (
>            test_my_module
>            ${CMAKE_BINARY_DIR}/bin/test_my_module
>            )

This will only work on Unix like systems. Doesn't CTest figure out  
that the program name is a target? I.e. doesn't this work (provided  
you did add_executable(test_my_module ...)):

add_test(test_my_module test_my_module)

>
> which allowed ctest to find the executable.  However, the executable  
> still can't find the dll, since ctest runs the test from $
> {CMAKE_CURRENT_BINARY_DIR} which is apparently not equal to $
> {CMAKE_RUNTIME_OUTPUT_DIRECTORY}.  As we've just belabored, putting  
> the dll in ${CMAKE_CURRENT_BINARY_DIR} is neither easy nor well  
> advised.

Well, how about passing the ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} as an  
argument to your test program, and then in the test program construct  
the full path to the plugin library? Or as an alternative, configure a  
source file defining the path to the CMAKE_RUNTIME_OUTPUT_DIRECTORY as  
a variable:

CMakeLists.txt:
------>8-------
# construct the file name of the loadable module (could also use the  
deprecated LOCATION property)
set(MODULE_PATH "CMAKE_RUNTIME_OUTPUT_DIRECTORY/$
{CMAKE_SHARED_MODULE_PREFIX}my_module${CMAKE_SHARED_MODULE_SUFFIX}")
file(TO_NATIVE "${MODULE_PATH}" MODULE_PATH)
# configure the test source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_my_module.c.in $
{CMAKE_CURRENT_BINARY_DIR}/test_my_module.c @ONLY)
# create the test executable
add_executable(test_my_module ${CMAKE_CURRENT_BINARY_DIR}/
test_my_module.c)
# add a test named test_my_module, running test_my_module
add_test(test_my_module test_my_module)
------<8-------

test_my_module.c.in:
------>8------
/* TODO make this work cross-platform */
#include <dlfcn.h>
#define MODULE_PATH "@MODULE_PATH@"

int main() {
   void* my_module = dlopen(MODULE_PATH, RTLD_NOW | RTLD_LOCAL);
   /* whatever you want to do */
   return 0;
}
------<8-------


>
> OK, now I'm actually getting worried.  Any other ideas, please?

I hope you get the idea from above...

>
> Again my goal is to simply bring a dll and it's test program  
> together so they run happily ever after.
>
> Thanks,
> -steve


HTH

Michael
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Philip Lowman
In reply to this post by King, Steven R
On Mon, Aug 31, 2009 at 1:08 AM, King, Steven R <[hidden email]> wrote:
I now put all my binaries and libraries in ${CMAKE_BINARY_DIR}/bin as Clint suggested.  This caused ctest to fail for lack of knowing where the test binary went.  I made this adjustment:

add_test    (
           test_my_module
           ${CMAKE_BINARY_DIR}/bin/test_my_module
           )

which allowed ctest to find the executable.  However, the executable still can't find the dll, since ctest runs the test from ${CMAKE_CURRENT_BINARY_DIR} which is apparently not equal to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}.  As we've just belabored, putting the dll in ${CMAKE_CURRENT_BINARY_DIR} is neither easy nor well advised.

OK, now I'm actually getting worried.  Any other ideas, please?

What we do at work is generate the test binaries in CMAKE_RUNTIME_OUTPUT_DIRECTORY as well.  This does tend to clutter up that directory but they don't get make installed so it's not a huge issue for us.

You might be able to use the ENVIRONMENT test property to append to the PATH environment variable CMAKE_RUNTIME_OUTPUT_DIRECTORY.  This would allow the test binaries (in theory) to find their dependent DLLs while not existing in CMAKE_RUNTIME_OUTPUT_DIRECTORY.

--
Philip Lowman

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Philip Lowman
On Mon, Aug 31, 2009 at 8:20 AM, Philip Lowman <[hidden email]> wrote:
On Mon, Aug 31, 2009 at 1:08 AM, King, Steven R <[hidden email]> wrote:
I now put all my binaries and libraries in ${CMAKE_BINARY_DIR}/bin as Clint suggested.  This caused ctest to fail for lack of knowing where the test binary went.  I made this adjustment:

add_test    (
           test_my_module
           ${CMAKE_BINARY_DIR}/bin/test_my_module
           )

which allowed ctest to find the executable.  However, the executable still can't find the dll, since ctest runs the test from ${CMAKE_CURRENT_BINARY_DIR} which is apparently not equal to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}.  As we've just belabored, putting the dll in ${CMAKE_CURRENT_BINARY_DIR} is neither easy nor well advised.

OK, now I'm actually getting worried.  Any other ideas, please?

What we do at work is generate the test binaries in CMAKE_RUNTIME_OUTPUT_DIRECTORY as well.  This does tend to clutter up that directory but they don't get make installed so it's not a huge issue for us.

You might be able to use the ENVIRONMENT test property to append to the PATH environment variable CMAKE_RUNTIME_OUTPUT_DIRECTORY.  This would allow the test binaries (in theory) to find their dependent DLLs while not existing in CMAKE_RUNTIME_OUTPUT_DIRECTORY.

Sorry forgot to mention, I believe this property is available only in CMake CVS.

--
Philip Lowman

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Clinton Stimpson
In reply to this post by King, Steven R
On 08/30/2009 11:08 PM, King, Steven R wrote:

>> Can't you put all executables and shared libraries in one directory, so they
>> are all local to each other?
>> In the top level CMakeLists.txt file just add
>> SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
>> SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
>>
>> The executables you specify in ADD_TEST() will have a working directory that
>> is ${CMAKE_CURRENT_BINARY_DIR}
>>      
> Thanks Clint and Tyler and others for your patient help.  The consolidated binary directory didn't work.
>
> I now put all my binaries and libraries in ${CMAKE_BINARY_DIR}/bin as Clint suggested.  This caused ctest to fail for lack of knowing where the test binary went.  I made this adjustment:
>
> add_test    (
>              test_my_module
>              ${CMAKE_BINARY_DIR}/bin/test_my_module
>              )
>
> which allowed ctest to find the executable.  However, the executable still can't find the dll, since ctest runs the test from ${CMAKE_CURRENT_BINARY_DIR} which is apparently not equal to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}.  As we've just belabored, putting the dll in ${CMAKE_CURRENT_BINARY_DIR} is neither easy nor well advised.
>
> OK, now I'm actually getting worried.  Any other ideas, please?
>    

How about this:

add_test (test_my_module test_my_module ${CMAKE_BINARY_DIR}/bin)

Then in your main(int, char*[]), you can use argv[1] as the path to load
the shared/dynamic library from.

Clint

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

King, Steven R
In reply to this post by Michael Wild
> > add_test    (
> >            test_my_module
> >            ${CMAKE_BINARY_DIR}/bin/test_my_module
> >            )
>
> This will only work on Unix like systems. Doesn't CTest figure out
> that the program name is a target? I.e. doesn't this work (provided
> you did add_executable(test_my_module ...)):
>
> add_test(test_my_module test_my_module)
 
Hi Michael,

I have the add_executable just as you show, but CTest gives up immediately since it can't find the test_my_module executable in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}.

Here are the bugs I think I've encountered with your collective help:

Bug 1: Cmake ignores ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} in the add_test() command.  Consequently ctest reports a failure due to not finding the test binary.

Bug 2: Locating a build output using the LOCATION property of a target is deprecated, but commands cannot substitute the target name for build output location.  In other words, commands like this fail:
        add_executable( foo foo.cpp )
        add_custom_command( OUTPUT new_foo COMMAND $(CMAKE_COMMAND) -E copy foo new_foo )

Cmake should recognize 'foo' as a target and implicitly substitute foo's build output.


But back to the dll test problem: Changing ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} forces me to hack all the ctests in my whole build tree, which I'm unwilling to do.  I will stick with Clint's copy_if_different idea to move the dll to the binary directory of the test program.
 
Thanks Clint, Michael, Philip Tyler and the list.  Community support here has been great even if the answers weren't what I hoped to hear.

Cheers,
-steve
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

King, Steven R
In case it's useful, here's a macro to copy an arbitrary file form the source directory to the binary directory.  The dependencies work such that the file is not copied if the destination is up-to-date.

This is working fine for me, but suggested improvements are very welcome.

Thanks,
-steve

#-------------------------------------------------------------------------------------------------
# Macro to copy an arbitrary file from the source directory to the binary directory.
macro( copy_file_from_src_to_bin file_arg )

# Always put the name of a custom command's output into a variable otherwise
# dependency checking doesn't seem to work.
set( SRC_OF_${file_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${file_arg} )
set( DEST_OF_${file_arg} ${CMAKE_CURRENT_BINARY_DIR}/${file_arg} )

# Copy the configuration file to the build directory for use by the test
add_custom_command        (
                          OUTPUT ${DEST_OF_${file_arg}}
                          COMMAND ${CMAKE_COMMAND} -E copy ${SRC_OF_${file_arg}} ${DEST_OF_${file_arg}}
                          DEPENDS ${SRC_OF_${file_arg}}
                          COMMENT "CUSTOM COMMAND: Copy ${file_arg} to build directory."
                          )

add_custom_target         (
                          copy_file_from_src_to_bin_${file_arg} ALL
                          DEPENDS ${DEST_OF_${file_arg}}
                          )

endmacro( copy_file_from_src_to_bin )
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Michael Wild

On 1. Sep, 2009, at 6:47, King, Steven R wrote:

> In case it's useful, here's a macro to copy an arbitrary file form  
> the source directory to the binary directory.  The dependencies work  
> such that the file is not copied if the destination is up-to-date.
>
> This is working fine for me, but suggested improvements are very  
> welcome.
>
> Thanks,
> -steve
>
> #-------------------------------------------------------------------------------------------------
> # Macro to copy an arbitrary file from the source directory to the  
> binary directory.
> macro( copy_file_from_src_to_bin file_arg )
>
> # Always put the name of a custom command's output into a variable  
> otherwise
> # dependency checking doesn't seem to work.
> set( SRC_OF_${file_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${file_arg} )
> set( DEST_OF_${file_arg} ${CMAKE_CURRENT_BINARY_DIR}/${file_arg} )
>
> # Copy the configuration file to the build directory for use by the  
> test
> add_custom_command        (
>                          OUTPUT ${DEST_OF_${file_arg}}
>                          COMMAND ${CMAKE_COMMAND} -E copy ${SRC_OF_$
> {file_arg}} ${DEST_OF_${file_arg}}
>                          DEPENDS ${SRC_OF_${file_arg}}
>                          COMMENT "CUSTOM COMMAND: Copy ${file_arg}  
> to build directory."
>                          )
>
> add_custom_target         (
>                          copy_file_from_src_to_bin_${file_arg} ALL
>                          DEPENDS ${DEST_OF_${file_arg}}
>                          )
>
> endmacro( copy_file_from_src_to_bin )


You are aware that configure_file with the COPYONLY argument does just  
that at CMake-time?

Michael
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Alexander Neundorf-3
In reply to this post by King, Steven R
On Friday 28 August 2009, King, Steven R wrote:
> > You don't need to do this. Since "my_module" is a CMake target, you can
> > just use "my_module" instead of ${SO_LOCATION} in the custom_command
> > below and CMake will figure out where the .so is on the disk>
>
> Hi Tyler  -- Substituting my_module did not work.  The copy fails.  Is this
> a cmake bug?

AFAIK this works only for the executable which is called by COMMAND:

add_custom_command ( ... COMMAND <executable> ... )

So, it's not a bug, this feature does not exist.

Alex
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: dependency in custom command?

Alexander Neundorf-3
In reply to this post by King, Steven R
On Friday 28 August 2009, King, Steven R wrote:
> Hello List,
> I'm new to cmake and liking it a lot.  I'm using cmake 2.6.3 on Linux.
>
> I'm building a dynamically loadable module and an executable to test it.
> Each lives in a different directory.  My test program needs to know the
> location of the dll when calling dlopen().   To solve this, I created a
> custom command to copy the dll to the binary directory of the test program.
>   This works, but I have an annoying dependency problem.  Specifically, if
> the dll gets rebuilt, the copy command does not execute.  The copy command
...

> # Create a custom build step to copy the dynamically loaded .so file
> # into the this directory so our test executable can find it.
> add_custom_command        (
>                           TARGET test_my_module
>                           POST_BUILD
>                           DEPENDS my_module  # no effect?
>                           COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION}
> ${CMAKE_CURRENT_BINARY_DIR} COMMENT "CUSTOM COMMAND: Copy my_module to
> build directory" )
>
>
> What should I do make the copy happen if the dll is rebuilt?

I must be missing something, but can't you assign the custom command to the
module instead to the executable ?

add_custom_command(TARGET my_module
                   POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION}
                           ${CMAKE_CURRENT_BINARY_DIR}
                   )

Alex
_______________________________________________
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