views:

273

answers:

1

Hello all, I'm facing a problem where in I build a shared library and and a unit-test executable (which is in a sub directory) I want to execute this test as a POST_BUILD operation for the shared library. So I gave

Add_Custom_Command (TARGET ShLibName POST_BUILD COMMAND unit_test_exe)

CMake throws an error message during generation process

CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle): "libCUEUtilities" of type SHARED_LIBRARY depends on "UtilitiesUnitTest" "UtilitiesUnitTest" of type EXECUTABLE depends on "libCUEUtilities"

At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries.

So, How can i achieve what i'm trying to do.

I'm using CMake 2.8.1 (RC3) with VS2005 generator.

Thanks in advance, Surya

A: 

Sounds like you want to run a unit test every time the shared library is compiled. Since the test executable already depends on the shared library, you can change the add_custom_command to run once the unit test executable has been built. For example:

add_library(CUEUtilities SHARED ${CUEUTILS_LIBRARY_SOURCES})
add_executable(unit_test_exe ${UNIT_TEST_EXE_SOURCES})
target_link_libraries(unit_test_exe CUEUtilities)
add_custom_command(TARGET unit_test_exe POST_BUILD 
                   COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unit_test_exe)

Changing any of the library sources will cause the library to be recompiled. Since the executable has a dependency on the library, the exe will get relinked, and finally the post-build step will be run again.

rq