Reputation: 1197
I'm facing a problem where I build a shared library 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.
Upvotes: 1
Views: 1507
Reputation: 56468
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.
Upvotes: 3