[CMake] dependency in custom command?
King, Steven R
steven.r.king at intel.com
Fri Aug 28 14:28:53 EDT 2009
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
More information about the CMake
mailing list